Jump to content
  • 0

Dynamic SQL Broadcaster


Question

Posted

This NPC will pull the message from database at given time and broadcast it globally.

Time for broadcasting cycle also can be edit in database table.

Every row added into table will act as one line of message.

5 answers to this question

Recommended Posts

Posted (edited)

CREATE  TABLE `ragnarok`.`auto_announce` (
 `id` SMALLINT(5) NOT NULL AUTO_INCREMENT ,
 `msg` TEXT NULL ,
 `clock` SMALLINT(5) UNSIGNED NOT NULL DEFAULT 0 ,
 `type` VARCHAR(45) NULL ,
 `desc` VARCHAR(45) NULL,
 PRIMARY KEY (`id`) )
ENGINE = MyISAM;

mapname,x,y,z script auto_announe 123,{
setarray .@t$[1],"Notice","Event","Misc"; //Add more as needed.
menu "Update MSGs",iUMSG,"Delete MSGs",iDMSG,"Cancel",iCancel;
 iCancel:
 close;
 iUMSG:
 mes "Type what your MSG will say.";
 mes "Example: ^00FF00 Like ExampleRO? Remember to vote every day!^000000";
 input .@msg$;
 next;
 mes "Are you sure about the following message?";
 mes .@msg$;
 menu "Yes",-,"No",iCancel;
 next;
 mes "Enter what time your message should appear.";
 mes "Example: ^00FF00 0000 = 12AM.  1200 = 12PM. 1812 = 6:12PM.";
 input .@clock;
 next;
 mes "Are you sure about this time?";
 mes ""+.@clock+"";
 menu "Yes",-,"No",iCancel;
 next;
 mes "Enter What type of message this is.";
 mes "Example: ^00FF00 Notice = Important information.^000000";
 mes "Example: ^00FF00 Event = Messages that are informative about events.^000000";
 mes "Example: ^00FF00 Misc = Everything else.^000000";
 set .@menu$,":";
 for(set .@i,0; .@i<getarraysize(.t$); set .@i,.@i+1)
  {set .@menu$,.@menu$+""+.t$[.@i]+":";}
 menu .@menu$,-;
 set .@type$,.t$[@menu];
 next;
 mes "Are you sure about this type?";
 mes .@type$;
 menu "Yes",-,"No",iCancel;
 next;
 mes "Please give a brief description so you can recognize it";
 mes "Note - Description can be no longer than 20 characters.";
 input .@desc$;
 if(getstrlen(.@desc$)>20)
  {next; mes "Invalid Description (Too Long). Try again.";
mes "Remember description can be no more than 20 keystrokes.";
input .@desc$;
if(getstrlen(.@desc$)>20){next; mes "Invalid Description (Too Long)."; close;}
 }
 query_sql"INSERT INTO `auto_announce`(`id`,`msg`,`clock`,`type`,`desc`)VALUES(,'"+.@msg$+"','"+.@clock+"','"+.@type$+"','"+.@desc$+"')";
 next;
 mes "The following message will appear at the given time with limitations to its type.";
 mes "^00FF00"+.@msg$+"^000000";
 mes "Time: ^00FF00"+.@clock+"^000000";
 mes "Type: ^00FF00"+.@type$+"^000000";
 mes "Desc: ^00FF00"+.@desc$+"^000000";
 close;

 iDMSG:
 mes "What type of message do you want to DELETE?";
 set .@menu,":";
 for(set .@i,0; .@i<getarraysize(.t$); set .@i,.@i+1)
  {set .@menu$,.@menu$+""+.t$[.@i]+":";}
 menu .@menu$,-;
 set .@type$,.t$[@menu];
 query_sql"SELECT(`id`,`msg`,`clock`,`desc`)FROM `auto_announce` WHERE `type`='"+.@type$+"'",.@id,.@msg$,.@clock,.@desc$;
 iDEL:
 next;
 mes "Select the message you wish to delete.";
 set .@menu$,":";
 for(set .@j,0; .@j<getarraysize(.@id); set .@j,.@j+1)
  {set .@menu$,.@menu+"Desc:^00FF00"+.@desc$[.@j]+"^000000 Time: ^00FF00"+.@clock[.@j]+"^000000";}
 menu .@menu$,-;
 next;
 mes "Are you sure you want to delete the following message?";
 mes "^00FF00"+.@msg$[@menu]+"^000000";
 mes "Time: ^00FF00"+.@clock[@menu]+"^000000";
 mes "Type: ^00FF00"+.@type$[@menu]+"^000000";
 mes "Desc: ^00FF00"+.@desc$[@menu]+"^000000";
 menu "Yes",-,"No",iDEL,"Cancel",iCancel;
 query_sql"DELETE FROM `auto_announce` WHERE `desc`='"+.@desc$[[@menu]]+"' AND `type`='"+.@type$[@menu]+"' AND `time`='"+.@clock[@menu]+"'";
 next;
 mes "Message Deleted.";
 close;
OnInit:
setarray .t$[1],"Notice","Event","Misc"; //Add more as needed.
set .type$,.t$[1]; //Do not use 0 as it will break the script.
query_sql"SELECT(`clock`)FROM(`auto_announce`)WHERE(`type`='"+.type$+"')",.@clock;
for(set .@i,0; .@i<getarraysize(.@clock); set .@i,.@i+1)
{set .clock$[.@i],""+.@clock[.@i]+"";
set .clock[.@i],.@clock[.@i];}
setnpctimer 0;
startnpctimer;
end;
OnTimer60000:
set .@time$,""+gettime(3)+""+gettime(2)+"";
for(set .@i,0; .@i<getarraysize(.clock$); set .@i,.@i+1)
{if(.@time$ == .clock$[.@i])
{setnpctimer 0; query_sql"SELECT(`msg`)FROM(`auto_announce`)WHERE(`clock`='"+.clock[.@i]+"' AND `type`='"+.@type$+"')",.@msg$;
 announce .@msg$; end;}
setnpctimer 0;
end;
}CREATE  TABLE `ragnarok`.`auto_announce` (
 `id` SMALLINT(5) NOT NULL AUTO_INCREMENT ,
 `msg` TEXT NULL ,
 `clock` SMALLINT(5) UNSIGNED NOT NULL DEFAULT 0 ,
 `type` VARCHAR(45) NULL ,
 `desc` VARCHAR(45) NULL,
 PRIMARY KEY (`id`) )
ENGINE = MyISAM;
mapname,x,y,z script auto_announe 123,{
setarray .@t$[1],"Notice","Event","Misc"; //Add more as needed.
menu "Update MSGs",iUMSG,"Delete MSGs",iDMSG,"Cancel",iCancel;
 iCancel:
 close;
 iUMSG:
 mes "Type what your MSG will say.";
 mes "Example: ^00FF00 Like ExampleRO? Remember to vote every day!^000000";
 input .@msg$;
 next;
 mes "Are you sure about the following message?";
 mes .@msg$;
 menu "Yes",-,"No",iCancel;
 next;
 mes "Enter what time your message should appear.";
 mes "Example: ^00FF00 0000 = 12AM.  1200 = 12PM. 1812 = 6:12PM.";
 input .@clock;
 next;
 mes "Are you sure about this time?";
 mes ""+.@clock+"";
 menu "Yes",-,"No",iCancel;
 next;
 mes "Enter What type of message this is.";
 mes "Example: ^00FF00 Notice = Important information.^000000";
 mes "Example: ^00FF00 Event = Messages that are informative about events.^000000";
 mes "Example: ^00FF00 Misc = Everything else.^000000";
 set .@menu$,":";
 for(set .@i,0; .@i<getarraysize(.t$); set .@i,.@i+1)
  {set .@menu$,.@menu$+""+.t$[.@i]+":";}
 menu .@menu$,-;
 set .@type$,.t$[@menu];
 next;
 mes "Are you sure about this type?";
 mes .@type$;
 menu "Yes",-,"No",iCancel;
 next;
 mes "Please give a brief description so you can recognize it";
 mes "Note - Description can be no longer than 20 characters.";
 input .@desc$;
 if(getstrlen(.@desc$)>20)
  {next; mes "Invalid Description (Too Long). Try again.";
mes "Remember description can be no more than 20 keystrokes.";
input .@desc$;
if(getstrlen(.@desc$)>20){next; mes "Invalid Description (Too Long)."; close;}
 }
 query_sql"INSERT INTO `auto_announce`(`id`,`msg`,`clock`,`type`,`desc`)VALUES(,'"+.@msg$+"','"+.@clock+"','"+.@type$+"','"+.@desc$+"')";
 next;
 mes "The following message will appear at the given time with limitations to its type.";
 mes "^00FF00"+.@msg$+"^000000";
 mes "Time: ^00FF00"+.@clock+"^000000";
 mes "Type: ^00FF00"+.@type$+"^000000";
 mes "Desc: ^00FF00"+.@desc$+"^000000";
 close;

 iDMSG:
 mes "What type of message do you want to DELETE?";
 set .@menu,":";
 for(set .@i,0; .@i<getarraysize(.t$); set .@i,.@i+1)
  {set .@menu$,.@menu$+""+.t$[.@i]+":";}
 menu .@menu$,-;
 set .@type$,.t$[@menu];
 query_sql"SELECT(`id`,`msg`,`clock`,`desc`)FROM `auto_announce` WHERE `type`='"+.@type$+"'",.@id,.@msg$,.@clock,.@desc$;
 iDEL:
 next;
 mes "Select the message you wish to delete.";
 set .@menu$,":";
 for(set .@j,0; .@j<getarraysize(.@id); set .@j,.@j+1)
  {set .@menu$,.@menu+"Desc:^00FF00"+.@desc$[.@j]+"^000000 Time: ^00FF00"+.@clock[.@j]+"^000000";}
 menu .@menu$,-;
 next;
 mes "Are you sure you want to delete the following message?";
 mes "^00FF00"+.@msg$[@menu]+"^000000";
 mes "Time: ^00FF00"+.@clock[@menu]+"^000000";
 mes "Type: ^00FF00"+.@type$[@menu]+"^000000";
 mes "Desc: ^00FF00"+.@desc$[@menu]+"^000000";
 menu "Yes",-,"No",iDEL,"Cancel",iCancel;
 query_sql"DELETE FROM `auto_announce` WHERE `desc`='"+.@desc$[[@menu]]+"' AND `type`='"+.@type$[@menu]+"' AND `time`='"+.@clock[@menu]+"'";
 next;
 mes "Message Deleted.";
 close;
OnInit:
setarray .t$[1],"Notice","Event","Misc"; //Add more as needed.
set .type$,.t$[1]; //Do not use 0 as it will break the script.
query_sql"SELECT(`clock`)FROM(`auto_announce`)WHERE(`type`='"+.type$+"')",.@clock;
for(set .@i,0; .@i<getarraysize(.@clock); set .@i,.@i+1)
{set .clock$[.@i],""+.@clock[.@i]+"";
set .clock[.@i],.@clock[.@i];}
setnpctimer 0;
startnpctimer;
end;
OnTimer60000:
set .@time$,""+gettime(3)+""+gettime(2)+"";
for(set .@i,0; .@i<getarraysize(.clock$); set .@i,.@i+1)
{if(.@time$ == .clock$[.@i])
{setnpctimer 0; query_sql"SELECT(`msg`)FROM(`auto_announce`)WHERE(`clock`='"+.clock[.@i]+"' AND `type`='"+.@type$+"')",.@msg$;
 announce .@msg$; end;}
setnpctimer 0;
end;
}

Haven't tested it.

Edited by Emistry
Please use [CODEBOX] or Attachments for long contents.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...