Sentry.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //(=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=)
  2. //( (c)2006 eAthena Development Team presents )
  3. //( ______ __ __ )
  4. //( /\ _ \/\ \__/\ \ v 1.00.00 )
  5. //( __\ \ \_\ \ \ ,_\ \ \___ __ ___ __ )
  6. //( /'__`\ \ __ \ \ \/\ \ _ `\ /'__`\/' _ `\ /'__`\ )
  7. //( /\ __/\ \ \/\ \ \ \_\ \ \ \ \/\ __//\ \/\ \/\ \_\.\_ )
  8. //( \ \____\\ \_\ \_\ \__\\ \_\ \_\ \____\ \_\ \_\ \__/.\_\ )
  9. //( \/____/ \/_/\/_/\/__/ \/_/\/_/\/____/\/_/\/_/\/__/\/_/ )
  10. //( _ _ _ _ _ _ _ _ _ _ _ _ _ )
  11. //( / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ )
  12. //( ( e | A | t | h | e | n | a ) ( S | c | r | i | p | t ) )
  13. //( \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ )
  14. //( )
  15. //(=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=)
  16. // Programmed by [Lance] ver. 1.1
  17. // ---------------------------------------------------------
  18. // [ Sentry System ]
  19. // - Guards main towns against aggresive monsters and bad
  20. // players.
  21. // [ Customization ]
  22. // - See OnInit:
  23. // =========================================================
  24. - script sentry_system -1,{
  25. function spawn_guardian {
  26. set .mob_id[getarg(0)], mobspawn("Guardian Sentry",1904,.mob_map$[getarg(0)],.mob_x[getarg(0)],.mob_y[getarg(0)]);
  27. mobattach .mob_id[getarg(0)]; // Attach events to this script.
  28. setmobdata .mob_id[getarg(0)], 24, 1; // Enable killer mode.
  29. setmobdata .mob_id[getarg(0)], 25,
  30. AI_ACTION_TYPE_DETECT|
  31. AI_ACTION_TYPE_KILL|
  32. AI_ACTION_TYPE_UNLOCK|
  33. AI_ACTION_TYPE_DEAD|
  34. AI_ACTION_TYPE_ATTACK; // Define engine callback routines.
  35. setmobdata .mob_id[getarg(0)], 26, 1; // Prevents random walking.
  36. setmobdata .mob_id[getarg(0)], 10, 1; // Enable AI mode 1.
  37. getmobdata .mob_id[getarg(0)], .@temp;
  38. set .@temp[9], .@temp[9]^(0x400&.@temp[9]); // Check and remove MD_CHANGECHASE mode flag.
  39. setmobdata .mob_id[getarg(0)], 9, .@temp[9];
  40. return;
  41. }
  42. function search_entry {
  43. set .@tmp, getarraysize(getarg(0));
  44. for(set .@i, 0; .@i < .@tmp; set .@i, .@i + 1){
  45. if(getelementofarray(getarg(0),.@i) == getarg(1))
  46. break;
  47. }
  48. if(.@i == .@tmp)
  49. return -1;
  50. else
  51. return .@i;
  52. }
  53. // Script Entry Point - When an event from the script engine is received.
  54. if(getarraysize(.ai_action) == 4){ // Checks if the data is formatted correctly.
  55. set .@tmp, search_entry(.mob_id, .ai_action[AI_ACTION_SRC]);
  56. switch(.ai_action[AI_ACTION_TYPE]){
  57. case AI_ACTION_TYPE_DETECT: // We see something...
  58. if(.ai_busy[.@tmp] == 0){ // Not busy
  59. switch(.ai_action[AI_ACTION_TAR_TYPE]){ // Check what have we here.
  60. case AI_ACTION_TAR_TYPE_PC: // It's a player
  61. if(Karma > .karma){ // pkarma is higher?
  62. unittalk .ai_action[AI_ACTION_SRC], "Who goes there!";
  63. unitemote .ai_action[AI_ACTION_SRC], e_gasp; // !
  64. unitattack .ai_action[AI_ACTION_SRC],.ai_action[AI_ACTION_TAR];
  65. // We're currently busy.
  66. set .ai_busy[.@tmp], .ai_action[AI_ACTION_TAR];
  67. }
  68. break;
  69. case AI_ACTION_TAR_TYPE_MOB: // It's a monster
  70. if(.ai_action[AI_ACTION_TAR] != .ai_action[AI_ACTION_SRC]){
  71. getmobdata .ai_action[AI_ACTION_TAR], .@temp;
  72. if(.@temp[9]&0x804){ // In Aggressive mode?
  73. unittalk .ai_action[AI_ACTION_SRC], "Protect the villagers we must!";
  74. unitemote .ai_action[AI_ACTION_SRC], e_gasp; // !
  75. unitattack .ai_action[AI_ACTION_SRC],.ai_action[AI_ACTION_TAR];
  76. // We're currently busy.
  77. set .ai_busy[.@tmp], .ai_action[AI_ACTION_TAR];
  78. }
  79. }
  80. break;
  81. }
  82. }
  83. break;
  84. case AI_ACTION_TYPE_KILL: // We eliminated the criminal
  85. if(.ai_action[AI_ACTION_TAR_TYPE] == AI_ACTION_TAR_TYPE_PC)
  86. set Karma, 0;
  87. case AI_ACTION_TYPE_UNLOCK: // Target lost :(
  88. if(.@tmp != -1){
  89. set .ai_busy[.@tmp], 0; // Remove him, we're free.
  90. }
  91. // Walk back to where we came from.
  92. unitwalk .ai_action[AI_ACTION_SRC],.mob_x[.@tmp],.mob_y[.@tmp];
  93. break;
  94. case AI_ACTION_TYPE_DEAD: // We got killed :(
  95. if(.ai_action[AI_ACTION_TAR_TYPE] == AI_ACTION_TAR_TYPE_PC){ // Attacker is a player?
  96. if(Karma < 250)
  97. set Karma, Karma + 5;
  98. else
  99. set Karma, 255;
  100. }
  101. sleep 10000; // 10 seconds until reinforcements arrive
  102. spawn_guardian .@tmp;
  103. break;
  104. case AI_ACTION_TYPE_ATTACK: // Someone attacked us
  105. if(.ai_action[AI_ACTION_TAR_TYPE] == AI_ACTION_TAR_TYPE_PC){ // Attacker is a player?
  106. if(Karma < 250)
  107. set Karma, Karma + 1;
  108. else
  109. set Karma, 255;
  110. }
  111. // The system's AI will auto attack any attackers. So we leave it here.
  112. break;
  113. }
  114. }
  115. deletearray .ai_action, getarraysize(.ai_action); // Cleans up and frees up memory
  116. end;
  117. OnInit:
  118. // Customization ---------------------------------------------------------------------
  119. setarray .mob_map$, "prt_fild08", "prt_fild05", "prt_fild06", "prt_gld";
  120. setarray .mob_x,176,369,29,165;
  121. setarray .mob_y,372,201,187,37;
  122. set .karma, 5;
  123. // -----------------------------------------------------------------------------------
  124. set .@tmp, getarraysize(.mob_map$);
  125. for(set .@i, 0; .@i < .@tmp; set .@i, .@i + 1){
  126. spawn_guardian .@i;
  127. }
  128. debugmes "[Sentry System] Spawned " + .@i + " guardians.";
  129. end;
  130. }