Comparing which is closer -
JaKe Elite - 31.12.2015
I have recently posted a topic about the Phone Signal.
Well this topic is similar to that except the issue this time is that the GetClosestTower always pickups the tower which has the lowest ID. I have created a tower at San Fierro Medical Center, and there is a tower I have placed on Doherty's Skyscrapers. The phone signal on San Fierro Medical Center is two (indicating that the signal range still works at San Fierro Medical Center, however I wanted to extend the signal on the ocean so I have added another tower). I have noticed that even I am near towerID 3 (San Fierro's Medical Center Phone Tower) the phone signal remains at two bars, It suppose to be five bars, the towerID over Doherty's is two. So i am guessing that my GetClosestTower always returns the lowest towerID nearby the player, I wanted to change the way how it works instead of returning the lowest towerID nearby the player (if there are two or more towers nearby the player) how can I compare which tower is closer to the player?
GetClosestTower code
PHP код:
stock GetClosestTower(playerid)
{
new i=0;
new Float:_pos[3];
GetPlayerPos(playerid, _pos[0], _pos[1], _pos[2]);
while(i != MAX_TOWERS)
{
if(IsPlayerInRangeOfPoint(playerid, tInfo[i][tower_Signal], tInfo[i][tower_Pos][0], tInfo[i][tower_Pos][1], tInfo[i][tower_Pos][2]) && GetPlayerInterior(playerid) == tInfo[i][tower_Interior] && GetPlayerVirtualWorld(playerid) == tInfo[i][tower_World])
{
if(tInfo[i][tower_Pos][2]+800.0 >= _pos[2])
{ // Ignore this part, This code extends the signal range to the skies.
return i;
}
else
{
return -1;
}
}
i++;
}
return -1;
}
Re: Comparing which is closer -
PrO.GameR - 31.12.2015
PHP код:
stock GetClosestTower(playerid,Float:searchrange=5.0)
{
new i=0,closest=-1;
new Float:_pos[3];
GetPlayerPos(playerid, _pos[0], _pos[1], _pos[2]);
while(i != MAX_TOWERS)
{
new towerdist=GetPlayerDistanceFromPoint(playerid, tInfo[i][tower_Signal], tInfo[i][tower_Pos][0], tInfo[i][tower_Pos][1], tInfo[i][tower_Pos][2]);
if(towerdist<searchrange && GetPlayerInterior(playerid) == tInfo[i][tower_Interior] && GetPlayerVirtualWorld(playerid) == tInfo[i][tower_World])
{
searchrange=towerdist;
closest=i;
}
i++;
}
return closest;
}
This is pretty much how it's done, change it to fit your needs.
Re: Comparing which is closer -
JaKe Elite - 31.12.2015
It didn't changed anything the signals are the same.. I would try doing my best to found a proper code as well while I am waiting for you guys to help me out
Re: Comparing which is closer -
jlalt - 31.12.2015
Well, is sginal being five when you're near other towers?
Re: Comparing which is closer -
JaKe Elite - 31.12.2015
It is being five when there are only one towers in players sight (1000 meters + signal range for each tower), otherwise if there are more towers on player's sight (if they caught up on the 1000 meters signal range) then yeah everything began to jammed up.
Re: Comparing which is closer -
jlalt - 31.12.2015
How much towers you have .-.? this should work on three xd >>
PHP код:
stock GetClosestTower(playerid)
{
new i=0;
new Float:_pos[3],Float:distance[MAX_TOWERS];
GetPlayerPos(playerid, _pos[0], _pos[1], _pos[2]);
while(i != MAX_TOWERS)
{
if(IsPlayerInRangeOfPoint(playerid, tInfo[i][tower_Signal], tInfo[i][tower_Pos][0], tInfo[i][tower_Pos][1], tInfo[i][tower_Pos][2]) && GetPlayerInterior(playerid) == tInfo[i][tower_Interior] && GetPlayerVirtualWorld(playerid) == tInfo[i][tower_World])
{
if(tInfo[i][tower_Pos][2]+800.0 >= _pos[2])
{ // Ignore this part, This code extends the signal range to the skies.
//return i;
distance[i] = GetPlayerDistanceFromPoint(playerid, tInfo[i][tower_Pos][0], tInfo[i][tower_Pos][1], tInfo[i][tower_Pos][2]);
if(MAX_TOWERS - 1 == i) {
for(new distance1 = i - 1; distance1 != 0; distance1++) {
if(distance[distance1] > distance[i] && distance[distance1] > distance[distance1-1])return distance1;
if(distance[distance1] < distance[i] && distance[i] > distance[distance1-1]) return i;
if(distance[distance1-1] > distance[i] && distance[i] < distance[distance1-1]) return distance1-1;
}
}
}
else
{
return -1;
}
}
i++;
}
return -1;
}
did not find better way to get most nearby tower
Re: Comparing which is closer -
Nero_3D - 31.12.2015
PHP код:
stock GetClosestTower(playerid) {
new
i = 0,
Float: X,
Float: Y,
Float: Z,
Float: tmp,
closest = -1,
Float: dist = Float: 0x7F800000
;
if(GetPlayerPos(playerid, X, Y, Z)) {
do {
if(IsPlayerInRangeOfPoint(playerid, tInfo[i][tower_Signal], tInfo[i][tower_Pos][0], tInfo[i][tower_Pos][1], tInfo[i][tower_Pos][2]) && GetPlayerInterior(playerid) == tInfo[i][tower_Interior] && GetPlayerVirtualWorld(playerid) == tInfo[i][tower_World]) {
if(tInfo[i][tower_Pos][2]+800.0 >= _pos[2]) { // Ignore this part, This code extends the signal range to the skies.
tmp = VectorSize(X - tInfo[i][tower_Pos][0], Y - tInfo[i][tower_Pos][1], Z - tInfo[i][tower_Pos][2]);
if(tmp < dist) {
closest = i;
dist = tmp;
}
}
}
} while(++i < MAX_TOWERS);
}
return closest;
}
Re: Comparing which is closer -
JaKe Elite - 31.12.2015
Thank you so much Nero_3D and jlait, Nero your code works pretty well, SWEET. Your help is appreciated same goes for you mah bruh, jlait who is always there on my topics.