Advertisement
Sehrentos

rAthena npc script unit control monster

Apr 21st, 2015
958
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.32 KB | None | 0 0
  1. //===== rAthena Script =======================================
  2. //= Guard - Unit Controller
  3. //===== By: ==================================================
  4. //= Sehrentos
  5. //===== Current Version: =====================================
  6. //= 1.0
  7. //===== Compatible With: =====================================
  8. //= rAthena Project
  9. //===== Description: =========================================
  10. //= Summon a Guard that last for X time and help player.
  11. //===== Additional Comments: =================================
  12. //= 1.0 Initial script.
  13. //= Custom mob add '/db/import/mob_db.txt':
  14. // 4000,SNIPER,Sniper,Sniper,175,100000,0,0,0,9,900,900,40,40,119,119,119,119,199,119,10,12,1,7,20,669,150,900,500,300,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  15. //= Custom mob add '/db/import/mob_skill_db.txt':
  16. // 4000,Sniper@NPC_ALLHEAL,idle,687,1,3000,10000,30000,yes,self,myhpltmaxrate,50,,,,,,,
  17. // 4000,Sniper@NPC_ALLHEAL,walk,687,1,3000,10000,30000,yes,self,myhpltmaxrate,50,,,,,,,
  18. // 4000,Sniper@AC_CONCENTRATION,attack,45,10,2500,0,5000,yes,target,always,0,,,,,,,
  19. // 4000,Sniper@HT_FREEZINGTRAP,attack,121,5,2500,0,5000,yes,target,always,0,,,,,,,
  20. // 4000,Sniper@AC_CHARGEARROW,attack,148,1,2500,0,5000,yes,target,always,0,,,,,,,
  21. // 4000,Sniper@AC_DOUBLE,attack,46,10,2500,0,5000,yes,target,always,0,,,,,,,
  22. // 4000,Sniper@HT_BLITZBEAT,attack,129,5,2500,0,5000,yes,target,always,0,,,,,,,
  23. // 4000,Sniper@SN_FALCONASSAULT,attack,381,5,2500,0,5000,yes,target,always,0,,,,,,,
  24. // 4000,Sniper@SN_FALCONASSAULT,chase,381,5,2500,0,5000,yes,target,always,0,,,,,,,
  25. // 4000,Sniper@HT_BLASTMINE,attack,122,5,2500,0,5000,yes,target,always,0,,,,,,,
  26. // 4000,Sniper@AC_CHARGEARROW,attack,148,1,2500,0,5000,yes,target,always,0,,,,,,,
  27. //= Custom mob add '/db/import/mob_avail.txt':
  28. // 4000,4012,1,7,3,1702,0,72,73,0,16,0 // SNIPER
  29. //============================================================
  30.  
  31. prontera,155,164,4 script Guard#prt_01 95,3,3,{
  32. // NPC area of effect set to 3 x 3 cell range
  33. mes "[ " + strnpcinfo(1) + " ]";
  34. if ( unitexists(@GID_Guardian) ) {
  35. getunitdata(@GID_Guardian, .@udata);
  36. for (.@i = 0; .@i < getarraysize(.@udata); .@i++ ) {
  37. mes .UMOB_INDEX$[.@i] + " = " + .@udata[.@i];
  38. }
  39. .@npc_time_tick = getnpctimer(0); // 0
  40. .@npc_time_ticks = getnpctimer(1); // 1-6
  41. .@npc_time_count = getnpctimer(2); // 6
  42. .@menu_gm$ = ":";
  43. if ( getgmlevel() >= 50 )
  44. .@menu_gm$ = "Edit my Guard:";
  45. mes "Timer: " + .@npc_time_tick + " / " + .@npc_time_ticks + " / " + .@npc_time_count;
  46. mes "Active hours: ^777777" + (.@npc_time_tick / 3600000) + "^000000"; // Hours
  47. mes "Active minutes: ^777777" + " : " + (.@npc_time_tick / 60000) + "^000000"; // Minutes
  48. mes "Active seconds: ^777777" + " : " + (.@npc_time_tick / 1000) + "^000000"; // Seconds
  49. // Has active guard
  50. switch ( select( .@menu_gm$ + "Remove my Guard:Leave") ) {
  51. case 1: callsub S_EditGuard; break;
  52. case 2: callsub S_RemoveGuard; break;
  53. default: break;
  54. }
  55. } else {
  56. // Do NOT have a guard
  57. mes "I will protect the city from any hostile creatures!";
  58. if ( select("I need guard:Leave") == 1 ) {
  59. callsub S_RentGuard;
  60. }
  61. }
  62. mes "Good bye!";
  63. close;
  64.  
  65. S_RemoveGuard:
  66. if ( unitexists(@GID_Guardian) ) {
  67. unitkill @GID_Guardian;
  68. }
  69. return;
  70.  
  71. S_EditGuard:
  72. if ( unitexists(@GID_Guardian) && getgmlevel() >= 50 ) {
  73. next;
  74. mes "[ " + strnpcinfo(1) + " ]";
  75. mes "Edit guard attributes.";
  76. .@select = select(.UMOB_MENU$) - 1;
  77. mes "Write new ( " + .UMOB_INDEX$[.@select] + " ) value.";
  78. input .@val, 0, 1000000000;
  79. setunitdata @GID_Guardian, .@select, .@val;
  80. getunitdata(@GID_Guardian, .@udata);
  81. mes "New unit data is:" + .@udata[.@select];
  82. }
  83. return;
  84.  
  85. S_RentGuard:
  86. // If unit exists
  87. if ( !unitexists(@GID_Guardian) ) {
  88. // Get player location
  89. getmapxy(.@map$, .@x, .@y, 0);
  90.  
  91. // Summon monster
  92. monster "prontera", rand(.@x, .@x-3), rand(.@y-3, .@y), .MOB_NAME$, .MOB_ID, 1, strnpcinfo(1) + "::OnUnitDeath";
  93. // Get last summon GID
  94. @GID_Guardian = $@mobid[0];
  95.  
  96. // Change unit data
  97. setunitdata @GID_Guardian, UMOB_MAXHP, 100000; // Max HP
  98. setunitdata @GID_Guardian, UMOB_MASTERAID, getcharid(3); // Master AID
  99. setunitdata @GID_Guardian, UMOB_SPEED, 100; // Speed
  100. setunitdata @GID_Guardian, UMOB_CRIT, 450; // Crit rate (1000=100%)
  101. setunitdata @GID_Guardian, UMOB_HIT, 250; // Hit rate (1000=100%)
  102.  
  103. setunitname @GID_Guardian, getmonsterinfo(.MOB_ID, 0) + " (" + strcharinfo(0) + ")"; // Name
  104.  
  105. unittalk @GID_Guardian, "Hey boss!", bc_area; // Talk
  106.  
  107. // Setup timer
  108. //dispbottom "Your contract will last for 15 minutes.";
  109. message strcharinfo(0), "Your \"Guard\" contract will last for 15 minutes.";
  110.  
  111. // Add timer to trigger after 10 minutes
  112. addtimer 600000, strnpcinfo(3) + "::On10mins";
  113. }
  114. return;
  115.  
  116. OnInit:
  117. .NPC_NAME$ = strnpcinfo(0);
  118. .MOB_ID = 4000; // Eclipse=1093
  119. .MOB_NAME$ = "--ja--"; // getmonsterinfo(.MOB_ID, 0);
  120. setarray .UMOB_INDEX$[0],
  121. "Size","Level","Hp","Max Hp",
  122. "Master AID","Map ID","Map X","Map Y",
  123. "Speed","Mode","Ai","Scoption",
  124. "Sex","Class","Hair style","Hair color",
  125. "Head bottom","Head middle","Head top","Cloth color",
  126. "Shield","Weapon","Look dir","Can move tick",
  127. "Str","Agi","Vit","Int",
  128. "Dex","Luk","Slave cpymstrmd","Dmg immune",
  129. "Atk range","Atk min","Atk max","Matk min",
  130. "Matk max","Def","Mdef","Hit",
  131. "Flee","Pdodge","Crit","Race",
  132. "Ele type","Ele level","A-motion","A-delay",
  133. "D-motion";
  134. .UMOB_MENU$ = implode(.UMOB_INDEX$, ":");
  135. end;
  136.  
  137. OnUnitDeath:
  138. debugmes .NPC_NAME$ + " Unit Death event";
  139. if ( !getattachedrid() ) {
  140. //stopnpctimer;
  141. end;
  142. }
  143. //stopnpctimer;
  144. @GID_Guardian = 0;
  145. end;
  146.  
  147. OnPCDieEvent:
  148. debugmes .NPC_NAME$ + " PC Die event";
  149. if ( !getattachedrid() )
  150. end;
  151. if ( unitexists(@GID_Guardian) )
  152. @GID_Guardian = 0;
  153. end;
  154.  
  155. // TIMERS
  156. On10mins:
  157. // After 10 minutes
  158. debugmes .NPC_NAME$ + " timer 10 min";
  159. if ( !getattachedrid() )
  160. end;
  161. if ( unitexists(@GID_Guardian) ) {
  162. message strcharinfo(0), "Your \"Guard\" contract will expire in 5 minute.";
  163. // Add next timer to trigger after 1 minute
  164. addtimer 60000, strnpcinfo(3) + "::On11mins";
  165. }
  166. end;
  167.  
  168. On11mins:
  169. // After 11 minutes
  170. debugmes .NPC_NAME$ + " timer 11 min";
  171. if ( !getattachedrid() )
  172. end;
  173. if ( unitexists(@GID_Guardian) ) {
  174. message strcharinfo(0), "Your \"Guard\" contract will expire in 4 minute.";
  175. addtimer 60000, strnpcinfo(3) + "::On12mins";
  176. }
  177. end;
  178.  
  179. On12mins:
  180. // After 12 minutes
  181. debugmes .NPC_NAME$ + " timer 12 min";
  182. if ( !getattachedrid() )
  183. end;
  184. if ( unitexists(@GID_Guardian) ) {
  185. message strcharinfo(0), "Your \"Guard\" contract will expire in 3 minute.";
  186. addtimer 60000, strnpcinfo(3) + "::On13mins";
  187. }
  188. end;
  189.  
  190. On13mins:
  191. // After 13 minutes
  192. debugmes .NPC_NAME$ + " timer 13 min";
  193. if ( !getattachedrid() )
  194. end;
  195. if ( unitexists(@GID_Guardian) ) {
  196. message strcharinfo(0), "Your \"Guard\" contract will expire in 2 minute.";
  197. addtimer 60000, strnpcinfo(3) + "::On14mins";
  198. }
  199. end;
  200.  
  201. On14mins:
  202. // After 14 minutes
  203. debugmes .NPC_NAME$ + " timer 14 min";
  204. if ( !getattachedrid() )
  205. end;
  206. if ( unitexists(@GID_Guardian) ) {
  207. message strcharinfo(0), "Your \"Guard\" contract will expire in 1 minute.";
  208. addtimer 60000, strnpcinfo(3) + "::On15mins";
  209. }
  210. end;
  211.  
  212. On15mins:
  213. // After 15 minutes (STOP)
  214. debugmes .NPC_NAME$ + " timer 15 min";
  215. if ( !getattachedrid() )
  216. end;
  217. if ( unitexists(@GID_Guardian) ) {
  218. message strcharinfo(0), "Your \"Guard\" contract expired!";
  219. unitkill @GID_Guardian;
  220. @GID_Guardian = 0;
  221. }
  222. end;
  223.  
  224. OnTouch:
  225. // Players attached
  226. end;
  227.  
  228. OnTouchNPC:
  229. // Monsters attached
  230. .@UNIT_GID = getattachedrid();
  231. //.@UNIT_NAME$ = rid2name(.@UNIT_GID);
  232. //debugmes "Target unit name:" + .@UNIT_NAME$;
  233.  
  234. // Get unit data
  235. getunitdata(.@UNIT_GID, .@data);
  236. .@MASTER_AID = .@data[4];
  237.  
  238. // Unit has a master
  239. if ( .@MASTER_AID ) {
  240. .@MASTER_NAME$ = rid2name(.@MASTER_AID); // "MonsterName", "PlayerName"
  241. .@online = isloggedin(.@MASTER_AID); // Monster=0, Player=1
  242. // Do not target player's units
  243. if ( .@online ) {
  244. //debugmes "Unit name:" + .@UNIT_NAME$;
  245. //debugmes "Master name:" + .@MASTER_NAME$;
  246. end;
  247. }
  248. }
  249.  
  250. // NPC emotion
  251. emotion 0;
  252.  
  253. // Kill monster/unit
  254. //unitkill .@UNIT_GID;
  255.  
  256. // Warp monster/unit away from the NPC
  257. unitwarp 0, "this", -1, -1;
  258. end;
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement