"&&" question
#1

Is it possible to use this in one line:
pawn Код:
if ((APlayerData[playerid][PlayerLevel] == 5) && (PoliceGetsWeapons == true) && (APlayerData[playerid][PlayerClass] == ClassPolice))
Is this even possible? Or not?

Since script is not working.

It compiles succesfull with no errors.
But (its a anti hack script) the command isn't working, it automatically resets the weapons even if the "&&" is included about APlayerData.

Script now:

pawn Код:
if ((APlayerData[playerid][PlayerLevel] == 5) && (PoliceGetsWeapons == true) && (APlayerData[playerid][PlayerClass] == ClassPolice))
    {
        // Do nothing
    }
    else
        ResetPlayerWeapons(playerid);
Our /agodon command:
pawn Код:
COMMAND:agodon(playerid,params[])
{
    if (APlayerData[playerid][PlayerLevel] >= 3)
    {
    GivePlayerWeapon(playerid,38,999999);
    SetPlayerHealth(playerid,999999);
    SetPlayerArmour(playerid,999999);
    SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}GOD Mode on.");
    }
    else
    SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}You are not an admin!");

    return 1;
}
The command itself doesn't really matters to it.
Anyone knows how I could fix this?
Reply
#2

use || or && but dont () your script

if (APlayerData[playerid][PlayerLevel] == 5 || PoliceGetsWeapons == true || APlayerData[playerid][PlayerClass] == ClassPolice)
{
}
Reply
#3

Lol when i opened up the topic, I thought is it one of my old questions(because of the avatar)

Quote:
Originally Posted by juraska
Посмотреть сообщение
use || or && but dont () your script

if (APlayerData[playerid][PlayerLevel] == 5 || PoliceGetsWeapons == true || APlayerData[playerid][PlayerClass] == ClassPolice)
{
}
() Don't affect your script at all.

|| means OR
&& means AND
so maybe there's some mistake at your code, for example PoliceGetsWeapons is false.
Reply
#4

Yes, that is possible.

|| = OR
&& = AND
: = ELSE
? = THEN

for example:
pawn Код:
CMD:kill(playerid, params[]) return if(GetPlayerWantedLevel(playerid, >= 1)) ? SendClientMessage(playerid, -1, "Can't use kill when wanted") : SetPlayerHealth(playerid, 0);
That's possible too.

Example is from JaTochNietDan.
Reply
#5

Quote:
Originally Posted by Max_Coldheart
Посмотреть сообщение
Yes, that is possible.

|| = OR
&& = AND
: = ELSE
? = THEN

for example:
pawn Код:
CMD:kill(playerid, params[]) return if(GetPlayerWantedLevel(playerid, >= 1)) ? SendClientMessage(playerid, -1, "Can't use kill when wanted") : SetPlayerHealth(playerid, 0);
That's possible too.

Example is from JaTochNietDan.
What the hell is this
pawn Код:
if(GetPlayerWantedLevel(playerid, >= 1)) ?
You dont use "?" after an if clause.
and why is >= 1 in the function?
Valid examples:
pawn Код:
return (GetPlayerWantedLevel(playerid) >= 0) SendClientMessage(playerid,RED," You are wanted!") : SendClientMessage(playerid,GREEN," OK!");
and
pawn Код:
if(GetPlayerWantedLevel(playerid) >= 0)
return SendClientMessage(playerid,RED," You are wanted!")
else
return SendClientMessage(playerid,GREEN," OK!");
Reply
#6

Quote:
Originally Posted by wups
Посмотреть сообщение
What the hell is this
pawn Код:
if(GetPlayerWantedLevel(playerid, >= 1)) ?
You dont use "?" after an if clause.
and why is >= 1 in the function?
Valid examples:
pawn Код:
return (GetPlayerWantedLevel(playerid) >= 0) SendClientMessage(playerid,RED," You are wanted!") : SendClientMessage(playerid,GREEN," OK!");
and
pawn Код:
if(GetPlayerWantedLevel(playerid) >= 0)
return SendClientMessage(playerid,RED," You are wanted!")
else
return SendClientMessage(playerid,GREEN," OK!");
As explained
? = then
and the >= is greater then, it is used mostly in commands for example if you had a /kick command and use if(PlayerInfo[playerid][pAdmin] == 1) then that would be only for 1 if you use >= that is anything higher then 1 or <= anything lower.
Reply
#7

Take a look at this topic: https://sampforum.blast.hk/showthread.php?tid=216730
Look for the 'The ternary operator', and you will know what the '?' & ':' will do
About the >=, that isnt greater then. Its greater then OR equals to.
Example
pawn Код:
if( 1 >= 3 ) == if( 1 is GREATER or EQUALS to 3 )
if( 1 <= 3 ) == if( 1 is LESS or EQUALS to 3 )
Reply
#8

Just to explain to wufs that his code is wrong and Max_Coldheart's was good
PHP код:
return (GetPlayerWantedLevel(playerid) >= 0SendClientMessage(playerid,RED," You are wanted!") : SendClientMessage(playerid,GREEN," OK!"); 
So if player's wanted level is 0 he is wanted?
Reply
#9

Quote:
Originally Posted by [MG]Dimi
Посмотреть сообщение
Just to explain to wufs that his code is wrong and Max_Coldheart's was good
PHP код:
return (GetPlayerWantedLevel(playerid) >= 0SendClientMessage(playerid,RED," You are wanted!") : SendClientMessage(playerid,GREEN," OK!"); 
So if player's wanted level is 0 he is wanted?
Max wasnt wrong with his code. That would actually work.
pawn Код:
CMD:kill(playerid, params[]) return if(GetPlayerWantedLevel(playerid, >= 1)) ? SendClientMessage(playerid, -1, "Can't use kill when wanted") : SetPlayerHealth(playerid, 0);
This will check if your wanted level is 1 or higher, if thats true, it will send the message. When it is 0, it will just kill you.
pawn Код:
if( (GetPlayerWantedLevel(playerid) >= 1 ) ?[THEN] SendClientMessage(playerid, ....) :[ELSE] SetPlayerHealth(playerid...);
Reply
#10

Quote:
Originally Posted by Wesley221
Посмотреть сообщение
Max wasnt wrong with his code. That would actually work.
pawn Код:
CMD:kill(playerid, params[]) return if(GetPlayerWantedLevel(playerid, >= 1)) ? SendClientMessage(playerid, -1, "Can't use kill when wanted") : SetPlayerHealth(playerid, 0);
This will check if your wanted level is 1 or higher, if thats true, it will send the message. When it is 0, it will just kill you.
pawn Код:
if( (GetPlayerWantedLevel(playerid) >= 1 ) ?[THEN] SendClientMessage(playerid, ....) :[ELSE] SetPlayerHealth(playerid...);
Max was wrong with his code. I don't know if you did not notice but there's a difference in doing
pawn Код:
if(GetPlayerWantedLevel(playerid, >= 1))
and
pawn Код:
if(GetPlayerWantedLevel(playerid) >= 1)
[url=https://sampwiki.blast.hk/wiki/GetPlayerWantedLevel]GetPlayerWantedLevel[url] returns the players wanted level, does not store it in an extra parameter.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)