SA-MP Forums Archive
Triggering function through RCON - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Triggering function through RCON (/showthread.php?tid=563714)



Triggering function through RCON - arad55 - 16.02.2015

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.


Re: Triggering function through RCON - Abagail - 16.02.2015

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


Re: Triggering function through RCON - arad55 - 16.02.2015

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


Re: Triggering function through RCON - dominik523 - 16.02.2015

Well you could just use CallRemoteFunction or CallLocalFunction for that.


Re: Triggering function through RCON - arad55 - 16.02.2015

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.


Re: Triggering function through RCON - xVIP3Rx - 16.02.2015

Use sscanf, similar to making a command.


Re: Triggering function through RCON - Extremo - 16.02.2015

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



Re: Triggering function through RCON - arad55 - 16.02.2015

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..


Re: Triggering function through RCON - xVIP3Rx - 16.02.2015

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


Re: Triggering function through RCON - arad55 - 16.02.2015

That works, thanks!