script_name('Count resources')
script_description('Count resources for mine(/rc). Если во время сбора ресурсов в подземной шахте, скупаете ресурсы в лавке, поставьте галочку"Лавка"')
script_author('bepis')
require("lib.moonloader")
local se = require "lib.samp.events"
local imgui = require('imgui')
local encoding = require("encoding")
encoding.default = 'CP1251'
u8 = encoding.UTF8
local undermineEnabled = false
local underminelavkaEnabled = false
local regularmineEnabled = false
local showResourcesWindow = false
local sw, sh = getScreenResolution()
local stone, metal, bronze, silver, gold, diamond, tkan, splav, materia, azbox = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
local resourcePrices = {
stone = 26000,
metal = 110000,
bronze = 80000,
silver = 18000,
gold = 50000,
diamond = 500000,
tkan = 18000000,
splav = 5000000,
materia = 4000000,
azbox = 1000000
}
local configPath = "C:\\Games\\Arizona\\moonloader\\config\\resources_config.txt"
local function loadConfig()
local file = io.open(configPath, 'r')
if file then
for line in file:lines() do
local resource, count = line:match("(%w+)%s+(%d+)")
if resource then
if resource == "stone" then stone = tonumber(count)
elseif resource == "metal" then metal = tonumber(count)
elseif resource == "bronze" then bronze = tonumber(count)
elseif resource == "silver" then silver = tonumber(count)
elseif resource == "gold" then gold = tonumber(count)
elseif resource == "diamond" then diamond = tonumber(count)
elseif resource == "tkan" then tkan = tonumber(count)
elseif resource == "splav" then splav = tonumber(count)
elseif resource == "materia" then materia = tonumber(count)
elseif resource == "azbox" then azbox = tonumber(count)
end
end
end
file:close()
end
end
local function saveConfig()
local file = io.open(configPath, 'w')
if file then
file:write(string.format("stone %d\n", stone))
file:write(string.format("metal %d\n", metal))
file:write(string.format("bronze %d\n", bronze))
file:write(string.format("silver %d\n", silver))
file:write(string.format("gold %d\n", gold))
file:write(string.format("diamond %d\n", diamond))
file:write(string.format("tkan %d\n", tkan))
file:write(string.format("splav %d\n", splav))
file:write(string.format("materia %d\n", materia))
file:write(string.format("azbox %d\n", azbox))
file:close()
end
end
local function calculateTotalValue()
local total = stone * resourcePrices.stone + metal * resourcePrices.metal + bronze * resourcePrices.bronze +
silver * resourcePrices.silver + gold * resourcePrices.gold + diamond * resourcePrices.diamond +
tkan * resourcePrices.tkan + splav * resourcePrices.splav + materia * resourcePrices.materia +
azbox * resourcePrices.azbox
return total
end
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then
sampAddChatMessage("{FFFFFF}[rc by bepis]: {FF0000}SAMP or SAMPFUNCS not loaded.", -1)
return
end
while not isSampAvailable() do wait(100) end
imgui.Process = false
sampRegisterChatCommand("rc", function()
showResourcesWindow = not showResourcesWindow
imgui.Process = showResourcesWindow
end)
loadConfig()
sampAddChatMessage("{FFD700}[rc by bepis] {FFFFFF}Скрипт загружен! Используйте /rc", -1)
while true do
wait(0)
end
end
local undermine = imgui.ImBool(false)
local underminelavka = imgui.ImBool(false)
local regularmine = imgui.ImBool(false)
function imgui.OnDrawFrame()
if not showResourcesWindow then return end
imgui.SetNextWindowSize(imgui.ImVec2(280, 330), imgui.Cond.FirstUseEver)
imgui.SetNextWindowPos(imgui.ImVec2(sw-1730, sh-330), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 1))
imgui.ShowCursor = false
imgui.Begin("", nil, imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoResize)
imgui.SameLine(imgui.GetWindowWidth() - 220); imgui.Text(u8"Счетчик ресурсов by bepis")
imgui.Separator()
imgui.Text(u8("Собрано камня: ") .. stone)
imgui.Text(u8("Собрано металла: ") .. metal)
imgui.Text(u8("Собрано бронзы: ") .. bronze)
imgui.Text(u8("Собрано серебра: ") .. silver)
imgui.Text(u8("Собрано золота: ") .. gold)
imgui.Text(u8("Собрано алмазов: ") .. diamond)
imgui.Text(u8("Собрано тканей: ") .. tkan)
imgui.Text(u8("Собрано сплавов: ") .. splav)
imgui.Text(u8("Собрано материи: ") .. materia)
imgui.Text(u8("Собрано сундуков с аз: ") .. azbox)
imgui.Separator()
imgui.Text(u8("Общий заработок: ") .. calculateTotalValue())
imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(0.2, 0.6, 0.8, 1))
if imgui.Button(u8("Очистить")) then
stone, metal, bronze, silver, gold, diamond, tkan, splav, materia, azbox = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
saveConfig()
end
imgui.PopStyleColor()
imgui.PushStyleColor(imgui.Col.CheckMark, imgui.ImVec4(0.2, 0.6, 0.8, 1))
if imgui.Checkbox(u8("Подземная шахта"), undermine) then
if undermine.v then
undermineEnabled = true
regularmine.v = false
regularmineEnabled = false
else
undermineEnabled = false
underminelavka.v = false
underminelavkaEnabled = false
end
end
if imgui.Checkbox(u8("Лавка"), underminelavka) then
if underminelavka.v then
underminelavkaEnabled = true
regularmine.v = false
regularmineEnabled = false
undermine.v = true
undermineEnabled = true
else
underminelavkaEnabled = false
if underminelavkaHandler then
se.onServerMessage = nil
end
end
end
if imgui.Checkbox(u8("Обычная шахта"), regularmine) then
if regularmine.v then
regularmineEnabled = true
undermine.v = false
undermineEnabled = false
underminelavka.v = false
underminelavkaEnabled = false
else
regularmineEnabled = false
end
end
imgui.PopStyleColor()
imgui.End()
end
function handleItemReceived(text)
if undermineEnabled and text:find("Вам был добавлен предмет '") then
local itemName = text:match("Вам был добавлен предмет '([^']+)'")
if itemName then
-- Увеличиваем количество ресурса в зависимости от полученного предмета
if itemName == "Камень" then
stone = stone + 3
elseif itemName == "Металл" then
metal = metal + 3
elseif itemName == "Бронза" then
bronze = bronze + 3
elseif itemName == "Серебро" then
silver = silver + 2
elseif itemName == "Золото" then
gold = gold + 2
elseif itemName == "Алмазный камень" then
diamond = diamond + 1
elseif itemName == "Прочная ткань" then
tkan = tkan + 1
elseif itemName == "Шахтерский сплав" then
splav = splav + 1
elseif itemName == "Темная материя" then
materia = materia + 1
elseif itemName == "Ларец с AZ-Монетами" then
azbox = azbox + 1
end
saveConfig() -- Сохраняем конфигурацию после обновления значений
end
end
end
function handleItemBought(text)
if underminelavkaEnabled and text:find("Вы купили (.+) %((%d+) шт%.%) у игрока .+ за %$%d+") then
local itemName = text:match("Вы купили (.+) %((%d+) шт%.%).*")
if itemName then
-- Уменьшаем количество ресурса в зависимости от купленного предмета
if itemName == "Камень" then
stone = stone - 3
elseif itemName == "Металл" then
metal = metal - 3
elseif itemName == "Бронза" then
bronze = bronze - 3
elseif itemName == "Серебро" then
silver = silver - 3
elseif itemName == "Золото" then
gold = gold - 3
elseif itemName == "Алмазный камень" then
diamond = diamond - 1
elseif itemName == "Прочная ткань" then
tkan = tkan - 1
elseif itemName == "Шахтерский сплав" then
splav = splav - 1
elseif itemName == "Темная материя" then
materia = materia - 1
elseif itemName == "Ларец с AZ-Монетами" then
azbox = azbox - 1
end
saveConfig() -- Сохраняем конфигурацию после обновления значений
end
end
end
function se.onDisplayGameText(style, tm, text)
if regularmineEnabled then
if text == "metal + 1" then
metal = metal + 1
elseif text == "stone + 1" then
stone = stone + 1
elseif text == "gold + 1" then
gold = gold + 1
elseif text == "bronze + 1" then
bronze = bronze + 1
elseif text == "silver + 1" then
silver = silver + 1
elseif text == "metal + 2" then
metal = metal + 2
elseif text == "stone + 2" then
stone = stone + 2
elseif text == "gold + 2" then
gold = gold + 2
elseif text == "bronze + 2" then
bronze = bronze + 2
elseif text == "silver + 2" then
silver = silver + 2
end
saveConfig() -- Сохраняем конфигурацию после обновления значений
end
end
function se.onServerMessage(color, text)
handleItemReceived(text)
handleItemBought(text)
end