FuriouZ Posted March 9, 2014 Posted March 9, 2014 Hello I have question What event should i use to check player data ? I think theese are wrong ? I mean, will they lag ? onClientRender onClientPreRender For example i got this function: -- addEventHandler("onClientRender", root, addEventHandler("onClientPreRender", root, function() local Arena = getElementData(player,"Arena"); if (Arena == "Stuntage" ) then setPedCanBeKnockedOffBike(localPlayer, false) else setPedCanBeKnockedOffBike(localPlayer, true) end end) I found another way setTimer But i thing it will lag, or not ? or: setTimer( function() local Arena = getElementData(player,"Arena"); if (Arena == "Stuntage" ) then setPedCanBeKnockedOffBike(localPlayer, false) else setPedCanBeKnockedOffBike(localPlayer, true) end end,5000,0) Wich one will be better ? Or should i use someting else ? Homepage @ http://rageresources.blogspot.com/ Offical Facebook @ https://www.facebook.com/pages/Rage-Scr ... fref=photo
Dealman Posted March 9, 2014 Posted March 9, 2014 No, using a timer would be much more efficient. onClientRender and onClientPreRender both trigger their attached function with every frame. So unless you need the function to be run 30-60 times per second, don't use those. Should read the Warning I added to those events in the wiki, to prevent wrong usage of those If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.
ixjf Posted March 9, 2014 Posted March 9, 2014 Hello I have question What event should i use to check player data ? I think theese are wrong ? I mean, will they lag ? onClientRender onClientPreRender For example i got this function: -- addEventHandler("onClientRender", root, addEventHandler("onClientPreRender", root, function() local Arena = getElementData(player,"Arena"); if (Arena == "Stuntage" ) then setPedCanBeKnockedOffBike(localPlayer, false) else setPedCanBeKnockedOffBike(localPlayer, true) end end) I found another way setTimer But i thing it will lag, or not ? or: setTimer( function() local Arena = getElementData(player,"Arena"); if (Arena == "Stuntage" ) then setPedCanBeKnockedOffBike(localPlayer, false) else setPedCanBeKnockedOffBike(localPlayer, true) end end,5000,0) Wich one will be better ? Or should i use someting else ? This is very inefficient - You only need to call setPedCanBeKnockedOffBike once. I used to know how to code, but then I took an arrow in the knee. Project Redivivus - Remaking Old School MTA With New Code MTA 0.6 Nightly 1 released
Moderators Citizen Posted March 9, 2014 Moderators Posted March 9, 2014 This is very inefficient - You only need to call setPedCanBeKnockedOffBike once. No. Because the player can switch between arenas. So put this code in a function and call it everytime the player choose/select an arena: function updateCanBeKnockedOffBike() local arena = getElementData(localPlayer, "Arena") if arena == "Stuntage" then setPedCanBeKnockedOffBike(localPlayer, false) else setPedCanBeKnockedOffBike(localPlayer, true) end end Has to be on the client side ofc. The rEvolution is coming ...
ixjf Posted March 9, 2014 Posted March 9, 2014 You just repeated what I said.? I used to know how to code, but then I took an arrow in the knee. Project Redivivus - Remaking Old School MTA With New Code MTA 0.6 Nightly 1 released
Moderators Citizen Posted March 9, 2014 Moderators Posted March 9, 2014 You just repeated what I said.? Not at all, you wanted him to do this code only once (then with onClientResourceStart) but in fact, he surely want it to be executed as many times the player will select a first/new arena. The rEvolution is coming ...
ixjf Posted March 9, 2014 Posted March 9, 2014 You misunderstood it - "call it once" as in call it whenever needed, not every frame. I used to know how to code, but then I took an arrow in the knee. Project Redivivus - Remaking Old School MTA With New Code MTA 0.6 Nightly 1 released
FuriouZ Posted March 9, 2014 Author Posted March 9, 2014 This is very inefficient - You only need to call setPedCanBeKnockedOffBike once. No. Because the player can switch between arenas. So put this code in a function and call it everytime the player choose/select an arena: function updateCanBeKnockedOffBike() local arena = getElementData(localPlayer, "Arena") if arena == "Stuntage" then setPedCanBeKnockedOffBike(localPlayer, false) else setPedCanBeKnockedOffBike(localPlayer, true) end end Has to be on the client side ofc. Thank you ! Homepage @ http://rageresources.blogspot.com/ Offical Facebook @ https://www.facebook.com/pages/Rage-Scr ... fref=photo
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