Jump to content

[help] 0.5 sec repair


MocroGunz

Recommended Posts

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
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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...