Judgement question
#1

All items are in this determine idk why

Код:
public OnPlayerModelSelectionEx(playerid, response, extraid, modelid)
{
	if(!response) return 1;
    if(extraid == 1) //Clothing items
    {
        printf("debug: %d", modelid);
		if(isCopCloth(modelid) && GetPVarInt(playerid, "Member") != 1 || GetPVarInt(playerid, "Member") != 2 || GetPVarInt(playerid, "Member") != 8) return scm(playerid, COLOR_LIGHTRED, "it's only for government.");
		if(isDonatorCloth(modelid) && GetPVarInt(playerid, "DonateRank") == 0 || GetPVarInt(playerid, "MonthDon") == 0) return scm(playerid, COLOR_LIGHTRED, "It's only for donator.");
  		SetPVarInt(playerid, "ToyModelC", modelid);
		ShowPlayerDialog(playerid, 294, DIALOG_STYLE_LIST, "Select Bone", "脊柱\n头部\n左臂\n右臂\n左手\n右手\n左腿\n右腿\n左脚\n右脚\n右小腿\n左小腿\n左前臂\n右前臂\n左肩\n右肩\n脖子\n下巴", "选择","取消");
    }
Код:
stock isCopCloth(modelid)
{
	if(modelid >= 19974 && modelid <= 19785 || modelid == 19347 || modelid == 19942 || modelid == 19520 || modelid == 19521 || modelid == 18637 || modelid == 19141) return 1;
	else return 0;
}
stock isDonatorCloth(modelid)
{
	if(modelid == 11704 || modelid == 1588 || modelid == 18963 || modelid == 19878 || modelid == 19528) return 1;
	else return 0;
}
Reply
#2

So... what's your problem?
Reply
#3

Quote:
Originally Posted by Jamester
Посмотреть сообщение
So... what's your problem?
It doesnt work like if I choose the regular clothing and the first iscopcloth will be called if I'm a cop and donatorcloth will be called. if i'm not cop and donator then they will be always shown: it's only for government
Reply
#4

PHP код:
if((isCopCloth(modelid) && GetPVarInt(playerid"Member") != 1) || GetPVarInt(playerid"Member") != || GetPVarInt(playerid"Member") != 8) return scm(playeridCOLOR_LIGHTRED"it's only for government.");
if((
isDonatorCloth(modelid) && GetPVarInt(playerid"DonateRank") == 0) || GetPVarInt(playerid"MonthDon") == 0) return scm(playeridCOLOR_LIGHTRED"It's only for donator."); 
Reply
#5

Quote:
Originally Posted by Jamester
Посмотреть сообщение
PHP код:
if((isCopCloth(modelid) && GetPVarInt(playerid"Member") != 1) || GetPVarInt(playerid"Member") != || GetPVarInt(playerid"Member") != 8) return scm(playeridCOLOR_LIGHTRED"it's only for government.");
if((
isDonatorCloth(modelid) && GetPVarInt(playerid"DonateRank") == 0) || GetPVarInt(playerid"MonthDon") == 0) return scm(playeridCOLOR_LIGHTRED"It's only for donator."); 
not work
Reply
#6

This is what I understand of the whole thing: if the cloth chosen is a cop cloth and the player is not a member of a governmental faction, it should tell him that. If the chosen cloth is a donator's cloth and the player is not a donator, it should tell him that as well. Right? In that case, you're mixing the right operators in your if-statements.

Here's what I made of it:
PHP код:
if(isCopCloth(modelid)) {
    if((
GetPVarInt(playerid"Member") != 1) && (GetPVarInt(playerid"Member") != 2) && (GetPVarInt(playerid"Member") != 8)) {
        return 
scm(playeridCOLOR_LIGHTRED"it's only for government.");
    }
}
if(
isDonatorCloth(modelid)) {
    if((
GetPVarInt(playerid"DonateRank") == 0) && (GetPVar(playerid"MonthDon") == 0)) {
        return 
scm(playeridCOLOR_LIGHTRED"It's only for donator."); 
    }

Refactored it becomes:
PHP код:
if(isCopCloth(modelid) && ((GetPVarInt(playerid"Member") != 1) && (GetPVarInt(playerid"Member") != 2) && (GetPVarInt(playerid"Member") != 8))) {
    return 
scm(playeridCOLOR_LIGHTRED"it's only for government.");
}
if(
isDonatorCloth(modelid) && ((GetPVarInt(playerid"DonateRank") == 0) && (GetPVar(playerid"MonthDon") == 0))) {
    return 
scm(playeridCOLOR_LIGHTRED"It's only for donator."); 

To understand why, you have to understand how these operators work:

The AND (&&) operator will evaluate to true only if both conditions are true. The OR (||) operator will evaluate to true if one of the conditions or both of them are true. In all other cases it will return false. Here's the truth-table for both operators.

I made a little truth table for both operators in mspaint:


WIKI page: https://sampwiki.blast.hk/wiki/Control_Structures#Operators
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)