Question: quite simple. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Question: quite simple. (
/showthread.php?tid=311642)
Question: quite simple. -
Dokins - 17.01.2012
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?
Re: Question: quite simple. - T0pAz - 17.01.2012
Use
switch statement.
Re: Question: quite simple. -
Dokins - 17.01.2012
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.
Re: Question: quite simple. -
Gh05t_ - 17.01.2012
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.
Respuesta: Question: quite simple. -
admantis - 17.01.2012
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!