diff --git a/autoheal.lua b/autoheal.lua new file mode 100644 index 0000000..7f123db --- /dev/null +++ b/autoheal.lua @@ -0,0 +1,110 @@ +script_name("autoheal") +script_author("treywisp") + +local sampev = require("samp.events") + +local state = { + active = false, + satiety = 0 +} + +local function notify(text) + sampAddChatMessage("[autoheal] {FFFFFF}" .. text, 0xDC143C) +end + +local function getAction() + local hp = getCharHealth(PLAYER_PED) or 0 + local satiety = tonumber(state.satiety) or 0 + + if satiety <= 20 then + return "eat" + elseif hp < 100 then + return "heal" + else + return "none" + end +end + +local function autoHeal() + local hp = getCharHealth(PLAYER_PED) or 0 + + if hp >= 100 then + notify("Здоровье уже полное, лечение не требуется") + return + end + + if state.active then + state.active = false + notify("Автохил остановлен вводом команды") + return + end + + state.active = true + sampSendChat("/stats") + notify("Автохил запущен. Начинаем проверку здоровья и сытости") + + lua_thread.create(function() + while state.active do + wait(500) + local action = getAction() + + if action == "eat" then + sampSendChat("/grib eat") + wait(1500) + elseif action == "heal" then + sampSendChat("/grib heal") + wait(1500) + else + state.active = false + notify("Автохил завершил работу, здоровье и сытость в норме") + end + end + end) +end + +function main() + if not isSampfuncsLoaded() or not isSampLoaded() then return end + while not isSampAvailable() do wait(100) end + + notify("Скрипт загружен. Команда активации и деактивации: /autoheal") + sampRegisterChatCommand("autoheal", autoHeal) +end + +function sampev.onShowDialog(id, style, title, button1, button2, text) + if not state.active then return end + if id == 22 and title == "Статистика персонажа" then + local satiety = text:match("Сытость[%s:%-]+(%d+)") + if satiety then + state.satiety = tonumber(satiety) + end + return false + end +end + +function sampev.onServerMessage(color, text) + if not state.active then return end + + local satiety = text:match("^%s*Вы съели%s+%{[%x]+%}'.-'%{[%x]+%}%.%s+Сытость пополнена до (%d+)%.") + or text:match("^ Здоровье%s+%d+/%d+%.%s+Сытость%s+(%d+)/%d+%.") + + if satiety then + state.satiety = tonumber(satiety) + return false + end + + if text:find("^ У вас нет этой еды") then + notify("Ошибка. Нет грибов в инвентаре") + state.active = false + return false + + elseif text:find("^ Недостаточно психохила") then + notify("Ошибка. Недостаточно психохила для лечения") + state.active = false + return false + + elseif text:find("^ Можно съесть до 5 штук раз в минуту") then + notify("Ошибка. Использовано более 5 психохила за минуту") + state.active = false + return false + end +end \ No newline at end of file