18.05.2012, 10:14
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
Now to add your Bots!
This will be the name that everyone will see when its connected to the IRC
Now this is just the rest of the config for the /whois
Now to Set up the connection so the server knows that irc server to connect the bots to
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.
The Core of connecting the Bots!
This is getting the bots id and grouping them, in our case only 1 bot.
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
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!
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!
Now to show when a player talks on the server! Lets Echo it to the IRC Server!
Playing with some Callbacks
All of these are included in the Plugin and irc include!
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
just a short tutorial, if you want anything else just leave a comment hope it helps someone
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"
pawn Code:
#define BOT_1_REALNAME "SA-MP Bot"
#define BOT_1_USERNAME "bot"
pawn Code:
#define IRC_SERVER "irc.foco.co"
#define IRC_PORT (6667)
#define IRC_CHANNEL "#testchannel"
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;
}
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);
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