/vrespawn
#1

Since I'm fairly new to loops, I wanted to make a /vrespawn that respawns all unoccupied vehicles.


Here is the code:

pawn Код:
dcmd_vrespawn(playerid,params[])
{
    #pragma unused params
    if(pi[playerid][admin] <= 0) return 0;
    if(sscanf(params,"u"))
    {
    for(new 1 = 0; i < MAX_VEHICLES; i++)
    {
    SendClientMessageToAll(COLOUR_YELLOW,"All unoccupied vehicles has been respawned");
    SetVehicleToRespawn(i);
    return 1;
    }
    return 1;
}
Errors:

Код:
C:\GTASER~1\GAMEMO~1\MyDm.pwn(1860) : error 001: expected token: "-identifier-", but found "-integer value-"
C:\GTASER~1\GAMEMO~1\MyDm.pwn(1862) : error 008: must be a constant expression; assumed zero
C:\GTASER~1\GAMEMO~1\MyDm.pwn(1863) : error 001: expected token: ")", but found ";"
C:\GTASER~1\GAMEMO~1\MyDm.pwn(1863) : error 036: empty statement
Could someone tell me what I've done wrong?
Reply
#2

Try:

pawn Код:
for(new i = 0; i < MAX_VEHICLES; i++)
Reply
#3

No, since vehicle ID's start with 1, it should be;
pawn Код:
for(new i = 1; i < MAX_VEHICLES; i++)
Reply
#4

Lol.. I actually saw the error now: for(new i = 0; i < MAX_VEHICLES; i++) I wrote new 1..


Thanks for the help!



EDIT:
pawn Код:
dcmd_vrespawn(playerid,params[])
{
    #pragma unused params
    if(pi[playerid][admin] <= 0) return 0;
    if(sscanf(params,"u"))
    {
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
    SendClientMessageToAll(COLOUR_YELLOW,"All unoccupied vehicles has been respawned");
    SetVehicleToRespawn(i);
    return 1;
    }
    }
    return 1;
}
Thats the code now.. The ClientMessage is being sent, but the vehicles doesnt respawn. Whats the problem now?
Reply
#5

I don't mean to bump, but if I don't, this topic will probably die.
Reply
#6

pawn Код:
dcmd_vrespawn(playerid,params[])
{
    #pragma unused params
    if(pi[playerid][admin] <= 0) return 0;
    if(sscanf(params,"u"))
    {
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
    SetVehicleToRespawn(i);
    }
    SendClientMessageToAll(COLOUR_YELLOW,"All unoccupied vehicles has been respawned");
    }
    return 1;
}
Reply
#7

As I said, vehicle ID's start with 1, so

pawn Код:
for(new i = 1; i < MAX_VEHICLES; i++)
Reply
#8

Oh well, whatever. Even I learned something today.
Reply
#9

Quote:
Originally Posted by Hiddos
Посмотреть сообщение
Oh well, whatever. Even I learned something today.
Same here.
Reply
#10

pawn Код:
dcmd_vrespawn(playerid, params[]) {
    #pragma unused params
    if(pi[playerid][admin] > 0) {
        new bool:VehicleUsed[MAX_VEHICLES], i;
        for( ; i != MAX_PLAYERS; i++) {
            if(IsPlayerInAnyVehicle(i)) {
                VehicleUsed[GetPlayerVehicleID(playerid)] = true;
            }
        }
        for(i = 1; i != MAX_VEHICLES; i++) {
            if(VehicleUsed[i] == false) {
                SetVehicleToRespawn(i);
            }
        }
        return SendClientMessageToAll(COLOUR_YELLOW,"All unoccupied vehicles has been respawned");
    }
    return 0;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)