Comparing which is closer
#1

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(
!= MAX_TOWERS)
    {
        if(
IsPlayerInRangeOfPoint(playeridtInfo[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;

Reply
#2

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(
!= MAX_TOWERS)
    {
new 
towerdist=GetPlayerDistanceFromPoint(playeridtInfo[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.
Reply
#3

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
Reply
#4

Well, is sginal being five when you're near other towers?
Reply
#5

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.
Reply
#6

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(
!= MAX_TOWERS)
    {
        if(
IsPlayerInRangeOfPoint(playeridtInfo[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(playeridtInfo[i][tower_Pos][0], tInfo[i][tower_Pos][1], tInfo[i][tower_Pos][2]);
                if(
MAX_TOWERS == i) {
                  for(new 
distance1 1distance1 != 0distance1++) {
                     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
Reply
#7

PHP код:
stock GetClosestTower(playerid) {
    new
        
0,
        
FloatX,
        
FloatY,
        
FloatZ,
        
Floattmp,
        
closest = -1,
        
Floatdist Float0x7F800000
    
;
    if(
GetPlayerPos(playeridXYZ)) {
        do {
            if(
IsPlayerInRangeOfPoint(playeridtInfo[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(tInfo[i][tower_Pos][0], tInfo[i][tower_Pos][1], tInfo[i][tower_Pos][2]);
                    if(
tmp dist) {
                        
closest i;
                        
dist tmp;
                    }
                }
            }
        } while(++
MAX_TOWERS);
    }
    return 
closest;

Reply
#8

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)