A simple command in PAWN

1.4k Views Asked by At

San Andreas Multiplayer (GTA) uses PAWN as its programming language. I'm an owner of a server on SA-MP and I'm not that pro so I'd like to get some help if possible. Basically, I have a command that checks player's statistics when he/she is online, but I'd like to have a command to check them when they're offline. That's the code of the commmand which checks player's statistics when he's online.

CMD:check(playerid, var[])
{
    new user;
    if(!Logged(playerid)) return NoLogin(playerid);
    if(Player[playerid][pAdmin] >= 2 || Player[playerid][pStaffObserver])
    {
        if(sscanf(var,"us[32]", user, var))
        {
            SendClientMessage(playerid, COLOR_WHITE, "{00BFFF}Usage:{FFFFFF} /check [playerid] [checks]");
            SendClientMessage(playerid, COLOR_GRAD2, "** [CHECKS]: stats");
            return 1;
        }
        if(!strcmp(var, "stats", true))
        {
            if(!Logged(user)) return NoLoginB(playerid);
            ShowStats(playerid, user);
        }
    }
    else
    {
        NoAuth(playerid);
    }
    return 1;
}

I use ZCMD command processor and Dini saving system. So I'd like to make CMD:ocheck that would display the stock ShowStats and it'll work like /ocheck [Firstname_Lastname].

Any help? Please help if possible.

Thanks

~Kevin

2

There are 2 best solutions below

0
On

Yes, basically, you have to get all the information from the file, so ShowStats will not work, because I suppose it gets all the information from enumerations and such, you have to write a brand new function, of getting all the offline info.

0
On

For the command that you require, you'll have to load data from the player's userfile.

You'll obviously begin with

if(!Logged(playerid)) return NoLogin(playerid);
if(Player[playerid][pAdmin] >= 2 || Player[playerid][pStaffObserver]) 
{

To check if the player using this is authorized to use this command. Following this,

if(str, "s[32]", name))

You cannot use 'u' as a formatter here, simply because you're checking an offline player's statistics. After this, you need to check if the user is actually registered If he isn't, you return that error the user of this command If he is, then check if he is online already. If he is online, return error to admin to use this command instead of 'ocheck' If he's offline, then you can safely proceed to load his statistics (you can use the code used for loading data when a player logs in, except this time it should only be printed

for eg,

format(str, sizeof(str), 
"Score: %s, Money: %d", 
dini_Int(file, "score"), dini_Int(file, "score") );