Jump to content
  • 0

Dynamic SQL Broadcaster


OnNplay

Question


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  141
  • Reputation:   15
  • Joined:  01/08/12
  • Last Seen:  

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.

Link to comment
Share on other sites

5 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  666
  • Reputation:   93
  • Joined:  04/27/12
  • Last Seen:  

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.
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  141
  • Reputation:   15
  • Joined:  01/08/12
  • Last Seen:  

Thanks for the long scripting effort. I will test it.

How about only allow GM99 to use NPC?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  666
  • Reputation:   93
  • Joined:  04/27/12
  • Last Seen:  

just add a check for the GM lvl near the top.

if(getgmlevel()!=99){end;}

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  81
  • Topics Per Day:  0.02
  • Content Count:  1654
  • Reputation:   583
  • Joined:  08/09/12
  • Last Seen:  

Hmm.. Why not just use the OnClock label on an invisible NPC script? I think it will make same effect.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  30
  • Topics Per Day:  0.01
  • Content Count:  782
  • Reputation:   82
  • Joined:  01/01/12
  • Last Seen:  

Maybe because it's easier to access phpMyAdmin then a file if you are using a remote server.

Link to comment
Share on other sites

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.

×
×
  • Create New...