how to destroy created vehicles?
#1

hi,

this is all my code that creates vehicles with a command in game.
The vehicles should be destroyed after they die (after they explode or get destroyed) but the problem is they are not destroyed the vehicles just respawn where they have been created with the command.
Also all vehicles that had been created with the command should be destroyed after a certain time using a loop, also there is a bug i think.
I post my current code and i hope some of you guys can tell me where my bugs are
thx in advance

pawn Код:
new RespawnedVehicle[MAX_PLAYERS];

//OnPlayerCommand
if (strcmp("/carrespawn", cmdtext, true) == 0)//the command
{
    new playerState = GetPlayerState(playerid);
    if(playerState == PLAYER_STATE_DRIVER)return SendClientMessage(playerid, 0xFF0000FF, "You are already in a vehicle!");
    DestroyVehicle(RespawnedVehicle[playerid]);
    RWRespawnedVehicle[playerid]=-1;
    new Float:Xc, Float:Yc, Float:Zc;
    GetPlayerPos(playerid, Xc, Yc, Zc);
    RespawnedVehicle[playerid] = CreateVehicle(422, Xc+3, Yc+3, Zc+3, 0.0,-1,-1, 600);
    PutPlayerInVehicle(playerid,RespawnedVehicle[playerid],0);
    return 1;
}

//OnVehicleDeath
for(new rws = 0; rws < sizeof(RespawnedVehicle); rws++)
{
    if(RespawnedVehicle[rws]==vehicleid)DestroyVehicle(RespawnedVehicle[rws]);
    RespawnedVehicle[rws]=-1;
}

//the loop i use in a time to destroy all created vehicles after a certain time
for(new rws; rws < sizeof(RespawnedVehicle); rws++)
{
    DestroyVehicle(RespawnedVehicle[rws]);
    RespawnedVehicle[rws]=-1;
}
Reply
#2

You need to loop playerids, as you save the vehicle id to a player variable.

Try this:

Код:
for(new rws; rws < MAX_PLAYERS; rws++)
Reply
#3

Quote:
Originally Posted by warcodes_
Посмотреть сообщение
You need to loop playerids, as you save the vehicle id to a player variable.

Try this:

Код:
for(new rws; rws < MAX_PLAYERS; rws++)
That's the exact same loop....he is doing sizeof(RespawnedVehicle), the size of the array is MAX_PLAYERS (default 500), so that isn't doing anything differently and won't help the issue. So please ensure you are actually providing useful information before posting.

I can't really see what's wrong myself, I've had issues with OnVehicleDeath so you could try OnVehicleSpawn
Reply
#4

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
That's the exact same loop....he is doing sizeof(RespawnedVehicle), the size of the array is MAX_PLAYERS (default 500), so that isn't doing anything differently and won't help the issue. So please ensure you are actually providing useful information before posting.

I can't really see what's wrong myself, I've had issues with OnVehicleDeath so you could try OnVehicleSpawn
Oh, i just noticed he is looping the same variable.

Now how stupid did my reply just sound now..thank you for pointing that out, i will try and actually look at the code next time, instead of jumping at my first discovery.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)