Bierbuikje Posted May 6, 2011 Share Posted May 6, 2011 Hello, I have some questions about freezing a vehicle. I make a server and with a .map file I create vehicles. What I want is when the server starts all the vehicles should be frozen immediately. But how to do this? I know I can get the vehicle by the following line: local vehicle = getElementByID("vehicle") And I know I can freeze the vehicle with the following line: setVehicleFrozen(vehicle,true) But how to run this immediately when the server starts? Thanks a lot! Bierbuikje Link to comment
nowofresh Posted May 6, 2011 Share Posted May 6, 2011 addEventHandler("onClientResourceStart", getRootElement( ), function ( ) getAllVehicles = function ( ) local vehicles = getElementByID( "vehicle" ); return vehicles; end; setVehiclesFrozen = function ( ) for _,vehicle in pairs ( getAllVehicles ( ) ) do setVehicleFrozen( vehicle, true ); end; end; end ) Link to comment
Bierbuikje Posted May 6, 2011 Author Share Posted May 6, 2011 Thank you! =D But why did you use 'getAllVehicles'? According to the mta wiki that function doesn't exist. And what does the part 'for _,vehicle in pairs ( getAllVehicles ( ) )' mean? Link to comment
Castillo Posted May 6, 2011 Share Posted May 6, 2011 That could be a little annoying, since it will execute that function every time a resource starts. Link to comment
proracer Posted May 6, 2011 Share Posted May 6, 2011 Yes like Solidsnake said, just change getRootElement to resourceRoot / getResourceRootElement(getThisResource) Link to comment
Antibird Posted May 7, 2011 Share Posted May 7, 2011 In theory, if you do some manipulations to parent element, same is done to it's children. UNTESTED addEventHandler( "onResourceStart", resourceRoot, function() setVehiclesFrozen( root, true ) end ) resourceRoot and root are predefined variables. Have a look at MTA element tree explanation to make it clear what the code above do. 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