added new function & added folder config & set name config to server-name.json

update
rubin 2 years ago
parent 32782e0168
commit f2ee17e748
  1. 62
      mafia-tools.lua

@ -12,11 +12,7 @@ function main()
lua_thread.create(script_update.main)
repeat wait(0) until sampGetCurrentServerName() ~= "SA-MP"
repeat wait(0) until sampGetCurrentServerName():find("Samp%-Rp.Ru") or sampGetCurrentServerName():find("SRP")
server = sampGetCurrentServerName():gsub("|", "")
server = (server:find("02") and "Two" or
(server:find("Revo") and "Revolution" or
(server:find("Legacy") and "Legacy" or (server:find("Classic") and "Classic" or
(server:find("Zero Two") and "Two" or "")))))
local server = getSampRpServerName()
if server == "" then
thisScript():unload()
end
@ -32,26 +28,24 @@ end
-->> REQUEST
request = {}
request.send = {}
request.base = {}
request.loop = function()
request.wait = 0
while true do
wait(0)
if os.time() - request.wait >= 5 then
request.wait = os.time()
local ip, port = sampGetCurrentServerAddress()
local _, myid = sampGetPlayerIdByCharHandle(PLAYER_PED)
local myname = sampGetPlayerNickname(myid)
local request_table = {
sender = myname,
server = string.format("%s:%s", ip, port),
room = "test",
send = {}
sender = getLocalPlayerNickname(),
server = getServerAddress(),
room = config.data.room,
send = request.send
}
request.send = {}
local url = string.format("http://mafia.deadpoo.net/%s", encodeJson(request_table))
local result, text = pcall(openURL, url, os.tmpname(), true)
if result then
sampfuncsLog(text)
local result = pcall(request.handler, text)
if not result then
addChatMessage("Сервер 'mafia-tools' не отвечает!")
@ -73,7 +67,9 @@ end
ammo_timer = {}
ammo_timer.onServerMessage = function(color, message)
if message:find("^ Следующее ограбление будет доступно в (%d+:%d+:%d+)") then
request.send[#request.send + 1] = {
}
end
end
ammo_timer.loop = function()
@ -118,15 +114,27 @@ end
config = {}
config.data = {}
config.default = {
time_2min = 0
time_2min = 0,
room = "all"
}
config.address = string.format("%s\\moonloader\\%s.json", getGameDirectory(), thisScript().name)
config.directory = string.format("%s\\moonloader\\config\\%s\\", getGameDirectory(), thisScript().name)
config.init = function()
if not doesDirectoryExist("moonloader\\config") then
createDirectory("moonloader\\config")
end
if not doesDirectoryExist(config.directory) then
createDirectory(config.directory)
end
config.address = string.format("%s\\%s-%s.json", config.directory, getSampRpServerName(), getLocalPlayerNickname())
if not doesFileExist(config.address) then
config.save(config.default)
end
config.read()
for k,v in pairs(config.default) do
if config.data[k] == nil then
config.data[k] = v
end
end
config.save(config.data)
end
config.save = function(data)
@ -172,6 +180,26 @@ function sampev.onServerMessage(color, message)
timer_2min.onServerMessage(color, message)
end
-->> NEW FUNCTION
function getLocalPlayerNickname()
return sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED)))
end
function getServerAddress()
local ip, port = sampGetCurrentServerAddress()
return string.format("%s:%s", ip, port)
end
function getSampRpServerName()
local result = ""
local server = sampGetCurrentServerName():gsub("|", "")
local server_find = { "02", "Two", "Revo", "Legacy", "Classic" }
for i = 1, #server_find do
if server:find(server_find[i]) then
result = server_find[i]
end
end
return result
end
-->> UPDATE MODULE
function openURL(url, fpath, message_off)
local text = ""

Loading…
Cancel
Save