Is it possible to make server side threads so that I can have the server poll users for a information every x seconds?
As it stands I know its possible to have the data come in from the client side every x seconds, but I’d rather have a more synchronised time this is done, so I know the data is as ‘fresh’ as possible without being a resource drain.
If you are triggering the client side method in the timeout function it should be fine.
I haven’t made code that does this myself but here’s an example from EssentialMode that is used to update the player money.
-- Function to update player money every 60 seconds.
local function savePlayerMoney()
SetTimeout(60000, function()
TriggerEvent("es:getPlayers", function(users)
for k,v in pairs(users)do
MySQL:executeQuery("UPDATE users SET `money`='@value' WHERE identifier = '@identifier'",
{['@value'] = v.money, ['@identifier'] = v.identifier})
end
end)
savePlayerMoney()
end)
end
savePlayerMoney()