Drugs amount...
#1

I need help basically I want the player to /td amount
/td is intake of the drugs here is the one part of it

pawn Код:
CMD:td(playerid,params[])//creating a use weed cmd.
{
    if(PlayerInfo[playerid][drugs] > 1)//this will check if the player has the weed or not.
    {
        new Float:Health;//the variable which will store player's health.
        GetPlayerHealth(playerid, Health);//this will get player's health and store it in the variable Health.(new Float:Health).
        SetPlayerHealth(playerid, Health+1);//this will add 20+ health to player's current health.
        PlayerInfo[playerid][drugs] -= 1;//this will minus player's amount of weed because he used some of it.
        SetTimerEx("Usedrugs", 10000, false, "d", playerid);//setting timer for the player for like 10 seconds.
        SendClientMessage(playerid, -1, "You are smoking 1 gram.");//this will send the player a message that he use one gram of weed.
    }
    else
    {
        SendClientMessage(playerid, -1, "You don't have any drugs.");//this error message will appear if he does not have weed to use.
    }
    return 1;
}
Reply
#2

So what exactly is wrong with the code you've posted?
Reply
#3

He wants to do /td [amount]
His script doesn't allow you to type how much weed you want to smoke.
Reply
#4

I'm not really sure, but I'll give it a try.
pawn Код:
CMD:td(playerid,params[])//creating a use weed cmd.
{
    if(PlayerInfo[playerid][drugs] > 0)//this will check if the player has the weed or not.
    {
        new Float:Health;//the variable which will store player's health.
        GetPlayerHealth(playerid, Health);//this will get player's health and store it in the variable Health.(new Float:Health).
        SetPlayerHealth(playerid, Health +20);//this will add 20+ health to player's current health.
        PlayerInfo[playerid][drugs] -= 1;//this will minus player's amount of weed because he used some of it.
        SetTimerEx("Usedrugs", 10000, false, "d", playerid);//setting timer for the player for like 10 seconds.
        SendClientMessage(playerid, -1, "You are smoking 1 gram.");//this will send the player a message that he use one gram of weed.
    }
    else
    {
        SendClientMessage(playerid, -1, "You don't have any drugs.");//this error message will appear if he does not have weed to use.
return 1;
    }
    return 1;
}
If you want it that you use /td amount of drugs name, I will make you another code for it But I think this will help ^
Reply
#5

I don't think that works -_-
Reply
#6

Try this:
pawn Код:
CMD:td(playerid,params[])//creating a use weed cmd.
{
    new tmp[128],idx;
    tmp = strtok(params, idx);
    if(!strlen(tmp))
    {
        SendClientMessage(playerid, 0xFFFFFFAA,"USAGE: /td [amount]");
        return 1;
    }
    new amount = strval(tmp);
    if(PlayerInfo[playerid][drugs] > amount)//this will check if the player has the weed or not.
    {
        new Float:Health;//the variable which will store player's health.
        GetPlayerHealth(playerid, Health);//this will get player's health and store it in the variable Health.(new Float:Health).
        SetPlayerHealth(playerid, Health +20);//this will add 20+ health to player's current health.
        PlayerInfo[playerid][drugs] -= amount;//this will minus player's amount of weed because he used some of it.
        SetTimerEx("Usedrugs", 10000, false, "d", playerid);//setting timer for the player for like 10 seconds.
        SendClientMessage(playerid, -1, "You are smoking 1 gram.");//this will send the player a message that he use one gram of weed.
    }
    else
    {
        SendClientMessage(playerid, -1, "You don't have any drugs.");//this error message will appear if he does not have weed to use.
        return 1;
    }
    return 1;
}
But i don't know how your timer callback looks like..
Reply
#7

Have you even tried it?
Reply
#8

Code using sscanf:

pawn Код:
CMD:td(playerid,params[])//creating a use weed cmd.
{
    new amount;
    if(sscanf(params, "d", amount)) return SendClientMessage(playerid, -1, "USAGE: /td [amount]");
    if(0 < amount <= PlayerInfo[playerid][drugs])//this will check if the player has the weed or not.
    {
        new Float:Health;//the variable which will store player's health.
        GetPlayerHealth(playerid, Health);//this will get player's health and store it in the variable Health.(new Float:Health).
        SetPlayerHealth(playerid, Health+1);//this will add 20+ health to player's current health.
        PlayerInfo[playerid][drugs] -= amount;//this will minus player's amount of weed because he used some of it.
        SetTimerEx("Usedrugs", 10000, false, "d", playerid);//setting timer for the player for like 10 seconds.
        format(string, sizeof(string), "You are smoking %d gram(s).", amount);
        SendClientMessage(playerid, -1, string);//this will send the player a message that he use one gram of weed.
    }
    else
    {
        SendClientMessage(playerid, -1, "You don't have enough drugs.");//this error message will appear if he does not have weed to use.
    }
    return 1;
}
Reply
#9

