Here you go... it should work. (should be wannounce and no 'Server')
Code:
//***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 "" //The string to place in front of the message
//Define and create variables
bool ann_debug = false;
uint32 ann_next_id = 0;
char errstr[255];
char HeadStr[255];
string body;
char query[255];
char display_str[255];
uint32 id, next_id;
QueryResult * result;
class Announcement
{
public:
void Run();
};
void Announcement::Run()
{
if(ann_debug) ShowMsg("Debug 1");
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!");
ann_next_id = 0;
return;
}
//Is there anything to display?
if(result->GetRowCount() == 0)
{
ShowMsg("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.SendWorldWideScreenText(display_str);
//Not Tested yet -> to prevent overscope
delete fields;
}
void ShowMsg(char * errmsg)
{
sprintf(errstr, "nAnnouncer v2: %s", errmsg);
sLog.outString(errstr);
}
void SetupAnnouncer(ScriptMgr * mgr)
{
Announcement Announcer;
ShowMsg(HeadStr);
//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!");
}
}
Edit: Ok I get some Errors too. Ill edit this when its fixed
Edit 2 : Sorry but Ill fix it next week