SA-MP Forums Archive
Is this possible? - 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: Is this possible? (/showthread.php?tid=634726)



Is this possible? - akib - 25.05.2017

Hi,

How to create 2 value using 'or'?

example:
Код:
new pos1 = x,y,z;
new pos2 = x,y,z;

if (IsPlayerInRangeOfPoint(playerid, 7.0, pos1 or pos2)) 
    {
    	SendClientMessage(playerid,0xFFFFFFFF,"You are near the stadium entrance!");
    }



Re: Is this possible? - RxErT - 25.05.2017

PHP код:
new pos1 x,y,z;
new 
pos2 x,y,z;

if (
IsPlayerInRangeOfPoint(playerid7.0pos1 or pos2)) 
    {
        
SendClientMessage(playerid,0xFFFFFFFF,"You are near the stadium entrance!");
    } 
Use this || or &&

Like this Example:

PHP код:
new pos1 x,y,z;
new 
pos2 x,y,z;

if (
IsPlayerInRangeOfPoint(playerid7.0pos1 || pos2)) 
    {
        
SendClientMessage(playerid,0xFFFFFFFF,"You are near the stadium entrance!");
    } 
PHP код:
new pos1 x,y,z;
new 
pos2 x,y,z;

if (
IsPlayerInRangeOfPoint(playerid7.0pos1 && pos2)) 
    {
        
SendClientMessage(playerid,0xFFFFFFFF,"You are near the stadium entrance!");
    } 



Re: Is this possible? - akib - 25.05.2017

Quote:
Originally Posted by RxErT
Посмотреть сообщение
PHP код:
new pos1 x,y,z;
new 
pos2 x,y,z;
if (
IsPlayerInRangeOfPoint(playerid7.0pos1 or pos2)) 
    {
        
SendClientMessage(playerid,0xFFFFFFFF,"You are near the stadium entrance!");
    } 
Use this || or &&

Like this Example:

PHP код:
new pos1 x,y,z;
new 
pos2 x,y,z;
if (
IsPlayerInRangeOfPoint(playerid7.0pos1 || pos2)) 
    {
        
SendClientMessage(playerid,0xFFFFFFFF,"You are near the stadium entrance!");
    } 
PHP код:
new pos1 x,y,z;
new 
pos2 x,y,z;
if (
IsPlayerInRangeOfPoint(playerid7.0pos1 && pos2)) 
    {
        
SendClientMessage(playerid,0xFFFFFFFF,"You are near the stadium entrance!");
    } 
Thanks!

can i also use more than 2 pos? like pos1 || pos2 || pos3 || pos4 ?


Re: Is this possible? - asri - 25.05.2017

yes


Re: Is this possible? - Burridge - 25.05.2017

Those examples are wrong, if you do it how RxErT does it you'll find yourself with errors.

This one below will check both and if the player is at one or the other will send the message.
Код:
if (IsPlayerInRangeOfPoint(playerid, 7.0, pos1) || IsPlayerInRangeOfPoint(playerid, 7.0, pos2)) 
{
    SendClientMessage(playerid,0xFFFFFFFF,"You are near the stadium entrance!");
}
This one will check both and if BOTH are met it will show the message.
Код:
if (IsPlayerInRangeOfPoint(playerid, 7.0, pos1) && IsPlayerInRangeOfPoint(playerid, 7.0, pos2)) 
{
    SendClientMessage(playerid,0xFFFFFFFF,"You are near the stadium entrance!");
}
https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint

EDIT: Vince's example is much better.


Re: Is this possible? - Vince - 25.05.2017

That doesn't work at all (edit: Burridge was faster). You need to repeat the entire IsPlayerInRangeOfPoint line. But if you have more than two or three sets of coordinates then I recommend using an array to keep your code neat and readable. So something like:
PHP код:
static const Float:coords[][3] = {
    {
x1y1z1},
    {
x2y2z2},
    {
x3y3z3},
    {
x4y4z4// no comma after last one
};
for(new 
isizeof(coords); i++)
{
    if(
IsPlayerInRangeOfPoint(playerid7.0coords[i][0], coords[i][1], coords[i][2])
    {
        
// do stuff
        
break; // this is here to stop the needless searching of the other locations as soon as one is found
    
}




Re: Is this possible? - akib - 25.05.2017

Quote:
Originally Posted by Vince
Посмотреть сообщение
That doesn't work at all (edit: Burridge was faster). You need to repeat the entire IsPlayerInRangeOfPoint line. But if you have more than two or three sets of coordinates then I recommend using an array to keep your code neat and readable. So something like:
PHP код:
static const Float:coords[][3] = {
    {
x1y1z1},
    {
x2y2z2},
    {
x3y3z3},
    {
x4y4z4// no comma after last one
};
for(new 
isizeof(coords); i++)
{
    if(
IsPlayerInRangeOfPoint(playerid7.0coords[i][0], coords[i][1], coords[i][2])
    {
        
// do stuff
        
break; // this is here to stop the needless searching of the other locations as soon as one is found
    
}

Thanks dude


Re: Is this possible? - CheezIt - 25.05.2017

What RxErT did could be technically done as follows (in general, but it still will not check if a player is in range of 2 different points): Float:(0.0 || 1.50), Float:(0.0 || 1.20), Float:(0.0 || 1.70)

But that only works with integers, plus the first coordinate always has to be 0. So, no...


Re: Is this possible? - saffierr - 26.05.2017

You got a lot of tips, though I wanted to say this.
|| means OR
'This || That' is basically 'This Or That'
And
&& is AND
'This && That' is 'This And That'

I hope you get it.


Re: Is this possible? - DRIFT_HUNTER - 26.05.2017

Quote:
Originally Posted by CheezIt
Посмотреть сообщение
What RxErT did could be technically done as follows (in general, but it still will not check if a player is in range of 2 different points): Float:(0.0 || 1.50), Float:(0.0 || 1.20), Float:(0.0 || 1.70)

But that only works with integers, plus the first coordinate always has to be 0. So, no...
You cant use conditional logic that way. 0 or anything else then 0 will always give true (or 1 if you will), converted to float, it will become 1.0