local samp = require("lib.samp.events")
local events = require 'lib.samp.events'
local samp = require "samp.events"
local enabled = false
local Answered = false
local WaitingAnswer = false
local CurQuest = 'Что?'
local questions = {}
function main()
while not isSampAvailable() do wait(0) end wait(1)
wait(1300)
sampAddChatMessage("{FFFFFF}[{FFAD40}Kladman{FFFFFF}] - {6495ED}Загружен!",-1)
while true do
wait(0)
if isKeyDown(49) and not sampIsChatInputActive() and not sampIsDialogActive() then
while isKeyDown(49) do wait(0) end
sampSendChat("/gun")
function events.onServerMessage(color, text)
if text:find("аксессуара!") then
sampAddChatMessage("{6495ED}Вы не одели лопату!{ffffff}", -1) return false
end
end
end
function samp.onDisplayGameText(style, timer, text)
if text:find('Press: ~g~Y') then
local data = samp_create_sync_data('player')
data.weapon = data.weapon + 64
data.send()
end
if text:find('Press: ~r~N') then
local data = samp_create_sync_data('player')
data.weapon = data.weapon + 128
data.send()
end
if text:find('ALT') then
local data = samp_create_sync_data('player')
data.keysData = data.keysData + 1024
data.send()
end
if text:find('~g~successfully') then
local data = samp_create_sync_data('player')
data.keysData = data.keysData + 1024
data.send()
end
if text:find('fail') or text:find('FAIL') or text:find('Fail') then
local data = samp_create_sync_data('player')
data.weapon = data.weapon + 1024
data.send()
end
end
function samp.onShowDialog(id, style, title, btn1, btn2, text)
questions = read_answers()
if id == 13101 then
if text:find('Максимальный срок деморгана в секундах') then
CurQuest = 'Максимальный срок деморгана в секундах'
else
if CurQuest:find('?') then
CurQuest = text:match('Вопрос:%s+(.*)?')
else
CurQuest = text:match('Вопрос:%s+(.*)%s+Введите')
end
end
if CurQuest then
CurQuest = CurQuest:gsub('%%', '')
CurQuest = CurQuest:gsub(' ', '')
CurQuest = CurQuest:gsub(',', '')
CurQuest = CurQuest:gsub('-', '')
CurQuest = CurQuest:gsub(' ', '')
for i = 1, #questions do
textik = questions[i]
if textik ~= nil then
question, answer = textik:match("{q = '(.*)', a = '(.*)'}")
if question ~= nil then
question = question:gsub('%%', '')
question = question:gsub(' ', '')
question = question:gsub(',', '')
question = question:gsub('-', '')
question = question:gsub(' ', '')
if CurQuest:find(question) then
math.randomseed(os.time())
sampAddChatMessage('{6495ED}Ответ:{FFFFFF}' ..answer, -1)
Answered = true
return true
end
end
end
end
end
if not Answered then
sampAddChatMessage('{6495ED}Ответ не найден, введите ответ и он будет сохранен', -1)
WaitingAnswer = true
end
end
end
function samp.onSendDialogResponse(id, btn, listId, input)
if id == 13101 then
if WaitingAnswer then
question = CurQuest
if question ~= nil then
answer = input
file = AnswerFile('a')
file:write("{q = '"..question.."', a = '"..answer.."'} \n")
file:close()
sampAddChatMessage('{6495ED}Добавлен вопрос/ответ '..question..' / '..answer, -1)
WaitingAnswer = false
end
end
end
end
function AnswerFile(mode)
return io.open('moonloader/AutoAnswer.txt', mode)
end
function read_answers()
local file = AnswerFile('r')
if file then
local data = {}
for line in file:lines() do
table.insert(data, line)
end
file:close()
return data
else
return nil
end
end
end
end
function samp_create_sync_data(sync_type, copy_from_player)
local ffi = require 'ffi'
local sampfuncs = require 'sampfuncs'
-- from SAMP.Lua
local raknet = require 'samp.raknet'
require 'samp.synchronization'
copy_from_player = copy_from_player or true
local sync_traits = {
player = {'PlayerSyncData', raknet.PACKET.PLAYER_SYNC, sampStorePlayerOnfootData},
vehicle = {'VehicleSyncData', raknet.PACKET.VEHICLE_SYNC, sampStorePlayerIncarData},
passenger = {'PassengerSyncData', raknet.PACKET.PASSENGER_SYNC, sampStorePlayerPassengerData},
aim = {'AimSyncData', raknet.PACKET.AIM_SYNC, sampStorePlayerAimData},
trailer = {'TrailerSyncData', raknet.PACKET.TRAILER_SYNC, sampStorePlayerTrailerData},
unoccupied = {'UnoccupiedSyncData', raknet.PACKET.UNOCCUPIED_SYNC, nil},
bullet = {'BulletSyncData', raknet.PACKET.BULLET_SYNC, nil},
spectator = {'SpectatorSyncData', raknet.PACKET.SPECTATOR_SYNC, nil}
}
local sync_info = sync_traits[sync_type]
local data_type = 'struct ' .. sync_info[1]
local data = ffi.new(data_type, {})
local raw_data_ptr = tonumber(ffi.cast('uintptr_t', ffi.new(data_type .. '*', data)))
-- copy player's sync data to the allocated memory
if copy_from_player then
local copy_func = sync_info[3]
if copy_func then
local _, player_id
if copy_from_player == true then
_, player_id = sampGetPlayerIdByCharHandle(PLAYER_PED)
else
player_id = tonumber(copy_from_player)
end
copy_func(player_id, raw_data_ptr)
end
end
-- function to send packet
local func_send = function()
local bs = raknetNewBitStream()
raknetBitStreamWriteInt8(bs, sync_info[2])
raknetBitStreamWriteBuffer(bs, raw_data_ptr, ffi.sizeof(data))
raknetSendBitStreamEx(bs, sampfuncs.HIGH_PRIORITY, sampfuncs.UNRELIABLE_SEQUENCED, 1)
raknetDeleteBitStream(bs)
end
-- metatable to access sync data and 'send' function
local mt = {
__index = function(t, index)
return data[index]
end,
__newindex = function(t, index, value)
data[index] = value
end
}
return setmetatable({send = func_send}, mt)
end