Distance problem
#1

Код:
public OpenCloseGates(playerid)
{
        new Float: dist;
        new gateID = GetClosestGate(playerid, dist);

        if(dist < 10.0)
        {
                if(IsAllowedToUseGate(playerid, gateID))
                {
                        ToggleGate(gateID);

                        return 1;
                }
                else
                {
                        SendClientMessage(playerid, COLOR_RED, "You dont have a remote to open this gate!");
                        return 1;
                }
        }
        else
        {
                SendClientMessage(playerid, COLOR_GRAY, "Youre not close to any gates!");
                return 1;
        }
}
But what happens is.. When this function is called up , it says Youre not close to any gate, Even if im near it.

Here is the other function
Код:
public GetClosestGate(playerid, &Float: distance)
{
        new Float: pX1, Float: pY1, Float: pZ1;

        GetPlayerPos(playerid, pX1, pY1, pZ1);

        distance = 999999.9;
        new Float: dist2;

        new ret;

        for(new i; i < MAX_GATES; i++)
        {

                dist2 = Distance(pX1, pY1, pZ1, Gate[i][CloseX], Gate[i][CloseY], Gate[i][CloseZ]);

                if(dist2 < distance && Gate[i][ParentId] == -1)
                {
                        distance = dist2;
                        ret = i;
                }
        }

        return ret;
}
Why is this happening, please help, thanx in advance
Reply
#2

Why dont u use "IsPlayerInRangeOfPoint" , that would be easier!

Код:
if(IsPlayerInRangeOfPoint(playerid, 10.0,1367.1448,-1290.2589,13.5469))//id,distance,axes
{
                 if(IsAllowedToUseGate(playerid, gateID))
                {
                        ToggleGate(gateID);

                        return 1;
                }
                else
                {
                        SendClientMessage(playerid, COLOR_RED, "You dont have a remote to open this gate!");
                        return 1;
                }
}
else
{
         SendClientMessage(playerid, COLOR_GRAY, "Youre not close to any gates!");
         return 1;
}
Reply
#3

No i didnt create a specific gate to use that function, It is a system which creates a gate in one line and opens the gate with simple commands with lot of functions. So can you help?
Reply
#4

What's your Distance function?
Reply
#5

Here
Код:
Float:Distance(Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2)
{
        new Float:temp=floatsqroot((x1-x2) * (x1-x2) + (y1-y2) * (y1-y2) + (z1-z2) * (z1-z2));
        if(temp < 0) temp=temp*(-1);
        return temp;
}
And the GetClosestGate function
Код:
public GetClosestGate(playerid, &Float: distance)
{
        new Float: pX, Float: pY, Float: pZ;
       
        GetPlayerPos(playerid, pX, pY, pZ);
       
        distance = 999999.9;
        new Float: dist2;
       
        new ret;
       
        for(new i; i < MAX_GATES; i++)
        {
               
                dist2 = Distance(pX, pY, pZ, Gate[i][CloseX], Gate[i][CloseY], Gate[i][CloseZ]);
               
                if(dist2 < distance && Gate[i][ParentId] == -1)
                {
                        distance = dist2;
                        ret = i;
                }
        }      
       
        return ret;
}
Reply
#6

bump! Please help very annoying prob
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)