Phone Signal
#1

I am creating a Phone Tower system, It seems working fine.
I am planning to add a signal bars in the left bottom screen of the screen below the Radar.

I had no idea what i am doing with this code (I have just copied this out of ProxDetector). The phone signal range is 1000, I wanted the bar to look a little bit realistic if possible. How can i do it?

Sorry about the code if it is terrible, I have ripped it off from ProxDetector.

PHP код:
new tower GetClosestTower(playerid);
if(
tower == -1// No Signal
{
    
PlayerTextDrawSetString(playeridTextdraw2"~w~Phone Signal - ~r~I I I I I");
}
else
{
    if(
IsPlayerInRangeOfPoint(playeridtInfo[tower][tower_Signal] / 100tInfo[tower][tower_Pos][0], tInfo[tower][tower_Pos][1], tInfo[tower][tower_Pos][2])) // Full Bar
    
{
        
PlayerTextDrawSetString(playeridTextdraw2"~w~Phone Signal - ~g~I I I I I");
    }
    else if(
IsPlayerInRangeOfPoint(playeridtInfo[tower][tower_Signal] / 50tInfo[tower][tower_Pos][0], tInfo[tower][tower_Pos][1], tInfo[tower][tower_Pos][2])) // Bar Four
    
{
        
PlayerTextDrawSetString(playeridTextdraw2"~w~Phone Signal - ~g~I I I I ~r~I");
    }
    else if(
IsPlayerInRangeOfPoint(playeridtInfo[tower][tower_Signal] / 25tInfo[tower][tower_Pos][0], tInfo[tower][tower_Pos][1], tInfo[tower][tower_Pos][2])) // Bar Three
    
{
        
PlayerTextDrawSetString(playeridTextdraw2"~w~Phone Signal - ~g~I I I ~r~I I");
    }
    else if(
IsPlayerInRangeOfPoint(playeridtInfo[tower][tower_Signal] / 5tInfo[tower][tower_Pos][0], tInfo[tower][tower_Pos][1], tInfo[tower][tower_Pos][2])) // Bar Two
    
{
        
PlayerTextDrawSetString(playeridTextdraw2"~w~Phone Signal - ~g~I I ~r~I I I");
    }
    else if(
IsPlayerInRangeOfPoint(playeridtInfo[tower][tower_Signal], tInfo[tower][tower_Pos][0], tInfo[tower][tower_Pos][1], tInfo[tower][tower_Pos][2])) // Bar One
    
{
        
PlayerTextDrawSetString(playeridTextdraw2"~w~Phone Signal - ~g~I ~r~I I I I");
    }

This code is a little bit unrealistic, I am a little bit close to the tower and yet the bar is two.
Any help would be appreciated.
Reply
#2

Use this code :
PHP код:
new tower GetClosestTower(playerid);
if(
tower == -1// No Signal
{
    
PlayerTextDrawSetString(playeridTextdraw2"~w~Phone Signal - ~r~I I I I I");
}
else
{
    new 
Float:dis GetPlayerDistanceFromPoint(playeridtInfo[tower][tower_Pos][0], tInfo[tower][tower_Pos][1], tInfo[tower][tower_Pos][2]);
    if(
dis tInfo[tower][tower_Signal] / // Bar One
    
{
        
PlayerTextDrawSetString(playeridTextdraw2"~w~Phone Signal - ~g~I ~r~I I I I");
    }
    else if(
dis tInfo[tower][tower_Signal] / 25 // Bar Two
    
{
        
PlayerTextDrawSetString(playeridTextdraw2"~w~Phone Signal - ~g~I I ~r~I I I");
    }
    else if(
dis tInfo[tower][tower_Signal] / 50// Bar Three
    
{
        
PlayerTextDrawSetString(playeridTextdraw2"~w~Phone Signal - ~g~I I I ~r~I I");
    }
    else if(
dis tInfo[tower][tower_Signal] / 100)
    {
        
PlayerTextDrawSetString(playeridTextdraw2"~w~Phone Signal - ~g~I I I I ~r~I"); // bar four
    
}
    else 
    {
        
PlayerTextDrawSetString(playeridTextdraw2"~w~Phone Signal - ~g~I I I I I"); // bar five
    
}

Your code wouldn't work as expected because if player is in range of tInfo[tower][tower_Signal] then he is also in range of tInfo[tower][tower_Signal] / any_natural_number because
x > x/natural_number.
Reply
#3

I will try it out, Thank you bruh. This post will be edited out after the test results.

Edit: Pretty much the same result, One Bar works fine on far distances. Two bar works as well, however Three Bar... I am in the front of the tower and it's still three bar. I have just figured out that the tower_Pos is located at the top of the tower (The object is a huge tower antenna the one we saw at San Fierro.)
Reply
#4

So then figure out the tower height and subtract that height from z coord or try going near top of tower just for testing bars.

EDIT:
Or you can try 2d distance thingy. In that you need to get player current pos and pass the Z coord of player's pos in place of z coord or tower pos in the function GetPlayerDistanceFromPoint
Reply
#5

Did you mean something like this?

Код:
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
new Float:dis = GetPlayerDistanceFromPoint(playerid, tInfo[tower][tower_Pos][0], tInfo[tower][tower_Pos][1], z);
Reply
#6

Yes.
Reply
#7

I am not sure if i have coded it wrong or we are dividing the tower range in a wrong number.

See the picture below
Reply
#8

Hm try printing distance that you get with printf, that'll let you know the main problem I think.
Reply
#9

Here is a suggestion, edit GetClosestTower(playerid) to give you the distance to closest tower instead, and -1 if it's not close enough, then simply use that for signals.
Reply
#10

1000= Range
5 = 5 Bars
so logic is 1000/5 = Range for 1 bar

If distance to tower is:

0..199= 5 bar
200..399 = 4 bars
400..599 = 3 bars
600..799 = 2 bars
800..999 = 1 bar
1000> = 0 bars
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)