Help with a cookie system. ++rep
#1

Hello.
I'm currently making a cookie system, and It's going well so far. Here's what I currently have.
pawn Код:
CMD:givecookie(playerid, params[]) // CMD for giving somebody a cookie
{
    new pid;
    new reason[128];
    new str[128];
    if(sscanf(params, "us[128]", pid, reason)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecookie [Player ID] [Reason]");
    if(!IsPlayerConnected(pid)) return SendClientMessage(playerid, COLOR_BRIGHTRED, "PlayerID is not connected.");
    if(PlayerInfo[playerid][pAdmin]>=2)
    {
     format(str, sizeof(str), "%s has been granted a cookie by Administrator %s. Reason: (%s)", GetName(pid), GetName(playerid), reason);
     SendClientMessageToAll(COLOR_ORANGE, str);
     format(str, sizeof(str), "You just gave a cookie to %s.", GetName(pid));
     SendClientMessage(playerid, COLOR_GREEN, str);
     PlayerInfo[pid][pCookies] ++;
    }
    else SendClientMessage(playerid, COLOR_BRIGHTRED, "You're not authorized to use this command.");
    return 1;
}
pawn Код:
CMD:resetcookies(playerid, params[])
{
        new pid;
        new reason[128];
        new str[128];
        if(sscanf(params, "us[128]", pid, reason)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /resetcookies [Player ID] [Reason]");
        if(!IsPlayerConnected(pid)) return SendClientMessage(playerid, COLOR_BRIGHTRED, "ERROR: Player is not connected");
        if(PlayerInfo[playerid][pAdmin]>=2)
        {
        format(str, sizeof(str), "Administrator %s has reset %s's Cookies. Reason: (%s)", GetName(playerid), GetName(pid), reason);
        SendClientMessageToAll(COLOR_ORANGE, str);
        format(str, sizeof(str), "You just reset %s's Cookies.", GetName(pid));
        SendClientMessage(playerid, COLOR_GREEN, str);
        PlayerInfo[pid][pCookies] = 0;
        }
        else SendClientMessage(playerid, COLOR_BRIGHTRED, "You're not authorized to use this command.");
        return 1;
  }
Alright, so say I wanted to make a /buyvip command. And the person needs 5 cookies to buy it. How could I take away 5 cookies, without deleting them all?

Also... When I /give the player a cookie, it doesn't save in the scriptfiles until he logs out. How could I save it instantly?

Thanks for your help.
Reply
#2

pawn Код:
PlayerInfo[playerid][pCookies] = PlayerInfo[playerid][pCookies] - 5;
EDIT:

Just read the rest of the question.

To save it instantly you check how it saves in OnPlayerDisconnect and take the crucial parts to save cookies.
Reply
#3

Quote:
Originally Posted by coole210
Посмотреть сообщение
pawn Код:
PlayerInfo[playerid][pCookies] = PlayerInfo[playerid][pCookies] - 5;
EDIT:

Just read the rest of the question.

To save it instantly you check how it saves in OnPlayerDisconnect and take the crucial parts to save cookies.
Thanks a ton.

EDIT: I've added
pawn Код:
new INI:File = INI_Open(UserPath(playerid));
     INI_WriteInt(File,"Cookies",PlayerInfo[playerid][pCookies]);
     INI_Close(File);
     PlayerInfo[pid][pCookies] ++;
To the command /givecookie, but it still doesn't save instantly. Am I forgetting something?
Reply
#4

WriteInt on Connect and Disconnect.
Reply
#5

Quote:
Originally Posted by Chrillzen
Посмотреть сообщение
WriteInt on Connect and Disconnect.
I've written OnPlayerConnect
pawn Код:
new INI:File = INI_Open(UserPath(playerid));
        INI_WriteInt(File,"Cookies",PlayerInfo[playerid][pCookies]);
        INI_Close(File);
And onplayer disconnect.
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_WriteInt(File,"Frozen",PlayerInfo[playerid][pFrozen]);
    INI_WriteInt(File,"Mute",PlayerInfo[playerid][pMute]);
    INI_WriteInt(File,"Cookies",PlayerInfo[playerid][pCookies]);
    INI_Close(File);
    return 1;
}
But the cookies sitll don't save instantly.
Reply
#6

It saves when you log out.
Reply
#7

Quote:
Originally Posted by Chrillzen
Посмотреть сообщение
It saves when you log out.
There's no way to make it save instantly?

EDIT: I've added this, to the command.
pawn Код:
INI_WriteInt(File,"Cookies",PlayerInfo[playerid][pCookies]+=iAmount);
     INI_WriteInt(File,"Cookies",PlayerInfo[playerid][pCookies]-=iAmount);
     INI_Close(File);
pawn Код:
new iPlayer;
    new iAmount;
    new iReason[MAX_STRINGS];
Would that save it, after I processed the command?
Here's the full command.
pawn Код:
CMD:givecookie(playerid, params[]) // CMD for giving somebody a cookie
{
    new iPlayer;
    new iAmount;
    new iReason[MAX_STRINGS];
    new str[256];
    if(sscanf(params, "usS[250]",iPlayer, iAmount, iReason)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecookie [Player ID] [Amount] [Reason]");
    if(!IsPlayerConnected(iPlayer)) return SendClientMessage(playerid, COLOR_BRIGHTRED, "PlayerID is not connected.");
    if(PlayerInfo[playerid][pAdmin]>=2)
    {
     format(str, sizeof(str), "%s has received %s Cookies by Administrator %s. Reason:%s ",GetName(iPlayer), iAmount,  GetName(playerid), iReason);
     SendClientMessageToAll(COLOR_ORANGE, str);
     format(str, sizeof(str), "You just gave a cookie to %s.", GetName(iPlayer));
     SendClientMessage(playerid, COLOR_GREEN, str);
        // PlayerInfo[iPlayer][pCookies] ++;
     PlayerInfo[playerid][pCookies] += iAmount;
     PlayerInfo[playerid][pCookies]-= iAmount;
     new INI:File = INI_Open(UserPath(playerid));
     INI_WriteInt(File,"Cookies",PlayerInfo[playerid][pCookies]+=iAmount);
     INI_WriteInt(File,"Cookies",PlayerInfo[playerid][pCookies]-=iAmount);
     INI_Close(File);
    }
    else SendClientMessage(playerid, COLOR_BRIGHTRED, "You're not authorized to use this command.");
    return 1;
}
This is under OnPlayerDisconnect.
pawn Код:
INI_WriteInt(File,"Cookies",PlayerInfo[playerid][pCookies]);
Reply
#8

Quote:
Originally Posted by rangerxxll
Посмотреть сообщение
There's no way to make it save instantly?

EDIT: I've added this, to the command.
pawn Код:
INI_WriteInt(File,"Cookies",PlayerInfo[playerid][pCookies]+=iAmount);
     INI_WriteInt(File,"Cookies",PlayerInfo[playerid][pCookies]-=iAmount);
     INI_Close(File);
pawn Код:
new iPlayer;
    new iAmount;
    new iReason[MAX_STRINGS];
Would that save it, after I processed the command?
Here's the full command.
pawn Код:
CMD:givecookie(playerid, params[]) // CMD for giving somebody a cookie
{
    new iPlayer;
    new iAmount;
    new iReason[MAX_STRINGS];
    new str[256];
    if(sscanf(params, "usS[250]",iPlayer, iAmount, iReason)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecookie [Player ID] [Amount] [Reason]");
    if(!IsPlayerConnected(iPlayer)) return SendClientMessage(playerid, COLOR_BRIGHTRED, "PlayerID is not connected.");
    if(PlayerInfo[playerid][pAdmin]>=2)
    {
     format(str, sizeof(str), "%s has received %s Cookies by Administrator %s. Reason:%s ",GetName(iPlayer), iAmount,  GetName(playerid), iReason);
     SendClientMessageToAll(COLOR_ORANGE, str);
     format(str, sizeof(str), "You just gave a cookie to %s.", GetName(iPlayer));
     SendClientMessage(playerid, COLOR_GREEN, str);
        // PlayerInfo[iPlayer][pCookies] ++;
     PlayerInfo[playerid][pCookies] += iAmount;
     PlayerInfo[playerid][pCookies]-= iAmount;
     new INI:File = INI_Open(UserPath(playerid));
     INI_WriteInt(File,"Cookies",PlayerInfo[playerid][pCookies]+=iAmount);
     INI_WriteInt(File,"Cookies",PlayerInfo[playerid][pCookies]-=iAmount);
     INI_Close(File);
    }
    else SendClientMessage(playerid, COLOR_BRIGHTRED, "You're not authorized to use this command.");
    return 1;
}
This is under OnPlayerDisconnect.
pawn Код:
INI_WriteInt(File,"Cookies",PlayerInfo[playerid][pCookies]);
Don't save it instantly if you want good performance. Save it only on OnPlayerDisconnect and load it only on OnPlayerConnect and make use of variables.
Reply
#9

Thanks guys. I just looked at a few Y_ini tutorials, and studied it. Thanks for your help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)