koragg Posted December 14, 2017 Share Posted December 14, 2017 (edited) It works as it should. I have constant 50 FPS (server's max) and don't get lags...but I still wanted to ask - is the below implementation badly done or it's ok to leave it like it is? function onResStart() setTimer(updatePJs, 300, 0) end addEventHandler("onResourceStart", resourceRoot, onResStart) function updatePJs() for i, player in ipairs(getElementsByType("player")) do local account = getPlayerAccount(player) if account and isGuestAccount(account) then if getElementData(player, "paintjob") then triggerClientEvent(root, "unloadVehiclePaintjob", resourceRoot, vehicle, tostring(getElementData(player, "paintjob"))) end return end if account and not isGuestAccount(account) then local vehicle = getPedOccupiedVehicle(player) local paintjob = getAccountData(account, "paintjob") or "NoPaintjob" setElementData(player, "paintjob", paintjob) if vehicle and paintjob then triggerClientEvent(root, "loadVehiclePaintjob", resourceRoot, vehicle, tostring(paintjob)) end end end end I can't make it work without the infinite timer but, still, I want to see what more experienced devs than me think about it Edited December 14, 2017 by koragg Link to comment
pa3ck Posted December 14, 2017 Share Posted December 14, 2017 In some scenarios you have no option but to use something like that. Although I see you're using elementData to check whether you'd need to load or unload the paintsjob. Element data somehow needs to be added / removed, right? When you add the elementData, why can't you just use the triggerClient/ServerEvent w/e side it is in and then load/unload? Link to comment
koragg Posted December 14, 2017 Author Share Posted December 14, 2017 (edited) 14 minutes ago, pa3ck said: In some scenarios you have no option but to use something like that. Although I see you're using elementData to check whether you'd need to load or unload the paintsjob. Element data somehow needs to be added / removed, right? When you add the elementData, why can't you just use the triggerClient/ServerEvent w/e side it is in and then load/unload? This function actually just makes sure that every player's vehicle is wearing the paintjob saved to that player's account, hence the infinite low timer. I load/unload the paintjob the way you mentioned in your 2nd question whenever a player clicks on some GUI stuff to select/change their PJ. But I couldn't figure out another way to keep all paintjobs synced with everyone else other than this one. The elementData is only used to transfer the account data to the client side. The check you're refering to is to see if a logged out player still has a paintjob and if so to remove it from their vehicle. Edited December 14, 2017 by koragg Link to comment
pa3ck Posted December 14, 2017 Share Posted December 14, 2017 Okay, so if I understand correctly, when a player logs in you can add an elementData from their accountData to save their paintjob. When somebody joins you can loop through all players and load the paintjobs client side based on their elementData which you have saved when they logged in. Use the event onPlayerLogout to remove elementData and trigger to every client to remove the paintjob. I guess that kinda does the same thing? Link to comment
koragg Posted December 14, 2017 Author Share Posted December 14, 2017 2 minutes ago, pa3ck said: Okay, so if I understand correctly, when a player logs in you can add an elementData from their accountData to save their paintjob. When somebody joins you can loop through all players and load the paintjobs client side based on their elementData which you have saved when they logged in. Use the event onPlayerLogout to remove elementData and trigger to every client to remove the paintjob. I guess that kinda does the same thing? Yeah, I was wondering if I should use 'onPlayerJoin' yesterday. Guess it will be more efficient that way. Link to comment
pa3ck Posted December 14, 2017 Share Posted December 14, 2017 Or you can use onClientResourceStart client side, so you can skip on a triggerClientEvent. 1 Link to comment
koragg Posted December 14, 2017 Author Share Posted December 14, 2017 4 minutes ago, pa3ck said: Or you can use onClientResourceStart client side, so you can skip on a triggerClientEvent. I'll try this. Doing it 'onPlayerJoin' gives a bug which I'm lazy to investigate and fix Link to comment
Fist Posted December 14, 2017 Share Posted December 14, 2017 34 minutes ago, koragg said: I'll try this. Doing it 'onPlayerJoin' gives a bug which I'm lazy to investigate and fix or just use "onPlayerLogin" Link to comment
koragg Posted December 14, 2017 Author Share Posted December 14, 2017 1 hour ago, Fist said: or just use "onPlayerLogin" Won't do because that would mean that paintjobs only get updated when someone logs in. What if i join alone and two guests join after me. They won't see my paintjob as the function wouldn't have been triggered because there was no login to trigger 'onPlayerLogin'. Link to comment
Moderators IIYAMA Posted December 14, 2017 Moderators Share Posted December 14, 2017 onClientResourceStart > triggerServerEvent > get all the paintjobs from a table > triggerClientEvent 1 Link to comment
koragg Posted December 15, 2017 Author Share Posted December 15, 2017 Seems fine for now. And avoided one trigger, thanks for the tips guys 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now