PDA

View Full Version : Radius. (WARNING)


Sasoft
30/12/2011, 11:09 AM
Hello, i'm trying to make a command where i'm able to give a skin to people in a radius.
I currently have this but it doesen't work. Could anyone tell me what i'm doing wrong.

CMD:setskins(playerid, params[])
{
if (PlayerInfo[playerid][pAdmin] >= 3)
{
new string[128], radius, skin;
if(sscanf(params, "dd", skin, radius))
{
SendClientMessageEx(playerid, COLOR_GRAD6, "[Syntax]: /setskins [skin] [radius]");
return 1;
}
if(!IsInvalidSkin(skin))
{
SendClientMessageEx(playerid, COLOR_GREY, "Invalid skin ID!");
return 1;
}
if(radius < 1 || radius > 50)
{
SendClientMessageEx(playerid, COLOR_WHITE, "Radius must be higher than 0 and lower than 51!");
return 1;
}
SetPlayerSkin(playerid, skin, radius);
format(string, sizeof(string), "You have given everyone skin %d in %d radius", skin, radius);
SendClientMessageEx(playerid, COLOR_LIGHTGREEN, string);
}
else
{
SendClientMessageEx(playerid, COLOR_GRAD1, "You are not authorized to use that command!");
}
return 1;
}


Warning: C:\Users\Bart\Downloads\0.3D\0.3D\gamemodes\syrp.p wn(58482) : warning 202: number of arguments does not match definition

LINE: 58482 SetPlayerSkin(playerid, skin, radius);

T0pAz
30/12/2011, 11:14 AM
playerid is only a player's id. Use for loop to check all the players and make an if statement using IsPlayerInRangeOfPoint to detect if the player is in radius. And also SetPlayerSkin takes 2 argument which is playerid and skin id.

silvan
30/12/2011, 01:02 PM
use a for loop here is an example


new Float:x, Float:y, Float:z;
GetPlayerPos(playerid,x,y,z);
for (new i=0; i < MAX_PLAYERS, i++)
{
if(IsPlayerInRangeOfPoint(i,radius,x,y,z))
{
SetPlayerSkin(i,skin);
}
}


This should work, + Rep me please if it does.

FTLOG
30/12/2011, 01:20 PM
Radius shoud be float to. When you do new radius; do new Float:radius;.

EDIT: And replace the second integer "d" in sscanf line with float "f"

Sasoft
30/12/2011, 07:17 PM
Alright thanks, so this will work?

CMD:setskins(playerid, params[])
{
if (PlayerInfo[playerid][pAdmin] >= 3)
{
new string[128], skin, Float:radius;
if(sscanf(params, "df", skin, radius))
{
SendClientMessageEx(playerid, COLOR_GRAD6, "[Syntax]: /setskins [skin] [radius]");
return 1;
}
if(!IsInvalidSkin(skin))
{
SendClientMessageEx(playerid, COLOR_GREY, "Invalid skin ID!");
return 1;
}
if(radius < 1 || radius > 50)
{
SendClientMessageEx(playerid, COLOR_WHITE, "Radius must be higher than 0 and lower than 51!");
return 1;
}
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid,X, Y, Z);

for (new i=0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInRangeOfPoint(i, radius, X, Y, Z))
{
SetPlayerSkin(i,skin);
}
}
format(string, sizeof(string), "You have given everyone skin %d in %d radius", skin, radius);
SendClientMessageEx(playerid, COLOR_LIGHTGREEN, string);
}
else
{
SendClientMessageEx(playerid, COLOR_GRAD1, "You are not authorized to use that command!");
}
return 1;
}

Elmin
30/12/2011, 08:41 PM
forward GetPlayerDistanceToPointEx(playerid,Float:x,Float: y,Float:z);
forward IsPlayerInSphere(playerid,Float:x,Float:y,Float:z, radius);

public GetPlayerDistanceToPointEx(playerid,Float:x,Float: y,Float:z)
{
new Float:x1,Float:y1,Float:z1;
new Float:tmpdis;
GetPlayerPos(playerid,x1,y1,z1);
tmpdis = floatsqroot(floatpower(floatabs(floatsub(x,x1)),2) +floatpower(floatabs(floatsub(y,y1)),2)+floatpower (floatabs(floatsub(z,z1)),2));
return floatround(tmpdis);
}
public IsPlayerInSphere(playerid,Float:x,Float:y,Float:z, radius)
{
if(GetPlayerDistanceToPointEx(playerid,x,y,z) < radius){
return 1;
}
return 0;
}



//add to your command
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid,X, Y, Z)


for (new i=0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInSphere(i,X, Y, Z, radius))
{
SetPlayerSkin(i,skin);
}
}


i hope that this will help ^^'