Files
autoheal/autoheal.lua

110 lines
3.0 KiB
Lua

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