Creating a new function
#1

Hey, I'm trying to create a weed system so when you /smokeweed it gets your health and adds +25hp. I haven't made a way to get weed (e.g growing it) so I've made a command for admins to give you it so I can test it out. Everything seems to be working well so far but I'm having troubles trying to get the amount of weed the player has.

E.g if the admin gave the player 3 grams, you can use /smokeweed 3 times, then it will say "You don't have any weed left!". I'm pretty sure I've done the /agiveweed correct (I'm concerned about the "amount" but pretty sure it's correct) and all I want now is for the /smokeweed command to get the amount of weed the player has (or was given by the admin) and continue from there. I've tried to create a "GetPlayerWeed" function so it can see how much weed the player has, but not sure how it will take -1 gram from the player once they use /smokeweed. Please help me out.

Thanks in advanced, here's the script.

pawn Код:
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!");
    {
        Weed[targetid] = amount;
        format(string, sizeof(string), "You have given %s weed!", GetOOCName(targetid));
        SendClientMessage(playerid, WHITE, string);
        format(string, sizeof(string), "Administrator %s has given you weed!", GetOOCName(playerid));
        SendClientMessage(targetid, WHITE, string);
        AdminActionLog(string);
    }
    return 1;
}
   
GetPlayerWeed(playerid, amount)
{
    new amount;
    if(Weed[playerid] = amount;         // need to fix
    return amount
}

CMD:smokeweed(playerid, params[])
{
    new string[128], amount;
    if(Weed [playerid] == 0) return SendClientMessage(playerid, WHITE, "You do not have any weed seeds!");
    if(Weed [playerid] == 1)
    {
        ApplyAnimation(playerid, "JST_BUISNESS", "smoke_01", 4.1, 1, 1, 1, 0, 1, 1);
        new Float:health;
        GetPlayerHealth(playerid, health);
        //if(health > 60) return SendClientMessage(playerid, WHITE, "You cannot smoke weed if your health is 60 or above!");
        SetPlayerHealth(playerid, health+25);
        GetPlayerWeed(playerid, amount);
        format(string, sizeof(string), "%s takes out a joint and smokes some weed.", GetOOCName(playerid));
        SendNearByMessage(playerid, ACTION_COLOR, string, 4);
    }
    return 1;
}
Already done
pawn Код:
new Weed[MAX_PLAYERS];
// and

Weed[playerid] = 0;

These are the errors I need to fix because either the function or the command is wrong

pawn Код:
C:\Users\cbrickell\Desktop\PWN\gamemodes\EGRP.pwn(414) : warning 219: local variable "amount" shadows a variable at a preceding level
C:\Users\cbrickell\Desktop\PWN\gamemodes\EGRP.pwn(415) : warning 211: possibly unintended assignment
C:\Users\cbrickell\Desktop\PWN\gamemodes\EGRP.pwn(415) : error 001: expected token: ")", but found ";"
C:\Users\cbrickell\Desktop\PWN\gamemodes\EGRP.pwn(415) : error 036: empty statement
C:\Users\cbrickell\Desktop\PWN\gamemodes\EGRP.pwn(417) : error 001: expected token: ";", but found "}"
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


3 Errors.
Thanks!
Reply
#2

pawn Код:
GetPlayerWeed(playerid, amount)
{
    new amount;
    if(Weed[playerid] = amount;         // need to fix
    return amount;
}
Reply
#3

It's still returning these errors

pawn Код:
C:\Users\cbrickell\Desktop\PWN\gamemodes\EGRP.pwn(414) : warning 219: local variable "amount" shadows a variable at a preceding level
C:\Users\cbrickell\Desktop\PWN\gamemodes\EGRP.pwn(415) : warning 211: possibly unintended assignment
C:\Users\cbrickell\Desktop\PWN\gamemodes\EGRP.pwn(415) : error 001: expected token: ")", but found ";"
C:\Users\cbrickell\Desktop\PWN\gamemodes\EGRP.pwn(415) : error 036: empty statement
C:\Users\cbrickell\Desktop\PWN\gamemodes\EGRP.pwn(412) : warning 203: symbol is never used: "amount"
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


2 Errors.
Reply
#4

pawn Код:
GetPlayerWeed(playerid, amount)
{
    Weed[playerid] = amount;
    return 1;
}
Reply
#5

Quote:
Originally Posted by Stinged
Посмотреть сообщение
pawn Код:
GetPlayerWeed(playerid, amount)
{
    Weed[playerid] = amount;
    return 1;
}
This got rid of all my errors, but when I type /smokeweed in game, nothing happens. Thanks for the help btw
Reply
#6

pawn Код:
GetPlayerWeed(playerid) return Weed[playerid];
That will return how much weed the player has.

Edit:
pawn Код:
GetPlayerWeed(playerid) return Weed[playerid];
CMD:smokeweed(playerid, params[])
{
    new string[128];
    if(GetPlayerWeed(playerid) == 0) return SendClientMessage(playerid, WHITE, "You do not have any weed seeds!");
    if(GetPlayerWeed(playerid) >= 1)
    {
        ApplyAnimation(playerid, "JST_BUISNESS", "smoke_01", 4.1, 1, 1, 1, 0, 1, 1);
        new Float:health;
        GetPlayerHealth(playerid, health);
        //if(health > 60) return SendClientMessage(playerid, WHITE, "You cannot smoke weed if your health is 60 or above!");
        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;
}
Reply
#7

Quote:
Originally Posted by awsomedude
Посмотреть сообщение
pawn Код:
GetPlayerWeed(playerid) return Weed[playerid];
That will return how much weed the player has.
Oh yeah right, sorry.
I didn't notice it's GetPlayerWeed, I thought it's SetPlayerWeed.
Reply
#8

Quote:
Originally Posted by awsomedude
Посмотреть сообщение
pawn Код:
GetPlayerWeed(playerid) return Weed[playerid];
That will return how much weed the player has.
Will I still need this?

pawn Код:
GetPlayerWeed(playerid, amount)
{
    new amount;
    if(Weed[playerid] = amount;         // need to fix
    return amount;
}
Reply
#9

You don't need GetPlayerWeed(playerid, amount)
Just use Weed[playerid] instead.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)