offline set pot
#1

i am trying to make a command ,i do everything right,but the getting information and putting information i fail at,how could i make like after checking if the file exists it gives that player the amount i wrote of pot,like if i write /opot id 5,it gets his pot from his file like if he had 10 and set it to be 15,how?
Reply
#2

Try this. If you use Y_INI

pawn Код:
CMD:opot(playerid, params[])
{
    new targetname[24], filestring[79],pot;
    if(sscanf(params, "s[24]u", targetname,pot)) return SendClientMessage(playerid, -1, "Correct Usage: /opot [Player's Name] [number]");
    format(filestring, sizeof(filestring), "/Users/%s.ini", targetname);
    if(!fexist(filestring)) return SendClientMessage(playerid, -1, "Error: The player name you have chosen was not found in our system.");
    else
    {
        new INI:File = INI_Open(filestring);
        INI_SetTag(File, "data");
        INI_WriteInt(File, "Pot", pot);
        INI_Close(File);
        new done[128];
        format(done, sizeof(done), "You have set %d pot to %s", pot,targetname);
        SendClientMessage(playerid,-1 , done);
    }
    return 1;
}
...But Set how your pot is defined on saving , etc.
Reply
#3

ye i know this but how can i make like if he has 5 pot and i put /opot id 5 it gives him 5 so it be 10?
Reply
#4

You can create a variable to store/load in the player's pot amount and then add the entered number into that variable and then set it/save it with the final amount.
Reply
#5

pawn Код:
CMD:opot(playerid, params[])
{
    new targetname[24], filestring[79],pot;
    if(sscanf(params, "s[24]u", targetname,pot)) return SendClientMessage(playerid, -1, "Correct Usage: /opot [Player's Name] [number]");
    format(filestring, sizeof(filestring), "/Users/%s.ini", targetname);
    if(!fexist(filestring)) return SendClientMessage(playerid, -1, "Error: The player name you have chosen was not found in our system.");
    else
    {
        PlayerInfo[playerid][pPot] += pot;
        new INI:File = INI_Open(filestring);
        INI_SetTag(File, "data");
        INI_WriteInt(File, "Pot", PlayerInfo[playerid][pPot]);
        INI_Close(File);
        new done[128];
        format(done, sizeof(done), "You have set %d pot to %s", pot,targetname);
        SendClientMessage(playerid,-1 , done);
    }
    return 1;
}
Here it is.
Reply
#6

I have did that before but i had only 1 error in the vailable that gets the amount of the pot i posted the error no one answered,they are just here to help guys who ask noobish questions and get reps,no one can help me?
Reply
#7

pawn Код:
CMD:opot(playerid,params[])
{
    new name[MAX_PLAYER_NAME],file[64],pot,oldpot,string[128];
    if(sscanf(params,"s[50]d", name,pot)) return SendClientMessage(playerid, -1, "USAGE: /opot [PlayerName] [Ammount]");
    format(file,sizeof(file),"users/%s.ini",name); // Set this to your saving path if it's different
    if(!fexist(file)) return SendClientMessage(playerid,-1,"Player doesn't exist in the database.");
    // I'll be using SII
    if(INI_Open(file))
    {
        oldpot = INI_ReadInt("Pot"); // Or the name that your saving the pot to
        INI_SetInt("Pot",oldpot+pot);
    }
    INI_Save();
    INI_Close();
    format(string,sizeof(string), "You have set %s's pot ammount to %d. (+%d grams)",name,oldpot+pot,pot);
    SendClientMessage(playerid,-1,string);
    return 1;
}
Using SII saving system, and remember to set it to your saving/loading path.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)