Why does /smokeweed work when got no weed?
#1

/smokeweed is working even when the player has no weed.. Even if an admin only gives the player 1 gram or so, they can still /smokeweed. They can also keep using /smokeweed even when their health is above 75? Please help me.
Thanks!

pawn Код:
GetPlayerWeed(playerid) return Weed[playerid];

CMD:agiveweed(playerid, params[])                                
{
    new targetid, string[128], amount;
    if(PlayerStat[playerid] [AdminLevel] < 2) return SendClientMessage(playerid, GREY, "You don't have access to this command!");
    if(sscanf(params, "ud[128]", targetid, amount)) return SendClientMessage(playerid, GREY, "USAGE: /agiveweed [playerid] [amount]");
    if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, GREY, "That player is not connected!");
    {
        GetPlayerWeed(playerid);
        Weed[targetid] = amount+1;
        format(string, sizeof(string), "You have given %s %d gram(s) of weed!", GetOOCName(targetid), amount);
        SendClientMessage(playerid, WHITE, string);
        format(string, sizeof(string), "Administrator %s has given you %d gram(s) of weed!", GetOOCName(playerid), amount);
        SendClientMessage(targetid, WHITE, string);
        AdminActionLog(string);
    }
    return 1;
}

   
CMD:smokeweed(playerid, params[])
{
    if(GetPlayerWeed(playerid) < 1 ) return SendClientMessage(playerid, WHITE, "You don't have any weed left!");
    {
        new Float:health;
        if(GetPlayerHealth(playerid, health) > 75) return SendClientMessage(playerid, WHITE, "You cannot smoke weed if your health is above 75!");
        {
            new string[128];
            ApplyAnimation(playerid, "JST_BUISNESS", "smoke_01", 4.1, 1, 1, 1, 0, 1, 1);
            SetPlayerHealth(playerid, health+25);
            format(string, sizeof(string), "%s takes out a joint and smokes some weed.", GetOOCName(playerid));
            SendNearByMessage(playerid, ACTION_COLOR, string, 4);
        }
    }
    return 1;                              
}
Edit: No errors or warning in the script

Also got

pawn Код:
new Weed[MAX_PLAYERS];
// and
Weed[playerid] = 0;
Reply
#2

pawn Код:
GetPlayerWeed(playerid) return Weed[playerid];

CMD:agiveweed(playerid, params[])                                
{
    new targetid, string[128], amount;
    if(PlayerStat[playerid] [AdminLevel] < 2) return SendClientMessage(playerid, GREY, "You don't have access to this command!");
    if(sscanf(params, "ud[128]", targetid, amount)) return SendClientMessage(playerid, GREY, "USAGE: /agiveweed [playerid] [amount]");
    if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, GREY, "That player is not connected!");
    else
    {
        GetPlayerWeed(playerid);
        Weed[targetid] = amount+1;
        format(string, sizeof(string), "You have given %s %d gram(s) of weed!", GetOOCName(targetid), amount);
        SendClientMessage(playerid, WHITE, string);
        format(string, sizeof(string), "Administrator %s has given you %d gram(s) of weed!", GetOOCName(playerid), amount);
        SendClientMessage(targetid, WHITE, string);
        AdminActionLog(string);
    }
    return 1;
}

   
CMD:smokeweed(playerid, params[])
{
    if(GetPlayerWeed(playerid) < 1 ) return SendClientMessage(playerid, WHITE, "You don't have any weed left!");
    else
        {
            new Float:health;
            if(GetPlayerHealth(playerid, health) > 75) return SendClientMessage(playerid, WHITE, "You cannot smoke weed if your health is above 75!");
            else
            {
                new string[128];
                ApplyAnimation(playerid, "JST_BUISNESS", "smoke_01", 4.1, 1, 1, 1, 0, 1, 1);
                SetPlayerHealth(playerid, health+25);
                format(string, sizeof(string), "%s takes out a joint and smokes some weed.", GetOOCName(playerid));
                SendNearByMessage(playerid, ACTION_COLOR, string, 4);
            }
        }
    return 1;                              
}
This will work
But i just messed up the intendation since I'm on mobile
Reply
#3

