SA-MP Forums Archive
Cooking system - 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: Cooking system (/showthread.php?tid=560800)



Cooking system - zaibaslr2 - 30.01.2015

Good evening everyone,
I'm making a campfire cooking system and I need some help. It should work like this: player select x amount of y item (for example, salmon x 10, tuna x 2, meat x 3 (number of items can be unlimited)). How can I save items and their quantities player selected into variables or something like that, and then load the data?
Thanks for any help.


Re: Cooking system - CalvinC - 30.01.2015

I just made a quick system with zcmd and sscanf as an example, you can take a look at it.
In this case, i made you able to cook 3 things at once, and you can pick between tuna and meat.
pawn Код:
new CookingItem1[MAX_PLAYERS];
new CookingQuantity1[MAX_PLAYERS];

new CookingItem2[MAX_PLAYERS];
new CookingQuantity2[MAX_PLAYERS];

new CookingItem3[MAX_PLAYERS];
new CookingQuantity3[MAX_PLAYERS];

CMD:cook(playerid, params[])
{
    new item, amount;
    if(sscanf(params, "s[128]i", item, amount)) return SendClientMessage(playerid, -1, "USAGE: /cook [item] [amount]");
    if(!strcmp(params, "meat", true))
    {
        SendClientMessage(playerid, -1, "You are now cooking Meat.");
        if(CookingItem1[playerid] == 0)
        {
            CookingItem1[playerid] = meat;
            CookingQuantity1[playerid] = amount;
        }
        else if(CookingItem2[playerid] == 0)
        {
            CookingItem2[playerid] = meat;
            CookingQuantity2[playerid] = amount;
        }
        else if(CookingItem3[playerid] == 0)
        {
            CookingItem3[playerid] = meat;
            CookingQuantity3[playerid] = amount;
        }
        else return SendClientMessage(playerid, -1, "You have no more space for cooking.");
    }
    if(!strcmp(params, "tuna", true))
    {
        SendClientMessage(playerid, -1, "You are now cooking Tuna.");
        if(CookingItem1[playerid] == 0)
        {
            CookingItem1[playerid] = tuna;
            CookingQuantit1[playerid] = amount;
        }
        if(CookingItem2[playerid] == 0)
        {
            CookingItem2[playerid] = tuna;
            CookingQuantity2[playerid] = amount;
        }
        else if(CookingItem3[playerid] == 0)
        {
            CookingItem3[playerid] = meat;
            CookingQuantity3[playerid] = amount;
        }
        else return SendClientMessage(playerid, -1, "You have no more space for cooking.");
    }
    return 1;
}
After you're done cooking, you have to reset the variable to 0.

EDIT: Just saw i made a flaw in the code, fixed it now.


Re: Cooking system - zaibaslr2 - 30.01.2015

Thanks for the code, but the problem is, I could create variables like
new CookItem1[MAX_PLAYERS];
new CookItem2[MAX_PLAYERS];
new CookItem3[MAX_PLAYERS];

but we don't know how many items player will pick, maybe it will be 20 items..
I thought of saving the ID's of items into string, but I have no idea how to load them after that.