Respawn all empty cars
#1

I got this command for admins which calls this Stock, When i do it, even if a player is in the car it still respawns the car. It's only suppose to respawn cars that people are not in. Whats wrong with the code? I don't see anything wrong with it

pawn Код:
if(strcmp(cmd, "/resallemptycars", true) == 0) {
        if(PlayerInfo[playerid][pAdmin] >= 3) {
            RespawnAllEmptyCars();
            SendClientMessageToAll(COLOR_RED, "[ADMIN] An Admin Has respawned all the empty cars");
            return 1;
        }
    }
pawn Код:
stock RespawnAllEmptyCars()
{
    for(new i = 0; i < GetMaxPlayers(); i++)
        for(new v;v<MAX_VEHICLES;v++)
            if(!IsPlayerInVehicle(i, v))SetVehicleToRespawn(v);
}
Reply
#2

Try This:

Код:
	if(strcmp(cmd, "/respawnallcars", true) == 0 || strcmp(cmd, "/carreset", true) == 0) 
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(PlayerInfo[playerid][pAdmin] < 4)
			{
			    SendClientMessage(playerid, COLOR_GRAD1, "** you are not authorized to use that command!");
			    return 1;
			}
			new bool:unwanted[CAR_AMOUNT];
			for(new player=0; player<MAX_PLAYERS; player++)
     		{
            	if(IsPlayerInAnyVehicle(player)) { unwanted[GetPlayerVehicleID(player)]=true; }
     		}
			for(new car = 1; car <= 1850; car++)
			{
				if(!unwanted[car]) SetVehicleToRespawn(car);
			}
			format(string, sizeof(string), "SERVER: All unused cars respawned by %s.", sendername);
			BroadCast(COLOR_WHITE,string);
			format(string, sizeof(string), "[ADMIN]: %s has Respawned All Cars.", sendername);
			ABroadCast(COLOR_LIGHTRED,string, 5);
			GameTextForAll("~w~Every Unused Car ~n~~g~Respawned!",5000,1);
			new y, m, d;
			new h,mi,s;
			getdate(y,m,d);
			gettime(h,mi,s);
			format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s Has Respawned All Unused Cars",d,m,y,h,mi,s,sendername);
			AdminLog(string);
		}
		return 1;
	}
Reply
#3

Try this. Add IsVehicleInUse somewhere and replace RespawnAllEmptyCars with my function.
pawn Код:
stock IsVehicleInUse(vid)
{
    for(new i = 0; i < GetMaxPlayers(); i++)
    {
    if(IsPlayerInVehicle(i, vid)) return 1;
    }
    return 0;
}

stock RespawnAllEmptyCars()
{
    for(new i=0; i < 700; i++)
    {
    if(!IsVehicleInUse(i)) SetVehicleToRespawn(i);
    }
}
Reply
#4

You must check if player is in car or as passenger as an 'if' before doing any events.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)