Hey, i got a global variable called currentTeam
If the player joins (serverside), it does
currentTeam = 'groove' --default team
TriggerEvent('gw:teamGet', source, function(team)
if team == 'groove' then
currentTeam = 'groove'
elseif team == 'ballas' then
currentTeam = 'ballas'
else
currentTeam = currentTeam
end
end)
that works fine!
but If I call the variable in client side
RegisterCommand('currentTeam', function()
local source = GetPlayerServerId(PlayerId())
TriggerServerEvent('gw:teamCheck', source)
print(currentTeam)
end)
function getPlayerTeam(identifier, callback)
if identifier ~= nil and type(identifier) == "string" then
MySQL.Async.fetchAll("SELECT team FROM team WHERE identifier = @identifier", {["@identifier"] = identifier},
function (result)
if result[1] then callback(result[1].team)
else callback(nil) end
end)
else
print("Error occurred while checking existance user, missing parameter or incorrect parameter: identifier")
end
end
RegisterCommand('getTeam', function(source)
getPlayerTeam(GetPlayerIdentifier(source, 0), function(team)
print("Your TEAM: "..team)
end)
end)
that is server sided, it works perfectly.
But if I try this in client side, team == nil value âŚ
RegisterNetEvent('gw:teamCheck')
AddEventHandler('gw:teamCheck', function(source)
TriggerEvent('gw:teamGet', source, function(team)
if team == 'groove' then
currentTeam = 'groove'
elseif team == 'ballas' then
currentTeam = 'ballas'
else
currentTeam = team
end
end)
end)
so almost workingâŚ
If I call the event, the print is sent with the right team
currentTeam = ''
-- Event to get variable currentTeam in client side
RegisterNetEvent('gw:currentTeamSend')
AddEventHandler('gw:currentTeamSend', function(currentTeam)
currentTeam = currentTeam
print("CurrentTeam:"..currentTeam)
end)
server
RegisterNetEvent('callTeam:currentTeam')
AddEventHandler('calTeam:currentTeam', function()
TriggerClientEvent('getTeam:currentTeam',-1,currentTeam)
end)
client
currentTeam = {}
RegisterNetEvent('getTeam:currentTeam')
AddEventHandler('getTeam:currentTeam', function(currentTeam)
currentTeam = currentTeam
end)
RegisterCommand('currentTeam', function()
TriggerServerEvent('callTeam:currentTeam')
Wait(100)--maybe useless just to let the time for value returning
print(currentTeam)
end)