Advertisement
Capuche

hunter_hunted

May 8th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.00 KB | None | 0 0
  1. //===== rAthena Script =======================================
  2. //= Hunting Player
  3. //===== By: ==================================================
  4. //= Capuche
  5. //===== Current Version: =====================================
  6. //= 1.0
  7. //===== Compatible With: =====================================
  8. //= rAthena SVN
  9. //===== Description: =========================================
  10. //= Base on a request from Paulind :
  11. //= http://rathena.org/board/topic/80798-pvp-script-hunters-hunted/
  12. //------------------------------------------------------
  13. //= Players register in the npc. After 10 mins, the npc give
  14. //= a unique and random number 1-128 and a target.
  15. //= The player kill his target => 3 points,
  16. //= otherwise => 1 point.
  17. //= 5 players with 30 points => end of event.
  18. //= @hunter command to display hunter points of player online.
  19. //============================================================
  20.  
  21. prontera,154,150,5 script Hunter Register 87,{
  22. function isinlist; //return the index of the player in the list ; -1 if not
  23. function newtarget; // set a new target in the online character list
  24. function initArrayNumber; // initialize an array size 128 ; each column is incremented +1 starting to 1
  25. function initOnlineArray; // copy data of players register online in some array + warp players
  26. function PlayerGetReward; // give a reward for each player online PO ; disabled fakename
  27. function dispatchAllTarget; // give a target for each PO
  28. function sortPointArray; // sort the online array order by point
  29. function deleteAllVar; // delete all variables unused
  30. function AddPoint; // add/remove hunters points
  31.  
  32. mes .npc_name$;
  33. mes "Wanna register in the hunter event ?";
  34. next;
  35. if ( prompt( ( .start == 2 ? "^777777~ Warp on event map^000000" : "" ), ( .start == 1 ? "^777777~ Register ?^000000" : "" ), "^777777~ About the event^000000", ( getgmlevel() > 59 ? "^FF0000[GM] Start/Stop Event^000000" : "" ) ) == 3 ) {
  36. mes .npc_name$;
  37. mes "Every 4 hours.. Wait 10 mins... battle...";
  38. close;
  39. }
  40. else if ( @menu == 4 ) { // gm menu
  41. if ( .start )
  42. select ( "Stop the event ?" );
  43. else
  44. select ( "Start the event ?" );
  45. if ( .start )
  46. awake strnpcinfo(0);
  47. else
  48. goto OnHour20;
  49. end;
  50. }
  51. else if ( .size_array_init > 127 && @menu == 2 ) {
  52. mes .npc_name$;
  53. mes "The event queue is full";
  54. close;
  55. }
  56. else if ( isinlist( ".list_init_cid", ".size_array_init" ) != -1 ) {
  57. if ( @menu == 1 ) {
  58. warp .event_map$,0,0;
  59. end;
  60. }
  61. mes .npc_name$;
  62. mes "You're already on my list";
  63. close;
  64. }
  65. else if ( @menu == 1 ) end;
  66. else if ( @menu == 2 ) {
  67. .list_init_cid[ .size_array_init ] = getcharid(0);
  68. .list_init_aid[ .size_array_init ] = getcharid(3);
  69.  
  70. .@i = rand( .size_num );
  71. .dispatch_num_init[ .size_array_init ] = .num[.@i];
  72.  
  73. deletearray .num[.@i], 1;
  74. .size_array_init++;
  75. .size_num--;
  76.  
  77. message strcharinfo(0),"You're now on the list.";
  78. }
  79. end;
  80.  
  81. OnHour00:
  82. OnHour04:
  83. OnHour08:
  84. OnHour12:
  85. OnHour16:
  86. OnHour20:
  87. initArrayNumber(); // initialize array to dispatch number to player
  88. .start = 1;
  89. initnpctimer;
  90. announce "[ Hunter Event ] : The event will start in 10 min !",0;
  91. end;
  92.  
  93. OnTimer600000: // 10 mins
  94. announce "[ Hunter Event ] : Event start.",0;
  95. .start = 2;
  96. stopnpctimer;
  97. initOnlineArray();
  98. bindatcmd "hunter",strnpcinfo(3)+"::OnAtcommand";
  99.  
  100. if ( .size_online >= .min_player ) {
  101. for ( .@i = 0; .@i < .size_mapflag; .@i++ )
  102. setmapflag .event_map$, .mapflag[.@i];
  103. dispatchAllTarget();
  104. sleep 900000; // 15 mins
  105. }
  106. sortPointArray();
  107. PlayerGetReward();
  108. deleteAllVar();
  109. unbindatcmd "hunter";
  110.  
  111. announce "[ Hunter Event ] : End of event.",0;
  112. mapwarp .event_map$,"prontera",150,150;
  113. for ( .@i = 0; .@i < .size_mapflag; .@i++ )
  114. removemapflag .event_map$, .mapflag[.@i];
  115. end;
  116.  
  117. OnPCLoginEvent:
  118. if ( !.start ) end;
  119. .@index = isinlist( ".list_init_cid", ".size_array_init" );
  120. if( .@index == -1 && strcharinfo(3) == .event_map$ ) {
  121. warp "prontera",0,0;
  122. end;
  123. }
  124. else if( .@index == -1 ) end;
  125. atcommand "@fakename [ "+ .dispatch_num_init[ .@index ] +" ] "+ strcharinfo(0) ;
  126. .list_cid_online[ .size_online ] = getcharid(0);
  127. .list_aid_online[ .size_online ] = getcharid(3);
  128. .dispatch_num_online[ .size_online ] = .dispatch_num_init[ .@index ];
  129. .size_online++;
  130. newtarget();
  131. end;
  132.  
  133. OnPCLogoutEvent:
  134. if ( !.start ) end;
  135. .@index = isinlist( ".list_cid_online", ".size_online" );
  136. if( .@index == -1 ) end;
  137. if ( .malus_logout )
  138. AddPoint( getcharid(0), -1, 0, -1, .malus_logout ); // if getarg(1) == -1 or getarg(2) == -1 => add getarg(4) * getarg(3) points
  139. .@num_ = .dispatch_num_online[ .@index ];
  140. deletearray .list_cid_online[ .@index ], 1;
  141. deletearray .list_aid_online[ .@index ], 1;
  142. deletearray .dispatch_num_online[ .@index ], 1;
  143. deletearray .target_online[ .@index ], 1;
  144. .size_online--;
  145. if( .size_online < 2 )
  146. awake strnpcinfo(0);
  147. for ( .@i = 0; .@i < .size_online; .@i++ )
  148. if ( .target_online[.@i] == .@num_ ) newtarget( .@i );
  149. end;
  150.  
  151. OnPCKillEvent:
  152. if ( !.start ) end;
  153. .@index = isinlist( ".list_cid_online", ".size_online" );
  154. if( .@index == -1 ) end;
  155. .@char_id = getcharid(0);
  156. attachrid( killedrid );
  157. .@index2 = isinlist( ".list_cid_online", ".size_online" );
  158. if( .@index2 == -1 ) end;
  159. AddPoint( getcharid(0), .@index, .@index2, -1 ); // <target>, <index online killer IO>, <IO Killed>, <rate points>
  160. .@main = AddPoint( .@char_id, .@index, .@index2, 1 );
  161. if ( .@main == .point_main )
  162. newtarget( .@index );
  163. sortPointArray();
  164. for ( .@i = 0; .@i < .size_online; .@i++ )
  165. if ( .count_point_online[.@i] >= 30 ) {
  166. .@num_winner++;
  167. if ( .@num_winner == 5 ) {
  168. awake strnpcinfo(0);
  169. end;
  170. }
  171. }
  172. doevent strnpcinfo(0) +"::OnRezu";
  173. end;
  174.  
  175. OnRezu:
  176. sleep2 3000;
  177. warp .event_map$,0,0;
  178. percentheal 100,100;
  179. end;
  180.  
  181. function AddPoint {
  182. .@i = isinlist( ".list_init_cid", ".size_array_init", getarg(0) );
  183. if ( getarg(1) == -1 || getarg(2) == -1 )
  184. .@points = getarg( 4,0 ) * getarg(3);
  185. else if( .target_online[ getarg(1) ] == .dispatch_num_online[ getarg(2) ] )
  186. .@points = .point_main * getarg(3);
  187. else
  188. .@points = .point_others * getarg(3);
  189. .count_point[.@i] = .count_point[.@i] + .@points;
  190. message rid2name( .list_init_aid[.@i] ), "You have "+ .@points +" Hunters points. Total : "+ .count_point[.@i] +" Hunters points";
  191. return .@points;
  192. }
  193.  
  194. function deleteAllVar {
  195. .size_array_init = .start = .size_num = .size_online = 0;
  196. deletearray .list_cid_online;
  197. deletearray .list_aid_online;
  198. deletearray .dispatch_num_online;
  199. deletearray .num;
  200. deletearray .list_init_cid;
  201. deletearray .dispatch_num_init;
  202. deletearray .count_point;
  203. deletearray .count_point_online;
  204. deletearray .target_online;
  205. return;
  206. }
  207.  
  208. function dispatchAllTarget {
  209. for( .@i = 0; .@i < .size_online; .@i++ ) {
  210. newtarget( .@i );
  211. charcommand "#fakename "+ rid2name( .list_aid_online[.@i] ) +" [ "+ .dispatch_num_online[.@i] +" ] "+ rid2name( .list_aid_online[.@i] ) ;
  212. }
  213. return;
  214. }
  215.  
  216. function isinlist {
  217. if ( getarg( 2,0 ) )
  218. .@char_id = getarg( 2,0 );
  219. else
  220. .@char_id = getcharid(0);
  221. while( .@i < getd( getarg(1) ) && getd( getarg(0) +"[" + .@i + "]" ) != .@char_id ) .@i++;
  222. if( .@i == getd( getarg(1) ) ) return -1;
  223. return .@i;
  224. }
  225.  
  226. function initArrayNumber {
  227. for( .@i = 0; .@i < 128; .@i++ )
  228. .num[.@i] = .@i +1;
  229. .size_num = 128;
  230. return;
  231. }
  232.  
  233. function initOnlineArray {
  234. for ( .@i = 0; .@i < .size_array_init; .@i++ )
  235. if( isloggedin( .list_init_aid[.@i], .list_init_cid[.@i] ) ) {
  236. .list_cid_online[ .size_online ] = .list_init_cid[.@i];
  237. .list_aid_online[ .size_online ] = .list_init_aid[.@i];
  238. .dispatch_num_online[ .size_online ] = .dispatch_num_init[.@i];
  239. warpchar .event_map$,0,0,.list_cid_online[ .size_online ];
  240. .size_online++;
  241. }
  242. return;
  243. }
  244.  
  245. function newtarget {
  246. if( getarg( 0,-1 ) == -1 )
  247. .@index = isinlist( ".list_cid_online", ".size_online" );
  248. else
  249. .@index = getarg( 0,-1 ) ;
  250.  
  251. do
  252. .@r = rand( .size_online );
  253. while( .@r == .@index );
  254. .target_online[ .@index ] = .dispatch_num_online[.@r];
  255. message rid2name( .list_aid_online[ .@index ] ), .list_cid_online[ .@index ] +" Your main target is now number [ "+ .target_online[ .@index ] +" ]";
  256. return;
  257. }
  258.  
  259. function PlayerGetReward {
  260. for ( .@i = 0; .@i < .size_online; .@i++ ) {
  261. charcommand "#fakename "+ rid2name( .list_aid_online[.@i] ) ;
  262. for ( .@j = 0; .@j < .size_reward; .@j += 3 ) {
  263. if( .count_point_online[.@i] >= .reward[.@j] ) {
  264. getitem .reward[.@j+1], .reward[.@j+2], .list_aid_online[.@i];
  265. break;
  266. }
  267. }
  268. }
  269. return;
  270. }
  271.  
  272. function sortPointArray {
  273. deletearray .count_point_online;
  274. for ( .@i = 0; .@i < .size_online; .@i += 1 ) {
  275. .@index = isinlist( ".list_init_cid", ".size_array_init", .list_cid_online[.@i] );
  276. .count_point_online[.@i] = .count_point[ .@index ];
  277. }
  278. .@k_size = .size_online;
  279. while ( .@k_size ) {
  280. .@test = .count_point_online;
  281. .@index = 0;
  282. for ( .@i = 1; .@i < .@k_size; .@i += 1 )
  283. if ( .@test < .count_point_online[.@i] ) {
  284. .@test = .count_point_online[.@i];
  285. .@index = .@i;
  286. }
  287.  
  288. .@save_point[.@k] = .count_point_online[ .@index ];
  289. .@save_aid[.@k] = .list_aid_online[ .@index ];
  290. .@save_cid[.@k] = .list_cid_online[ .@index ];
  291. .@save_dispatch_num[.@k] = .dispatch_num_online[ .@index ];
  292. .@save_target[.@k] = .target_online[ .@index ];
  293. deletearray .count_point_online[ .@index ], 1;
  294. deletearray .list_aid_online[ .@index ], 1;
  295. deletearray .list_cid_online[ .@index ], 1;
  296. deletearray .dispatch_num_online[ .@index ], 1;
  297. deletearray .target_online[ .@index ], 1;
  298. .@k_size = .@k_size -1;
  299. .@k += 1;
  300. }
  301. copyarray .count_point_online, .@save_point, .size_online;
  302. copyarray .list_aid_online, .@save_aid, .size_online;
  303. copyarray .list_cid_online, .@save_cid, .size_online;
  304. copyarray .dispatch_num_online, .@save_dispatch_num, .size_online;
  305. copyarray .target_online, .@save_target, .size_online;
  306. return;
  307. }
  308.  
  309. OnInit:
  310. .npc_name$ = "^ff0000- [ Hunter NPC ] -^000000";
  311. .malus_logout = 3; // num malus points if log out ? (0: disabled)
  312. .point_main = 3; // points when killing main target / - points for main killed
  313. .point_others = 1; // points when killing others targets
  314. .event_map$ = "geffen"; // event map
  315. .min_player = 10; // number min players to start
  316. setarray .reward, 30, 501, 1, // Typo : <points min>, <item ID>, <amount items>
  317. 29, 502, 1,
  318. 19, 503, 1,
  319. 9, 504, 1,
  320. 1, 505, 1;
  321.  
  322. // Don't touch
  323. // -----------
  324. .size_reward = getarraysize( .reward );
  325. setarray .mapflag, mf_noreturn, mf_nowarp, mf_noteleport, mf_nowarpto, mf_pvp;
  326. .size_mapflag = getarraysize( .mapflag );
  327. for( ; .@i < .size_mapflag; .@i++ )
  328. removemapflag .event_map$, .mapflag[.@i];
  329. end;
  330. OnAtcommand:
  331. if ( !.start ) end;
  332. .@index = isinlist( ".list_cid_online", ".size_online" );
  333. if( .@index == -1 ) end;
  334. sortPointArray();
  335. .@size = .size_online > 30 ? 30 : .size_online ;
  336. dispbottom "Top 30 Hunters Online - { Name : Hunters Points }";
  337. for ( .@i = 0; .@i < .@size; .@i += 1 )
  338. dispbottom rid2name( .list_aid_online[.@i] ) +" : "+ .count_point_online[.@i];
  339. end;
  340. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement