SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Scripting Help (https://forum.sa-mp.com/forumdisplay.php?f=12)
-   -   IF Conditional Sentence. (https://forum.sa-mp.com/showthread.php?t=637455)

DarkMaster1998 14/07/2017 10:25 PM

IF Conditional Sentence.
 
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:

PHP Code:

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))



NaS 14/07/2017 10:37 PM

Re: IF Conditional Sentence.
 
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

Re: IF Conditional Sentence.
 
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.

DarkMaster1998 14/07/2017 10:43 PM

Re: IF Conditional Sentence.
 
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

Re: IF Conditional Sentence.
 
Quote:

Originally Posted by DarkMaster1998 (Post 3901992)
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:

Code:

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

Re: IF Conditional Sentence.
 
It works!
Thank you buddies :) .

OneDay 15/07/2017 08:40 AM

Re: IF Conditional Sentence.
 
Quote:

Originally Posted by DarkMaster1998 (Post 3901985)
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:

PHP Code:

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 Code:

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))




All times are GMT. The time now is 09:30 PM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.