Is this possible?
#1

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!");
    }
Reply
#2

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!");
    } 
Reply
#3

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 ?
Reply
#4

yes
Reply
#5

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

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
    
}

Reply
#7

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
Reply
#8

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

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)