How to make a /checkcookies command? Partially done.
#1

Hi,
I'm wanting to make a command like /cookies [playerid] Which will check how many cookies the player has. I already have cookies in my scriptfiles, and whatnot. But how do I check the player's cookies, and then send a client message back to my player saying how much cookies he has? Here's what I got so far.

pawn Код:
CMD:cookies(playerid, params[])
{
    new pCookies;
    new target;
    new str[128];
    if(sscanf(params, "u[128]", target)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /cookies [Player ID]");
    if!IsPlayerConnected(target)) return SendClientMessage(playerid, COLOR_BRIGHTRED, "ERROR: Player is not connected");
    if(PlayerInfo[playerid][pAdmin] >=1
    {
        format(str, sizeof(str), "You have checked %s's Cookies.", GetName(target));
        SendClientMessage(playerid, COLOR_CYAN, str);
It's not finished yet. But what else do I need to add? Thanks!
Reply
#2

Get the variable of the "player cookies", and in format just add the %d or %i to add numbers inside a string.

pawn Код:
CMD:cookies(playerid, params[])
{
    new id;
    if(sscanf(params, "u", id)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /cookies [Player ID]");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000, "This player is not connected!");
    new str[64];
    format(str, sizeof(str), "%s(%d) does have %d cookies.", GetName(id), id, /*Put here the player variable of the cookies*/);
    SendClientMessage(playerid, COLOR_WHITE, str);
    return 1;
}
Reply
#3

Quote:
Originally Posted by BigETI
Посмотреть сообщение
Get the variable of the "player cookies", and in format just add the %d or %i to add numbers inside a string.

pawn Код:
CMD:cookies(playerid, params[])
{
    new id;
    if(sscanf(params, "u", id)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /cookies [Player ID]");
    if(id == INVALID_PLAYER_ID) retur SendClientMessage(playerid, 0xFF0000, "This player is not connected!");
    new str[64];
    format(str, sizeof(str), "%s(%d) does have %d cookies.", GetName(id), id, /*Put here the player variable of the cookies*/);
    SendClientMessage(playerid, COLOR_WHITE, str);
    return 1;
}
Thanks man.
EDIT: Do you happen to know how to save it instantly, when I do the command /givecookie? I saves when I relog, but not instantly. Here's my current /givecookie command.
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);
     new INI:File = INI_Open(UserPath(playerid));
     INI_WriteInt(File,"Cookies",PlayerInfo[playerid][pCookies]);
     INI_Close(File);
     PlayerInfo[pid][pCookies] ++;
    }
    else SendClientMessage(playerid, COLOR_BRIGHTRED, "You're not authorized to use this command.");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)