local mb = require('MoonBot')
local ev = require('lib.samp.events')
local imgui = require('mimgui')
local ffi = require ('ffi')
local ev = require('lib.samp.events')
local encoding = require('encoding')
encoding.default = 'CP1251'
local u8 = encoding.UTF8
local new, str, sizeof = imgui.new, ffi.string, ffi.sizeof
local inputField = new.char[256]()
local sizeX, sizeY = getScreenResolution()
imgui.OnInitialize(function()
imgui.GetIO().IniFilename = nil
imgui.Theme()
end)
local renderWindow = new.bool(), new.bool()
local password = '123123'
local dist = 10
local raznos = false
local botData = {}
local presets = {}
local botName = new.char[256]()
local inputPreset = new.char(256)
local newFrame = imgui.OnFrame(
function() return renderWindow[0] end,
function(player)
imgui.SetNextWindowPos(imgui.ImVec2(220,200), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
imgui.SetNextWindowSize(imgui.ImVec2(600, 300), imgui.Cond.FirstUseEver)
imgui.Begin(u8"Меню Бота-Пса", renderWindow, imgui.WindowFlags.NoResize)
if imgui.CollapsingHeader(u8' Управление Пёсиками') then
imgui.Text(u8"Регистрация Пса")
if imgui.InputText(u8"Введите кличку нового Пса##botName", botName, sizeof(botName)) then
text = u8:decode(ffi.string(botName))
end
if imgui.Button(u8'Добавить Пса') then
sampProcessChatInput(string.format('/pes.add %s', ffi.string(botName)))
end
imgui.Text(u8'Ваши собаки') imgui.NextColumn()
for k, lBot in pairs(botData) do
local bot = mb.getBotHandleByIndex(lBot.index)
imgui.Separator()
imgui.Text(string.format('%s[%d]', bot.name, bot.index)) imgui.NextColumn()
imgui.Text(bot.connected and u8'Подключен' or u8'Не подключен') imgui.NextColumn()
if imgui.Button(u8'Удалить') then
sampProcessChatInput('/pes.remove ' .. bot.index)
end
end
end
if imgui.CollapsingHeader(u8'Гавкалка') then
imgui.Text(u8"Используйте: (Индекс пса) и (то что он прогавкает)")
imgui.Text(u8"Пишите без скобок!")
if imgui.InputText(u8"Введите то что гавкнет Пёс##botName", botName, sizeof(botName)) then
text = u8:decode(ffi.string(botName))
end
if imgui.Button(u8'Пёс! Гавкай!') then
sampProcessChatInput(string.format('/gav %s', ffi.string(botName)))
end
end
imgui.End()
end
)
function main()
repeat wait(0) until isSampAvailable()
sampAddChatMessage("{FF0000}[Pes Bot] {FFFFFF}Скрипт успешно загружен", -1)
sampAddChatMessage("{FF0000}[Pes Bot] {FFFFFF}Автор : sosnov", -1)
sampRegisterChatCommand('pesm', function() renderWindow[0] = not renderWindow[0] end) -- по команде
--mb.disconnectAfterUnload(false)
mb.registerIncomingRPC(61) -- dialog
mb.registerIncomingRPC(68) -- spawnInfo
mb.registerIncomingRPC(134) -- textdraw
sampRegisterChatCommand('gav', function(param)
if param ~= nil then
for k, lBot in pairs(botData) do
if param[1] == '/' then
mb.getBotHandleByIndex(lBot.index):sendCommand(param)
else
mb.getBotHandleByIndex(lBot.index):sendChat(param)
end
end
else
sampAddChatMessage('{FF0000}[Pes Bot]{FFFFFF}Используй: /gav [msg]')
end
if param:match('%d+ .+') then
local index, msg = param:match('(%d+) (.+)')
index = tonumber(index)
local found = false
for k, lBot in pairs(botData) do
if lBot.index == index then
if msg[1] == '/' then
mb.getBotHandleByIndex(lBot.index):sendCommand(msg)
else
mb.getBotHandleByIndex(lBot.index):sendChat(msg)
end
found = true
break
end
end
if not found then
sampAddChatMessage('{FF0000}[Pes Bot]{FFFFFF}Не нашли Пса с таким индексом')
end
else
sampAddChatMessage('{FF0000}[Pes Bot]{FFFFFF}Используй: {A7A7A7}/gav [Index] [msg]')
end
end)
sampRegisterChatCommand('pes.add', function(param)
if param:len() >= 3 then
local bot = mb.add(param)
table.insert(botData, {
index = bot.index,
logined = false,
rvanka = false,
bot:sendRequestSpawn(0)
})
bot:connectAsNPC(true)
bot:connect()
sampAddChatMessage(string.format('{FF0000}[Pes Bot]{FFFFFF}Подключаем %s (Номер: %d)', bot.name, bot.index), -1)
end
end)
sampRegisterChatCommand('pes.remove', function(param)
if param:match('%d+') then
local index = tonumber(param)
for k, bot in pairs(mb.getBots()) do
if bot.index == index then
sampAddChatMessage(string.format('{FF0000}[Pes Bot]{FFFFFF}Удалить %s (Номер: %d)', bot.name, bot.index), -1)
for j, lBot in pairs(botData) do
if lBot.index == bot.index then
table.remove(botData, j)
break
end
end
mb.remove(index)
break
end
end
end
end)
sampRegisterChatCommand('fas', function()
raznos = not raznos
for k, lBot in pairs(botData) do
local bot = mb.getBotHandleByIndex(lBot.index)
if bot ~= nil then
if not bot.connected and lBot.logined then
lBot.rvanka = false
end
end
end
sampAddChatMessage('raznos mode ' .. (raznos and 'ON' or 'OFF'), -1)
end)
while true do
wait(50)
mb.updateCallbacks()
local ped, playerId = nil, -1
if raznos then
local x, y, z = getCharCoordinates(PLAYER_PED)
_, ped = findAllRandomCharsInSphere(x, y, z, 100, true, true)
_, playerId = sampGetPlayerIdByCharHandle(ped)
if _ and not sampIsPlayerPaused(playerId) and not sampIsPlayerNpc(playerId) then
-- fine :3
else
ped = nil
end
end
for k, lBot in pairs(botData) do
local bot = mb.getBotHandleByIndex(lBot.index)
if bot ~= nil then
if not bot.connected and lBot.logined then
lBot.logined = false
end
if raznos then
if lBot.logined and ped ~= nil then
local angle = getCharHeading(ped)
local data = mb.getPlayerData()
local multiplier = 10
local x, y, z = getCharCoordinates(ped)
data.health = getCharHealth(PLAYER_PED)
data.armor = 0
data.weapon = 0
data.moveSpeed.x, data.moveSpeed.y, data.moveSpeed.z = math.sin(-math.rad(angle)) * multiplier, math.cos(-math.rad(angle)) * multiplier, multiplier
data.position.x, data.position.y, data.position.z = x - math.sin(-math.rad(angle)), y - math.cos(-math.rad(angle)), z + (isCharOnFoot(ped) and 0.5 or -1)
bot:sendPlayerData(data)
lBot.rvanka = true
else
lBot.rvanka = false
end
else
lBot.rvanka = false
end
end
end
if ped ~= nil and raznos then
printStringNow(string.format('Fisting for ~r~%s[%d]', sampGetPlayerNickname(playerId), playerId), 500)
end
end
end
function onBotIncomingPacket(bot, rpcId, bs)
--sampfuncsLog(string.format('%s [%d] got packet: %d', bot.name, bot.index, packetId))
if packetId == 41 then
sampAddChatMessage(string.format('{FF0000}[Pes Bot]{FFFFFF} %s [%d] успешно зашел (PlayerID: %d)', bot.name, bot.index, bot.playerID), -1)
end
end
function onBotIncomingRPC(bot, rpcId, bs)
if rpcId == 12 then
for k, lBot in pairs(botData) do
if lBot.index == bot.index then
local x, y, z = bs:readFloat(), bs:readFloat(), bs:readFloat()
lBot.position = {x = x, y = y, z = z}
sampAddChatMessage(string.format('{FF0000}[Pes Bot]{FFFFFF} %s[%d] {FFFFFF}сменил позицию {A7A7A7}(x: %d, y: %d, z: %d)', bot.name, bot.index, math.floor(x), math.floor(y), math.floor(z)))
end
end
end
--sampAddChatMessage('got rpc: ' .. rpcId, -1)
if rpcId == 61 then
local dialogId = bs:readInt16()
local style = bs:readInt8()
local title = bs:readString8()
local btn1 = bs:readString8()
local btn2 = bs:readString8()
if title:find('Авторизация') then
sampAddChatMessage(string.format('{FF0000}[Pes Bot]{FFFFFF} %s [%d] загружается...', bot.name, bot.index), -1)
bot:sendDialogResponse(dialogId, 1, 0, password)
end
if title:find('%(1/4%)') then
sampAddChatMessage(string.format('{FF0000}[Pes Bot]{FFFFFF} %s [%d] регистрируется...', bot.name, bot.index), -1)
bot:sendDialogResponse(dialogId, 1, 0, password)
end
if title:find('%[2/5%]') or title:find('%[3/5%]') or title:find('%[3/4%]') then
bot:sendDialogResponse(dialogId, 1, 0, '')
sampAddChatMessage(string.format('{FF0000}[Pes Bot]{FFFFFF} %s [%d] скипнул диалог (Заголовок: %s)', bot.name, bot.index, title), -1)
end
end
if rpcId == 68 then
for k, lBot in pairs(botData) do
if lBot.index == bot.index and not lBot.logined then
local team = bs:readInt8()
local skin = bs:readInt32()
local unk = bs:readInt8()
local x, y, z = bs:readFloat(), bs:readFloat(), bs:readFloat()
lBot.position = {x = x, y = y, z = z}
lBot.logined = true
bot:sendRequestSpawn()
bot:sendSpawn()
sampAddChatMessage(string.format('{FF0000}[Pes Bot]{FFFFFF} %s[%d] заспавнился', bot.name, bot.index))
break
end
end
end
if rpcId == 134 then
local tdId = bs:readInt16()
bs:ignoreBits(264)
local x, y = bs:readFloat(), bs:readFloat()
if x == 233.000000 and y == 367.000000 then
for k, lBot in pairs(botData) do
if lBot.index == bot.index then
local sync = mb.getPlayerData()
sync.position.x, sync.position.y, sync.position.z = lBot.position.x, lBot.position.y, lBot.position.z
sync.health = 100
sync.armor = 0
sync.quaternion.w, sync.quaternion.x, sync.quaternion.y, sync.quaternion.z = 0, 0, 0, 0
sync.moveSpeed.x, sync.moveSpeed.y, sync.moveSpeed.z = 0, 0, 0
sync.weapon = 0
lBot.logined = false
bot:sendPlayerData(sync)
bot:sendClickTextdraw(tdId)
bot:sendRequestSpawn()
bot:sendSpawn()
addMessage(string.format('{FF0000}[Pes Bot]{FFFFFF} %s[%d] выбрал скин', bot.name, bot.index))
break
end
end
end
end
end
function onScriptTerminate(script, quitGame)
if script == thisScript() then
mb.unload()
end
end
function ev.onSendPlayerSync(data)
local offset = 0
for k, lBot in pairs(botData) do
if lBot.logined and lBot ~= nil and not lBot.rvanka then
offset = offset + 1
local angle = getCharHeading(PLAYER_PED) - 90
local sync = mb.getPlayerData()
sync.position.x, sync.position.y, sync.position.z = data.position.x + math.sin(-math.rad(angle)) * offset, data.position.y + math.cos(-math.rad(angle)) * offset, data.position.z
sync.health = data.health
sync.armor = 0
sync.quaternion.w, sync.quaternion.x, sync.quaternion.y, sync.quaternion.z = data.quaternion[0], data.quaternion[1], data.quaternion[2], data.quaternion[3]
sync.moveSpeed.x, sync.moveSpeed.y, sync.moveSpeed.z = data.moveSpeed.x, data.moveSpeed.y, data.moveSpeed.z
sync.weapon = 0
local bot = mb.getBotHandleByIndex(lBot.index)
bot:sendPlayerData(sync)
end
end
end
function imgui.Theme()
imgui.SwitchContext()
imgui.GetStyle().FramePadding = imgui.ImVec2(3.5, 3.5)
imgui.GetStyle().FrameRounding = 3
imgui.GetStyle().ChildRounding = 2
imgui.GetStyle().WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
imgui.GetStyle().WindowRounding = 2
imgui.GetStyle().ItemSpacing = imgui.ImVec2(5.0, 4.0)
imgui.GetStyle().ScrollbarSize = 13.0
imgui.GetStyle().ScrollbarRounding = 0
imgui.GetStyle().GrabMinSize = 8.0
imgui.GetStyle().GrabRounding = 1.0
imgui.GetStyle().WindowPadding = imgui.ImVec2(4.0, 4.0)
imgui.GetStyle().ButtonTextAlign = imgui.ImVec2(0.0, 0.5)
imgui.GetStyle().Colors[imgui.Col.WindowBg] = imgui.ImVec4(0.14, 0.12, 0.16, 1.00)
imgui.GetStyle().Colors[imgui.Col.ChildBg] = imgui.ImVec4(0.30, 0.20, 0.39, 0.00)
imgui.GetStyle().Colors[imgui.Col.PopupBg] = imgui.ImVec4(0.05, 0.05, 0.10, 0.90)
imgui.GetStyle().Colors[imgui.Col.Border] = imgui.ImVec4(0.89, 0.85, 0.92, 0.30)
imgui.GetStyle().Colors[imgui.Col.BorderShadow] = imgui.ImVec4(0.00, 0.00, 0.00, 0.00)
imgui.GetStyle().Colors[imgui.Col.FrameBg] = imgui.ImVec4(0.30, 0.20, 0.39, 1.00)
imgui.GetStyle().Colors[imgui.Col.FrameBgHovered] = imgui.ImVec4(0.41, 0.19, 0.63, 0.68)
imgui.GetStyle().Colors[imgui.Col.FrameBgActive] = imgui.ImVec4(0.41, 0.19, 0.63, 1.00)
imgui.GetStyle().Colors[imgui.Col.TitleBg] = imgui.ImVec4(0.41, 0.19, 0.63, 0.45)
imgui.GetStyle().Colors[imgui.Col.TitleBgCollapsed] = imgui.ImVec4(0.41, 0.19, 0.63, 0.35)
imgui.GetStyle().Colors[imgui.Col.TitleBgActive] = imgui.ImVec4(0.41, 0.19, 0.63, 0.78)
imgui.GetStyle().Colors[imgui.Col.MenuBarBg] = imgui.ImVec4(0.30, 0.20, 0.39, 0.57)
imgui.GetStyle().Colors[imgui.Col.ScrollbarBg] = imgui.ImVec4(0.30, 0.20, 0.39, 1.00)
imgui.GetStyle().Colors[imgui.Col.ScrollbarGrab] = imgui.ImVec4(0.41, 0.19, 0.63, 0.31)
imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabHovered] = imgui.ImVec4(0.41, 0.19, 0.63, 0.78)
imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabActive] = imgui.ImVec4(0.41, 0.19, 0.63, 1.00)
imgui.GetStyle().Colors[imgui.Col.CheckMark] = imgui.ImVec4(0.56, 0.61, 1.00, 1.00)
imgui.GetStyle().Colors[imgui.Col.SliderGrab] = imgui.ImVec4(0.41, 0.19, 0.63, 0.24)
imgui.GetStyle().Colors[imgui.Col.SliderGrabActive] = imgui.ImVec4(0.41, 0.19, 0.63, 1.00)
imgui.GetStyle().Colors[imgui.Col.Button] = imgui.ImVec4(0.41, 0.19, 0.63, 0.44)
imgui.GetStyle().Colors[imgui.Col.ButtonHovered] = imgui.ImVec4(0.41, 0.19, 0.63, 0.86)
imgui.GetStyle().Colors[imgui.Col.ButtonActive] = imgui.ImVec4(0.64, 0.33, 0.94, 1.00)
imgui.GetStyle().Colors[imgui.Col.Header] = imgui.ImVec4(0.41, 0.19, 0.63, 0.76)
imgui.GetStyle().Colors[imgui.Col.HeaderHovered] = imgui.ImVec4(0.41, 0.19, 0.63, 0.86)
imgui.GetStyle().Colors[imgui.Col.HeaderActive] = imgui.ImVec4(0.41, 0.19, 0.63, 1.00)
imgui.GetStyle().Colors[imgui.Col.ResizeGrip] = imgui.ImVec4(0.41, 0.19, 0.63, 0.20)
imgui.GetStyle().Colors[imgui.Col.ResizeGripHovered] = imgui.ImVec4(0.41, 0.19, 0.63, 0.78)
imgui.GetStyle().Colors[imgui.Col.ResizeGripActive] = imgui.ImVec4(0.41, 0.19, 0.63, 1.00)
imgui.GetStyle().Colors[imgui.Col.PlotLines] = imgui.ImVec4(0.89, 0.85, 0.92, 0.63)
imgui.GetStyle().Colors[imgui.Col.PlotLinesHovered] = imgui.ImVec4(0.41, 0.19, 0.63, 1.00)
imgui.GetStyle().Colors[imgui.Col.PlotHistogram] = imgui.ImVec4(0.89, 0.85, 0.92, 0.63)
imgui.GetStyle().Colors[imgui.Col.PlotHistogramHovered] = imgui.ImVec4(0.41, 0.19, 0.63, 1.00)
imgui.GetStyle().Colors[imgui.Col.TextSelectedBg] = imgui.ImVec4(0.41, 0.19, 0.63, 0.43)
end