sscanf and OnRconCommand
#1

I have been experiencing an issue with sscanf, I thought it works like it would do on in-game commands (etc... /test)

I am not sure if i have done it correctly since i haven't used sscanf onRconCommand call back yet.
Can someone tell me if i have done something wrong or something?

NOTE: I am not that lazy to fix the problem, I can fix the problem by myself but due to lack of knowledge of sscanf OnRconCommand, i will need your help on this one.

Here is the source code.

pawn Код:
public OnRconCommand(cmd[])
{
    new string[128], parameters[128], parameters2[128], parameters3[128], parameter2;

    // custom command customhelp
   
    if(!strcmp(cmd, "customhelp", true))
    {
        print("JaKe's custom RCON commands @ 2015");
        print("/b, /admins, /a, /admin, /c, /v, /w, /fakea, /fakec");
    }

    // command /b
    if(!strcmp(cmd, "b", true))
    {
        if(sscanf(cmd[2], "is[128]", parameter2, parameters)) return print("USAGE: /rcon b [playerid] [message]");
        if(parameter2 == INVALID_PLAYER_ID) return print("NOTE: Player not connected.");

        format(string, sizeof(string), "(( [X] RCON Admin: %s ))", parameters);
        print(string);

        new
            Float: f_Radius = 20.0, Float: f_playerPos[3];

        GetPlayerPos(parameter2, f_playerPos[0], f_playerPos[1], f_playerPos[2]);
        foreach(Player, i)
        {
            if(GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(parameter2))
            {
                if(IsPlayerInRangeOfPoint(i, f_Radius / 16, f_playerPos[0], f_playerPos[1], f_playerPos[2])) {
                    SendClientMessageEx(i, COLOR_FADE1, string);
                }
                else if(IsPlayerInRangeOfPoint(i, f_Radius / 8, f_playerPos[0], f_playerPos[1], f_playerPos[2])) {
                    SendClientMessageEx(i, COLOR_FADE2, string);
                }
                else if(IsPlayerInRangeOfPoint(i, f_Radius / 4, f_playerPos[0], f_playerPos[1], f_playerPos[2])) {
                    SendClientMessageEx(i, COLOR_FADE3, string);
                }
                else if(IsPlayerInRangeOfPoint(i, f_Radius / 2, f_playerPos[0], f_playerPos[1], f_playerPos[2])) {
                    SendClientMessageEx(i, COLOR_FADE4, string);
                }
                else if(IsPlayerInRangeOfPoint(i, f_Radius, f_playerPos[0], f_playerPos[1], f_playerPos[2])) {
                    SendClientMessageEx(i, COLOR_FADE5, string);
                }
            }
        }
    }
   
    // command /admins
    if(!strcmp(cmd, "admins", true))
    {
        foreach(new i : Player)
        {
            if(PlayerInfo[i][pAdmin] >= 1)
            {
                format(string, sizeof string, "[PlayerID: %d] [AdminLevel: %d] - %s", i, PlayerInfo[i][pAdmin], GetPlayerNameEx(i));
                print(string);
            }
        }
    }

    // command /mods
    if(!strcmp(cmd, "mods", true))
    {
        foreach(new i : Player)
        {
            if(PlayerInfo[i][pHelper] >= 1)
            {
                format(string, sizeof string, "[PlayerID: %d] [ModLevel: %d] - %s", i, PlayerInfo[i][pHelper], GetPlayerNameEx(i));
                print(string);
            }
        }
    }

    // command /admin
   
    if(!strcmp(cmd, "a", true))
    {
        if(sscanf(cmd[2], "s[128]", parameters)) return print("USAGE: /rcon a(dmin) [adminchat]");

        format(string, sizeof string, "* RCON Console: %s", parameters);
        print(string);
        SendAdminMessage(COLOR_YELLOW, string);
        Log("logs/adminchat.log", string);
    }
    if(!strcmp(cmd, "admin", true))
    {
        if(sscanf(cmd[6], "s[128]", parameters)) return print("USAGE: /rcon a(dmin) [adminchat]");

        format(string, sizeof string, "* RCON Console: %s", parameters);
        print(string);
        SendAdminMessage(COLOR_YELLOW, string);
        Log("logs/adminchat.log", string);
    }

    // command /c
   
    if(!strcmp(cmd, "c", true))
    {
        if(sscanf(cmd[2], "s[128]", parameters)) return print("USAGE: /rcon c [advisor chat]");

        format(string, sizeof string, "** RCON Console: %s", parameters);
        print(string);
        SendAdvisorMessage(COLOR_COMBINEDCHAT, string);
        Log("logs/cchat.log", string);
    }
   
    // command /v
   
    if(!strcmp(cmd, "v", true))
    {
        if(sscanf(cmd[2], "s[128]", parameters)) return print("USAGE: /rcon v [vip chat]");

        format(string, sizeof string, "** RCON Console: %s", parameters);
        print(string);
        SendVIPMessage(COLOR_VIP, string);
        Log("logs/vipchat.log", string);
    }
   
    // command /w

    if(!strcmp(cmd, "w", true))
    {
        if(sscanf(cmd[2], "us[128]", parameter2, parameters)) return print("USAGE: /rcon w [playerid] [message]");

        format(string, sizeof string, "RCON whispered to %s(ID%d): %s", GetPlayerNameEx(parameter2), parameter2, parameters);
        print(string);

        format(string, sizeof string, "RCON messages you: %s", parameters);
        SendClientMessage(parameter2, COLOR_WHITE, string);
    }
   
    // fake admin
   
    if(!strcmp(cmd, "fakea", true))
    {
        if(sscanf(cmd[6], "p<,>s[128]s[128]s[128]", parameters, parameters2, parameters3)) return print("USAGE: /rcon fakea [rank] [name] [adminchat]");

        format(string, sizeof string, "* %s %s: %s", parameters, parameters2, parameters3);
        print(string);
        SendAdminMessage(COLOR_YELLOW, string);
        Log("logs/adminchat.log", string);
    }

    // fake c
   
    if(!strcmp(cmd, "fakec", true))
    {
        if(sscanf(cmd[6], "p<,>s[128]s[128]s[128]", parameters, parameters2, parameters3)) return print("USAGE: /rcon fakec [rank] [name] [advisorchat]");

        format(string, sizeof string, "* %s %s: %s", parameters, parameters2, parameters3);
        print(string);
        SendAdvisorMessage(COLOR_COMBINEDCHAT, string);
        Log("logs/cchat.log", string);
    }
    return 1;
}
Reply
#2

