MocroGunz Posted March 26, 2010 Share Posted March 26, 2010 i get bad argument error : function healcar(vehicle) local vehicle = getPedOccupiedVehicle(vehicle) outputChatBox('car fixed.', source) fixVehicle ( vehicle ) end setTimer( healcar, 500, 0 ) -- timer changes all vehicles fix to random every 0.5 sec. Link to comment
Callum Posted March 26, 2010 Share Posted March 26, 2010 You cannot set a timer outside of a function. try; function healcar(vehicle) for k, v in ipairs ( getElementsByType("player") ) do if ( isPedInVehicle(v) ) then local vehicle = getPedOccupiedVehicle(v) outputChatBox('car fixed.', v) fixVehicle ( vehicle ) end end end function startTimer() setTimer( healcar, 500, 0 ) -- timer changes all vehicles fix to random every 0.5 sec. end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), startTimer ) Note: looping through every player every 0.5 seconds can cause strain on the server. Link to comment
MocroGunz Posted March 26, 2010 Author Share Posted March 26, 2010 You cannot set a timer outside of a function. try; function healcar(vehicle) for k, v in ipairs ( getElementsByType("player") ) do if ( isPedInVehicle(v) ) then local vehicle = getPedOccupiedVehicle(v) outputChatBox('car fixed.', v) fixVehicle ( vehicle ) end end end function startTimer() setTimer( healcar, 500, 0 ) -- timer changes all vehicles fix to random every 0.5 sec. end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), startTimer ) Note: looping through every player every 0.5 seconds can cause strain on the server. This works but what can i do so it dont cause strain on the server Link to comment
x86 Posted March 26, 2010 Share Posted March 26, 2010 Please use setVehicleDamageProof instead using timers.. Realise: 128 players on the server, every 0.5 second 128 loops... Link to comment
Andre9977 Posted March 26, 2010 Share Posted March 26, 2010 Not to cause server overload you shall move frequent timers like that to the player's side. If code like that executes on the player's side the server doesn't receive extra load from that. And for many things that in SA-MP for example you use a workaround (healing the vehicle in a timer) can be avoided in MTA using a simple function (this case setVehicleDamageProof) Sebas, I don't think the timer would be much of a killer though, specially if we don't include any hard calculations or very thorough code there. I've had a timer looping through 200 online players every 500 milliseconds and the features were very essential for the gamemode (I'm talking SA-MP). 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