Question: quite simple.
#1

Take for instance that I want to create say 5 gas stations, How would I check if the person is in range of any of them without having to use || each time in an if statement?
Reply
#2

Use switch statement.
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
Firstly what's wrong with ||? Secondly you can put everything in an array and loop through the elements one at a time, but that's slower than a single check if your positions are quite static.
Well is there any limit to the amount of times using it? I worry,I was just wondering if there was another way around it, how would I create a thing like random messages? as in? Like Welcome to the server, every 15 minutes.
Reply
#4

Quote:
Originally Posted by Dokins
Посмотреть сообщение
Take for instance that I want to create say 5 gas stations, How would I check if the person is in range of any of them without having to use || each time in an if statement?
There is no issue with using if statements as it evaluates each condition individually. Usage of logical operators (most notable ||) within a single expression is reliable as the condition is passed quite quickly to the next statement. As stated there are alternative methods than doing what you've requested.
Reply
#5

You can make an array with all the possible gas stations and then loop all over them, checking if you are near any of these gas stations this way:

This is an example of ****** idea

pawn Код:
enum GasStationEnum
{
    Float:gas_x,
    Float:gas_y,
    Float:gas_z,
}
// Each gas station will have 3 arguments: the x, y, and z positions.

new gGasStations[][GasStationEnum] =
{
    {1381.866699, 459.125488, 20.345203},
    {-1328.8250,2677.2173,49.7665},
    {656.4265,-559.8610,16.5015}
};
// ^ You can add your own

CMD:fill( playerid, params[] ) // example command
{
    for( new i = 0; i < sizeof( GasStationEnum ); i++ ) // We loop all the possible elements in the array
    {
        if ( IsPlayerInRangeOfPoint( playerid, 5.0, gGasStations[i][gas_x], gGasStations[i][gas_y], gGasStations[i][gas_z] ) )
        {
            // do something
        }
    }
    return 1;
}
The only limit is a slower code once you have an extreme ammount of gas stations!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)