Advertisement
Skorm

Toasty's WOE Controller v1.22

Apr 20th, 2017
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 23.43 KB | None | 0 0
  1. //======================================================================================================
  2. //= toasty's woe controller (formerly woe info banner)
  3. //===== by: ============================================================================================
  4. //= toastofdoom (aka: iheart)
  5. //===== current version: ===============================================================================
  6. //= 1.22
  7. //===== description: ===================================================================================
  8. //= a woe controller function which controls castle based woe by utilising npc events.
  9. //= includes a npc that provides information on the next woe session
  10. //=
  11. //= this script is kinda @reloadscript/@loadnpc safe, provided that someone clicks the npcs afterwards
  12. //= to start the oninit function. that said..it is recommended that you don't use @reloadscript/@loadnpc
  13. //= but reset your server.
  14. //= Support Thread: https://rathena.org/board/topic/57377-dead-link-toastys-woe-controller/
  15. //===== changelog: =====================================================================================
  16. //= 1.22
  17. //= - fixed an issue regarding the controller getting confused when using @reloadscript/loadnpc while
  18. //=   woe was still active. (thanks to annie for pointing out)
  19. //= 1.21
  20. //= - fixed a misspelt variable name (thanks to rahuldev345 for pointing out)
  21. //= 1.20
  22. //= - project renamed to 'toasty's woe controller'. the script originally was only used to display woe
  23. //=   times then i 1st wrote it 3yrs ago and i feel it's purpose is more to control woe these days. so
  24. //=   name change to better reflect purpose.
  25. //= - added support for novice woe. region teleport goes to the novice warper npc (default in prontera)
  26. //=   change position in .region_maps, .region_x, .region_y if needed.
  27. //= - region warp now only displays regions that have castles used at least once. (eg. if you don't
  28. //=   configure any castles for payon region, payon will not show up)
  29. //= - optimised woe active/inactive map notifier. old method used too many loops for something that
  30. //=   can happen alot.
  31. //= - adjusted menus to be abit more friendly. 'next's will always display before 'menu's
  32. //= - fixed bug with woe autostarting when only configured for 2 sessions in one day
  33. //= - added some nifty code that prevents catastrophic failure of the script if you try to run a trunk
  34. //=   version on a stable server (ie. if you do, it will show an error message, but script will still
  35. //=   run perfectly fine - check out woetoggler function for those that want to peek at it =p)
  36. //= 1.11
  37. //= - fixed timer glitch when players only configured sessions for one day of the week
  38. //= - adjusted timer to show remaining time more accurately
  39. //= - modified .num_woes calculation due to bug regarding 0's being counted as unset values in arrays
  40. //= 1.10
  41. //= - expanded script to allow castle based configuration
  42. //= - moved away from portal based woe control. now using donpcevents to onagitend/2 events. provided
  43. //=   castles are linked to the main agit commands in this manner, they will be controllable using this
  44. //=   script.
  45. //= - added an onloadmap woe available notifier. can be disabled by setting .notify_woe to 0 in the
  46. //=   config section.
  47. //= - did some funky color coding.
  48. //= - added coordinate based warping per region (see .region_x & .region_y in the constants section)
  49. //= 1.02
  50. //= - added delwaitingroom to banner npc to prevent memory leaks from bug #2325
  51. //= - to reduce spamming of waitingroom packets to players banner npc only now updates when the banner
  52. //=   text changes. thus min time between updates is now 1sec regardless of setting.
  53. //= - added setting for rate which banner time is updated (.banner_refresh_rate) in the config section.
  54. //= - added agitstart2/end2 to provide woe2 support (hope it works ^_^;)
  55. //= 1.01
  56. //= - hardcoded in refresh value for banner npc instead of getting it from config from woeinfobase. had
  57. //=   issues starting the script after @reloadscript/@loadnpc
  58. //======================================================================================================
  59. -   script  woeinfobase -1,{
  60.  
  61.     onstartmenu:
  62.         if(.init == 0)
  63.             donpcevent strnpcinfo(3)+"::oninit";
  64.    
  65.     onstartmenu2:
  66.         mes "The " + ((.state)?"^008000current":"^dd0000next") + "^000000 WoE session is: ";
  67.         mes " ";
  68.         mes "Day: ^0000dd" + .daysofweek$[.woe_day[.woe_index]];
  69.         mes "^000000Start Time: ^008000" + .woe_0_str$[.woe_index];
  70.         mes "^000000End Time: ^dd0000" + .woe_1_str$[.woe_index];
  71.         mes "^000000Region:";
  72.  
  73.         set .@state_strs$, ".woe_state_str_" + .woe_state[.woe_index] + "$";
  74.         for(set .@i, 0; .@i < .num_regions; set .@i, .@i + 1) {
  75.             set .@output$, getd(.@state_strs$ + "[" + .@i + "]");
  76.             if(.@output$ != "")
  77.                 mes "^000000- ^0000dd" + .@output$;
  78.         }
  79.         next;
  80.        
  81.         if(getgmlevel() >= .gm_access)
  82.             select(
  83.                 "Warp to Castle Grounds",
  84.                 "View Castle Owners",
  85.                 "View All WoE Times",
  86.                 ((!.state)?"Start Next WoE":"End Current WoE"),
  87.                 ((.state)?"":"skip next woe session")
  88.                 );
  89.         else
  90.             select(
  91.                 "Warp to Castle Grounds",
  92.                 "View Castle Owners",
  93.                 "View All WoE Times");
  94.            
  95.         switch(@menu) {
  96.             case 1:     //warp
  97.                 mes "Which region would you like to warp to?";
  98.                 next;
  99.                 select(.region_warp$[.woe_state[.woe_index]]);
  100.                 if(@menu < 1 || @menu > .num_regions)
  101.                     close;
  102.                                
  103.                 close2;
  104.                 warp .region_maps$[@menu - 1], .region_x[@menu - 1], .region_y[@menu - 1];
  105.                 end;
  106.             case 2:     //view         
  107.                 set .@woe_state_array$, ".woe_state_" + .woe_state[.woe_index];
  108.                 for(set .@i, 0; .@i < .num_regions; set .@i, .@i + 1) {
  109.                     set .@k, 0;
  110.                     set .@castles$, ".castles_" + .regions$[.@i] + "$";
  111.                     set .@castle_check, getd(.@woe_state_array$ + "[" + .@i + "]");
  112.                     while(.@castle_check && .@k < .num_castles[.@i]) {
  113.                         if(.@castle_check & (1 << .@k)) {
  114.                             set .@map$, getd(.@castles$+"["+.@k+"]");
  115.                             if (getcastledata(.@map$,1)) {
  116.                                 dispbottom "The [" + getcastlename(.@map$) + "] castle of the [" + .region_names$[.@i] + "] region is currently held by the [" + getguildname(getcastledata(.@map$,1)) + "] guild.";
  117.                             } else {
  118.                                 dispbottom "The [" + getcastlename(.@map$) + "] castle of the [" + .region_names$[.@i] + "] region is currently unoccupied.";
  119.                             }
  120.                             set .@castle_check, .@castle_check - (1 << .@k);
  121.                         }
  122.                         set .@k, .@k + 1;      
  123.                     }
  124.                 }
  125.                 break;
  126.             case 3:     //woe times
  127.                 for(set .@i, 0; .@i < .num_woes; set .@i, .@i + 1) {                           
  128.                     dispbottom "- " + .daysofweek$[.woe_day[.@i]] + " " + .woe_0_str$[.@i] + "-" + .woe_1_str$[.@i];
  129.                     set .@woe_state_str_array$, ".woe_state_str_" + .woe_state[.@i] + "$";
  130.                     for(set .@k, 0; .@k < .num_regions; set .@k, .@k + 1) {
  131.                         set .@output$, getd(.@woe_state_str_array$ + "[" + .@k + "]");
  132.                         if(.@output$ != "")
  133.                             dispbottom "        " + .@output$;
  134.                     }
  135.                 }
  136.                 break;
  137.             case 4:     //start next;
  138.                 if(getgmlevel() <.gm_access) close;
  139.                
  140.                 mes "^ff0000Are you sure you want to " + ((!.state)?"start the next woe session?":"end the current woe session?");
  141.                 next;
  142.                 if(select("yes:no") == 2) break;
  143.                
  144.                 set .remaintime, 0; //might not work sometimes...you have like a 500ms window out of 505ms i guess..
  145.                 sleep2 .timer_refresh_rate; //wait abit so the menu doesn't screw up (how long it takes for the timer to update)
  146.                 break;
  147.             case 5:     //skip next;
  148.                 if(getgmlevel() <.gm_access || .state) close;
  149.                
  150.                 mes "^ff0000Are you sure you want to skip the next WoE session^000000";
  151.                 next;
  152.                 if(select("yes:no") == 2) break;
  153.                 if(.state) {    //you really can't do this with woe active
  154.                     next;
  155.                     mes "Sorry, in the time you took making your decision, WoE started";
  156.                     mes "Please either manually end it first or wait";
  157.                     break;         
  158.                 }
  159.                 set .woe_index, (.woe_index + 1) % .num_woes;
  160.                 donpcevent strnpcinfo(3)+"::onupdatecounttick";
  161.                 sleep2 .timer_refresh_rate;
  162.                 break;
  163.             default: close;    
  164.         }
  165.         goto onstartmenu2;
  166.    
  167.     oninit:
  168.  
  169.         //-----------------------------------------------------------------------------------------//
  170.         //config start                                                                             //
  171.         //-----------------------------------------------------------------------------------------//
  172.        
  173.         set .gm_access, 60;
  174.        
  175.         //woe timings needs to be ordered ascendingly unless you want to do weird
  176.         //stuff like skip a region every other week or so...
  177.         //also times can't overlap. uses second of day(gettimetick(1)) for timing
  178.         // eg 1am -> 3600, 2:30pm -> 52200, midnight -> 86400 (anything past that doesn't work)
  179.         //note: woe_0 is start times, woe_1 is end times. ignore how it's called but
  180.         //       don't change it either since it's dynamically used
  181.         //       also..woe has to end on the same day it starts (it's easier that way..)
  182.         setarray .woe_day[0],   0,    1,    3,    5;
  183.         setarray .woe_0[0], 72000,72000,72000,72000;
  184.         setarray .woe_1[0], 75600,75600,75600,75600;
  185.         setarray .woe_state[0], 0,    0,    0,    0;
  186.        
  187.         //woe state settings. every woe session can be defined as a particular state of castle configuration.
  188.         //.woe_state_#[%] = $
  189.         // # - state number
  190.         // % - region number
  191.         // $ - binary representation of castles that are active for that region in that state (
  192.         //     (ie. 0 is no castles, 5 is castle 0 and 2  (2^0 + 2^2 = 5))
  193.         setarray .woe_state_0[0],1,0,0,0,0,0,0;
  194.        
  195.         //setting for if script handles woe controller function. disable agit_controller.txt if you are using this.
  196.         //for if you want to use something else to handle your woe stuff but only this script
  197.         //to show info (1 - on, 0 - off...duh)
  198.         set .active_woe, 1;
  199.        
  200.        
  201.         //woe inactive on map notifier. basically notifies player if the castle they are entering is
  202.         //woe active or not
  203.         set .notify_woe, 1;
  204.        
  205.         //-----------------------------------------------------------------------------------------//
  206.         //config end                                                                               //
  207.         //-----------------------------------------------------------------------------------------//
  208.        
  209.        
  210.         //-----------------------------------------------------------------------------------------//
  211.         //constants start - don't touch this unless you know what you are doing                    //
  212.         //-----------------------------------------------------------------------------------------//
  213.        
  214.         //castle maps by region
  215.         setarray .castles_prtg$[0],"prtg_cas01","prtg_cas02","prtg_cas03","prtg_cas04","prtg_cas05";
  216.         setarray .castles_payg$[0],"payg_cas01","payg_cas02","payg_cas03","payg_cas04","payg_cas05";
  217.         setarray .castles_gefg$[0],"gefg_cas01","gefg_cas02","gefg_cas03","gefg_cas04","gefg_cas05";
  218.         setarray .castles_aldeg$[0],"aldeg_cas01","aldeg_cas02","aldeg_cas03","aldeg_cas04","aldeg_cas05";
  219.         setarray .castles_arug$[0],"arug_cas01","arug_cas02","arug_cas03","arug_cas04","arug_cas05";
  220.         setarray .castles_schg$[0],"schg_cas01","schg_cas02","schg_cas03","schg_cas04","schg_cas05";
  221.         setarray .castles_novi$[0],"nguild_alde","nguild_gef","nguild_pay","nguild_prt";
  222.        
  223.         //woe kill functions for each castle
  224.         setarray .woe_kill_prtg$[0],"agit#prtg_cas01::onagitend","agit#prtg_cas02::onagitend","agit#prtg_cas03::onagitend","agit#prtg_cas04::onagitend","agit#prtg_cas05::onagitend";
  225.         setarray .woe_kill_payg$[0],"agit#payg_cas01::onagitend","agit#payg_cas02::onagitend","agit#payg_cas03::onagitend","agit#payg_cas04::onagitend","agit#payg_cas05::onagitend";
  226.         setarray .woe_kill_gefg$[0],"agit#gefg_cas01::onagitend","agit#gefg_cas02::onagitend","agit#gefg_cas03::onagitend","agit#gefg_cas04::onagitend","agit#gefg_cas05::onagitend";
  227.         setarray .woe_kill_aldeg$[0],"agit#aldeg_cas01::onagitend","agit#aldeg_cas02::onagitend","agit#aldeg_cas03::onagitend","agit#aldeg_cas04::onagitend","agit#aldeg_cas05::onagitend";
  228.         setarray .woe_kill_arug$[0],"manager#aru01_02::onagitend2","manager#aru02_02::onagitend2","manager#aru03_02::onagitend2","manager#aru04_02::onagitend2","manager#aru05_02::onagitend2";
  229.         setarray .woe_kill_schg$[0],"manager#sch01_02::onagitend2","manager#sch02_02::onagitend2","manager#sch03_02::onagitend2","manager#sch04_02::onagitend2","manager#sch05_02::onagitend2";
  230.         setarray .woe_kill_novi$[0],"agit_n01::onagitend","agit_n02::onagitend","agit_n03::onagitend","agit_n04::onagitend";
  231.        
  232.         //region prefixs
  233.         setarray .regions$[0],"prtg","payg","gefg","aldeg","arug","schg","novi";
  234.        
  235.         //region info
  236.         setarray .region_names$[0],"Prontera", "Payon", "Geffen", "Aldebaran", "Arunafeltz", "Schwarzwald", "Novice castles";
  237.         setarray .region_maps$[0],"prt_gld", "pay_gld", "gef_fild13", "alde_gld", "aru_gld", "sch_gld", "prontera";
  238.         //coords to warp player to region (0 is random)
  239.         setarray .region_x[0],0, 0, 0, 0, 0, 0, 148;
  240.         setarray .region_y[0],0, 0, 0, 0, 0, 0, 163;
  241.  
  242.         setarray .waitmsg$[0], "WoE Starts: ", "WoE Ends: ";
  243.         setarray .startmsg$[0], "WoE is Starting", "WoE is Ending";
  244.    
  245.         set .ticks_in_day, 86400;   //mmm...magic numbers
  246.         setarray .daysofweek$[0], "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";
  247.  
  248.         set .timer_refresh_rate, 500;   //how many ms per timer refresh...keep less than 1000 (in milliseconds)
  249.         set .change_state_sleep, 3000;  //how long to show "woe is start|end-ing" msg for in ms. (in milliseconds)
  250.                                         //make sure woe sessions are longer than this xd
  251.         set .banner_refresh_rate, 10;   //how many seconds per banner refresh...keep 1 or above (in seconds)
  252.        
  253.         //-----------------------------------------------------------------------------------------//
  254.         //constants end                                                                            //
  255.         //-----------------------------------------------------------------------------------------//
  256.  
  257.         set .num_regions, getarraysize(.regions$);
  258.         set .num_woes, getarraysize(.woe_1);
  259.        
  260.         //force woe to end if active
  261.         callfunc "woetoggler", 0;
  262.        
  263.         for(set .@i, 0; .@i < .num_regions; set .@i, .@i + 1) {
  264.             //count num castles per region
  265.             set .num_castles[.@i], getarraysize(getd(".castles_" + .regions$[.@i] + "$"));
  266.         }
  267.        
  268.         //convert timestamps to readable format
  269.         for(set .@i, 0; .@i < .num_woes; set .@i, .@i + 1)
  270.         {
  271.             set .@hrs, .woe_0[.@i] / 3600;
  272.             set .@mins, .woe_0[.@i] % 3600 / 60;
  273.             set .@output$, ((.@hrs % 12)?.@hrs%12:12) + ":" + ((.@mins < 10)?"0"+.@mins:.@mins) + " " + ((.@hrs > 12)?"pm":"am");  
  274.            
  275.             set .woe_0_str$[.@i], .@output$;       
  276.            
  277.             set .@hrs, .woe_1[.@i] / 3600;
  278.             set .@mins, .woe_1[.@i] % 3600 / 60;
  279.             set .@output$, ((.@hrs % 12)?.@hrs%12:12) + ":" + ((.@mins < 10)?"0"+.@mins:.@mins) + " " + ((.@hrs > 12)?"pm":"am");  
  280.            
  281.             set .woe_1_str$[.@i], .@output$;       
  282.         }
  283.        
  284.         //calc number of woe states and consolidate states to create list of castles used
  285.         set .num_states, 0;
  286.         while(getarraysize(getd(".woe_state_" + (.num_states)))) {
  287.             set .@state$, ".woe_state_" + .num_states;
  288.             set .@i, 0;
  289.             while(.@i < getarraysize(getd(.@state$))) {
  290.                 set .castleusage[.@i], .castleusage[.@i] | getd(.@state$ + "[" + .@i + "]");
  291.                 set .@i, .@i + 1;
  292.             }
  293.             set .num_states, .num_states + 1;          
  294.         }
  295.  
  296.         for(set .@i, 0; .@i < .num_states; set .@i, .@i + 1) {                         
  297.             set .@woe_state_array$, ".woe_state_" + .@i;
  298.             for(set .@k, 0; .@k < .num_regions; set .@k, .@k + 1) {
  299.                 if(.castleusage[.@k] > 0) {
  300.                     set .@castles$, ".castles_" + .regions$[.@k] + "$";
  301.                     set .@castle_check, getd(.@woe_state_array$ + "[" + .@k + "]");
  302.                     if(.@castle_check == 0) { //region not in this state
  303.                         //region warp menu string
  304.                         set .region_warp$[.@i], .region_warp$[.@i] + "^dd0000" + .region_names$[.@k] + "^000000:";
  305.                         continue;
  306.                     } else {
  307.                         if(.@castle_check >= ((1 << .num_castles[.@k]) - 1)) {
  308.                             //includes all castles...just list as region.
  309.                             setd(".woe_state_str_" + .@i + "$[" + .@k + "]", .region_names$[.@k]);
  310.                            
  311.                             //region warp menu string
  312.                             set .region_warp$[.@i], .region_warp$[.@i] + "^008000" + .region_names$[.@k] + "^000000:";
  313.                         } else {
  314.                             set .@j, 0;
  315.                             set .@output$, "";
  316.                             while(.@j < .num_castles[.@k]) {
  317.                                 if(.@castle_check & (1 << .@j)) {
  318.                                     set .@output$, .@output$ + getcastlename(getd(.@castles$+"["+.@j+"]"));
  319.                                     set .@castle_check, .@castle_check - (1 << .@j);
  320.                                     if(.@castle_check) {
  321.                                         if(.@output$ != "")
  322.                                         set .@output$, .@output$ + ", ";
  323.                                     } else
  324.                                         break;
  325.                                 }
  326.                                 set .@j, .@j + 1;
  327.                             }
  328.                             setd(".woe_state_str_" + .@i + "$[" + .@k + "]", .region_names$[.@k] + " ("+  .@output$ + ")");
  329.                            
  330.                             //region warp menu string
  331.                             set .region_warp$[.@i], .region_warp$[.@i] + "^008000" + .region_names$[.@k] + " ("+  .@output$ + ")^000000:";
  332.                         }
  333.                     }
  334.                 } else {
  335.                     set .region_warp$[.@i], .region_warp$[.@i] + ":";
  336.                 }
  337.             }
  338.         }
  339.        
  340.         donpcevent strnpcinfo(3)+"::onfindcurindex";
  341.         donpcevent strnpcinfo(3)+"::onupdatecounttick";
  342.            
  343.         if(.active_woe) {
  344.             if(.notify_woe) {
  345.                 //set mapflag for all castle maps
  346.                 for(set .@i, 0; .@i < .num_regions; set .@i, .@i + 1) {
  347.                     set .@region_array$, ".castles_" + .regions$[.@i] + "$";
  348.                     for(set .@k, 0; .@k < .num_castles[.@i]; set .@k, .@k + 1) {
  349.                         setmapflag getd(.@region_array$ + "[" + .@k + "]"), mf_loadevent;
  350.                         setd(".loadmap_region_" + getd(.@region_array$ + "[" + .@k + "]"), .@i + 1);
  351.                         setd(".loadmap_castleindex_" + getd(.@region_array$ + "[" + .@k + "]"), .@k);
  352.                     }
  353.                 }
  354.             }
  355.             //activates woe if needed
  356.             donpcevent strnpcinfo(3)+"::ondowoe";
  357.         }
  358.         //flag that init occured
  359.         set .init, 1;
  360.    
  361.     onwoetimer:
  362.         //timer stuff
  363.         while (1) {
  364.             set .remaintime, .count_tick - gettimetick(2);
  365.             set .bannertimer, .remaintime - (.remaintime % .banner_refresh_rate) + .banner_refresh_rate;
  366.             set .min, .bannertimer / 60;
  367.             set .sec, .bannertimer - .min * 60;
  368.             set .hr, .min / 60;
  369.             set .min, .min - .hr * 60;
  370.             set .roommsg$, .waitmsg$[.state] + .hr + ":" + ((.min < 10 )?"0":"") + .min + ":" + ((.sec < 10 )?"0":"") + .sec;
  371.             sleep .timer_refresh_rate;
  372.            
  373.             if(.remaintime <= 0) {
  374.                 if(.active_woe) {
  375.                     donpcevent strnpcinfo(3)+"::ondowoe";
  376.                     }
  377.                 set .roommsg$, .startmsg$[.state];
  378.                
  379.                 set .woe_index, (.woe_index + .state) % .num_woes;  //go to next index if needed
  380.                 set .state, (.state + 1) % 2;                       //flip state
  381.  
  382.                 donpcevent strnpcinfo(3)+"::onupdatecounttick";
  383.                 sleep .change_state_sleep;
  384.             }
  385.         }
  386.         end;    //obligatory end =d    
  387.  
  388.     onupdatecounttick:
  389.         set .count_tick, getd(".woe_" + .state + "[" + .woe_index + "]");
  390.         set .count_tick, gettimetick(2) + .count_tick - gettimetick(1) + (.woe_day[.woe_index] - gettime(4) + 7) % 7 * .ticks_in_day;
  391.  
  392.         if(gettimetick(2) > .count_tick)
  393.             set .count_tick, .count_tick + 7 * .ticks_in_day;
  394.         end;
  395.    
  396.     onfindcurindex:
  397.    
  398.         set .@cur_day, gettime(4);     
  399.         set .@cur_tick, gettimetick(1);
  400.        
  401.         set .woe_index, 0;
  402.         set .state, 0;
  403.  
  404.         for(set .@i, 0; .@i < .num_woes; set .@i, .@i + 1) {
  405.             if(.woe_day[.@i] < .@cur_day)
  406.                 continue;
  407.        
  408.             if(.woe_day[.@i] == .@cur_day) {
  409.                 if(.woe_0[.@i] >= .@cur_tick) {
  410.                     set .woe_index, .@i;
  411.                     set .state, 0;
  412.                     break;
  413.                 }
  414.                 if(.woe_1[.@i] >= .@cur_tick) {
  415.                     set .woe_index, .@i;
  416.                     set .state, 1;
  417.                     break;
  418.                 }
  419.             }
  420.             if(.woe_day[.@i] > .@cur_day) {
  421.                 set .woe_index, .@i;
  422.                 set .state, 0;
  423.                 break;
  424.             }      
  425.         }
  426.         end;
  427.            
  428.     //on map notifier
  429.     //comment out onpcloadmapevent label if .notify_woe is disabled to prevent unnecessary triggering
  430.     onpcloadmapevent:
  431.         if(.state && .notify_woe) {
  432.             getmapxy(.@map$, .@x, .@y, 0);
  433.             set .@region, getd(".loadmap_region_" + .@map$) - 1;
  434.             if(.@region >= 0) {
  435.                 set .@castleindex, getd(".loadmap_castleindex_" + .@map$);
  436.                 if(getd(".woe_state_" + .woe_state[.woe_index] + "[" + .@region + "]") & 1 << .@castleindex)
  437.                     dispbottom "the [" + getcastlename(.@map$) + "] castle is available for conquering during this woe session";
  438.                 else
  439.                     dispbottom "the [" + getcastlename(.@map$) + "] castle is not available for conquering during this woe session";
  440.             }
  441.         }
  442.         end;
  443.        
  444.     //------------------------------------------------------------------------------
  445.     // woe controller stuff here
  446.     //------------------------------------------------------------------------------
  447.        
  448.     ondowoe:   
  449.         if((.state == 0 && .init) || (.state == 1 && !agitcheck())) {   //starting
  450.             callfunc "woetoggler", 1;  
  451.            
  452.             //kills woe in all castles that shouldn't have woe
  453.             set .@woe_state_array$, ".woe_state_" + .woe_state[.woe_index];
  454.             for(set .@i, 0; .@i < .num_regions; set .@i, .@i + 1) {
  455.                 set .@castles$, ".castles_" + .regions$[.@i] + "$";
  456.                 set .@castle_check, getd(.@woe_state_array$ + "[" + .@i + "]");
  457.                
  458.                 for(set .@k, 0; .@k < .num_castles[.@i]; set .@k, .@k + 1) {
  459.                     set .@map$, getd(.@castles$+"["+.@k+"]");
  460.                     if((.@castle_check & (1 << .@k)) == 0) {
  461.                         donpcevent getd(".woe_kill_" + .regions$[.@i] + "$[" + .@k + "]");
  462.                     }
  463.                 }
  464.             }
  465.  
  466.             announce "The War of Emperium has begun!",bc_all;
  467.             donpcevent strnpcinfo(3)+"::ondisplayowners";
  468.         } else {            //ending
  469.             if(agitcheck()) {
  470.                 callfunc "woetoggler", 0;
  471.                 announce "The War of Emperium is over!",bc_all;
  472.                 donpcevent strnpcinfo(3)+"::ondisplayowners";
  473.             }
  474.         }
  475.         end;
  476.        
  477.     ondisplayowners:    //displays based on current region
  478.         set .@woe_state_array$, ".woe_state_" + .woe_state[.woe_index];
  479.         for(set .@i, 0; .@i < .num_regions; set .@i, .@i + 1) {
  480.             set .@k, 0;
  481.            
  482.             set .@castle_check, getd(.@woe_state_array$ + "[" + .@i + "]");
  483.             set .@castles$, ".castles_" + .regions$[.@i] + "$";
  484.            
  485.             while(.@castle_check && .@k < .num_castles[.@i]) {
  486.                 if(.@castle_check & (1 << .@k)) {
  487.                     set .@map$, getd(.@castles$+"["+.@k+"]");
  488.                     if (getcastledata(.@map$,1)) {
  489.                         announce "the [" + getcastlename(.@map$) + "] castle of the [" + .region_names$[.@i] + "] region is currently held by the [" + getguildname(getcastledata(.@map$,1)) + "] guild.",bc_all;
  490.                     } else {
  491.                         announce "the [" + getcastlename(.@map$) + "] castle of the [" + .region_names$[.@i] + "] region is currently unoccupied.",bc_all;
  492.                     }
  493.                     set .@castle_check, .@castle_check - (1 << .@k);
  494.                 }              
  495.                 set .@k, .@k + 1;      
  496.             }
  497.         }
  498.         end;
  499. }
  500. phtownall,200,176,5 script  WoE Info    2_BULLETIN_BOARD,{
  501.     if(getwaitingroomstate(3, strnpcinfo(3)) == -1)
  502.         donpcevent strnpcinfo(3)+"::oninit";
  503.  
  504.     doevent "woeinfobase::onstartmenu";
  505.     end;
  506.    
  507.     oninit:
  508.         while (1) {
  509.             //only updates if msg is different
  510.             set .banner$, getwaitingroomstate(4, strnpcinfo(3));
  511.             if(getvariableofnpc(.roommsg$, "woeinfobase") != .banner$) {
  512.                 delwaitingroom;
  513.                 waitingroom getvariableofnpc(.roommsg$, "woeinfobase"), 0;
  514.             }
  515.             sleep 500;
  516.         }
  517.         end;
  518. }
  519.  
  520. //zomg! it duplicates!!
  521. //phtownall,204,176,5   duplicate(woe info) woe info#2winfo 2_BULLETIN_BOARD
  522.  
  523. //---------------------------------------------------------------------------------------------------------------------
  524.  
  525. //these two functions handle woe's activation/deactivation. since stable does not have agitstart2/agitend2,
  526. //using the trunk version will result in catastrophic failure of the script. double declaration of the following
  527. //functions fixes this (you will get warning messages though)
  528.  
  529. function    script  woetoggler  { //<state> = 0|1
  530.     if(getarg(0)) {
  531.         agitstart; 
  532.     } else {
  533.         agitend;
  534.     }
  535.     return;
  536. }
  537.  
  538. //if stable script will fail parsing this function, but the rest of the script will still be usable
  539. function    script  woetoggler  { //<state> = 0|1
  540.     if(getarg(0)) {
  541.         agitstart;
  542.         agitstart2;    
  543.     } else {
  544.         agitend;
  545.         agitend2;  
  546.     }
  547.     return;
  548. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement