Jump to content

Recommended Posts

  • 38 years later...
Posted

Hey,

I've got the following announcer script(Modified by me)

void World::SendBroadcast()
{
   std::string msg;
   static int nextid;

   QueryResult *result;
   if(nextid != 0)
   {
       QueryResult *result = WorldDatabase.PQuery("SELECT `text`, `next` FROM `autobroadcast` WHERE `id` = %u", nextid);
   }
   else
   {
       QueryResult *result = WorldDatabase.PQuery("SELECT `text`, `next` FROM `autobroadcast` ORDER BY RAND() LIMIT 1");
   }

   if(!result)
       return;

   nextid = result->Fetch()[1].GetUInt8();
   msg = result->Fetch()[0].GetString();
   delete result;

   static uint32 abcenter = 0;
   abcenter = sConfig.GetIntDefault("AutoBroadcast.Center", 0);
   if(abcenter == 0)
   {
       sWorld.SendWorldText(LANG_AUTO_BROADCAST, msg.c_str());

       sLog.outString("AutoBroadcast: '%s'",msg.c_str());
   }
   if(abcenter == 1)
   {
       WorldPacket data(SMSG_NOTIFICATION, (msg.size()+1));
       data << msg;
       sWorld.SendGlobalMessage(&data);

       sLog.outString("AutoBroadcast: '%s'",msg.c_str());
   }
   if(abcenter == 2)
   {
       sWorld.SendWorldText(LANG_AUTO_BROADCAST, msg.c_str());

       WorldPacket data(SMSG_NOTIFICATION, (msg.size()+1));
       data << msg;
       sWorld.SendGlobalMessage(&data);

       sLog.outString("AutoBroadcast: '%s'",msg.c_str());
   }
}

the sql table:

CREATE TABLE IF NOT EXISTS `autobroadcast` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `text` longtext NOT NULL,
 `next` int(11) NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;

INSERT INTO `autobroadcast` (`id`, `text`, `next`) VALUES
(1, 'type /join World to chat with all players', 2),
(2, 'Don''t forget to vote 4 us at ******', 3),
(3, 'Also check our forums at ******', 1);

Somehow it crashes on

nextid = result->Fetch()[1].GetUInt8();

Can anyone help me with fixing this ?

Thanks for your time, Xeross

Posted

that's wrong:

QueryResult *result;

if(nextid != 0)

{

QueryResult *result = WorldDatabase.PQuery("SELECT `text`, `next` FROM `autobroadcast` WHERE `id` = %u", nextid);

}

else

{

QueryResult *result = WorldDatabase.PQuery("SELECT `text`, `next` FROM `autobroadcast` ORDER BY RAND() LIMIT 1");

}

you redefine result in the if... do it so:
QueryResult *result;

if(nextid != 0)

{

result = WorldDatabase.PQuery("SELECT `text`, `next` FROM `autobroadcast` WHERE `id` = %u", nextid);

}

else

{

result = WorldDatabase.PQuery("SELECT `text`, `next` FROM `autobroadcast` ORDER BY RAND() LIMIT 1");

}

Posted
If you guys want it i can post a patch for it.

It's the default announcer but with something added to let it announce in a certain order

would be nice to have it on a patch, and cool work ^_^

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use