Quote:
Originally Posted by Macronix
Посмотреть сообщение
Try this:
pawn Код:
CMD:td(playerid,params[])//creating a use weed cmd.
{
    new tmp[128],idx;
    tmp = strtok(params, idx);
    if(!strlen(tmp))
    {
        SendClientMessage(playerid, 0xFFFFFFAA,"USAGE: /td [amount]");
        return 1;
    }
    new amount = strval(tmp);
    if(PlayerInfo[playerid][drugs] > amount)//this will check if the player has the weed or not.
    {
        new Float:Health;//the variable which will store player's health.
        GetPlayerHealth(playerid, Health);//this will get player's health and store it in the variable Health.(new Float:Health).
        SetPlayerHealth(playerid, Health +20);//this will add 20+ health to player's current health.
        PlayerInfo[playerid][drugs] -= amount;//this will minus player's amount of weed because he used some of it.
        SetTimerEx("Usedrugs", 10000, false, "d", playerid);//setting timer for the player for like 10 seconds.
        SendClientMessage(playerid, -1, "You are smoking 1 gram.");//this will send the player a message that he use one gram of weed.
    }
    else
    {
        SendClientMessage(playerid, -1, "You don't have any drugs.");//this error message will appear if he does not have weed to use.
        return 1;
    }
    return 1;
}
But i don't know how your timer callback looks like..
C:\Users\Grand\Desktop\Ultimate Gaming Ground\filterscripts\drugs.pwn(66) : error 017: undefined symbol "strtok"
C:\Users\Grand\Desktop\Ultimate Gaming Ground\filterscripts\drugs.pwn(66) : error 033: array must be indexed (variable "tmp")
C:\Users\Grand\Desktop\Ultimate Gaming Ground\filterscripts\drugs.pwn(65) : warning 203: symbol is never used: "idx"

MY TIME CALL BACK =
pawn Код:
forward Usedrugs(playerid);
public Usedrugs(playerid)
{
    SendClientMessage(playerid, -1,"The Grams you have used are finished.");
    return 1;
}
Reply
#10

Quote:
Originally Posted by Xabi
Посмотреть сообщение
Code using sscanf:

pawn Код:
CMD:td(playerid,params[])//creating a use weed cmd.
{
    new amount;
    if(sscanf(params, "d", amount)) return SendClientMessage(playerid, -1, "USAGE: /td [amount]");
    if(0 < amount <= PlayerInfo[playerid][drugs])//this will check if the player has the weed or not.
    {
        new Float:Health;//the variable which will store player's health.
        GetPlayerHealth(playerid, Health);//this will get player's health and store it in the variable Health.(new Float:Health).
        SetPlayerHealth(playerid, Health+1);//this will add 20+ health to player's current health.
        PlayerInfo[playerid][drugs] -= amount;//this will minus player's amount of weed because he used some of it.
        SetTimerEx("Usedrugs", 10000, false, "d", playerid);//setting timer for the player for like 10 seconds.
        format(string, sizeof(string), "You are smoking %d gram(s).", amount);
        SendClientMessage(playerid, -1, string);//this will send the player a message that he use one gram of weed.
    }
    else
    {
        SendClientMessage(playerid, -1, "You don't have enough drugs.");//this error message will appear if he does not have weed to use.
    }
    return 1;
}
I'm using this atm thanks btw...
+ you did miss out
pawn Код:
new string[128];
I added it in.

Now my buydrugs command does not function properly

pawn Код:
CMD:buydrugs(playerid,params[])
{
    new amount;
    if(sscanf(params,"i",amount)) return SendClientMessage(playerid, -1, "USAGE:/buydrugs (Amount)");

    if(amount > 0)
    {
        PlayerInfo[playerid][drugs] = amount;
        GivePlayerMoney(playerid, -( amount * 10)); // change 10 for the price of 1 drug
        new string[ 128 ];
        format(string, sizeof(string), "You have Bought %d Drugs", amount);
        SendClientMessage(playerid, -1, string);
        }
    return 1;
}
It does not work properly as it replaces how many drugs you have lets say I'm carrying 10 and buy 20 more it will say I have 20 and my 10 will just go and be vanished somewere
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)