 |
Server Help Community forums for Subgame, ASSS, and bots
|
Author |
Message |
Guest
Offline
|
Posted: Tue Sep 06, 2005 11:42 am Post subject: Bot sends msg to Chat channel |
 |
|
|
|
I'm using the hybrid core. How would I get the bot to send a pre determand message every 30 mintues to the bots listed chat channel? |
|
Back to top |
|
 |
Cerium Server Help Squatter

Age:42 Gender: Joined: Mar 05 2005 Posts: 807 Location: I will stab you. Offline
|
Posted: Tue Sep 06, 2005 2:00 pm Post subject: |
 |
|
|
|
If using the AS frontend:
1) In spawn.ini, set the chat channels your bot will join when it connects, or send the public messages '?chat=channels' (same way as in ss).
2) Use the ASConnection.sendChannelMessage(#, MESSAGE) function, where ASConnection is an instance of the ASConnection object, # is the chat channel to send the message to and MESSAGE is the message to send (String).
-----
If using the TWCore Emu:
See distorts tutorial, Im sure it has something there for it.
Wrap the appropriate messaging function in a TimerTask class, and schedule it with a Timer to run every 30 minutes (1800000 milliseconds).
Ill probably write a quick code sample when I wake up if one of the other java guys doesnt beat me to it. _________________ There are 7 user(s) ignoring me right now. |
|
Back to top |
|
 |
D1st0rt Miss Directed Wannabe

Age:37 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Tue Sep 06, 2005 5:28 pm Post subject: |
 |
|
|
|
Go ahead, you called it _________________
 |
|
Back to top |
|
 |
Cerium Server Help Squatter

Age:42 Gender: Joined: Mar 05 2005 Posts: 807 Location: I will stab you. Offline
|
Posted: Tue Sep 06, 2005 8:12 pm Post subject: |
 |
|
|
|
Ok then...
Youre still getting the twcore tutorial.
Anyway this is mostly copy/paste from the tutorial bot, but Ive added a few chunklets of code for the timer creation/registration.
package bots.TutorialBot;
import hybrid.core.*;
import hybrid.core.consts.*;
import hybrid.core.events.*;
import hybrid.core.events.ss.*;
import frontend.alphaspawn.*;
import frontend.alphaspawn.tools.command.*;
public class Lesson1 extends AlphaSpawn
{
/**
* The ASConnection object will be used throughout most of the tutorials. This is the AlphaSpawn
* extension of the SSConnection class, which provides a number of support functions and interfaces
* for player tracking and command handling. If you play on using the AlphaSpawn frontend, you
* should get used to working with the ASConnection object and the connection framework in general.
*/
private ASConnection objConnection;
public Lesson1()
{
// Set this bots author and contact info...
super("Cerium", "Cerium@gmail.com");
CommandManager objCommands = CommandManager.getInstance();
objCommands.registerCommand("!test", new TutorialCommand());
// Attempt to open a connection...
this.objConnection = (ASConnection) ASConnection.open();
if(this.objConnection != null)
{
/* The connection was opened successfully. At this point we need to allocate a username and
* password for the connection to use. The SpawnConfiguration class provides a few functions
* for managing the names provided in spawn.ini.
*
* The allocateLoginInfo() assigns a single username for use with this bot.
*/
LoginInfo objLoginInfo = SpawnConfiguration.allocateLoginInfo();
if(objLoginInfo != null)
{
/* Once we have a username, we can set the info in the connection. This is optional, but
* is easier than handling than handling the Connected event manually.
*
* Once the info is set, we tell our ASConnection object to connect. Calling connect()
* with no parameters tells the connection to use the zone IP and port specified in
* spawn.ini.
*/
this.objConnection.setLoginInfo(objLoginInfo);
this.objConnection.connect();
/* Now we setup the timer task. the AlphaSpawn class provides a Timer for us, so we just
* need to create the TimerTask (See the ChatTask class below)
/
super.objTimer.schedule(new ChatTask(), 1800000, 1800000);
} else {
// A username could not be allocated. This bot relies on a connection that is able to
// login. Without a username, we need to shutdown.
BotSpawn.shutdown("Unable to allocate a username!");
}
} else {
// We were unable to allocate a connection, so were shutting down.
BotSpawn.shutdown("Unable to allocate a connection!");
}
}
/**
* The ChatTask class is our TimerTask to send a message at a set interval. Its not very extensive,
* so the run function is all we need to take care of.
*/
private class ChatTask extends TimerTask
{
public void run()
{
// Make sure the connection isnt null, and check that its online...
if(objConnection != null && objConnection.isOnline())
{
/* Send our message. This sends the message to the first chat channel the bot is joined to.
* This is identical to typing ';Hello internet!' in game.
*
* Before this will work, we need to either set the channels in spawn.ini, or send the
* public message ?chat=channel where 'channel' is the name of the channel to join.
*/
objConnection.sendChannelMessage(1, "Hello internet!");
}
}
}
protected void processEvent(HybridEvent objEvent)
{
// Ignore null or dead events...
if(objEvent == null || !objEvent.isAlive()) { return; }
System.out.println("Received event: " + objEvent.getEventName());
}
}
|
|
|
Back to top |
|
 |
D1st0rt Miss Directed Wannabe

Age:37 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Thu Sep 08, 2005 12:05 am Post subject: |
 |
|
|
|
A TimerTask article is on my to do list, just don't have any time these days |
|
Back to top |
|
 |
Guest
Offline
|
Posted: Thu Sep 08, 2005 12:05 am Post subject: |
 |
|
|
|
Thanks Cer, works like a charm  |
|
Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
Software by php BB © php BB Group Server Load: 178 page(s) served in previous 5 minutes.
|