function main()
repeat wait(0) until isSampAvailable()
wait(2000)
sampRegisterChatCommand('autozp', saveToIni)
sampRegisterChatCommand('savepick', saveCoordinates)
msg('Загружен')
loadFromIni()
while true do
wait(0)
if state then
wait(2000)
local iniFile = io.open(iniPath, "r")
for line in iniFile:lines() do
local key, value = line:match("(%a+)=(-?%d+%.?%d*)")
if key and value then
if key == "pick" then
aaaaaaa = tonumber(value)
end
end
end
iniFile:close()
sampSendPickedUpPickup(aaaaaaa)
msg('Переоделся')
state = false
end
end
end
function saveToIni()
value = not value
local file = io.open(iniPath2, "w")
file:write(string.format("value=%s", tostring(value)))
file:close()
if value then
msg('Включено')
else
msg('Выключено')
end
end
function loadFromIni()
local file = io.open(iniPath2, "r")
for line in file:lines() do
local key, val = line:match("(%a+)=(.-)$")
if key == 'value' then
value = val
end
end
value = stringtoboolean[value]
file:close()
end
function saveCoordinates() -- Сохранить корды пикапа
local plx, ply, plz = getCharCoordinates(PLAYER_PED)
local precent = 0
local xxx, yyy, zzz = 0, 0, 0
os.remove(iniPath)
for id = 0, 6095 do
local pickup = sampGetPickupHandleBySampId(id)
local x, y, z = getPickupCoordinates(pickup)
if x ~= 0 and z ~= 17.5 then
local d = math.sqrt((x - plx)^2 + (y - ply)^2 + (z - plz)^2)
local percent_similarity = 100 - (d / 30000) * 100
if percent_similarity > precent then
precent = percent_similarity
xxx, yyy, zzz = x, y, z
aaaaaaa = id
end
end
end
local iniFile = io.open(iniPath, "a+")
iniFile:write(string.format("pick=%f\n", aaaaaaa))
iniFile:close()
msg('Сохранил')
end
function msg(message) -- Вывод текста в чат
local tag = '{0000FF}[NEW afkZP]: {FFCC00}'
sampAddChatMessage(tag .. message, -1)
end
function sampev.onServerMessage(color, text) -- Проверить подключение к серверу
if value then
if (text:find("На сервере есть инвентарь")) then
state = true
end
end
end
function sampev.onShowDialog(id, style, title, button1, button2, tekst) -- На диалог переодевания
if value then
if tekst:find('Переодется в {31853A}рабочую{FFFFFF} форму.') then
lua_thread.create(function()
wait(60)
local listbox = sampGetListboxItemByText('Переодется в {31853A}рабочую{FFFFFF} форму.')
sampSendDialogResponse(id, 1, listbox, nil)
sampCloseCurrentDialogWithButton(0)
end)
elseif tekst:find('Переодеться') then
lua_thread.create(function()
wait(60)
local listbox = sampGetListboxItemByText('Переодеться')
sampSendDialogResponse(id, 1, listbox, nil)
sampCloseCurrentDialogWithButton(0)
end)
end
end
end
function sampGetListboxItemByText(text, plain)
if not sampIsDialogActive() then return -1 end
plain = not (plain == false)
for i = 0, sampGetListboxItemsCount() - 1 do
if sampGetListboxItemText(i):find(text, 1, plain) then
return i
end
end
return -1
end