fixed crashes

update
rubin 2 years ago
parent b47cee68ae
commit 34569ce5df
  1. 161
      mafia-tools.lua

@ -1,6 +1,6 @@
script_name('mafia-tools')
script_author("Serhiy_Rubin")
script_version("07.02.2023.1")
script_version("05.02.2023.2")
sampev = require 'samp.events'
inicfg = require "inicfg"
@ -30,6 +30,7 @@ function main()
while true do
wait(0)
live = os.time()
msg.loop()
end
end
@ -643,7 +644,7 @@ get_guns.isCanOpen = false
get_guns.onServerMessage = function(color, message)
if message == "{FFFFFF} Вы можете использовать {00AB06}/getgun [ID игрока]{FFFFFF}, чтобы выдать оружие другим членам организации" then
if get_guns.getgun then
return true, false
return false
end
end
if message == " Вы не на складе оружия своей организации / у вас нет доступа!" or message == " Склад закрыт" then
@ -656,7 +657,7 @@ get_guns.onServerMessage = function(color, message)
if not get_guns.check_warehouse then
get_guns.check_warehouse = true
get_guns.check_warehouse_time = os.time()
return true, false
return false
end
end
if message:find("^ Склад .+ %{00AB06%}открыт") or message == " Склад открыт" then
@ -664,18 +665,18 @@ get_guns.onServerMessage = function(color, message)
if not get_guns.check_warehouse then
get_guns.check_warehouse = true
get_guns.check_warehouse_time = os.time()
return true, false
return false
end
end
if message == " Вам недоступна эта функция" then
if not get_guns.check_warehouse then
get_guns.check_warehouse = true
get_guns.check_warehouse_time = os.time()
return true, false
return false
end
end
if message:find("^ %d+/%d+ Матов | %d+/%d+ Аптечек") and os.time() - get_guns.check_warehouse_time < 2 then
return true, false
return false
end
if message:find("^ .+%[%d+%]: (.+)") then
get_guns.messages[#get_guns.messages+1] = message:match("^ .+%[%d+%]: (.+)")
@ -703,16 +704,18 @@ get_guns.onTextDrawHide = function(id)
end
get_guns.onShowDialog = function(id, style, title, button1, button2, text)
if title == "Статистика персонажа" then
local frac, rank = text:match("Организация\t(.+).Ранг\tКонсильере.%[(.+)%]")
rank = rank:gsub("Лидер", "10")
rank = tonumber(rank)
config.data.stats.rank = rank
config.data.stats.frac = frac
config.save(config.data)
local frac, rank = text:match("Организация\t(.+).Ранг\t.+%[(.+)%]")
if rank ~= nil then
rank = rank:gsub("Лидер", "10")
rank = tonumber(rank)
config.data.stats.rank = rank
config.data.stats.frac = frac
config.save(config.data)
end
if not get_guns.check_stats then
get_guns.check_stats = true
get_guns.antiflood = os.time() - 28
return true, false
return false
end
end
if title == "Склад оружия" then
@ -723,19 +726,11 @@ get_guns.onShowDialog = function(id, style, title, button1, button2, text)
else
get_guns.getgun = false
end
return true, false
end
end
end
get_guns.weapon = {}
get_guns.onSendWeaponsUpdate = function(playerTarget, actorTarget, weapons) -- ганы при использовании
for i = 1, #weapons do
get_guns.weapon[weapons[i]["slot"]] = weapons[i]["ammo"]
if weapons[i]["ammo"] == 0 then
table.remove(get_guns.weapon, weapons[i]["slot"])
return false
end
end
end
get_guns.weapon = {} -- >> onSendPacket
get_guns.onResetPlayerWeapons = function()
get_guns.weapon = {}
end
@ -766,7 +761,7 @@ get_guns.loop = function()
get_guns.start_get()
else
if wasKeyPressed(vkeys[config.data.get_guns.key]) and get_guns.getgun then
addChatMessage("Выполняется взятие ганов")
msg.add("Выполняется взятие ганов")
end
end
if #get_guns.messages > 0 then
@ -815,11 +810,10 @@ get_guns.start_get = function()
get_guns.getgun = true
antiflood.send[#antiflood.send+1] = "/getgun"
else
addChatMessage("У Вас достаточно оружия!")
msg.add("У Вас достаточно оружия!")
end
end
-->> INVITE HELPER
invite_helper = {}
invite_helper.data = {}
@ -844,20 +838,22 @@ invite_helper.onServerMessage = function(color, message)
end
end
invite_helper.onSendCommand = function(cmd)
if cmd:lower():find("%/invite %d+") then
local id, rank = cmd:lower():match("%/invite (%d+)"), config.data.invite_helper.rank
if cmd:lower():find("%/invite (%d+) (%d+)") then
id, rank = cmd:lower():match("%/invite (%d+) (%d+)")
if cmd:find("%/invite %d+") then
local id, rank = cmd:match("%/invite (%d+)"), config.data.invite_helper.rank
if cmd:find("%/invite (%d+) (%d+)") then
id, rank = cmd:match("%/invite (%d+) (%d+)")
end
local id = tonumber(id)
id = tonumber(id)
local result, name = getNickNameByPlayerId(id)
if result then
local score = sampGetPlayerScore(id)
if score >= config.data.invite_helper.lvl then
invite_helper.data[name] = "/giverank "..id.." "..rank
else
addChatMessage(string.format("У игрока %s[%d] всего %d уровень. Нужен %d уровень!", name, id, score, config.data.invite_helper.lvl))
return true, false
if ScoresAndPings[id] ~= nil then
local score = ScoresAndPings[id].score
if score >= config.data.invite_helper.lvl then
invite_helper.data[name] = "/giverank "..id.." "..rank
else
msg.add(string.format("У игрока %s[%d] всего %d уровень. Нужен %d уровень!", name, id, score, config.data.invite_helper.lvl))
return false
end
end
end
end
@ -1294,34 +1290,24 @@ config.read = function()
end
end
events = {}
events.handler = function(handler, param)
for i = 1, #handler do
local result, pack = handler[i](table.unpack(param))
if result then
return pack
end
end
end
events.onServerMessage = {
get_guns.onServerMessage
}
events.onSendCommand = {
invite_helper.onSendCommand
}
events.onShowDialog = {
get_guns.onShowDialog
}
-->> EVENTS
function processEvent(func, args)
if args == nil then
args = {}
end
local kk = table.pack(func(table.unpack(args)))
if kk.n > 0 then
return kk
end
end -- by QRLK (edith.lua)
function sampev.onServerMessage(color, message)
if os.time() - live < 3 then
timer_2min.onServerMessage(color, message)
ammo_timer.onServerMessage(color, message)
invite_helper.onServerMessage(color, message)
local result = events.handler(events.onServerMessage, { color, message })
if result ~= nil then
return result
local res = processEvent(get_guns.onServerMessage, table.pack(color, message))
if res then
return table.unpack(res)
end
end
end
@ -1339,20 +1325,26 @@ function sampev.onSendPickedUpPickup(id)
end
end --> by Benya
end
ScoresAndPings = {}
function sampev.onUpdateScoresAndPings(data)
ScoresAndPings = data
end
function sampev.onSendCommand(cmd)
antiflood.set()
local result = events.handler(events.onSendCommand, { cmd })
if result ~= nil then
return result
local res = processEvent(invite_helper.onSendCommand, table.pack(cmd))
if res then
return table.unpack(res)
end
end
function sampev.onSendChat(message)
antiflood.set()
local score = sampGetPlayerScore(tonumber(message))
addChatMessage(score)
end
function sampev.onShowDialog(id, style, title, button1, button2, text)
local result = events.handler(events.onShowDialog, { id, style, title, button1, button2, text })
if result ~= nil then
return result
local res = processEvent(get_guns.onShowDialog, table.pack(id, style, title, button1, button2, text))
if res then
return table.unpack(res)
end
end
function sampev.onShowTextDraw(id, data)
@ -1361,8 +1353,22 @@ end
function sampev.onTextDrawHide(id)
get_guns.onTextDrawHide(id)
end
function sampev.onSendWeaponsUpdate(playerTarget, actorTarget, weapons)
get_guns.onSendWeaponsUpdate(playerTarget, actorTarget, weapons)
function onSendPacket(id, bs)
if id == 204 then
raknetBitStreamIgnoreBits(bs,40)
local count = raknetBitStreamGetNumberOfUnreadBits(bs) / 32
for i = 1, count do
local slot = raknetBitStreamReadInt8(bs)
local weapon = raknetBitStreamReadInt8(bs)
local ammo = raknetBitStreamReadInt16(bs)
if get_guns.weapon ~= nil then
get_guns.weapon[slot] = ammo
if ammo == 0 then
table.remove(get_guns.weapon, slot)
end
end
end
end
end
function sampev.onResetPlayerWeapons()
get_guns.onResetPlayerWeapons()
@ -1500,6 +1506,13 @@ function split(str, delim, plain)
until not pos
return tokens
end
function sendRpcCommand(text)
local bs = raknetNewBitStream()
raknetBitStreamWriteInt32(bs, #text)
raknetBitStreamWriteString(bs,text)
raknetSendRpc(50,bs)
raknetDeleteBitStream(bs)
end
-->> UPDATE MODULE
function openURL(url, fpath, message_off)
@ -1551,6 +1564,19 @@ function addChatMessage(text)
sampAddChatMessage(tag..text, 0xFFFFFFFF)
end
-->> Chat Message HOOK (Для addChatMessage вне хука samp events)
msg = {}
msg.list = {}
msg.add = function(arg)
msg.list[#msg.list+1] = arg
end
msg.loop = function()
if #msg.list > 0 then
addChatMessage(msg.list[1])
table.remove(msg.list, 1)
end
end
script_update = {
version_url = "http://git.deadpoo.net/rubin/mafia-tools/raw/branch/master/version",
script_url = "http://git.deadpoo.net/rubin/mafia-tools/raw/branch/master/mafia-tools.lua",
@ -1747,3 +1773,4 @@ utf8({ "sampSetCurrentDialogEditboxText" }, "Utf8ToAnsi")
utf8({ "sampHasDialogRespond" }, nil, "AnsiToUtf8")
utf8({ "sampev", "onServerMessage" }, "AnsiToUtf8", "Utf8ToAnsi")
utf8({ "sampev", "onShowDialog" }, "AnsiToUtf8", "Utf8ToAnsi")
utf8({ "sampev", "onSendCommand" }, "AnsiToUtf8", "Utf8ToAnsi")
Loading…
Cancel
Save