Sentry.cpp 5.0 KB

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