Respawn All Empty Cars
#1

Hello,

I have a script for respawn all cars and i wil a script for empty cars..
I have this script: (And only for RCON )

Code:
 if(!strcmp(cmdtext, "/respawncar", true))
    {
        for(new i = 0; i < MAX_VEHICLES; i++)
        {
         SetVehicleToRespawn(i);
        }
        return 1;
     }
Thanks
Reply
#2

Code:
RespawnEmptyCars();
public RespawnEmptyCars()
{
for(new i=0; i<MAX_VEHICLES; i++)
{
for(new pl = 0; pl<MAX_PLAYERS; pl++)
{
if(IsPlayerConnected(pl))
{
if(!IsVehicleInUse(i))//if(!IsPlayerInVehicle(pl, i))
{
SetVehicleToRespawn(i);
}
}
}
}
}
Edit:
Code:
stock IsVehicleInUse(vehicleid)
{
    for(new i=0; i<GetMaxPlayers(); i++)
    {
        if(IsPlayerConnected(i))
        {
            if(GetPlayerVehicleID(i) == vehicleid)
            return true;
        }
    }
    return false;
}
you need both to work
Reply
#3

Not work or what is the command? /RespawnEmptyCars? (And i have logged in in rcon....)
Reply
#4

Code:
	if (strcmp(cmdtext, "/respawncars", true) == 0)
	{
	if(IsPlayerAdmin(playerid))
	{
	RespawnEmptyCars();
	}
	else
	{
	SendClientMessage(playerid,COLOR_WHITE,"Only rcon admins can use this command");
	}
	return 1;
	}
Reply
#5

I hope you've re-defined MAX_VEHICLES and MAX_PLAYERS to the correct amounts.

pawn Code:
stock SetEmptyVehiclesToRespawn()
{
    new bool:activeveh[MAX_VEHICLES + 1], tempveh;

    for(new i; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            tempveh = GetPlayerVehicleID(i);
            if(tempveh != INVALID_VEHICLE_ID)
            {
                activeveh[tempveh] = true;
            }
        }
    }

    for(new v = 1; v < (MAX_VEHICLES + 1); v++)
    {
        if(!activeveh[v])
        {
            SetVehicleToRespawn(v);
        }
    }

    return 1;
}
pawn Code:
if(strcmp(cmdtext, "/respawncars", true) == 0)
{
    if(IsPlayerAdmin(playerid))
    {
        SetEmptyVehiclesToRespawn();
        return 1;
    }
    else return SendClientMessage(playerid, COLOR_WHITE, "Only rcon admins can use this command");
}
Edit: Sorry, had a bug in the code. I totally forgot that vehicle IDs start from 1.
Reply
#6

TY ALL
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)