Well lets see what responses we have so far:
Quote:
Originally Posted by Pottus
You need define an array of phone points or use dynamic areas.
|
Oh wait... that's all we really needed.
-----
So lets take a deeper insight to things. If you are using these coords:
Quote:
world_object_telephone[1] = posx:123.1 posy:35.5 posz:22.1;
world_object_telephone[2] = posx:222.2 posy:10.0 posz: 15.5;
world_object_telephone[3] = posx:1422.2 posy:150.0 posz: 105.5;
|
That would translate into floats like this:
pawn Code:
123.1, 35.5, 22.1
222.2, 10.0, 15.5
1422.2, 150.0, 105.5
Now if we add those to an array called 'PhoneCoords', we'll be able to organise things a bit more. So lets set a maximum of '3' phone booths for the time being.
pawn Code:
new Float:PhoneCoords[3][3]
We're creating an array called 'PhoneCoords' that stores values as floats, hence the 'Float:' tag. We will have 3 phone booths, with 3 coordinates. The 'x', 'y' and 'z' coordinates. Hence the two '[3]' sizes.
Now we can add our coordinates.
pawn Code:
new Float:PhoneCoords[3][3] = {
123.1, 35.5, 22.1
222.2, 10.0, 15.5
1422.2, 150.0, 105.5
};
But this isn't right, the only thing separating the coordinates from each other is a new line, the compiler won't understand that...
pawn Code:
new Float:PhoneCoords[3][3] = {
{123.1, 35.5, 22.1},
{222.2, 10.0, 15.5},
{1422.2, 150.0, 105.5}
};
Ahh, that looks better. But I won't go explaining why it looks the way it does, because that's very basic programming and you should be able to study that for yourself.
To see whether a player is in range of a phone booth, you can use this code in any way you want, but I'm going to put it in the form of a custom function.
pawn Code:
IsPlayerInRangeOfPhone(playerid, Float:range = 5.0)
{
for(new i = 0; i < sizeof(PhoneCoords); i++)
{
if(!IsPlayerInRangeOfPoint(playerid, range, PhoneCoords[i][0], PhoneCoords[i][1], PhoneCoords[i][2])) continue;
return 1;
}
return 0;
}
And that's all it takes. To use that function somewhere, all you need to do is:
pawn Code:
if(IsPlayerInRangeOfPhone(playerid)) //Player is near a phone booth. (Within 5.0 units)
else //Player is NOT near a phone booth
You can change the range by adding a second parameter, but the default value of the range is '5.0', as shown in the function by this value:
You can change this range to however you want. Lets say you want to look for phone booths within 15.0 units of the player, so you would do:
pawn Code:
if(IsPlayerInRangeOfPhone(playerid, 15.0)) //Player is in range of a phone booth (Within 15.0 units)
else //Player is NOT within range of a phone booth
-----
This is just one method of doing what you want to do, or as Pottus suggested you can create your own dynamic phone booth system... but something tells me that you might not be able to do this just yet at your skill level, so you might need to study up a bit more.