30.03.2014, 19:09
Hello,
LINK 1: https://sampwiki.blast.hk/wiki/Scripting_Basics#global
pawn Код:
new FreeCar[MAX_PLAYERS] = INVALID_VEHICLE_ID; //this is a global variable, LINK 1.
OnPlayerConnect(playerid) FreeCar[playerid] = -1;
OnPlayerDisconnect(playerid) FreeCar[playerid] = -1;
//im setting the global variable to -1 so its invalid when a player connects, and disconnects, this should be stated when dealing with multiple players so it wont mess up between them...
if (strcmp("/freecar", cmdtext, true, 8) == 0) //thats ur cmd
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid,x,y,z);
FreeCar[playerid] = CreateVehicle(542,x,y,z,90,-1,-1,0); //here we are specifying that variable to this spawned car of this player by adding 'playerid' next to it
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
if (GetPlayerVehicleSeat(playerid) == 0 && FreeCar[playerid] != -1) //when the player exits the vehicle, and his state is as a driver and his car IS NOT equal to -1(as when he connected) this car gets removed :]
{
DestroyVehicle(vehicleid);
FreeCar[playerid] = -1; //then this sets the variable to -1 again so when he/she types the cmd again, the variable will be specified to the new spawned car.
return 1;
}
return 0;
}