PDA

View Full Version : IF Conditional Sentence.


DarkMaster1998
14/07/2017, 10:25 PM
Hey.. So i have this if and i can't write more conditions if i do then the compiler gives me an error message (2 Long input).. Should i use array ?? with for loop in the if cond.. or what i have tried but it didn't work. :confused:

if(IsPlayerInRangeOfPoint(playerid, 20.0, 2177.5725,-1973.2252,13.2218) || IsPlayerInRangeOfPoint(playerid, 20.0, -2048.5581,173.2598,28.4962) || IsPlayerInRangeOfPoint(playerid, 20.0, -353.9812,1540.1951,75.5625) || IsPlayerInRangeOfPoint(playerid, 20.0, 92.0248,-164.9822,2.5938) || IsPlayerInRangeOfPoint(playerid, 20.0, -1688.0195,1035.4976,45.2109) || IsPlayerInRangeOfPoint(playerid, 20.0, -1787.5283,1216.6865,25.1250) || IsPlayerInRangeOfPoint(playerid, 20.0, -2181.6172,712.8118,53.8906))
{

NaS
14/07/2017, 10:37 PM
Technically you could split the conditions into multiple parts, but that would be ugly.

I'd recommend using an array here, it's much cleaner and easier to manage especially if you are adding more.

Alternatively you could use Streamer Areas (from Incognito's Streamer Plugin), however that doesn't always make sense (eg. for very rare use-cases it doesn't need to be checked constantly).

Paulice
14/07/2017, 10:42 PM
You can extend the character limit per line to 4,095 with Zeex's PAWN Compiler Patches (http://forum.sa-mp.com/showthread.php?p=2768123). I do encourage the use of an array combined with a loop however.

DarkMaster1998
14/07/2017, 10:43 PM
Ya i quite agree with that.. but i can't do it with an array, something is going wrong can u do it for me.. not the whole array just a one example and how to put it in the if condition .. i would appreciate that.

NaS
14/07/2017, 10:49 PM
Ya i quite agree with that.. but i can't do it with an array, something is going wrong can u do it for me.. not the whole array just a one example and how to put it in the if condition .. i would appreciate that.

Something like:


new Float:Areas[][3] =
{
{2177.5725,-1973.2252,13.2218},
{-2048.5581,173.2598,28.4962},
{-353.9812,1540.1951,75.5625}
};

for(new i = 0; i < sizeof(Areas); i ++) if(IsPlayerInRangeOfPoint(playerid, 20.0, Areas[i][0], Areas[i][1], Areas[i][2]))
{
// Do something

break; // We found one area, so don't continue.
}

DarkMaster1998
14/07/2017, 10:59 PM
It works!
Thank you buddies :) .

OneDay
15/07/2017, 08:40 AM
Hey.. So i have this if and i can't write more conditions if i do then the compiler gives me an error message (2 Long input).. Should i use array ?? with for loop in the if cond.. or what i have tried but it didn't work. :confused:

if(IsPlayerInRangeOfPoint(playerid, 20.0, 2177.5725,-1973.2252,13.2218) || IsPlayerInRangeOfPoint(playerid, 20.0, -2048.5581,173.2598,28.4962) || IsPlayerInRangeOfPoint(playerid, 20.0, -353.9812,1540.1951,75.5625) || IsPlayerInRangeOfPoint(playerid, 20.0, 92.0248,-164.9822,2.5938) || IsPlayerInRangeOfPoint(playerid, 20.0, -1688.0195,1035.4976,45.2109) || IsPlayerInRangeOfPoint(playerid, 20.0, -1787.5283,1216.6865,25.1250) || IsPlayerInRangeOfPoint(playerid, 20.0, -2181.6172,712.8118,53.8906))
{


Press enter.

if (
IsPlayerInRangeOfPoint(playerid, 20.0, 2177.5725,-1973.2252,13.2218) ||
IsPlayerInRangeOfPoint(playerid, 20.0, -2048.5581,173.2598,28.4962) ||
IsPlayerInRangeOfPoint(playerid, 20.0, -353.9812,1540.1951,75.5625) ||
IsPlayerInRangeOfPoint(playerid, 20.0, 92.0248,-164.9822,2.5938) ||
IsPlayerInRangeOfPoint(playerid, 20.0, -1688.0195,1035.4976,45.2109) ||
IsPlayerInRangeOfPoint(playerid, 20.0, -1787.5283,1216.6865,25.1250) ||
IsPlayerInRangeOfPoint(playerid, 20.0, -2181.6172,712.8118,53.8906))
{