PDA

View Full Version : Auto Announcer



StickyIcky
25-07-08, 01:43 AM
This is an auto announcer

Works on both Ascent and Mangos

Announcer.cpp

//***This script was released under CodeCraft and cannot be redistrubted without giving credits**
//Title of Script: Anouncer v2
//Description of Script: Sends a worldwide announcement in timed intervals.
//Author: Daikenkaiking
//Credits: Supalosa for his xml script that I learned some functions from.

#include "StdAfx.h"
#include "Setup.h"

//Configure these as you wish
#define BREAKTIME 300000 //The amount of seconds * 1000 you want to wait in between messages
#define HEADERSTR "[Announcer]" //The string to place in front of the message

//Define and create variables
uint32 ann_next_id = 0;

class Announcement
{
public:
void Run();
};

void Announcement::Run()
{
// Variable Defines
char query[255];
char display_str[255];
string body;
uint32 id, next_id;

if(ann_next_id == 0)
{
sprintf(query, "SELECT * FROM announcer_txt ORDER BY RAND() LIMIT 1");
} else {
sprintf(query, "SELECT * FROM announcer_txt WHERE id = %i", ann_next_id);
}
QueryResult * result = WorldDatabase.Query(query);

//Uh oh!
if(!result)
{
ShowMsg("Something went wrong or there is no data to display!");
ann_next_id = 0;
return;
}

//Lets get the data, and set everyting up
Field * fields = result->Fetch();
id = fields[0].GetUInt32();
body = fields[1].GetString();
next_id = fields[2].GetUInt32();

//We may need to set next id, and set last id
if(next_id != 0)
ann_next_id = next_id;
else
ann_next_id = 0;

//Lets format the String to display and then display it!
sprintf(display_str, "%s %s", HEADERSTR, body.c_str());
sWorld.SendWorldText(display_str);

//to prevent overscope and leaking
WorldDatabase.FreeQueryResult(result);
}

void ShowMsg(char * errmsg)
{
char errstr[255];
sprintf(errstr, "\nAnnouncer v2: %s", errmsg);
sLog.outString(errstr);
}

void SetupAnnouncer(ScriptMgr * mgr)
{
Announcement Announcer;
//If all is good, set up the timer event and lets roll!
if(BREAKTIME >= 1000)
{
TimedEvent * te = TimedEvent::Allocate(&Announcer, new CallbackP0<Announcement>(&Announcer, &Announcement::Run), 1, BREAKTIME, 0);
sWorld.event_AddEvent(te);
ShowMsg("Announcer has been started!");
} else {
//Someone has their time set under 1 second. ;P
ShowMsg("Announcer has been disabled. Please insure you have the config set right!");
}

}


Setup.h

void SetupAnnouncer(ScriptMgr * mgr);
void ShowMsg(char * errmsg);

Add to Char Table

CREATE TABLE `announcer_txt` (
`id` int(3) NOT NULL auto_increment,
`body` tinytext NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;

Chmun
03-08-08, 07:12 AM
can u make a setup.cpp +Repx1

Apple
03-08-08, 07:15 AM
btw , i am already using it on my server forgot to give u +REp , so +Rep now

Jonatan.Biz
21-08-08, 01:28 PM
1>..\src\Announcer\Announcer.cpp(42) : error C3861: 'ShowMsg': identifier not found

I guess most of these scripts are outdated... :(

Edit!! :D Didn't see the box underneath.

Synthetic
31-08-08, 08:02 AM
Hmm, mate this script is very big i must say. U should check out the lua announcer that i've made ;) Anyways its nice and works perfect.

StickyIcky
31-08-08, 09:56 PM
This one works perfect too...and its made from Daikaikenking...a great C++ scripter