SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 14/07/2017, 10:25 PM   #1
DarkMaster1998
Little Clucker
 
Join Date: Jun 2017
Posts: 10
Reputation: 0
Thumbs down 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.

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

DarkMaster1998 is offline   Reply With Quote
Old 14/07/2017, 10:37 PM   #2
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,652
Reputation: 559
Default 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).
NaS is offline   Reply With Quote
Old 14/07/2017, 10:43 PM   #3
DarkMaster1998
Little Clucker
 
Join Date: Jun 2017
Posts: 10
Reputation: 0
Default 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.
DarkMaster1998 is offline   Reply With Quote
Old 14/07/2017, 10:49 PM   #4
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,652
Reputation: 559
Default Re: IF Conditional Sentence.

Quote:
Originally Posted by DarkMaster1998 View Post
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.
}
NaS is offline   Reply With Quote
Old 14/07/2017, 10:42 PM   #5
Paulice
Huge Clucker
 
Join Date: Jul 2017
Posts: 424
Reputation: 44
Default 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.
Paulice is offline   Reply With Quote
Old 14/07/2017, 10:59 PM   #6
DarkMaster1998
Little Clucker
 
Join Date: Jun 2017
Posts: 10
Reputation: 0
Default Re: IF Conditional Sentence.

It works!
Thank you buddies .
DarkMaster1998 is offline   Reply With Quote
Old 15/07/2017, 08:40 AM   #7
OneDay
Huge Clucker
 
Join Date: Sep 2015
Posts: 293
Reputation: 134
Default Re: IF Conditional Sentence.

Quote:
Originally Posted by DarkMaster1998 View Post
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 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))

OneDay is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
/report cannot get a sentence whando Scripting Help 2 10/11/2013 03:40 AM
Conditional expression Riddick94 Scripting Help 3 27/01/2013 08:17 PM
Conditional script problem Swiftz Help Archive 3 16/04/2011 02:38 AM
Not displaying whole sentence.. Ihsan_Cingisiz Help Archive 4 31/05/2010 06:20 PM
First letter sentence ErF Help Archive 8 27/02/2010 03:52 PM


All times are GMT. The time now is 06:10 AM.


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