Jump to content

Help! with car start/stop script


Guest James1

Recommended Posts

Posted

function carStart ( commandName, playerSource ) 
        local theVehicle = getPlayerOccupiedVehicle ( playerSource ) 
        local theDriver = getVehicleController ( theVehicle ) 
        local chance = { 1, 2 }  
        if ( theDriver == playerSource ) then 
                local enginestate = getVehicleEngineState( theVehicle ) 
                if( enginestate == true ) then 
                        outputChatBox( "The vehicle is already on.", playerSource, 0, 255, 0 ) 
                else 
                        setTimer( setVehicleEngineState ( theVehicle, true ), 2000, 1 ) 
                        local success = math.rand( 1, #chance ) 
                        if( success == 1 ) then 
                                setTimer( setVehicleEngineState ( theVehicle, true ), 2000, 1 ) 
                                setTimer( call( getThisResource(), "sendLocalDoAction", "The vehicle's engine starts.", sourcePlayer ) ) 
                        elseif( success == 2 ) then 
                                call( getThisResource(), "sendLocalMeAction", "attempts to turn on their vehicle.", sourcePlayer ) 
                                setTimer( call( getThisResource(), "sendLocalDoAction", "The vehicle does not start.", sourcePlayer ) ) 
                        end 
                end  
        else 
                outputChatBox ( "You are not the driver.", playerSource, 125, 125, 125 ) 
        end 
end 
  
addCommandHandler ("startcar", carStart) 
  
------------Car-Stop-------------- 
  
function carStop ( commandName, playerSource ) 
        local theVehicle = getPlayerOccupiedVehicle ( playerSource ) 
        local theDriver = getVehicleController ( theVehicle )  
        if ( theDriver == playerSource ) then 
                local enginestate = getVehicleEngineState( theVehicle ) 
                if( enginestate == false ) then 
                        outputChatBox( "The vehicle is already off.", playerSource, 255, 0, 0 ) 
                else 
                        setVehicleEngineState( theVehicle, false ) 
                        call( getThisResource(), "sendLocalMeAction", "turns their engine off.", playerSource ) 
                end  
        else 
                outputChatBox ( "You are not the driver.", playerSource, 125, 125, 125 ) 
        end 
end 
  
addCommandHandler ("stopcar", carStop) 
  
---------------------------------- 
  

It just tells me You are not the driver. Also, I get nil values for local enginestate = getVehicleEngineState ( theVehicle )

please help me fix any errors you see! thanks[/code]

Posted

Wrong section. Also, the problem appears to be that you have written the arguments to the function the wrong way. it's Source, Command, Argument 1, Arg. 2, etc, not Command, source.

  • Recently Browsing   0 members

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