I’m digging through some unfinished, public code. What I see on server side doesn’t make sense to me. Isn’t this starting when the server start and no one even joined yet? Or is this being triggered every time someone joins?
But maybe I’m just unexperienced and “know nothing”. Can someone confirm/deny my believes?
Edit.: This is on server side.
AddEventHandler('onResourceStart', function(resourceName)
if (GetCurrentResourceName() ~= resourceName) then return end
for _, src in ipairs(GetPlayers()) do
TriggerEvent("createPlayer")
end
end)
My best guess is that this is being run somewhere late as in when there are already players on the server and you’re just starting the resource. Then it would make sense to create new players for each player in the server but the way that code works is very questionable…
Personally, I’d not use that. Maybe I’m the unexperienced “know nothing” and the guy who wrote it is a genius, who knows lol
If this is on the client, then this only starts right as the client loads in, so no, this would not be useless.
But if it’s on the server, then yeah, it might very well be “useless”. Unless however, it’s there to fix any issues that arise if someone decides to restart the script on a live server. Or it could be a leftover from development (so they didn’t have to restart the server every time they made a change).
But regardless, I would agree with @sniper45yt, the code does look very “questionable”. Why ipairs and not pairs? And why no params to the “createPlayer” event? What is this even supposed to do?
This is on server side. And (re)starting this resource mid session would be ridiculous as this is a base of a DM framework.
So, I guess the code is just retarded. This is not the only questionable code I found in there, but just couldn’t understand why anyone would write… This.
So, thanks for the response. I thought it looked so stupid, it had have to have “some function” in the end. It’s like you’re sitting during early AM hours over your code, swearing what’s wrong, just to figure out in the morning you forgot a coma. So, I was unsure and was curious what others might think.
Oh yeah, under the circumstances you describe this would be useless. Might be a good idea to steer away from the framework if this isn’t the only questionable code.