This is utterly confusing....How can this be?
#1

When I type /usedrug weed, it uses cocaine, when I type /usedrug coke it uses weed!

What the hell?


pawn Код:
CMD:usedrug(playerid, params[])
{
    if(LoggedIn[playerid] == 0)return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
    if(Cocaine[playerid] && Weed[playerid] == 0)return SendClientMessage(playerid, COLOUR_GREY, "You do not have any drugs to use.");
    new usage[24], string[128];
    if(sscanf(params, "s[24]", usage)) return SendClientMessage(playerid, COLOUR_GREY, "USAGE: /usedrug [drug] - Drug types: weed, coke.");
   
    if(strcmp(usage, "coke", true))
        {
            if(IsDrugged[playerid] == 1) return SendClientMessage(playerid, COLOUR_GREY, "You are already using drugs.");
            SetPlayerWeather(playerid, 39);
            SetPlayerDrunkLevel(playerid, 3000);
            Cocaine[playerid] = Cocaine[playerid] - 1;
            DrugUsed[playerid] = 1;
            IsDrugged[playerid] = 1;
            DruggedTime[playerid] = 45;
            PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
            MySQL_SetInteger(PlayerSQLID[playerid], "Cocaine", Cocaine[playerid], "accounts");
            SetTimer("DruggedTimer", 1000, 1);
            format(string, sizeof(string), "You have taken 1 gram of cocaine, you will recieve an armour boost after the effects wear off.");
            SendClientMessage(playerid, COLOUR_WHITE, string);
            }
    if(strcmp(usage, "weed", true))
        {
            if(IsDrugged[playerid] == 1) return SendClientMessage(playerid, COLOUR_GREY, "You are already using drugs.");
            SetPlayerWeather(playerid, 20);
            SetPlayerDrunkLevel(playerid, 3000);
            Weed[playerid] = Weed[playerid] - 1;
            DrugUsed[playerid] = 2;
            DruggedTime[playerid] = 45;
            PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
            MySQL_SetInteger(PlayerSQLID[playerid], "Weed", Weed[playerid], "accounts");
            SetTimer("DruggedTimer", 1000, 1);
            format(string, sizeof(string), "You have taken 1 gram of weed, you will recieve a health boost after the effects wear off.");
            SendClientMessage(playerid, COLOUR_WHITE, string);
       

        }
    return 1;
}
Reply
#2

pawn Код:
CMD:usedrug(playerid, params[])
{
    if(LoggedIn[playerid] == 0)return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
    if(Cocaine[playerid] && Weed[playerid] == 0)return SendClientMessage(playerid, COLOUR_GREY, "You do not have any drugs to use.");
    new usage[24], string[128];
    if(sscanf(params, "s[24]", usage)) return SendClientMessage(playerid, COLOUR_GREY, "USAGE: /usedrug [drug] - Drug types: weed, coke.");
   
    if(!strcmp(usage, "coke", true))
        {
            if(IsDrugged[playerid] == 1) return SendClientMessage(playerid, COLOUR_GREY, "You are already using drugs.");
            SetPlayerWeather(playerid, 39);
            SetPlayerDrunkLevel(playerid, 3000);
            Cocaine[playerid] = Cocaine[playerid] - 1;
            DrugUsed[playerid] = 1;
            IsDrugged[playerid] = 1;
            DruggedTime[playerid] = 45;
            PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
            MySQL_SetInteger(PlayerSQLID[playerid], "Cocaine", Cocaine[playerid], "accounts");
            SetTimer("DruggedTimer", 1000, 1);
            format(string, sizeof(string), "You have taken 1 gram of cocaine, you will recieve an armour boost after the effects wear off.");
            SendClientMessage(playerid, COLOUR_WHITE, string);
            }
    if(!strcmp(usage, "weed", true))
        {
            if(IsDrugged[playerid] == 1) return SendClientMessage(playerid, COLOUR_GREY, "You are already using drugs.");
            SetPlayerWeather(playerid, 20);
            SetPlayerDrunkLevel(playerid, 3000);
            Weed[playerid] = Weed[playerid] - 1;
            DrugUsed[playerid] = 2;
            DruggedTime[playerid] = 45;
            PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
            MySQL_SetInteger(PlayerSQLID[playerid], "Weed", Weed[playerid], "accounts");
            SetTimer("DruggedTimer", 1000, 1);
            format(string, sizeof(string), "You have taken 1 gram of weed, you will recieve a health boost after the effects wear off.");
            SendClientMessage(playerid, COLOUR_WHITE, string);
       

        }
    return 1;
}
You must add ! before the strcmp
Reply
#3

