Jump to content

Freeze a vehicle?


Recommended Posts

Posted

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

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

Posted

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?

Posted

That could be a little annoying, since it will execute that function every time a resource starts.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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.

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