简体   繁体   中英

A simple command in PAWN

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

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") );

是的,基本上,您必须从文件中获取所有信息,因此 ShowStats 将不起作用,因为我想它从枚举中获取所有信息,因此您必须编写一个全新的函数来获取所有离线信息。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM