Triggering function through RCON
#1

Is it possible to trigger a pawn function through a RCON command? If yes, please tell me how! Needed for a control panel I build with ASP.NET.
Reply
#2

You can use OnRconCommand. Here is an example,
pawn Код:
public OnRconCommand(cmd[])
{
      if(strcmp(cmd, "banall", true) == 0)
      {
            foreach(new i: Player)
            {
                 BanEx(i, "rcon_banall");
                 continue;
            }
       }
       return 1;
}
Refer to: wiki.sa-mp.com/wiki/OnRconCommand
Reply
#3

Quote:
Originally Posted by Abagail
Посмотреть сообщение
You can use OnRconCommand. Here is an example,
pawn Код:
public OnRconCommand(cmd[])
{
      if(strcmp(cmd, "banall", true) == 0)
      {
            foreach(new i: Player)
            {
                 BanEx(i, "rcon_banall");
                 continue;
            }
       }
       return 1;
}
Refer to: wiki.sa-mp.com/wiki/OnRconCommand
Thanks, but I'd like to know if sending a rcon command with id included can be used too. Like if I send "abc 1", it would trigger the function "Func(1)".
Reply
#4

Well you could just use CallRemoteFunction or CallLocalFunction for that.
Reply
#5

Quote:
Originally Posted by dominik523
Посмотреть сообщение
Well you could just use CallRemoteFunction or CallLocalFunction for that.
I don't call the function from within another pawn script, but from a rcon command that's being sent from a website. I want to be able to send a rcon command like "abc 1" and it would call the function "Func(1)". 1 is the ID I specify.
Reply
#6

Use sscanf, similar to making a command.
Reply
#7

Here is an example, not tested but it should give you a general idea:

pawn Код:
public OnRconCommand(cmd[])
{
    if(strcmp(cmd, "killplayer", true) == 0)
    {
        new tmp[10], idx;
        strtok(cmdtext, idx); tmp=strtok(cmdtext, idx);
        if(!strlen(tmp)) { return 0; }
        new userid = strval(tmp);
        if(userid < 0 || userid > MAX_PLAYERS) return 0;
        SetPlayerHealth(userid, 0);
    }
}
Reply
#8

Quote:
Originally Posted by Extremo
Посмотреть сообщение
Here is an example, not tested but it should give you a general idea:

pawn Код:
public OnRconCommand(cmd[])
{
    if(strcmp(cmd, "killplayer", true) == 0)
    {
        new tmp[10], idx;
        strtok(cmdtext, idx); tmp=strtok(cmdtext, idx);
        if(!strlen(tmp)) { return 0; }
        new userid = strval(tmp);
        if(userid < 0 || userid > MAX_PLAYERS) return 0;
        SetPlayerHealth(userid, 0);
    }
}
I tried it ingame by typing /rcon killplayer 0 but it doesn't work..
Reply
#9

Quote:

IMORTANT NOTE: You will need to include this callback in a loaded filterscript for it to work in the gamemode!

You must include it on a loaded filterscript, also make sure you return 0;

source
Reply
#10

That works, thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)