SA-MP Forums Archive
Help with "||" - 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: Help with "||" (/showthread.php?tid=665748)



Help with "||" - ImTobi - 14.04.2019

I have a Problem with the "||" or "or" function

Code:
if(pInfo[playerid][fraktion] != 1 || pInfo[playerid][fraktion] != 4)return SendClientMessage(playerid, COLOR_RED, "You are not a member of the SFPD or LSPD.");
i am in the LSPD, but it shows the error


Re: Help with "||" - Jstylezzz - 14.04.2019

That's because this variable won't have two values at the same time. In other words, the two conditions will never be met at the same time. That means that one of your conditions will always trigger.


Re: Help with "||" - ImTobi - 14.04.2019

Quote:
Originally Posted by Jstylezzz
View Post
That's because this variable won't have two values at the same time. In other words, the two conditions will never be met at the same time. That means that one of your conditions will always trigger.
How can i do it then?

it isn't like "if fraction is 1 and 4" it should chekc if its one OR the other


Re: Help with "||" - Jstylezzz - 14.04.2019

Technically this if statement will trigger when your faction is not 1 and when it's not 4. The thing is, when faction is equal to 1, it is not equal to 4, which causes the if statement to trigger. Same the other way around. If your faction is 4, it is not 1, which will cause the first check to trigger the if statement.

I'm guessing this is part of a command? Which faction IDs should be able to use it? If both ID 1 and ID 4 are allowed to use it, you can change || to &&.


Re: Help with "||" - ImTobi - 14.04.2019

Quote:
Originally Posted by Jstylezzz
View Post
Technically this if statement will trigger when your faction is not 1 and when it's not 4. The thing is, when faction is equal to 1, it is not equal to 4, which causes the if statement to trigger. Same the other way around. If your faction is 4, it is not 1, which will cause the first check to trigger the if statement.

I'm guessing this is part of a command? Which faction IDs should be able to use it? If both ID 1 and ID 4 are allowed to use it, you can change || to &&.
Code:
CMD:pdht(playerid, params[])
{
	if(eingeloggt[playerid] == 0)return SendClientMessage(playerid, COLOR_RED, "Du bist noch nicht eingeloggt.");
	if(pInfo[playerid][fraktion] != 1 && pInfo[playerid][fraktion] != 4)return SendClientMessage(playerid, COLOR_RED, "You aren't a member of the SFPD or the LSPD.");
	if(pInfo[playerid][duty] != 1)return SendClientMessage(playerid, COLOR_RED, "Du bist nicht im Dienst.");
	if(SWAT[playerid] == 1)return SendClientMessage(playerid, COLOR_RED, "Du kannst keine Weste anziehen wenn du SWAT bist.");
	if(GetPVarInt(playerid,"HutAn") == 1)
	{
		SetPVarInt(playerid, "HutAn", 0);
		//DestroyObject(PDHut[playerid]);
		RemovePlayerAttachedObject(playerid, 1);
		SendClientMessage(playerid, COLOR_WHITE, "Du hast den Hut abgenommen.");
		pdhutan[playerid] = 0;
		return 1;
	}
	SetPVarInt(playerid,"HutAn",1);
	//new Float:x,Float:y,Float:z;
	//GetPlayerPos(playerid,x,y,z);
	//PDHut[playerid] = CreateObject(19096, x,y,z, 0.0000, -90.0000, 0.0000); //CowboyHat3
	SetPlayerAttachedObject(playerid, 1, 19096, 2, 0.130, 0.012, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0,0);
	SendClientMessage(playerid, COLOR_WHITE, "Du hast den Hut aufgesetzt.");
	pdhutan[playerid] = 1;
	return 1;
}
so like that?


Re: Help with "||" - Jstylezzz - 14.04.2019

Quote:
Originally Posted by ImTobi
View Post
Code:
CMD:pdht(playerid, params[])
{
	if(eingeloggt[playerid] == 0)return SendClientMessage(playerid, COLOR_RED, "Du bist noch nicht eingeloggt.");
	if(pInfo[playerid][fraktion] != 1 && pInfo[playerid][fraktion] != 4)return SendClientMessage(playerid, COLOR_RED, "Du bist kein Mitglied vom SFPD oder LSPD.");
	if(pInfo[playerid][duty] != 1)return SendClientMessage(playerid, COLOR_RED, "Du bist nicht im Dienst.");
	if(SWAT[playerid] == 1)return SendClientMessage(playerid, COLOR_RED, "Du kannst keine Weste anziehen wenn du SWAT bist.");
	if(GetPVarInt(playerid,"HutAn") == 1)
	{
		SetPVarInt(playerid, "HutAn", 0);
		//DestroyObject(PDHut[playerid]);
		RemovePlayerAttachedObject(playerid, 1);
		SendClientMessage(playerid, COLOR_WHITE, "Du hast den Hut abgenommen.");
		pdhutan[playerid] = 0;
		return 1;
	}
	SetPVarInt(playerid,"HutAn",1);
	//new Float:x,Float:y,Float:z;
	//GetPlayerPos(playerid,x,y,z);
	//PDHut[playerid] = CreateObject(19096, x,y,z, 0.0000, -90.0000, 0.0000); //CowboyHat3
	SetPlayerAttachedObject(playerid, 1, 19096, 2, 0.130, 0.012, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0,0);
	SendClientMessage(playerid, COLOR_WHITE, "Du hast den Hut aufgesetzt.");
	pdhutan[playerid] = 1;
	return 1;
}
so like that?
Guessing that ID 1 and 4 represent SFPD and LSPD, that should work
If you are ID 1, the first check will return false which will skip the other check, which in turn just skips over the if statement and its code block. Same idea for ID 4.


Re: Help with "||" - ImTobi - 14.04.2019

Quote:
Originally Posted by Jstylezzz
View Post
Guessing that ID 1 and 4 represent SFPD and LSPD, that should work
If you are ID 1, the first check will return false which will skip the other check, which in turn just skips over the if statement and its code block. Same idea for ID 4.
thxxxx that worked! REP