Sentry.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. return;
  38. }
  39. function search_entry {
  40. set .@tmp, getarraysize(getarg(0));
  41. for(set .@i, 0; .@i < .@tmp; set .@i, .@i + 1){
  42. if(getelementofarray(getarg(0),.@i) == getarg(1))
  43. break;
  44. }
  45. if(.@i == .@tmp)
  46. return -1;
  47. else
  48. return .@i;
  49. }
  50. // Script Entry Point - When an event from the script engine is received.
  51. if(getarraysize(.ai_action) == 4){ // Checks if the data is formatted correctly.
  52. set .@tmp, search_entry(.mob_id, .ai_action[AI_ACTION_SRC]);
  53. switch(.ai_action[AI_ACTION_TYPE]){
  54. case AI_ACTION_TYPE_DETECT: // We see something...
  55. if(.ai_busy[.@tmp] == 0){ // Not busy
  56. switch(.ai_action[AI_ACTION_TAR_TYPE]){ // Check what have we here.
  57. case AI_ACTION_TAR_TYPE_PC: // It's a player
  58. if(getd("$pkarma_"+.ai_action[AI_ACTION_TAR]) > .karma){ // pkarma is higher?
  59. unittalk .ai_action[AI_ACTION_SRC], "Who goes there!";
  60. unitemote .ai_action[AI_ACTION_SRC], e_gasp; // !
  61. unitattack .ai_action[AI_ACTION_SRC],.ai_action[AI_ACTION_TAR];
  62. // We're currently busy.
  63. set .ai_busy[.@tmp], .ai_action[AI_ACTION_TAR];
  64. }
  65. break;
  66. case AI_ACTION_TAR_TYPE_MOB: // It's a monster
  67. if(.ai_action[AI_ACTION_TAR] != .ai_action[AI_ACTION_SRC]){
  68. getmobdata .ai_action[AI_ACTION_TAR], .@temp;
  69. if(.@temp[9]&0x804){ // In Aggressive mode?
  70. unittalk .ai_action[AI_ACTION_SRC], "Protect the villagers we must!";
  71. unitemote .ai_action[AI_ACTION_SRC], e_gasp; // !
  72. unitattack .ai_action[AI_ACTION_SRC],.ai_action[AI_ACTION_TAR];
  73. // We're currently busy.
  74. set .ai_busy[.@tmp], .ai_action[AI_ACTION_TAR];
  75. }
  76. }
  77. break;
  78. }
  79. }
  80. break;
  81. case AI_ACTION_TYPE_KILL: // We eliminated the criminal
  82. if(.ai_action[AI_ACTION_TAR_TYPE] == AI_ACTION_TAR_TYPE_PC)
  83. setd "$pkarma_"+.ai_action[AI_ACTION_TAR], 0;
  84. case AI_ACTION_TYPE_UNLOCK: // Target lost :(
  85. if(.@tmp != -1){
  86. set .ai_busy[.@tmp], 0; // Remove him, we're free.
  87. }
  88. // Walk back to where we came from.
  89. unitwalk .ai_action[AI_ACTION_SRC],.mob_x[.@tmp],.mob_y[.@tmp];
  90. break;
  91. case AI_ACTION_TYPE_DEAD: // We got killed :(
  92. if(.ai_action[AI_ACTION_TAR_TYPE] == AI_ACTION_TAR_TYPE_PC){ // Attacker is a player?
  93. setd "$pkarma_"+.ai_action[AI_ACTION_TAR], getd("$pkarma_"+.ai_action[AI_ACTION_TAR]) + 5;
  94. }
  95. sleep 10000; // 10 seconds until reinforcements arrive
  96. spawn_guardian .@tmp;
  97. break;
  98. case AI_ACTION_TYPE_ATTACK: // Someone attacked us
  99. if(.ai_action[AI_ACTION_TAR_TYPE] == AI_ACTION_TAR_TYPE_PC){ // Attacker is a player?
  100. setd "$pkarma_"+.ai_action[AI_ACTION_TAR], getd("$pkarma_"+.ai_action[AI_ACTION_TAR]) + 1;
  101. }
  102. // The system's AI will auto attack any attackers. So we leave it here.
  103. break;
  104. }
  105. }
  106. deletearray .ai_action, getarraysize(.ai_action); // Cleans up and frees up memory
  107. end;
  108. OnInit:
  109. // Customization ---------------------------------------------------------------------
  110. setarray .mob_map$, "prt_fild08.gat", "prt_fild05.gat", "prt_fild06.gat", "prt_gld.gat";
  111. setarray .mob_x,176,369,29,165;
  112. setarray .mob_y,372,201,187,37;
  113. set .karma, 5;
  114. // -----------------------------------------------------------------------------------
  115. set .@tmp, getarraysize(.mob_map$);
  116. for(set .@i, 0; .@i < .@tmp; set .@i, .@i + 1){
  117. spawn_guardian .@i;
  118. }
  119. debugmes "[Sentry System] Spawned " + .@i + " guardians.";
  120. end;
  121. }