SA-MP Forums Archive
Vehicles States? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Vehicles States? (/showthread.php?tid=97692)



Vehicles States? - almighty - 16.09.2009

hi... again... xD, im trying to make an engine on off command for vehicles and i'd like to know if theres a way to make some states (like ON OFF) to set to each vehicle.....



Re: Vehicles States? - Backwardsman97 - 16.09.2009

Sure.

pawn Код:
new bool:EngineRunning[MAX_VEHICLES];
new OldVehicle[MAX_PLAYERS];

public OnPlayerStateChange(playerid,newstate,oldstate)
{
   if(newstate == 2)
   {
     new vehi = GetPlayerVehicleID(playerid);
     OldVehicle[playerid] = vehi;
     EngineRunning[vehi] = true;
   }
   if(newstate == 1 && oldstate == 2)
   {
     EngineRunning[OldVehicle[playerid]] = false;
   }
   return 1;
}
I don't think GetPlayerVehicleID will work when his new state equals on foot so I made a variable to store his last vehicle. That should work though. Edit: I think you mean to turn vehicles on and off. This will just store if someone is in it. Shit...


Re: Vehicles States? - almighty - 16.09.2009

yea i mean to turn the engine on of... but i thinkg that code gave me the solution ^^... I didn't knew how to put certains "states" to the vehicles and you just gave me the idea.... thx....


Re: Vehicles States? - Donny_k - 16.09.2009

pawn Код:
public OnPlayerStateChange( playerid, newstate, oldstate )
{
  if ( newstate == PLAYER_STATE_DRIVER ) TogglePlayerControllable( playerid, false );
  return 1;
}

//wherever you want to start it, say a keypress or a command
TogglePlayerControllable( playerid, true );
This will freeze the player every time he gets in a vehicle as the driver until you fire the command or the keypress which you want to start the vehicle again. There is no need to use variables or whatever here IMO as you use the state like you would the variable anyway.

Ofcourse this may conflict somewhere due to commands and features I don't know about (your script) but a quick fix could be made I'm sure.