pawn Код:
CMD:smokeweed(playerid, params[])
{
    if(!GetPlayerWeed(playerid)) return SendClientMessage(playerid, GREY, "You don't have any weed left!");
    {
        new Float:health; GetPlayerHealth(playerid, health);
        if(health > 75) return SendClientMessage(playerid, GREY, "You cannot smoke weed if your health is above 75!");
        {
            new string[128];
            ApplyAnimation(playerid, "JST_BUISNESS", "smoke_01", 4.1, 1, 1, 1, 0, 1, 1);
            SetPlayerHealth(playerid, health+25);
            format(string, sizeof(string), "%s takes out a joint and smokes some weed.", GetOOCName(playerid));
            SendNearByMessage(playerid, -1, string, 4);
        }
    }
    return 1;
}
should work
Reply
#4

Thanks!!
Reply
#5

Quote:
Originally Posted by DavidBilla
Посмотреть сообщение
pawn Код:
GetPlayerWeed(playerid) return Weed[playerid];

CMD:agiveweed(playerid, params[])                                
{
    new targetid, string[128], amount;
    if(PlayerStat[playerid] [AdminLevel] < 2) return SendClientMessage(playerid, GREY, "You don't have access to this command!");
    if(sscanf(params, "ud[128]", targetid, amount)) return SendClientMessage(playerid, GREY, "USAGE: /agiveweed [playerid] [amount]");
    if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, GREY, "That player is not connected!");
    else
    {
        GetPlayerWeed(playerid);
        Weed[targetid] = amount+1;
        format(string, sizeof(string), "You have given %s %d gram(s) of weed!", GetOOCName(targetid), amount);
        SendClientMessage(playerid, WHITE, string);
        format(string, sizeof(string), "Administrator %s has given you %d gram(s) of weed!", GetOOCName(playerid), amount);
        SendClientMessage(targetid, WHITE, string);
        AdminActionLog(string);
    }
    return 1;
}

   
CMD:smokeweed(playerid, params[])
{
    if(GetPlayerWeed(playerid) < 1 ) return SendClientMessage(playerid, WHITE, "You don't have any weed left!");
    else
        {
            new Float:health;
            if(GetPlayerHealth(playerid, health) > 75) return SendClientMessage(playerid, WHITE, "You cannot smoke weed if your health is above 75!");
            else
            {
                new string[128];
                ApplyAnimation(playerid, "JST_BUISNESS", "smoke_01", 4.1, 1, 1, 1, 0, 1, 1);
                SetPlayerHealth(playerid, health+25);
                format(string, sizeof(string), "%s takes out a joint and smokes some weed.", GetOOCName(playerid));
                SendNearByMessage(playerid, ACTION_COLOR, string, 4);
            }
        }
    return 1;                              
}
This will work
But i just messed up the intendation since I'm on mobile
Still lets you /smokeweed as much as you want even if the admin only gives you 1 gram
Reply
#6

Then, just add another if clause & a new parameter to your command

New parameter:

PHP код:
new ammount
Like this :

PHP код:
if(GetPlayerWeed(playerid) < ammount)
{
    
SendClienMessage(playerid,-1,"You don't have enough weed!");
}
else
{
//////If the player has enough weed, run code

Reply
#7

Quote:
Originally Posted by [CG]Milito
Посмотреть сообщение
Then, just add another if clause & a new parameter to your command

New parameter:

PHP код:
new ammount
Like this :

PHP код:
if(GetPlayerWeed(playerid) < ammount)
{
    
SendClienMessage(playerid,-1,"You don't have enough weed!");
}
else
{
//////If the player has enough weed, run code

Just added this, but I can still /smokeweed as much as I want
Reply
#8

Quote:
Originally Posted by Josh_Main
Посмотреть сообщение
Just added this, but I can still /smokeweed as much as I want
Make a very simple command showing the amount of weed the player has, and then tell me what you get when you use it.

You're probably not resetting the Weed variable.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)