What's wrong with this? +rep
#1

Hi,
I'm still working on my cookie system, but I'm having problems with this command.
pawn Код:
CMD:cookies(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin]>=1)
    {
        new id;
        if(sscanf(params, "r", 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) has (%d) Cookies.", GetName(id),PlayerInfo[playerid][pCookies]);
        SendClientMessage(playerid, COLOR_WHITE, str);
    }
    else SendClientMessage(playerid, COLOR_BRIGHTRED, "You're not authorized to use this command.");
    return 1;
}
I want that command to check a player's cookies. Not just mine. like /cookies [playerid/partofname] Then it will read their file from my scriptfiles, and tell me how much cookies they have.

This isn't working, all the current command does is say "Name has () cookies" How can I get this working? Thanks you.
Reply
#2

I didn't quite get your problem. Do you want an command that reads the value stored inside a flatfile?
Reply
#3

Quote:
Originally Posted by Cameltoe
Посмотреть сообщение
I didn't quite get your problem. Do you want an command that reads the value stored inside a flatfile?
Alright. I made a command to give a player a cookie, which will then save it in a file, along with the rest of the variables.
Here's the 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;
}
Now... I want to make it, so Administrators can use the command /cookies, to check a players current cookies.
Reply
#4

pawn Код:
CMD:cookies(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin]>=1)
    {
        new id, str[64];
        if(sscanf(params, "r", id)) return SendClientMessage(playerid, 0x0, "USAGE: /cookies [Player ID]");
        if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000, "This player is not connected!");
        format(str, sizeof(str), "%s(%d) has (%d) Cookies.", GetName(id), id,PlayerInfo[playerid][pCookies]);
        SendClientMessage(playerid, 0x0, str);
    }
    else SendClientMessage(playerid, 0x0, "You're not authorized to use this command.");
    return 1;
}
Reply
#5

pawn Код:
//@ cookies
format(str, sizeof(str), "%s(%d) has (%d) Cookies.", GetName(id),PlayerInfo[playerid][pCookies]);
// --> PlayerInfo[playerid][pCookies]

//So I guess you are checking your cookies not the target's cookies?
//(%s), (%d), and (%d)
//in the format there are only : GetName(id), PlayerInfo[playerid][pCookies]
//as i know getname returns the name not also the id

//@ givecookie
new INI:File = INI_Open(UserPath(playerid));
INI_WriteInt(File,"Cookies",PlayerInfo[playerid][pCookies]);
//Your giving it to yourself, not pid.
Reply
#6

pawn Код:
CMD:cookies(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin]>=1)
    {
        new id, str[64];
        if(sscanf(params, "r", id)) return SendClientMessage(playerid, 0x0, "USAGE: /cookies [Player ID]");
        if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000, "This player is not connected!");
        format(str, sizeof(str), "%s(%d) has (%d) Cookies.", GetName(id), id,PlayerInfo[id][pCookies]);
        SendClientMessage(playerid, 0x0, str);
    }
    else SendClientMessage(playerid, 0x0, "You're not authorized to use this command.");
    return 1;
}
Formatting error look at GetName(id), id,PlayerInfo[id][pCookies].

I added id there, test if it works now

Edit:

pawn Код:
INI_WriteInt(File,"Cookies",PlayerInfo[playerid][pCookies]);
INI_Close(File);
PlayerInfo[pid][pCookies] ++;
You are giving pid cookies, though you save your own file.

Should be:

pawn Код:
PlayerInfo[pid][pCookies] ++;
INI_WriteInt(File,"Cookies",PlayerInfo[pid][pCookies]);
INI_Close(File);
Reply
#7

Thanks guys. I've tested the command, but its a bit bugged... Everytime I /givecookie to someone, it adds to my cookies too. And my friend says it says he has 0 cookies when he does the command /mycookies... If you don't know what I mean, let me know. Oh, and here's the /mycookies command.
pawn Код:
CMD:mycookies(playerid, params[])
{
    new cstring[64];
    format(cstring, sizeof(cstring), "You have %d Cookies.", PlayerInfo[playerid][pCookies]);
    SendClientMessage(playerid, COLOR_WHITE, cstring);
    return 1;
Reply
#8

Quote:
Originally Posted by Basicz
Посмотреть сообщение
pawn Код:
//@ cookies
format(str, sizeof(str), "%s(%d) has (%d) Cookies.", GetName(id),PlayerInfo[playerid][pCookies]);
// --> PlayerInfo[playerid][pCookies]

//So I guess you are checking your cookies not the target's cookies?
//(%s), (%d), and (%d)
//in the format there are only : GetName(id), PlayerInfo[playerid][pCookies]
//as i know getname returns the name not also the id

//@ givecookie
new INI:File = INI_Open(UserPath(playerid));
INI_WriteInt(File,"Cookies",PlayerInfo[playerid][pCookies]);
//Your giving it to yourself, not pid.
I am trying to look at the Target's cookies.

EDIT: I just saw your post Camel, testing now.
Reply
#9

Alright, I'm still in need of help. When I do /givecookie to a player, it gives a cookie to everyone on the server. And I only want the selected player to get a cookie. Also, /resetcookies resets every ones cookies, not just the selected person. Here's my current code for the commands.

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));
     PlayerInfo[pid][pCookies] ++;
     INI_WriteInt(File,"Cookies",PlayerInfo[pid][pCookies]);
     INI_Close(File);
    }
    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;
  }
pawn Код:
CMD:cookies(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin]>=1)
    {
        new id, str[64];
        if(sscanf(params, "r", id)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /cookies [Player ID]");
        if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000, "This player is not connected!");
        format(str, sizeof(str), "%s(%d) has (%d) Cookies.", GetName(id), id,PlayerInfo[playerid][pCookies]);
        SendClientMessage(playerid, 0x0, str);
    }
    else SendClientMessage(playerid, 0x0, "You're not authorized to use this command.");
    return 1;
}
What else is wrong?... I really need to get this thing working.
Reply
#10

Well, I can only see one problem there, that is the command " /givecookie " :
pawn Код:
new INI:File = INI_Open(UserPath(playerid)); // Opening the admin's file ? Should be ' INI_Open( UserPath( pid ) ); '
PlayerInfo[pid][pCookies] ++;
INI_WriteInt(File,"Cookies",PlayerInfo[pid][pCookies]);
INI_Close(File);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)