SA-MP Forums Archive
Why does /smokeweed work when got no weed? - 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: Why does /smokeweed work when got no weed? (/showthread.php?tid=539679)



Why does /smokeweed work when got no weed? - Josh_Main - 29.09.2014

/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;



Re: Why does /smokeweed work when got no weed? - DavidBilla - 29.09.2014

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


Re: Why does /smokeweed work when got no weed? - Kyance - 29.09.2014

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


Re: Why does /smokeweed work when got no weed? - Josh_Main - 30.09.2014

Thanks!!


Re: Why does /smokeweed work when got no weed? - Josh_Main - 30.09.2014

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


Re: Why does /smokeweed work when got no weed? - [CG]Milito - 30.09.2014

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




Re: Why does /smokeweed work when got no weed? - Josh_Main - 01.10.2014

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


Re: Why does /smokeweed work when got no weed? - Stinged - 01.10.2014

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.