Help with car spawning and destroying - 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: Help with car spawning and destroying (
/showthread.php?tid=147953)
Help with car spawning and destroying -
[SsC11]MAVERIK - 15.05.2010
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
Re: Help with car spawning and destroying -
Paladin - 15.05.2010
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
Re: Help with car spawning and destroying -
DeathOnaStick - 15.05.2010
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).
Re: Help with car spawning and destroying -
Paladin - 15.05.2010
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.