Help with car spawning and destroying
#1

I'm trying to do that when a player exit from his spawned vehicle with a menu, the vehicle get destroyed.. i did this:

Код:
public CreateVehiclePro(playerid, modelid)
{
DestroyVehicle(carspawned[playerid]);
carspawned[playerid] = CreateVehicle(modelid, X+6,Y,Z+1, Angle, random(127), random(127), -1);
PutPlayerInVehicle(playerid, carspawned[playerid], 0);
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{

	if(vehicleid == carspawned[playerid]){
	entercar[playerid] = 1;
	}
	else {
	entercar[playerid] = 0;
	}
	return 1;
}

public OnPlayerStateChange(playerid,newstate,oldstate)
{
  if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT)
	{
	cartimer[playerid] = SetTimerEx("DestroyVehiclePro",30000, false, "i", playerid);
	}
	if(newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT && entercar[playerid] != 0)
	{
	KillTimer(cartimer[playerid]);
	}
  return 1;
}

public DestroyVehiclePro(playerid)
{
DestroyVehicle(carspawned[playerid]);
return 1;
}
But some times the cars get destroyed with no reason

Thank you



Reply
#2

Could be one of the following:
  • It could have something to do with your 'cartimer', maybe it's not being killed properly.
  • When the player disconnects you need to reset the variables for the next player that is going to join
Hope that helped
Reply
#3

Quote:
Originally Posted by Micro [KDMR-Host.com
]
  • You can't set your unique playerid variables to 0 on reset as there is ID 0 (Set it to something like 552)
I don't understand this point, cuz he's using an array.

We need OnPlayerExitVehicle (or smth like that), to fix it i think.
By the way you dont need the OnPlayerEnterVehicle stuff (i guess), cause you will need to put all into OnPlayerExitVehicle, and if you don't enter the vehicle, you cant exit it (i hope you understand my point).
Reply
#4

Quote:
Originally Posted by DeathOnaStick
Quote:
Originally Posted by Micro [KDMR-Host.com
]
  • You can't set your unique playerid variables to 0 on reset as there is ID 0 (Set it to something like 552)
I don't understand this point, cuz he's using an array.
Sorry I confused myself, edited.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)