Function problem
#1

It's a function that should work properly to get distance between the player which used the command and the playerid chosen:
pawn Код:
stock GetPlayerDistanceToPoint(playerid,Float:x,Float:y,Float:z)
{
    new Float:x1,Float:y1,Float:z1;
    new Float:dis;
    GetPlayerPos(playerid,x1,y1,z1);
    dis = floatsqroot((x-x1)*(x-x1)+(y-y1)*(y-y1)+(z-z1)*(z-z1));
    return floatround(dis);
}
pawn Код:
CMD:getdistance(playerid, params[])
{
    new id, string[230];
    new Float:x,Float:y,Float:z;
    if(sscanf(params, "u", id)) return Msg(playerid, color, ""#red"USAGE: "#green"/getdistance <playerid>");
    if(!Connect(playerid)) return Msg(playerid, color, NOT_CONNECTED);
    format(string,sizeof(string),""#red"Distance to "#green"%s (id: %d): "#blue"%d",GetMyName(id),id,GetPlayerDistanceToPoint(playerid,x,y,z));
    Msg(playerid, color, string);
    return 1;
}
I tested myself this command and just me give some weird distances, as: 2290, 2280, 2287...

It may not be due it's myself, and distance from to me is 0, but I think something is wrong on function, or I've made the code wrong. Anyway hope anyone can help me. Thanks,
Reply
#2

You never load the coordinates of the other player to x/y/z, so you are calculating the distance to 0, 0, 0
Reply
#3

pawn Код:
stock GetPlayerDistanceToPoint(playerid,Float:x,Float:y,Float:z) // I have to define that on code (x, y, z) ...
{
    new Float:x1,Float:y1,Float:z1; // To get player pos
    new Float:dis; // Distance
    GetPlayerPos(playerid,x1,y1,z1); // Getplayer position
    dis = floatsqroot((x-x1)*(x-x1)+(y-y1)*(y-y1)+(z-z1)*(z-z1)); // Compare player distance to the point put. error may be here, though
    return floatround(dis);
}
Reply
#4

The GetPlayerDistanceToPoint function should work, it is this:

pawn Код:
CMD:getdistance(playerid, params[])
{
    new id, string[230];
    new Float:x,Float:y,Float:z;
    if(sscanf(params, "u", id)) return Msg(playerid, color, ""#red"USAGE: "#green"/getdistance <playerid>");
    if(!Connect(playerid)) return Msg(playerid, color, NOT_CONNECTED);
    GetPlayerPos(id, x, y, z);    // This was missing
    format(string,sizeof(string),""#red"Distance to "#green"%s (id: %d): "#blue"%d",GetMyName(id),id,GetPlayerDistanceToPoint(playerid,x,y,z));
    Msg(playerid, color, string);
    return 1;
}
Reply
#5

thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)