Need help making this shorter.
#1

First off, i'd like to say i'm sorry about the title, i couldn't think how to describe it.

Alright, so i made a timer, so when i type /plantseeds, each minute that goes by, the GramAmount increases by one. So lets say it passed 1 minute since i planted it, it will be 1, if its 2 minutes, the grams will be 2, and so forth.

Now, i need to figure out how to "Simplify" this because i don't want several lines of uselessness on my script.
The timer starts when i plant the seeds, and this is the public timer:

pawn Код:
public GrowingPeriod(playerid)
{
    if(GramAmount == 0)
    {
        GramAmount = 1;
        SetTimerEx("GrowingPeriod", 60000, false, "i", playerid);
    }
    if(GramAmount == 1)
    {
        GramAmount = 2;
        SetTimerEx("GrowingPeriod", 60000, false, "i", playerid);
    }
    if(GramAmount == 2)
    {
        GramAmount = 3;
        SetTimerEx("GrowingPeriod", 60000, false, "i", playerid);
    }
    if(GramAmount == 3)
    {
        GramAmount = 4;
        SetTimerEx("GrowingPeriod", 60000, false, "i", playerid);
    }
    if(GramAmount == 4)
    {
        GramAmount = 5;
        SetTimerEx("GrowingPeriod", 60000, false, "i", playerid);
    }
    if(GramAmount == 5)
    {
        GramAmount = 6;
        SetTimerEx("GrowingPeriod", 60000, false, "i", playerid);
    }
    return 1;
}
Now, instead of doing if(GramAmount == *something*) i want it to be shorter so that as it increases, after one minute, it will increase once again, and so forth, until it reaches 45 ((*define MAX_GRAMS 45)).

If this is possible, please show me how to do it. If generous enough, i'd love it if you fixed it.

((If you need anything else, such as the commands, /plantseeds, etcetra, please tell me))

Thanks in advance,
Beginning Scripter =>KurtBag<=
Reply
#2

pawn Код:
public GrowingPeriod(playerid)
{
    GramAmount++;
    if(GramAmount != MAX_GRAMS) SetTimerEx("GrowingPeriod", 60000, false, "i", playerid);
}
playerid is passed as a param however it isn't being used, I'm sure you'll be using it in the future with something like GramAmount[playerid][plantid]
Reply
#3

pawn Код:
public GrowingPeriod()
{
    GramAmount++; //Will do always +1
    if(GramAmount == 45)
    {
        //Do your stuff here for if it reaches 45
    }
}
First of all there is no need of the variable playerid in your example. Remove this variable (if not needed) and remove also the SetTimerEx functions.
Just edit the main timer's repeating state to true and remove the uneeded extension for this callback (ofc if not needed)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)