thread corutina fix & delete inspect

test-utf-8
rubin 2 years ago
parent b69043e037
commit e3bc7f9491
  1. 94
      TruckHUD.lua

@ -2,7 +2,6 @@ script_name("TruckHUD")
script_author("Serhiy_Rubin")
script_version("2209011")
local inspect = require("inspect")
local inicfg = require "inicfg"
local dlstatus = require("moonloader").download_status
@ -158,6 +157,8 @@ binder_mode_sms = false
stop_downloading_1, stop_downloading_2, stop_downloading_3, stop_downloading_4, stop_downloading_5 = false, false, false, false, false
threads = {}
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(0) end
@ -231,6 +232,7 @@ function main()
doPair()
doPickup()
doPtt()
trailer_fix_afk()
if script_run then
doCruise()
if not sampIsScoreboardOpen() and sampIsChatVisible() and not isKeyDown(116) and not isKeyDown(121) and fastmapshow == nil then
@ -2085,14 +2087,39 @@ end
function loadEvents()
function sampev.onSendVehicleSync()
time_send_trailer_sync = os.time()
sampfuncsLog("onSendVehicleSync")
end
function sampev.onSendTrailerSync()
time_send_trailer_sync = os.time()
sampfuncsLog("send traile sync")
-- if os.time() - time_send_trailer_sync < 2 then
-- if isCharInAnyCar(PLAYER_PED) then
-- local car = storeCarCharIsInNoSave(PLAYER_PED)
-- local ptr = getCarPointer(car)
-- local trailer = readMemory(ptr + 1224, 4, false)
-- if readMemory(ptr + 1224, 4, false) == 0 and trailer > 0 then
-- time_send_trailer_sync = os.time()
-- local data = samp_create_sync_data("vehicle")
-- data.send()
-- local data = samp_create_sync_data("trailer")
-- data.send()
-- say("SYNC SEND")
-- end
-- end
end
function sampev.onVehicleSync(playerId, vehicleId, data)
lua_thread.create(luChecker.vehicleSync, playerId, vehicleId, data)
threads[#threads+1] = lua_thread.create(luChecker.vehicleSync, playerId, vehicleId, data)
end
function sampev.onTrailerSync(playerId, data)
lua_thread.create(luChecker.trailerSync, playerId, data)
threads[#threads+1] = lua_thread.create(luChecker.trailerSync, playerId, data)
end
function sampev.onVehicleStreamOut(vehicleId)
lua_thread.create(luChecker.vehicleStream, false, vehicleId)
threads[#threads+1] = lua_thread.create(luChecker.vehicleStream, false, vehicleId)
end
function sampev.onSendChat(message)
antiflood = os.clock() * 1000
@ -4360,13 +4387,60 @@ function getPort(x, y, z)
end
-->> TRAILER FIX
--- luCheckerCargo
--[[
time_send_trailer_sync = os.time()
function trailer_fix_afk()
settings_save()
end
inifiles.Settings.luCheckerCargo
]]
function samp_create_sync_data(sync_type, copy_from_player)
local ffi = require "ffi"
local sampfuncs = require "sampfuncs"
local raknet = require "samp.raknet"
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)))
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(playerPed)
else
player_id = tonumber(copy_from_player)
end
copy_func(player_id, raw_data_ptr)
end
end
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
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
Loading…
Cancel
Save