Car Destory Help X2 (Different) -
RandomDude - 12.07.2013
If a person spawns a car then gets out and spawns another one , one car stays and it causes lag... Is there a way when the player enters another vehicle his old one gets destroyed...?
Thanks
Re: Car Destory Help X2 (Different) -
RandomDude - 12.07.2013
............
Re: Car Destory Help X2 (Different) -
kristo - 12.07.2013
pawn Код:
new lastcar[MAX_PLAYERS];
native IsValidVehicle(vehicleid);
public OnPlayerConnect(playerid)
{
lastcar[playerid] = -1;
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if (newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT)
{
if (IsValidVehicle(lastcar[playerid])) DestroyVehicle(lastcar[playerid]);
lastcar[playerid] = GetPlayerVehicleID(playerid);
}
else if (newstate == PLAYER_STATE_ONFOOT) lastcar[playerid] = -1;
return 1;
}
I also added some extra checks that aren't needed but make it a bit safer.
Re: Car Destory Help X2 (Different) -
RandomDude - 12.07.2013
Next time PAWN /PAWN please
Thanks!
Re: Car Destory Help X2 (Different) -
RandomDude - 12.07.2013
It doesn't work.
Re: Car Destory Help X2 (Different) -
JimmyCh - 12.07.2013
pawn Код:
if(pVehicles[playerid] != -1)
{
for(new i; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(IsPlayerInVehicle(i, pVehicles[playerid])) DestroyVehicle(pVehicles[playerid]);
}
}
}
DestroyVehicle(pVehicles[playerid]);
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, ang);
pVehicles[playerid] = CreateVehicle(vid, x, y, z, ang, -1, -1, 0);
vVW = GetPlayerVirtualWorld(playerid);
vINT = GetPlayerInterior(playerid);
SetVehicleVirtualWorld(pVehicles[playerid], vVW);
LinkVehicleToInterior(pVehicles[playerid], vINT);
PutPlayerInVehicle(playerid, pVehicles[playerid], 0);
Use those.
Re: Car Destory Help X2 (Different) -
kristo - 12.07.2013
Quote:
Originally Posted by JimmyCh
pawn Код:
if(pVehicles[playerid] != -1) { for(new i; i < MAX_PLAYERS; i++) { if(IsPlayerConnected(i)) { if(IsPlayerInVehicle(i, pVehicles[playerid])) DestroyVehicle(pVehicles[playerid]); } } } DestroyVehicle(pVehicles[playerid]); GetPlayerPos(playerid, x, y, z); GetPlayerFacingAngle(playerid, ang); pVehicles[playerid] = CreateVehicle(vid, x, y, z, ang, -1, -1, 0); vVW = GetPlayerVirtualWorld(playerid); vINT = GetPlayerInterior(playerid); SetVehicleVirtualWorld(pVehicles[playerid], vVW); LinkVehicleToInterior(pVehicles[playerid], vINT); PutPlayerInVehicle(playerid, pVehicles[playerid], 0);
Use those.
|
I can see a mistake here:
pawn Код:
for(new i; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(IsPlayerInVehicle(i, pVehicles[playerid])) DestroyVehicle(pVehicles[playerid]);
}
}
}
I believe you wanted to destroy the car if nobody is using it, but it does the opposite.
pawn Код:
new found;
for(new i; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(IsPlayerInVehicle(i, pVehicles[playerid]))
{
found = 1;
break;
}
}
}
}
if (!found) DestroyVehicle(pVehicles[playerid]);
Edit: Really bad tabbing :S
Re: Car Destory Help X2 (Different) -
RandomDude - 13.07.2013
Still none work.
Basically what I want is...
If a player spawns a vehicle then spawns another one.. One vehicle stays I want that vehicle destroyed
How can I do this?
Re: Car Destory Help X2 (Different) -
Konstantinos - 13.07.2013
Quote:
Originally Posted by kvann
pawn Код:
new lastcar[MAX_PLAYERS];
native IsValidVehicle(vehicleid);
public OnPlayerConnect(playerid) { lastcar[playerid] = -1; return 1; }
public OnPlayerStateChange(playerid, newstate, oldstate) { if (newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT) { if (IsValidVehicle(lastcar[playerid])) DestroyVehicle(lastcar[playerid]); lastcar[playerid] = GetPlayerVehicleID(playerid); } else if (newstate == PLAYER_STATE_ONFOOT) lastcar[playerid] = -1; return 1; }
I also added some extra checks that aren't needed but make it a bit safer.
|
That should work, but an advise. Check if the vehicleid the player is in is not the one lastcar[playerid] "holds", because it will delete the player's current vehicle.
EDIT: So when he spawns a second, to destroy the first one. Then go to your command and destroy the vehicle. Store the vehicleid when you create the vehicle.
Re: Car Destory Help X2 (Different) -
RandomDude - 13.07.2013
Quote:
Originally Posted by _Zeus
That should work, but an advise. Check if the vehicleid the player is in is not the one lastcar[playerid] "holds", because it will delete the player's current vehicle.
|
That does not work