yuhsing

Untitled

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