12.07.2013, 16:25
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
Thanks
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;
}
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);
pawn Код:
|
for(new i; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(IsPlayerInVehicle(i, pVehicles[playerid])) DestroyVehicle(pVehicles[playerid]);
}
}
}
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]);
pawn Код:
|