All vehicles Respawn
#1

Alright guys I really can't figure this out. Well I ask you clearly, what I want is a Rcon admin command, using strcmp which is /respawnall and all the un occupied cars will be respawned. Well I found an old thread about it but I really can't get it right. I want it in strcmp. I started up with the strcmp command then, IsPlayerAdmin but I got stuck after that. It will be better if someone could provide the full code to me. I always get loose identation... Any help is much appreciated.
Reply
#2

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp(cmdtext, "/respawnall", true))
    {
        if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You need to be RCON admin to use this command.");
        for (new v = 1; v != MAX_VEHICLES; ++v)
        {
            if (!GetVehicleModel(v)) continue; // vehicle doesn't exist, skip it..
            if (!IsVehicleOccupied(v)) SetVehicleToRespawn(v); // vehicle is not occupied, respawn it..
        }
        return 1;
    }
    return 0;
}

IsVehicleOccupied(vehicleid)
{
    foreach(new i : Player)
    {
        if (IsPlayerInVehicle(i, vehicleid) return 1;
    }
    return 0;
}
I used foreach because it's faster since it loops through connected players only.
I'm going to say this - you shouldn't be using strcmp for commands but ZCMD or y_commands because they're faster.

Last, getting warnings about loosing indentation does not mean the code is wrong. All you have to do is indent the code properly: https://sampwiki.blast.hk/wiki/Errors_Li...se_indentation
Reply
#3

Alright thanks man. The help is much appreciated. +Rep.
Reply
#4

@Konstantinos
You should loop only once through the players and mark these vehicles in an array as used and than loop through the vehicles and respawn the valid and unoccupied ones
Reply
#5

Thanks Nero_3D. In a second thought, it loops more times that it should.

Here it is in case Sting. or someone else wants it:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp(cmdtext, "/respawnall", true))
    {
        if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You need to be RCON admin to use this command.");
       
        new
            bool: occupied_vehicle[MAX_VEHICLES char];
       
        foreach(new i : Player) occupied_vehicle{GetPlayerVehicleID(i)} = true;
        for (new v = 1; v != MAX_VEHICLES; ++v)
        {
            if (!GetVehicleModel(v) || occupied_vehicle{v}) continue;
            SetVehicleToRespawn(v);
        }
        return 1;
    }
    return 0;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)