Quote:
Originally Posted by Tanush123
Посмотреть сообщение
pawn Код:
CMD:usedrug(playerid, params[])
{
    if(LoggedIn[playerid] == 0)return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
    if(Cocaine[playerid] && Weed[playerid] == 0)return SendClientMessage(playerid, COLOUR_GREY, "You do not have any drugs to use.");
    new usage[24], string[128];
    if(sscanf(params, "s[24]", usage)) return SendClientMessage(playerid, COLOUR_GREY, "USAGE: /usedrug [drug] - Drug types: weed, coke.");
   
    if(!strcmp(usage, "coke", true))
        {
            if(IsDrugged[playerid] == 1) return SendClientMessage(playerid, COLOUR_GREY, "You are already using drugs.");
            SetPlayerWeather(playerid, 39);
            SetPlayerDrunkLevel(playerid, 3000);
            Cocaine[playerid] = Cocaine[playerid] - 1;
            DrugUsed[playerid] = 1;
            IsDrugged[playerid] = 1;
            DruggedTime[playerid] = 45;
            PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
            MySQL_SetInteger(PlayerSQLID[playerid], "Cocaine", Cocaine[playerid], "accounts");
            SetTimer("DruggedTimer", 1000, 1);
            format(string, sizeof(string), "You have taken 1 gram of cocaine, you will recieve an armour boost after the effects wear off.");
            SendClientMessage(playerid, COLOUR_WHITE, string);
            }
    if(!strcmp(usage, "weed", true))
        {
            if(IsDrugged[playerid] == 1) return SendClientMessage(playerid, COLOUR_GREY, "You are already using drugs.");
            SetPlayerWeather(playerid, 20);
            SetPlayerDrunkLevel(playerid, 3000);
            Weed[playerid] = Weed[playerid] - 1;
            DrugUsed[playerid] = 2;
            DruggedTime[playerid] = 45;
            PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
            MySQL_SetInteger(PlayerSQLID[playerid], "Weed", Weed[playerid], "accounts");
            SetTimer("DruggedTimer", 1000, 1);
            format(string, sizeof(string), "You have taken 1 gram of weed, you will recieve a health boost after the effects wear off.");
            SendClientMessage(playerid, COLOUR_WHITE, string);
       

        }
    return 1;
}
You must add ! before the strcmp
Yes but why?
Reply
#4

So the code will work? Did you try
Reply
#5

strcmp return 0 on success due to the way the strings are compared in the first place. I read a post about it a whole time ago about it having to do something with subtraction of character values (e.g. 'A' has the value 65).
Reply
#6

Stupid really. I would have made it 1 if it matches and 0 if not. No wonder people get confused.
Reply
#7

But why does it has to be if(strcmp / if(!strcmp).
Can't it be something like
pawn Код:
if(str,"Coke")
{
     //code
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
It's not stupid because it's not "strsame", it's "strcmp" - COMPARE the strings and return the DIFFERENCE. If they're the same there's no difference, i.e. 0. People get confused because they assume they know what functions do based on a cursory reading of what they're commonly used for and what they think they know about other languages which I keep trying to tell them aren't PAWN.
Oh ****** I love you.

no homo
Reply
#9

Quote:
Originally Posted by Tanush123
Посмотреть сообщение
But why does it has to be if(strcmp / if(!strcmp).
Can't it be something like
pawn Код:
if(str,"Coke")
{
     //code
pawn Код:
#define IsSame(%0,%1) !strcmp(%0,%1,true,strlen(%1)) //Newbie def. ;)

//Example:
if(IsSame("SOMEBULLSHITINEVEREXPECTED","SOMEBULLSHITINEVEREXPECTED"))
    {
        print("ok!");
    }
//will print: ok!

OR:

#define strsame !strcmp

if(strsame("ABC123", "ABC123", true, 6))
    {
        print("fdok!");
    }
Reply
#10

I wrote a guide on exactly this, check out my signature and you'll understand why.
https://sampforum.blast.hk/showthread.php?tid=250454
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)