first commit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
local pendingCallbacks = {}
|
||||
local callbackCounter = 0
|
||||
local resourceName = GetCurrentResourceName()
|
||||
local responseEvent = ('devx_core:client:callback:%s'):format(resourceName)
|
||||
|
||||
function DevXTriggerCallback(name, payload, callback)
|
||||
assert(type(name) == 'string' and name:match('^[%w_%-]+:[%w_%-]+$'),
|
||||
'Callbackname ist ungültig.')
|
||||
assert(type(callback) == 'function', 'Clientcallback muss eine Funktion sein.')
|
||||
|
||||
callbackCounter = callbackCounter + 1
|
||||
local requestId = ('%s:%s:%s'):format(resourceName, GetGameTimer(), callbackCounter)
|
||||
|
||||
pendingCallbacks[requestId] = callback
|
||||
|
||||
TriggerServerEvent(
|
||||
('devx_core:server:callback:%s:%s'):format(resourceName, name),
|
||||
requestId,
|
||||
payload or {}
|
||||
)
|
||||
|
||||
SetTimeout(22000, function()
|
||||
local pending = pendingCallbacks[requestId]
|
||||
if not pending then return end
|
||||
|
||||
pendingCallbacks[requestId] = nil
|
||||
pending({
|
||||
ok = false,
|
||||
error = ('Keine Antwort auf %s. Prüfe die txAdmin- und F8-Konsole.'):format(name)
|
||||
})
|
||||
end)
|
||||
end
|
||||
|
||||
RegisterNetEvent(responseEvent)
|
||||
AddEventHandler(responseEvent, function(requestId, result)
|
||||
local callback = pendingCallbacks[requestId]
|
||||
if not callback then return end
|
||||
|
||||
pendingCallbacks[requestId] = nil
|
||||
callback(result or { ok = false, error = 'Leere Serverantwort.' })
|
||||
end)
|
||||
@@ -0,0 +1,63 @@
|
||||
local PlayerData = nil
|
||||
|
||||
local function notify(message)
|
||||
BeginTextCommandThefeedPost('STRING')
|
||||
AddTextComponentSubstringPlayerName(message)
|
||||
EndTextCommandThefeedPostTicker(false, false)
|
||||
end
|
||||
|
||||
exports('GetPlayerData', function()
|
||||
return PlayerData
|
||||
end)
|
||||
|
||||
exports('IsPlayerLoaded', function()
|
||||
return PlayerData ~= nil
|
||||
end)
|
||||
|
||||
exports('Notify', notify)
|
||||
|
||||
RegisterNetEvent('devx_core:client:playerData', function(data)
|
||||
PlayerData = data
|
||||
LocalPlayer.state:set('devxCharacterId', data.characterId, true)
|
||||
TriggerEvent('devx_core:client:playerLoaded', data)
|
||||
end)
|
||||
|
||||
CreateThread(function()
|
||||
while true do
|
||||
Wait(DevXConfig.PositionSaveIntervalMs)
|
||||
if PlayerData then
|
||||
local ped = PlayerPedId()
|
||||
if DoesEntityExist(ped) and not IsEntityDead(ped) then
|
||||
local coords = GetEntityCoords(ped)
|
||||
TriggerServerEvent('devx_core:server:updatePosition', {
|
||||
x = coords.x,
|
||||
y = coords.y,
|
||||
z = coords.z,
|
||||
heading = GetEntityHeading(ped)
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterCommand('coords', function()
|
||||
local ped = PlayerPedId()
|
||||
local coords = GetEntityCoords(ped)
|
||||
local text = ('vector4(%.2f, %.2f, %.2f, %.2f)'):format(
|
||||
coords.x, coords.y, coords.z, GetEntityHeading(ped)
|
||||
)
|
||||
print(text)
|
||||
notify(text)
|
||||
end, false)
|
||||
|
||||
RegisterCommand('unstuck', function()
|
||||
if not PlayerData then return end
|
||||
local spawn = DevXConfig.StreetSpawn
|
||||
SetEntityCoords(PlayerPedId(), spawn.x, spawn.y, spawn.z, false, false, false, false)
|
||||
SetEntityHeading(PlayerPedId(), spawn.heading)
|
||||
notify('Du wurdest zum Straßenstart teleportiert.')
|
||||
end, false)
|
||||
|
||||
RegisterNetEvent('devx_core:client:returnedToWorld', function()
|
||||
notify('Du wurdest in die öffentliche Welt zurückgesetzt.')
|
||||
end)
|
||||
Reference in New Issue
Block a user