IF Conditional Sentence.
#1

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.

PHP код:
if(IsPlayerInRangeOfPoint(playerid20.02177.5725,-1973.2252,13.2218) || IsPlayerInRangeOfPoint(playerid20.0, -2048.5581,173.2598,28.4962) || IsPlayerInRangeOfPoint(playerid20.0, -353.9812,1540.1951,75.5625) || IsPlayerInRangeOfPoint(playerid20.092.0248,-164.9822,2.5938) || IsPlayerInRangeOfPoint(playerid20.0, -1688.0195,1035.4976,45.2109) || IsPlayerInRangeOfPoint(playerid20.0, -1787.5283,1216.6865,25.1250) || IsPlayerInRangeOfPoint(playerid20.0, -2181.6172,712.8118,53.8906))

Reply
#2

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).
Reply
#3

You can extend the character limit per line to 4,095 with Zeex's PAWN Compiler Patches. I do encourage the use of an array combined with a loop however.
Reply
#4

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.
Reply
#5

Quote:
Originally Posted by DarkMaster1998
Посмотреть сообщение
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.
}
Reply
#6

It works!
Thank you buddies .
Reply
#7

Quote:
Originally Posted by DarkMaster1998
Посмотреть сообщение
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.

PHP код:
if(IsPlayerInRangeOfPoint(playerid20.02177.5725,-1973.2252,13.2218) || IsPlayerInRangeOfPoint(playerid20.0, -2048.5581,173.2598,28.4962) || IsPlayerInRangeOfPoint(playerid20.0, -353.9812,1540.1951,75.5625) || IsPlayerInRangeOfPoint(playerid20.092.0248,-164.9822,2.5938) || IsPlayerInRangeOfPoint(playerid20.0, -1688.0195,1035.4976,45.2109) || IsPlayerInRangeOfPoint(playerid20.0, -1787.5283,1216.6865,25.1250) || IsPlayerInRangeOfPoint(playerid20.0, -2181.6172,712.8118,53.8906))

Press enter.

PHP код:
if (
    
IsPlayerInRangeOfPoint(playerid20.02177.5725,-1973.2252,13.2218) ||
    
IsPlayerInRangeOfPoint(playerid20.0, -2048.5581,173.2598,28.4962) ||
    
IsPlayerInRangeOfPoint(playerid20.0, -353.9812,1540.1951,75.5625) ||
    
IsPlayerInRangeOfPoint(playerid20.092.0248,-164.9822,2.5938) ||
    
IsPlayerInRangeOfPoint(playerid20.0, -1688.0195,1035.4976,45.2109) ||
    
IsPlayerInRangeOfPoint(playerid20.0, -1787.5283,1216.6865,25.1250) ||
    
IsPlayerInRangeOfPoint(playerid20.0, -2181.6172,712.8118,53.8906))

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)