Area Respawn
#1

Hey guys, I wanted to create a command to respawn cars within a certain radius of the player using the command so you don't have to respawn all the server's cars if only one area is messed up.
But if I get in game and type in the right format just nothing happens. And I do not get any error back when compiling. Any ideas?

Код:
CMD:arearespawn(playerid, params[]) {
	new Float:radius;
	if(playerVariables[playerid][pAdminLevel] < 2) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use that command!");
	if(sscanf(params, "i", radius)) return SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/arearespawn [Radius in Meters]");
	GetPlayerPos(playerid, playerVariables[playerid][pPos][0], playerVariables[playerid][pPos][1], playerVariables[playerid][pPos][2]);
	
	for (new x = 0; x < MAX_VEHICLES; x++) {
	    if(IsVehicleInRangeOfPoint(x, radius, playerVariables[playerid][pPos][0], playerVariables[playerid][pPos][1], playerVariables[playerid][pPos][2])) {
	        SetVehicleToRespawnEx(x);
	        format(szMessage, sizeof(szMessage), "You have respawned all cars within the radius of %i meters.", radius);
	        SendClientMessage(playerid, COLOR_NICESKY, szMessage);
	        format(szMessage, sizeof(szMessage), "AdmCmd:{FFFFFF} %s just performed an area respawn with the radius of %i meters.", playerVariables[playerid][pAdminName], radius);
	        submitToAdmins(szMessage, COLOR_HOTORANGE);
		}
	}
	return 1;
}
Код:
stock IsVehicleInRangeOfPoint(vehicleid, Float: radius, Float:x, Float:y, Float:z) {

	new
		Float:Floats[6];

	GetVehiclePos(vehicleid, Floats[0], Floats[1], Floats[2]);
	Floats[3] = (Floats[0] -x);
	Floats[4] = (Floats[1] -y);
	Floats[5] = (Floats[2] -z);
	if (((Floats[3] < radius) && (Floats[3] > -radius)) && ((Floats[4] < radius) && (Floats[4] > -radius)) && ((Floats[5] < radius) && (Floats[5] > -radius)))
		return 1;
	return 0;
}
Reply
#2

Well try this first.

if(sscanf(params, "i", radius))

Change to

if(sscanf(params, "f", radius))
Reply
#3

pawn Код:
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);
            }
        }
    }
}
Command:

pawn Код:
CMD:arearespawn(playerid, params[])
{
    new Float:radius;
    if(playerVariables[playerid][pAdminLevel] < 2) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use that command!");
    if(sscanf(params, "d", radius)) return SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/arearespawn [Radius in Meters]");
    if(radius < 1 || radius > 40)return SendClientMessage(playerid, -1, "Dot radio (1 - 40)");
    RespawnNearbyVehicles(playerid, radius);
    format(szMessage, sizeof(szMessage), "You have respawned all cars within the radius of %i meters.", radius);
    SendClientMessage(playerid, COLOR_NICESKY, szMessage);
    format(szMessage, sizeof(szMessage), "AdmCmd:{FFFFFF} %s just performed an area respawn with the radius of %i meters.", playerVariables[playerid][pAdminName], radius);
    submitToAdmins(szMessage, COLOR_HOTORANGE);
    return 1;
}
Reply
#4

Quote:
Originally Posted by Zume-Zero
Посмотреть сообщение
pawn Код:
stock 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);
            }
        }
    }
}
Command:

pawn Код:
CMD:arearespawn(playerid, params[])
{
    new Float:radius;
    if(playerVariables[playerid][pAdminLevel] < 2) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use that command!");
    if(sscanf(params, "f", radius)) return SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/arearespawn [Radius in Meters]");
    if(radius < 1 || radius > 40)return SendClientMessage(playerid, -1, "Dot radio (1 - 40)");
    RespawnNearbyVehicles(playerid, radius);
    format(szMessage, sizeof(szMessage), "You have respawned all cars within the radius of %f meters.", radius);
    SendClientMessage(playerid, COLOR_NICESKY, szMessage);
    format(szMessage, sizeof(szMessage), "AdmCmd:{FFFFFF} %s just performed an area respawn with the radius of %f meters.", playerVariables[playerid][pAdminName], radius);
    submitToAdmins(szMessage, COLOR_HOTORANGE);
    return 1;
}
Got it to work. Thank you both guys, you were really helpful.
Also in the code shown above you need to make the "RespawnNearbyVehicles" a stock and change the %d and %i to %f, because it is a float abviously.

Cheers!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)