/respawncars problem
#1

My codes:
Код:
CMD:respawncars(playerid, params[])
{
	if (PlayerInfo[playerid][pAdmin] >= 2)
	{
		new string[128], radius;
		if(sscanf(params, "d", radius)) return SendClientMessageEx(playerid, COLOR_WHITE, "Tip: /respawncars [radius]");

		if(radius < 1 || radius > 500)
		{
			SendClientMessageEx(playerid, COLOR_WHITE, "Radius must be higher than 0 and lower than 500!");
			return 1;
		}
		RespawnNearbyVehicles(playerid, radius);
		format(string, sizeof(string), "You have respawned all vehicles within a radius of %d.", radius);
		SendClientMessageEx(playerid, COLOR_GREY, string);
	}
	else
	{
		SendClientMessageEx(playerid, COLOR_GRAD1, "You are not authorized to use that command!");
	}
	return 1;
}
How to make something like:
/respawncars will respawn every cars in San Andreas that means i don't want the radius.

And how to make something like if i do /respawncars while someone in car then that car won't respawn. that mean:

/respawncars will just respawn which car is not using.
Reply
#2

pawn Код:
command(respawnvehicles, playerid, parms[])
{
    if (PlayerInfo[playerid][pAdmin] >= 2)
    {
        for(new v = 0; v < MAX_VEHICLES; v++)
        {
            SetVehicleToRespawn(v);
        }
    }
    else return SendClientMessage(playerid, GREY, AdminOnly);
    return 1;
}
??
Reply
#3

if someone is driving car it wont destroy?
Reply
#4

I ain't got time to create a command right now so I took one out of my old old admin script, not sure if it still works though.

pawn Код:
CMD:respawncars(playerid, params[])
{
    new string[128];
    if(!IsPlayerAdmin(playerid)) return 0;
    else
    {
        format(string, sizeof(string), "Admin %s(%d) has respawned all unused vehicles!", GetName(playerid), playerid);
        SCMTA(COLOR_RED, string);
        for(new vehicle = 0; vehicle < MAX_VEHICLES; vehicle++)
        {
            if(IsPlayerInCar(vehicle))
            {
                DestroyVehicle(vehicle);
            }
        }
    }
    return 1;
}



stock IsPlayerInCar(vehicleid)
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerInVehicle(i, vehicleid)) return 0;
    }
    return 1;
}
Reply
#5

i get many fucking errors for that.
Reply
#6

Try this,


pawn Код:
stock IsVehicleOccupied(vehicleid, driveronly=-1)
{
for (new i = 0; i != MAX_PLAYERS; ++i)
{
    if(driveronly != -1)
    {
        if(GetPlayerVehicleID(i) == vehicleid && GetVehicleSeatID(i) == 0) return true;
    }
    else
    {
        if(GetPlayerVehicleID(i) == vehicleid) return true;
    }
}
return false;
}
Put -1 for driveronly if you want a driver to be present and anything else will detect if anyone is in there period. I tested it and it should compile fine. Just check if the vehicle is occupied using this in your command and it should work fine. Note, you dont have to use the second argument as it's purely optional(hence the "=-1").

EDIT: here's the command,
pawn Код:
CMD:respawncars(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] >= 2)
    {
        new string[128], radius;
        if(sscanf(params, "d", radius)) return SendClientMessageEx(playerid, COLOR_WHITE, "Tip: /respawncars [radius]");

        if(radius < 1 || radius > 500)
        {
            SendClientMessageEx(playerid, COLOR_WHITE, "Radius must be higher than 0 and lower than 500!");
            return 1;
        }
 
        if(IsVehicleOccupied(vehicleid, -1)) RespawnNearbyVehicles(playerid, radius);
        format(string, sizeof(string), "You have respawned all vehicles within a radius of %d.", radius);
        SendClientMessageEx(playerid, COLOR_GREY, string);
    }
    else
    {
        SendClientMessageEx(playerid, COLOR_GRAD1, "You are not authorized to use that command!");
    }
    return 1;
}
Reply
#7

But i want to respawn all cars but not which is driving. i don't want the /respawncars [radius]. just /respawncars
Reply
#8

Show RespawnNearbyVehicles
Reply
#9

Код:
RespawnNearbyVehicles(playerid, Float:radi)
{
	new Float:x, Float:y, Float:z;
	GetPlayerPos(playerid, x, y, z);
	for(new i=1; i<MAX_VEHICLES; i++)
	{
		if(GetVehicleModel(i))
		{
			new Float:posx, Float:posy, Float:posz;
			new Float:tempposx, Float:tempposy, Float:tempposz;
			GetVehiclePos(i, posx, posy, posz);
			tempposx = (posx - x);
			tempposy = (posy - y);
			tempposz = (posz - z);
			if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
			{
				SetVehicleToRespawn(i);
			}
		}
	}
}
Reply
#10

Hm in cmd respawn
pawn Код:
new bool:Used[MAX_VEHICLES char],ID;
for(new i=0; i != MAX_PLAYERS; i++) if(IsPlayerConnected(i))
{
    ID = GetPlayerVehicleID(i);
    if(!ID) continue;
    Used{ID} = true;
}
for(new v=1; v != MAX_VEHICLES; v++)
    if(GetVehicleModel(v) && !Used{v})
        SetVehicleToRespawn(v);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)