fix collectgarbage + & thread delete, now functions

test-utf-8
rubin 2 years ago
parent c17889ac85
commit 350a253188
  1. 93
      TruckHUD.lua

@ -198,7 +198,7 @@ function main()
createDirectory(AdressFolder) createDirectory(AdressFolder)
end end
settings_load() settings_load()
threads_save[#threads_save+1] = lua_thread.create(get_time) lua_thread.create(get_time)
logAvailable() logAvailable()
for k,v in pairs(prices_mon) do for k,v in pairs(prices_mon) do
prices_mon[k] = inifiles.tmonitor[k] prices_mon[k] = inifiles.tmonitor[k]
@ -209,10 +209,12 @@ function main()
font = renderCreateFont(inifiles.Render.FontName, inifiles.Render.FontSize, inifiles.Render.FontFlag) font = renderCreateFont(inifiles.Render.FontName, inifiles.Render.FontSize, inifiles.Render.FontFlag)
--gmap area --gmap area
threads_save[#threads_save+1] = lua_thread.create(transponder) lua_thread.create(transponder)
threads_save[#threads_save+1] = lua_thread.create(fastmap) lua_thread.create(fastmap)
threads_save[#threads_save+1] = lua_thread.create(renderTruckers) lua_thread.create(renderTruckers)
threads_save[#threads_save+1] = lua_thread.create(luChecker.checker) lua_thread.create(luChecker.checker)
lua_thread.create(doCruise)
--lua_thread.create(script_update.main) --lua_thread.create(script_update.main)
@ -231,7 +233,6 @@ function main()
doPickup() doPickup()
doPtt() doPtt()
if script_run then if script_run then
doCruise()
if not sampIsScoreboardOpen() and sampIsChatVisible() and not isKeyDown(116) and not isKeyDown(121) and fastmapshow == nil then if not sampIsScoreboardOpen() and sampIsChatVisible() and not isKeyDown(116) and not isKeyDown(121) and fastmapshow == nil then
doRenderStats() doRenderStats()
doRenderMon() doRenderMon()
@ -476,7 +477,7 @@ function doControl()
delay.dir = 1 delay.dir = 1
end end
if i == 7 and script_run then if i == 7 and script_run then
threads[#threads+1] = lua_thread.create(showTruckers) lua_thread.create(showTruckers)
end end
if i == 8 then if i == 8 then
ShowDialog1(1) ShowDialog1(1)
@ -829,7 +830,7 @@ function doDialog()
end end
if str:find("Î÷èñòèòü íåèñïîëüçóåìóþ ïàìÿòü ñêðèïòà") then if str:find("Î÷èñòèòü íåèñïîëüçóåìóþ ïàìÿòü ñêðèïòà") then
local mem_do = string.format('%0.2f MB', (tonumber(gcinfo()) / 1000)) local mem_do = string.format('%0.2f MB', (tonumber(gcinfo()) / 1000))
collectgarbage() collectgarbage("step")
sampAddChatMessage('Ïàìÿòè î÷èùåíà. Áûëî: '..mem_do..'. Ñòàëî: '..string.format('%0.2f MB', (tonumber(gcinfo()) / 1000)), -1) sampAddChatMessage('Ïàìÿòè î÷èùåíà. Áûëî: '..mem_do..'. Ñòàëî: '..string.format('%0.2f MB', (tonumber(gcinfo()) / 1000)), -1)
ShowDialog1(1) ShowDialog1(1)
end end
@ -1063,31 +1064,34 @@ end
cruise = false cruise = false
function doCruise() function doCruise()
if not inifiles.Settings.Cruise then return end while true do
additional_key_stop = { "VK_W", "VK_S", "VK_SPACE" } wait(0)
local car = storeCarCharIsInNoSave(playerPed) if inifiles.Settings.Cruise and script_run then
if not isCharInAnyCar(playerPed) or not isCarEngineOn(car) then additional_key_stop = { "VK_W", "VK_S", "VK_SPACE" }
if cruise then local car = storeCarCharIsInNoSave(playerPed)
cruise = false if not isCharInAnyCar(playerPed) or not isCarEngineOn(car) then
printStringNow('~R~cruise control - OFF', 1500) if cruise then
end cruise = false
return printStringNow('~R~cruise control - OFF', 1500)
end end
if not sampIsChatInputActive() and not sampIsDialogActive() and not sampIsCursorActive() then end
if not cruise and isKeyDown(vkeys["VK_W"]) and isKeyDown(vkeys[inifiles.Settings.Key4]) then if not sampIsChatInputActive() and not sampIsDialogActive() and not sampIsCursorActive() then
repeat if not cruise and isKeyDown(vkeys["VK_W"]) and isKeyDown(vkeys[inifiles.Settings.Key4]) then
wait(100) cruise = true
until not isKeyDown(vkeys["VK_W"]) printStringNow('~G~cruise control - ON', 1500)
cruise = true repeat
printStringNow('~G~cruise control - ON', 1500) wait(100)
elseif cruise and not isKeyDown(vkeys[inifiles.Settings.Key4]) and select(1, check_press_key(additional_key_stop)) then until not isKeyDown(vkeys["VK_W"])
cruise = false elseif cruise and not isKeyDown(vkeys[inifiles.Settings.Key4]) and select(1, check_press_key(additional_key_stop)) then
printStringNow('~R~cruise control - OFF', 1500) cruise = false
printStringNow('~R~cruise control - OFF', 1500)
end
end
if cruise then
setGameKeyState(16, 255)
end
end end
end end
if cruise then
setGameKeyState(16, 255)
end
end end
function doRenderStats() function doRenderStats()
@ -1973,7 +1977,7 @@ function ShowDialog1(int, dtext, dinput, string_or_number, ini1, ini2)
) )
end end
if int == 4 then if int == 4 then
threads[#threads+1] = lua_thread.create( lua_thread.create(
function() function()
wait(100) wait(100)
local key = "" local key = ""
@ -2095,23 +2099,24 @@ function loadEvents()
time_send_trailer_sync = 0 time_send_trailer_sync = 0
function sampev.onSendVehicleSync() function sampev.onSendVehicleSync()
time_send_trailer_sync = os.time() time_send_trailer_sync = os.time()
sampfuncsLog("onSendVehicleSync")
end end
function sampev.onSendTrailerSync() function sampev.onSendTrailerSync()
sampfuncsLog("send traile sync")
if os.time() - time_send_trailer_sync >= 2 then if os.time() - time_send_trailer_sync >= 2 then
local data = samp_create_sync_data("vehicle") local data = samp_create_sync_data("vehicle")
data.send() data.send()
end end
end end
function sampev.onVehicleSync(playerId, vehicleId, data) function sampev.onVehicleSync(playerId, vehicleId, data)
threads[#threads+1] = lua_thread.create(luChecker.vehicleSync, playerId, vehicleId, data) --lua_thread.create(luChecker.vehicleSync, playerId, vehicleId, data)
luChecker.vehicleSync(playerId, vehicleId, data)
end end
function sampev.onTrailerSync(playerId, data) function sampev.onTrailerSync(playerId, data)
threads[#threads+1] = lua_thread.create(luChecker.trailerSync, playerId, data) --lua_thread.create(luChecker.trailerSync, playerId, data)
luChecker.trailerSync(playerId, data)
end end
function sampev.onVehicleStreamOut(vehicleId) function sampev.onVehicleStreamOut(vehicleId)
threads[#threads+1] = lua_thread.create(luChecker.vehicleStream, false, vehicleId) --lua_thread.create(luChecker.vehicleStream, false, vehicleId)
luChecker.vehicleStream(false, vehicleId)
end end
function sampev.onSendChat(message) function sampev.onSendChat(message)
antiflood = os.clock() * 1000 antiflood = os.clock() * 1000
@ -2193,7 +2198,8 @@ function loadEvents()
antiflood = os.clock() * 1000 antiflood = os.clock() * 1000
end end
function sampev.onVehicleStreamIn(vehicleId, data) function sampev.onVehicleStreamIn(vehicleId, data)
threads[#threads+1] = lua_thread.create(luChecker.vehicleStream, true, vehicleId, data) --lua_thread.create(luChecker.vehicleStream, true, vehicleId, data)
luChecker.vehicleStream(true, vehicleId, data)
if inifiles ~= nil and not inifiles.Settings.Tuning and (data.type == 403 or data.type == 515) then if inifiles ~= nil and not inifiles.Settings.Tuning and (data.type == 403 or data.type == 515) then
data.modSlots[8] = 0 data.modSlots[8] = 0
return {vehicleId, data} return {vehicleId, data}
@ -2651,7 +2657,7 @@ function loadEvents()
end end
if string.find(Dtitle, "Ðàáîòû") and delay.dir == 3 then if string.find(Dtitle, "Ðàáîòû") and delay.dir == 3 then
threads[#threads+1] = lua_thread.create( lua_thread.create(
function() function()
repeat repeat
wait(0) wait(0)
@ -2673,7 +2679,7 @@ function loadEvents()
end end
function sampev.onCreate3DText(id, color, position, distance, testLOS, attachedPlayerId, attachedVehicleId, text) -- f3d1 function sampev.onCreate3DText(id, color, position, distance, testLOS, attachedPlayerId, attachedVehicleId, text) -- f3d1
threads[#threads+1] = lua_thread.create( lua_thread.create(
function(id, color, position, distance, testLOS, attachedPlayerId, attachedVehicleId, textt) function(id, color, position, distance, testLOS, attachedPlayerId, attachedVehicleId, textt)
for k, v in pairs(find_3dText) do for k, v in pairs(find_3dText) do
@ -2765,7 +2771,7 @@ function loadEvents()
end end
function sampev.onRemove3DTextLabel(Cid) -- f3d2 function sampev.onRemove3DTextLabel(Cid) -- f3d2
threads[#threads+1] = lua_thread.create(function(Cid) lua_thread.create(function(Cid)
if id_3D_text == Cid then if id_3D_text == Cid then
id_3D_text = msk_timestamp id_3D_text = msk_timestamp
load_location = false load_location = false
@ -3631,7 +3637,7 @@ function get_time()
_time = os.time() _time = os.time()
if inifiles.Settings.AutoClear then if inifiles.Settings.AutoClear then
threads = {} threads = {}
collectgarbage() collectgarbage("step")
end end
end end
end end
@ -4104,6 +4110,7 @@ end
function luChecker.checkerLoad(playerId, data, position) -- Ïðîâåðêà êîãäà èãðîê ïîëó÷èë ãðóç function luChecker.checkerLoad(playerId, data, position) -- Ïðîâåðêà êîãäà èãðîê ïîëó÷èë ãðóç
if luChecker.truckers[playerId]["trailerData"]["trailerId"] ~= data["trailerId"] then if luChecker.truckers[playerId]["trailerData"]["trailerId"] ~= data["trailerId"] then
say(luChecker.truckers[playerId]["trailerData"]["trailerId"].." - "..data["trailerId"])
sampAddChatMessage(data["trailerId"],-1) sampAddChatMessage(data["trailerId"],-1)
if getLocalPlayerId() ~= playerId then if getLocalPlayerId() ~= playerId then
local trucker_x, trucker_y, trucker_z = position.x, position.y, position.z local trucker_x, trucker_y, trucker_z = position.x, position.y, position.z
@ -4378,7 +4385,7 @@ script_update = {
script_update.menu.init() script_update.menu.init()
end, end,
command = function() command = function()
threads[#threads+1] = lua_thread.create(function() lua_thread.create(function()
local fpath = os.tmpname() local fpath = os.tmpname()
local result, text = openURL(script_update.auto_update_url, fpath) local result, text = openURL(script_update.auto_update_url, fpath)
if result and text ~= "" and text:find(thisScript().name:gsub("%-", "%%-")) then if result and text ~= "" and text:find(thisScript().name:gsub("%-", "%%-")) then

Loading…
Cancel
Save