- 1
- 0
как вы наверно уже наверно знаете train бот от mdx scripts был слит с открытым кодом. но сейчас его крашит при завершении рейса, когда ты появляешься в здании депо. кто знает из-за чего и как это можно (или невозможно) пофиксить?
Lua:
script_name("MDX | TRAIN BOT")
script_author("madrasso")
script_version("1.4")
script_properties("work-in-pause")
local hook = require('lib.samp.events')
local encoding = require('lib.encoding')
local memory = require('memory')
local request = require('lib.requests')
memory.fill(0x00531155, 0x90, 5, true) -- fix jump
local font = renderCreateFont("Arial", 10, 12)
encoding.default = 'CP1251'
u8 = encoding.UTF8
cp1251 = encoding.CP1251
local inicfg = require('inicfg')
local config = inicfg.load({
settings = {
id = 0;
['auto-crash'] = false;
}
}, '[mdx scripts] TRAIN BOT');
local other = {color = '2e82ff'};
local points = {
[1] = {2822.626953125, 90.498596191406, 24.95460319519};
[2] = {2864.75, 1329.0899658203, 9.7203121185303};
[3] = {1392.3271484375, 2632.25, 9.7203121185303};
[4] = {-1944.375, 82.024803161621, 24.618618011475};
[5] = {838.77020263672, -1388.5576171875, -2.7222609519958}
}
local info = {
status = false;
state = false;
flights = 0;
earn = 0;
pickUp = nil;
point = 'не обнаружен';
speed = 34;
dist = 210;
wait = 5000;
boostSpeed = false;
}
function chat(msg, type)
if type == nil then type = true end
local color = (type and other.color or 'f50575')
local msg = msg:gsub('{color}', '{'..color..'}')
sampAddChatMessage(' mdx scripts {FFFFFF}| '..msg, (type and '0x'..other.color or 0xf50575))
end
local function xf()
while not isSampAvailable() do wait(0) end
chat('ПЭНИС СНИМАЙ МАСКУ А АВИТО ПРОДАДДИИМ!!!')
if tonumber(config['settings']['id']) >= 1 then
chat('По умолчанию установлен ид вконтакте: {color}'..config['settings']['id'])
end
if config['settings']['auto-crash'] then
chat('По умолчанию включена функция автокраша')
end
end
function main()
xf()
while not isSampfuncsLoaded() or not isSampLoaded() do wait(0) end
commands();
lua_thread.create(function()
while true do wait(0)
if info['status'] then
renderDrawBoxWithBorder(39, 215, 200, 90, 0xAA000000, 3, 0x90f50575)
renderFontDrawText(font, "Поинт: "..info['point'], 49, 230, 0xFFFFFFFF, 0x90000000)
renderFontDrawText(font, "Заработано: "..info['earn'], 49, 250, 0xFFFFFFFF, 0x90000000)
renderFontDrawText(font, "Количество рейсов: "..info['flights'], 49, 270, 0xFFFFFFFF, 0x90000000)
local text, _, _, _ = sampGetChatString(99)
if text:find('closed the connection') or text:find("You are banned from this server") or text:find('Use /quit to exit or press') or text:find("Lost connection to the server") then
sampAddChatMessage(" ", -1)
sendVK('Вы были кикнуты.')
end
end
end
end)
while true do wait(0)
if info['pickUp'] then
if info['pickUp'][1] and info['pickUp'][2] and info['pickUp'][3] then
if isCharInAnyCar(PLAYER_PED) then
local car = storeCarCharIsInNoSave(PLAYER_PED);
local speed = getCarSpeed(car)
printString(math.floor(speed), 50)
local x,y,z = getCharCoordinates(PLAYER_PED)
local dist = getDistanceBetweenCoords3d(x,y,z, info['pickUp'][1], info['pickUp'][2], info['pickUp'][3])
local tormoz = tonumber((info['boostSpeed'] and '120' or info['dist']));
local tormoz2 = tonumber((info['boostSpeed'] and '15' or '80'));
if tonumber(dist) < tormoz and tonumber(dist) > tormoz2 then
info['state'] = 'brake'
elseif tonumber(dist) < 10 then
info['state'] = 'full_brake'
end
end
if info['status'] and info['state'] == 'gas' and isCharInAnyCar(PLAYER_PED) then
local car = storeCarCharIsInNoSave(PLAYER_PED);
local speed = getCarSpeed(car)
if speed < tonumber(info['speed']) then
if info['boostSpeed'] and speed < 10 then
for i = speed, info['speed'], 2 do
wait(200)
setTrainSpeed(car, i);
end
end
press_gas();
end
elseif info['status'] and isCharInAnyCar(PLAYER_PED) then
local car = storeCarCharIsInNoSave(PLAYER_PED);
local speed = getCarSpeed(car)
if info['state'] == 'brake' then
if speed >= 8 then
if info['boostSpeed'] then
print('bost brake')
for i = speed, 7, -4 do
wait(150)
if isCharInAnyCar(PLAYER_PED) then
setTrainSpeed(car, i);
end
end
end
press_brake();
end
elseif info['state'] == 'full_brake' then
if speed > 1.2 then
if info['boostSpeed'] then
print('bost brake full')
wait(300)
if isCharInAnyCar(PLAYER_PED) then
setTrainSpeed(car, 1);
end
end
press_brake();
else
if isCharInAnyCar(PLAYER_PED) then
setTrainSpeed(car, 0.6);
end
wait(500);
if isCharInAnyCar(PLAYER_PED) then
setTrainSpeed(car, 0);
end
wait(info['wait']);
if isCharInAnyCar(PLAYER_PED) then
setTrainSpeed(car, 0);
info['state'] = 'gas'
end
wait(500)
end
end
elseif info['status'] and info['state'] == 'toPickUp' then
GoToCoord(-2095.4909667969, 514.75042724609, 1487.6927490234);
GoToCoord(-2098.5727539063, 512.82043457031, 1487.6927490234);
GoToCoord(-2102.4104003906, 512.78045654297, 1487.6927490234);
good_dialog = false;
while not good_dialog do
setGameKeyState(21, 255);
sampForceOnfootSync();
wait(5000);
end
good_dialog = false;
info['state'] = false;
end
end
end
end
end
function commands()
sampRegisterChatCommand('tgo', train_start)
sampRegisterChatCommand('tgo.id', train_id)
sampRegisterChatCommand('tgo.crash', train_crash)
sampRegisterChatCommand('tgo.speed', train_speed)
sampRegisterChatCommand('tgo.dist', train_dist)
sampRegisterChatCommand('tgo.wait', train_wait)
sampRegisterChatCommand('tgo.boost', function()
info['boostSpeed'] = not info['boostSpeed']
chat('Буст скорости {color}'..(info['boostSpeed'] and 'активирован' or 'деактивирован'),info['boostSpeed'])
end);
end
function hook.onServerMessage(color, msg)
if msg:find('Рейс успешно завершен') then
info['earn'] = info['earn'] + tonumber(msg:match('Заработано за рейс: (%d+)%$'))
info['flights'] = info['flights'] + 1
sendVK('Рейс успешно завершен.\n\nЗаработано виртов: '..info['earn']..'\n Количество рейсов проехано: '..info['flights'])
lua_thread.create(function() info['state'] = false wait(9000) info['state'] = 'toPickUp' end)
elseif msg:match('Администратор .*:.*{%w+}.*') then
local admin, answer = msg:match('Администратор (.*):.*{%w+}(.*)')
sendVK('Администратор '..tostring(admin)..': '..tostring(answer))
wait (4123)
if config['settings']['auto-crash'] then sampSendChat("/n я тут") end
end
end
function hook.onTextDrawSetString(id, text)
if id == 2074 then
info['pickUp'] = points[tonumber(text)]
info['point'] = tonumber(text)
print('Point: '..tonumber(text))
end
end
function hook.onShowDialog(id, style, title, btn1, btn2, text)
if info['status'] then
if text:find('Вы хотите занять очередь на регистрацию рейса') then
good_dialog = true
sampSendDialogResponse(id, 1, -1, -1)
return false
elseif text:find('Ваша очередь подошла, завершить регистрацию рейса') then
info['state'] = false
lua_thread.create(function()
sendVK('Новый рейс успешно начат.')
wait(15000)
info['state'] = 'gas';
end)
sampSendDialogResponse(id, 1, -1, -1)
return false
elseif text:find'Сейчас все рабочие места на рейсах заняты' then
sampSendDialogResponse(id, 1, -1, -1)
return false
elseif text:find('в живой очереди на регистрацию рейса') then
sampSendDialogResponse(id, 1, -1, -1)
return false
elseif text:find('Вы хотите освободить своё место в очереди') then
good_dialog = true
sampSendDialogResponse(id, 0, -1, -1)
return false
end
end
end
function train_start()
info['status'] = not info['status']
WorkInBackground(info['status']);
chat('Статус бота: {color}'..(info['status'] and 'включен' or 'выключен'), info['status'])
if isCharInAnyCar(PLAYER_PED) then
info['state'] = (info['status'] and 'gas' or false)
end
end
function train_id(var)
if tonumber(var) == nil or #var == 0 or tonumber(var) <= 0 then
chat('Неверно указан ид вконтакте.', false)
return
else
chat('Установлен новый ид вконтакте: {color}'..tonumber(var))
config['settings']['id'] = tonumber(var)
inicfg.save(config, '[mdx scripts] TRAIN BOT')
end
end
function train_crash()
config['settings']['auto-crash'] = not config['settings']['auto-crash']
chat('Автоматический краш {color}'..(config['settings']['auto-crash'] and 'включен' or 'выключен'), config['settings']['auto-crash'])
end
function train_speed(var)
if tonumber(var) == nil or #var == 0 or tonumber(var) <= 0 then
chat('Укажите число.', false)
return
else
chat('Установлена новая максимальная скорость: {color}'..tonumber(var))
info['speed'] = tonumber(var);
end
end
function train_dist(var)
if tonumber(var) == nil or #var == 0 or tonumber(var) <= 0 then
chat('Укажите число.', false)
return
else
chat('Установлена новая дистанция начатия торзможения: {color}'..tonumber(var))
info['dist'] = tonumber(var);
end
end
function train_wait(var)
if tonumber(var) ~= nil then
chat('Установлена новая задержка остановки на станциях: {color}'..tonumber(var))
info['wait'] = tonumber(var);
else
chat('Укажите число.', false)
return
end
end
function press_gas()
writeMemory(0xB73458 + 0x20, 1, 255, false)
end
function press_brake()
writeMemory(0xB73458 + 0x1C, 1, 255, false)
end
function GoToCoord(x,y,z)
local koef1, koef2 = 1.05, 0.02
local function getPov(ang)
return (ang^koef1)*koef2*100/memory.getfloat(0xB7CB50, true)
end
while not locateCharAnyMeans2d(PLAYER_PED, x, y, 1, 1, true) and info['status'] do
local POSX,POSY,POSZ = getCharCoordinates(PLAYER_PED)
local angle = math.acos((x-POSX)/math.sqrt((x - POSX)*(x - POSX)+(y - POSY)*(y - POSY)))
if POSY > y then angle = 2*math.pi - angle end --получение угла
if angle < 0 then angle = angle + 2*math.pi end
angle = math.deg(angle)
local angX = math.asin((z-POSZ)/math.sqrt((z-POSZ)^2+(y-POSY)^2))
local cpx,cpy,cpz = getActiveCameraCoordinates()
local cx,cy,cz = getActiveCameraPointAt()
local curangle = math.acos((cx-cpx)/math.sqrt((cx-cpx)*(cx-cpx)+(cy-cpy)*(cy-cpy)))
if cpy > cy then curangle = 2*math.pi - curangle end -- получение текущего угла камеры
curangle = math.deg(curangle)
local heading = getCharHeading(PLAYER_PED) + 90
if heading > 360 then heading = heading - 360 end
local angsum = 360 - curangle + angle
if angsum > 360 then angsum = angsum - 360 end
if angsum < 180 then curangle = curangle + getPov(angsum)
else curangle = curangle - getPov(360-angsum) end
local xAngle = math.asin((z-POSZ)/math.sqrt((z-POSZ)^2+(math.sqrt((x-POSX)^2+(y-POSY)^2))^2))
setCameraPositionUnfixed(xAngle,math.rad(curangle)+math.pi)
setGameKeyState(1, -255)
wait(0)
end
end
function WorkInBackground(work)
local memory = require 'memory'
if work then
memory.setuint8(7634870, 1)
memory.setuint8(7635034, 1)
memory.fill(7623723, 144, 8)
memory.fill(5499528, 144, 6)
else
memory.setuint8(7634870, 0)
memory.setuint8(7635034, 0)
memory.hex2bin('5051FF1500838500', 7623723, 8)
memory.hex2bin('0F847B010000', 5499528, 6)
end
end
function sendVK(text)
if tonumber(config['settings']['id']) == nil or type(config['settings']['id']) ~= 'number' then
chat('Неверно указан ид страницы, отправка сообщения отменена.', false)
return
end
local _, myid = sampGetPlayerIdByCharHandle(PLAYER_PED)
local text = toSendGet("[TRAIN-BOT]\n"..text.."\n\n - "..sampGetPlayerNickname(myid).."["..myid.."] - "..tostring(getServer()).."❤")
local result, response = pcall(request.get, "http://scripts.mdx-scripts.ru/notifications/messages.php?message="..text.."&id="..config['settings']['id'].."&type=send")
end
function toSendGet(str)
local diff = urlencode(u8:encode(str, 'CP1251'))
return diff
end
function urlencode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
function getServer()
servers = {"Phoenix", "Tucson", "Scottdale", "Chandler", "Brainburg", "Saint Rose", "Mesa", "Red-Rock", "Yuma"}
for i = 1, #servers do
if sampGetCurrentServerName():find(servers[i]) then
return servers[i]
end
end
return 'Unknown'
end
function SearchMarker(posX, posY, posZ, radius, isRace)
local ret_posX = 0.0
local ret_posY = 0.0
local ret_posZ = 0.0
local isFind = false
for id = 0, 31 do
local MarkerStruct = 0
if isRace then MarkerStruct = 0xC7F168 + id * 56
else MarkerStruct = 0xC7DD88 + id * 160 end
local MarkerPosX = representIntAsFloat(readMemory(MarkerStruct + 0, 4, false))
local MarkerPosY = representIntAsFloat(readMemory(MarkerStruct + 4, 4, false))
local MarkerPosZ = representIntAsFloat(readMemory(MarkerStruct + 8, 4, false))
if MarkerPosX ~= 0.0 or MarkerPosY ~= 0.0 or MarkerPosZ ~= 0.0 then
if getDistanceBetweenCoords3d(MarkerPosX, MarkerPosY, MarkerPosZ, posX, posY, posZ) < radius then
ret_posX = MarkerPosX
ret_posY = MarkerPosY
ret_posZ = MarkerPosZ
isFind = true
radius = getDistanceBetweenCoords3d(MarkerPosX, MarkerPosY, MarkerPosZ, posX, posY, posZ)
end
end
end
return isFind, ret_posX, ret_posY, ret_posZ, radius
end
function hook.onSendVehicleSync(data)
if info['status'] then
if tonumber(math.sqrt(data.moveSpeed.x * data.moveSpeed.x + data.moveSpeed.y * data.moveSpeed.y + data.moveSpeed.z * data.moveSpeed.z) * 126) > 80 then
data.moveSpeed.x = 0
data.moveSpeed.y = 0.66996252536774
data.moveSpeed.z = 0.0033537545241416
end
end
end
function hook.onSendDeathNotification(reason, killerId)
sendVK('Вы умерли.')
end