-- slapFix.lua - Исправленная версия с API для костыля
local sampev = require("samp.events")
require("addon")
-- Глобальные переменные (в _G)
_G.mode = 2
_G.state = 0
_G.x2, _G.y2, _G.z2 = 0, 0, 0
_G.x, _G.y, _G.z = 0, 0, 0
local speedv = -0.07
local b = 0
local need_speed = false
local need_speed_f = false
-- Эта функция будет вызываться извне (из slap_bridge.lua)
rawset(_G, "triggerSlap", function()
if _G.mode == 2 then
print("Slapped (via API)")
_G.x2, _G.y2, _G.z2 = getBotPosition()
_G.state = 1
elseif _G.mode == 1 then
print("Ignore slap (mode 1)")
end
end)
function FailBot()
if _G.state == 1 then
if _G.z2 ~= _G.z then
if _G.z2 >= _G.z then _G.z = _G.z2 end
_G.z = _G.z + speedv
need_speed_f = true
setBotPosition(_G.x, _G.y, _G.z)
updateSync()
need_speed_f = false
if _G.z2 >= _G.z then
b = _G.x2 + 1
speedv = -0.1
setBotPosition(_G.x2, _G.y2, _G.z2)
updateSync()
_G.state = 2
end
end
end
if _G.state == 2 then
if _G.x2 <= b then
_G.x2 = _G.x2 + 0.2
need_speed = true
setBotPosition(_G.x2, _G.y2, _G.z2)
updateSync()
need_speed = false
else
_G.state = 0
end
end
end
function sampev.onSendPlayerSync(data)
if need_speed == true then data.moveSpeed.z = 0.05 end
if need_speed_f == true then
local spz = speedv / 5
data.moveSpeed.z = spz
speedv = speedv - 0.8
if speedv < -0.8 then
speedv = -0.8
end
end
end
function onRunCommand(cmd)
local args = {}
for arg in cmd:gmatch("%S+") do
table.insert(args, arg)
end
if args[1] == '!slapmode' then
local arg = args[2]
if arg == nil then
print('Select mode: 1 - if you stay afk | 2 - for emulate slap')
return false
end
if arg == "1" or arg == "2" then
_G.mode = tonumber(arg)
print("Current mode - "..arg)
else
print('Select mode: 1 - if you stay afk | 2 - for emulate slap')
end
return false
end
end
function onLoad()
newTask(function()
while true do
FailBot()
wait(90)
end
end)
end
function sampev.onSetPlayerPos(pos)
_G.x = pos.x
_G.y = pos.y
_G.z = pos.z
local px, py, pz = getBotPosition()
if px == _G.x and py == _G.y and pz ~= _G.z and _G.state == 0 then
if _G.mode == 2 then
print("Slapped")
_G.x2, _G.y2, _G.z2 = getBotPosition()
_G.state = 1
elseif _G.mode == 1 then
print("Ignore slap")
return false
end
end
end
-- Для отладки
print("DEBUG: mode =", _G.mode)
print("DEBUG: state =", _G.state)
print("DEBUG: triggerSlap =", type(rawget(_G, "triggerSlap")))
-- Принудительно записываем функцию в _G (если она не была)
if not rawget(_G, "triggerSlap") then
rawset(_G, "triggerSlap", function()
print("triggerSlap called from _G")
if _G.mode == 2 then
_G.x2, _G.y2, _G.z2 = getBotPosition()
_G.state = 1
end
end)
end