Distance problem - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Distance problem (
/showthread.php?tid=251875)
Distance problem -
Swiftz - 29.04.2011
Код:
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
AW: Distance problem -
Pancake - 29.04.2011
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;
}
Re: Distance problem -
Swiftz - 29.04.2011
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?
Re: Distance problem -
Backwardsman97 - 29.04.2011
What's your Distance function?
Re: Distance problem -
Swiftz - 29.04.2011
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;
}
Re: Distance problem -
Swiftz - 02.05.2011
bump! Please help very annoying prob