SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 29/09/2014, 02:57 PM   #1
Josh_Main
Huge Clucker
 
Join Date: Mar 2012
Location: Main-Hosts.com
Posts: 446
Reputation: 12
Default Creating a new function

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 Code:
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 Code:
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 Code:
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!
Josh_Main is offline   Reply With Quote
Old 29/09/2014, 03:05 PM   #2
MasonSFW
Huge Clucker
 
MasonSFW's Avatar
 
Join Date: Feb 2014
Location: Thailand
Posts: 302
Reputation: 14
Default Re: Creating a new function

pawn Code:
GetPlayerWeed(playerid, amount)
{
    new amount;
    if(Weed[playerid] = amount;         // need to fix
    return amount;
}
__________________
5.175.181.128:7777 - Updated 2015

Join us, Great community .

_________________________________________________
My work:
MasonSFW is offline   Reply With Quote
Old 29/09/2014, 03:12 PM   #3
Josh_Main
Huge Clucker
 
Join Date: Mar 2012
Location: Main-Hosts.com
Posts: 446
Reputation: 12
Default Re: Creating a new function

It's still returning these errors

pawn Code:
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.
Josh_Main is offline   Reply With Quote
Old 29/09/2014, 03:21 PM   #4
Stinged
High-roller
 
Join Date: Feb 2013
Posts: 1,574
Reputation: 187
Default Re: Creating a new function

pawn Code:
GetPlayerWeed(playerid, amount)
{
    Weed[playerid] = amount;
    return 1;
}
Stinged is offline   Reply With Quote
Old 29/09/2014, 03:25 PM   #5
Josh_Main
Huge Clucker
 
Join Date: Mar 2012
Location: Main-Hosts.com
Posts: 446
Reputation: 12
Default Re: Creating a new function

Quote:
Originally Posted by Stinged View Post
pawn Code:
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
Josh_Main is offline   Reply With Quote
Old 29/09/2014, 03:27 PM   #6
awsomedude
Big Clucker
 
awsomedude's Avatar
 
Join Date: Oct 2011
Posts: 190
Reputation: 47
Default Re: Creating a new function

pawn Code:
GetPlayerWeed(playerid) return Weed[playerid];

That will return how much weed the player has.

Edit:
pawn Code:
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;
}

Last edited by awsomedude; 29/09/2014 at 06:41 PM.
awsomedude is offline   Reply With Quote
Old 29/09/2014, 03:31 PM   #7
Stinged
High-roller
 
Join Date: Feb 2013
Posts: 1,574
Reputation: 187
Default Re: Creating a new function

Quote:
Originally Posted by awsomedude View Post
pawn Code:
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.
Stinged is offline   Reply With Quote
Old 29/09/2014, 04:26 PM   #8
Josh_Main
Huge Clucker
 
Join Date: Mar 2012
Location: Main-Hosts.com
Posts: 446
Reputation: 12
Default Re: Creating a new function

Quote:
Originally Posted by awsomedude View Post
pawn Code:
GetPlayerWeed(playerid) return Weed[playerid];

That will return how much weed the player has.
Will I still need this?

pawn Code:
GetPlayerWeed(playerid, amount)
{
    new amount;
    if(Weed[playerid] = amount;         // need to fix
    return amount;
}
Josh_Main is offline   Reply With Quote
Old 29/09/2014, 06:15 PM   #9
DavidBilla
Huge Clucker
 
DavidBilla's Avatar
 
Join Date: Aug 2013
Location: Planet Earth
Posts: 303
Reputation: 35
Default Re: Creating a new function

You don't need GetPlayerWeed(playerid, amount)
Just use Weed[playerid] instead.
DavidBilla is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with creating function Johnson_boy Help Archive 7 24/04/2011 10:35 AM
Creating a function [ Need help ] Cameltoe Help Archive 3 23/08/2010 06:10 PM


All times are GMT. The time now is 02:10 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.