It works exactly the same way as in commands.

The difference, is that the first parameter is the command itself.

PHP код:
public OnRconCommand(cmd[])
{
    new 
command[40];
    
    if(
sscanf(cmd,"s[40]",command))
        return 
0;
    
    if(!
strcmp(command,"test",true))
    {
        
printf("You typed rcon command 'test'!");
        
        return 
1;
    }
    else if(!
strcmp(command,"anothertest",true))
    {
        
printf("You typed rcon command 'anothertest'!");
        
        return 
1;
    }
    return 
0;

Hope it helps.
Reply
#3

So wait, i have to sscanf the whole thing?

If that's the case, how am i suppose to do the thing? I am still confused.
Reply
#4

You can make use of the silent SSCANF parameter. (Optional Strings)

For example:
pawn Код:
public OnRconCommand(cmd[])
{
    new command[30], params[128];
    if(sscanf(cmd, "s[30]S()[128]", command, params)) return print("[RCON] Invalid Command.");
   
    if(!strcmp(command, "customhelp", true))
    {
        print("JaKe's custom RCON commands @ 2015");
        print("/b, /admins, /a, /admin, /c, /v, /w, /fakea, /fakec");
    }

    // command /b
    if(!strcmp(command, "b", true))
    {
        new targetid, message[128];
        if(sscanf(params, "is[128]", targetid, message)) return print("USAGE: /rcon b [playerid] [message]");
        if(!IsPlayerConnected(targetid) || targetid == INVALID_PLAYER_ID) return print("NOTE: Player not connected.");

        new string[144];
        format(string, sizeof(string), "(( [X] RCON Admin: %s ))", message);
        print(string); //Print or SendClientMessage?

        new Float:f_Radius = 20.0, Float:f_playerPos[3];
        GetPlayerPos(targetid, f_playerPos[0], f_playerPos[1], f_playerPos[2]);
        foreach(new i : Player)
        {
            if(GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(targetid))
            {
                if(!IsPlayerInRangeOfPoint(i, f_Radius, f_playerPos[0], f_playerPos[1], f_playerPos[2])) continue;
                if(IsPlayerInRangeOfPoint(i, f_Radius / 2, f_playerPos[0], f_playerPos[1], f_playerPos[2])) SendClientMessageEx(i, COLOR_FADE4, string);
                else if(IsPlayerInRangeOfPoint(i, f_Radius / 4, f_playerPos[0], f_playerPos[1], f_playerPos[2])) SendClientMessageEx(i, COLOR_FADE3, string);
                else if(IsPlayerInRangeOfPoint(i, f_Radius / 8, f_playerPos[0], f_playerPos[1], f_playerPos[2])) SendClientMessageEx(i, COLOR_FADE2, string);
                else if(IsPlayerInRangeOfPoint(i, f_Radius / 16, f_playerPos[0], f_playerPos[1], f_playerPos[2])) SendClientMessageEx(i, COLOR_FADE1, string);
                else SendClientMessageEx(i, COLOR_FADE5, string);
            }
        }
        return 1;
    }
    //etc...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)