[Tutorial] Adding IRC Into your Gamemode Using Incognito's Plugin!
#1

Adding IRC!

You Will need:

* The Plugin and Include File, Found here! https://sampforum.blast.hk/showthread.php?tid=98803



Let's Get Started!


At the top of your Gamemode you will obviously need

pawn Code:
#include <irc>

Now to add your Bots!
This will be the name that everyone will see when its connected to the IRC
pawn Code:
#define BOT_1_NICKNAME "BotA"
Now this is just the rest of the config for the /whois
pawn Code:
#define BOT_1_REALNAME "SA-MP Bot"
#define BOT_1_USERNAME "bot"
Now to Set up the connection so the server knows that irc server to connect the bots to

pawn Code:
#define IRC_SERVER "irc.foco.co"
#define IRC_PORT (6667)
#define IRC_CHANNEL "#testchannel"
No Explanation needed really...

Last part of the defines:

Defining now manny bots we will be connecting to the irc server, i think you can connect 5 at one time without having your ip incresed how ever you shouldn't need more that 1 - 2 bots unless you have a very popular server.
pawn Code:
#define MAX_BOTS (1)

The Core of connecting the Bots!


This is getting the bots id and grouping them, in our case only 1 bot.
pawn Code:
new gBotID[MAX_BOTS], gGroupID;


pawn Code:
public OnFilterScriptInit()
{
gBotID[0] = IRC_Connect(IRC_SERVER, IRC_PORT, BOT_1_NICKNAME, BOT_1_REALNAME, BOT_1_USERNAME);
IRC_SetIntData(gBotID[0], E_IRC_CONNECT_DELAY, 20);
return 1;
}
Lets Break it down!
This is conencting our bot to the server via the IRC_Server and IRC_Port we defined before, we are also naming the bot and setting up its /whois
pawn Code:
gBotID[0] = IRC_Connect(IRC_SERVER, IRC_PORT, BOT_1_NICKNAME, BOT_1_REALNAME, BOT_1_USERNAME);
Now this is the delay, not really needed but is good when you are conencting several bots and giving your server time to load all of your codes!
pawn Code:
IRC_SetIntData(gBotID[0], E_IRC_CONNECT_DELAY, 20);

Okay, at this stage your bots will connect when your server is online! but they will not play any role what so ever! so lets do some simple connection messages!

pawn Code:
public OnPlayerConnect(playerid)
{
    new joinMsg[128], name[MAX_PLAYER_NAME]; //here we are creating a local variable for getting the players name
    GetPlayerName(playerid, name, sizeof(name));
    format(joinMsg, sizeof(joinMsg), "02[%d] 03*** %s has joined the server.", playerid, name);
    IRC_GroupSay(gGroupID, IRC_CHANNEL, joinMsg); //joing the player to the channel that we defined!
    return 1;
}


Now to show when a player talks on the server! Lets Echo it to the IRC Server!
pawn Code:
public OnPlayerText(playerid, text[])
{
    new name[MAX_PLAYER_NAME], ircMsg[256]; Again creating a local Variable for name!
    GetPlayerName(playerid, name, sizeof(name)); //getting the players name.
    format(ircMsg, sizeof(ircMsg), "02[%d] 07%s: %s", playerid, name, text); //creating the message
    IRC_GroupSay(gGroupID, IRC_CHANNEL, ircMsg);
//rest of your OnPlayerText Here!
    return 1;
}




Playing with some Callbacks
All of these are included in the Plugin and irc include!


pawn Code:
public IRC_OnConnect(botid, ip[], port)
{
    printf("*** IRC_OnConnect: Bot ID %d connected to %s:%d", botid, ip, port); //Just making a simple print to show what bot connected and what ip and port it has connected! you can expand on this easly!
    return 1;
}


A Command!

Okay so for time purpses im not going to make 2345 commands ill just show you one, now this will let you talk from IRC in to your game server! by using !say

pawn Code:
IRCCMD:say(botid, channel[], user[], host[], params[]) //making the command, in this case "say"
{
    // Check if the user has at least voice in the channel
    if (IRC_IsVoice(botid, channel, user))
    {
        // Check if the user entered any text
        if (!isnull(params))
        {
            new msg[128]; //creating the local variable for the msg.

            // Echo the formatted message
            format(msg, sizeof(msg), "02*** %s on IRC: %s", user, params);
            IRC_GroupSay(gGroupID, channel, msg);
            format(msg, sizeof(msg), "*** %s on IRC: %s", user, params);
            SendClientMessageToAll(0x0000FFFF, msg);//you can change colors here
        }
    }
    return 1;
}

just a short tutorial, if you want anything else just leave a comment hope it helps someone
Reply
#2

Nice... I Use It. Good work
Reply
#3

I don't get it
Reply
#4

hmm how can i send a message to the player which typed it ?

so only he can see the message ?
for ex: he typed a wrong cmd syntax
Reply
#5

nice but i cant understand
Reply
#6

Could you maybe explain something for me,

Now I've never seen anyone actually with this problem that has been fixed.

So I am calling a function called 'SendIRCMessageToAdmins(msg[]);' okay?

Now that will take the message and echo it to admin channel, now when I try to echo a few messages at the same time, for example i use !cmds. it doesn't seem to echo them in order, they are all over like the Channel Operator commands are in 2 different places.

Is there a way to fix this? or make them go in order. As I am trying to look for a way of doing this, in one function without having to use repetitive code all the time.

Any help would be nice.

Just for anyone who needs an better explanation:

<SomeRandomOperator> !cmds
<Bot[0]> !say, !ann, !rules, !players
<Bot[1]> [OP] !ban, !kick, !suspend
<Bot[2]> [ALL] !servertime, !admins
<Bot[0]> [OP] !lastlogins, !find, !ocheck
<Bot[1]> !checkbiz, !checkhouse

As you can see this is just an example, but it shows how the [OP] commands are mixed in between the normal commands for players and general commands.

If anyone knows a way to make them come in order, then that would be appreciated .
Reply
#7

very good.
Reply
#8

But only i can chat others can't chat form irc to server
Reply
#9

This is very useful.Thanks a lot again Flake,i'll use it when i'll set up an IRC network for our new upcoming server.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)