Advertisement
Sehrentos

rAthena NPC script Enchant

Oct 8th, 2018
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.76 KB | None | 0 0
  1. //===== rAthena Script =======================================
  2. //= Enchant NPC
  3. //===== By: ==================================================
  4. //= Sehrentos
  5. //===== Current Version: =====================================
  6. //= 1.2
  7. //===== Compatible With: =====================================
  8. //= rAthena Project
  9. //===== Description: =========================================
  10. //= Enchant player's equipment. Support multiple enchants.
  11. //===== Additional Comments: =================================
  12. //= 1.0 Initial script.
  13. //= 1.1 Remove enchant option.
  14. //= 1.2 Added .max_enchant option.
  15. //============================================================
  16. // shop/cashshop/itemshop/pointshop
  17. - shop enc_atk -1,501:300;
  18. - shop enc_def -1,501:300;
  19. - shop enc_stats -1,501:300;
  20.  
  21. prt_in,65,68,4 script Enchant#prt1 4_M_MERCAT1,{
  22. disable_items;
  23. switch(select("Attack:Defence:Stats:Remove")) {
  24. case 1: @shop_name$ = "enc_atk"; break;
  25. case 2: @shop_name$ = "enc_def"; break;
  26. case 3: @shop_name$ = "enc_stats"; break;
  27. case 4: callsub S_Remove; break;
  28. default: end;
  29. }
  30. callshop @shop_name$, 1;
  31. npcshopattach @shop_name$;
  32. end;
  33.  
  34. OnInit:
  35. // Settings: shop names, currencies, items, prices
  36. .max_enchant = 2; // Max amount of enchants 0-4
  37. setarray .shop_name$[0], "enc_atk", "enc_def", "enc_stats";
  38. setarray .shop_currency$[0],"Zeny", "Zeny", "Zeny";
  39. setarray .enc_atk_id[0], 4760, 4761, 4806, 4815, 4814, 4813, 4812, 4826, 4827, 4828, 4829, 4830, 4831, 4819, 4766, 4767,4764,4765, 4807, 4842, 4818, 4817, 4816, 4843, 4844, 4811, 4810, 4809, 4808, 4820, 4821, 4822, 4823, 4824, 4825, 4832, 4833, 4834, 4835, 4836, 4837, 4838, 4839, 4840, 4841;
  40. setarray .enc_atk_price[0],10000,20000,30000,10000,20000,30000,40000,50000,60000,70000,80000,90000,100000,10000,20000,30000,5000,7000,10000,20000,10000,20000,30000,40000,50000,10000,20000,30000,40000,50000,60000,70000,80000,90000,100000,10000,20000,30000,40000,50000,60000,70000,80000,90000,100000;
  41. setarray .enc_def_id[0], 4805, 4850, 4851, 4852,4762, 4763,4786,4787,4788,4789, 4790,4791,4792,4793, 4794,4795,4796,4797,4798,4799,4800,4801, 4802;
  42. setarray .enc_def_price[0],10000,20000,40000,60000,5000,12000,2000,4000,6000,8000,10000,3000,5000,9000,12000,1000,2000,3000,4000,5000,2500,5000,10000;
  43. setarray .enc_stats_id[0], 4700,4710,4720,4730,4740,4750, 4701,4711,4721,4731,4741,4751, 4702,4712,4722,4732,4742,4752, 4703,4713,4723,4733,4743,4753, 4704,4714,4724,4734,4744,4754, 4705,4715,4725,4735,4745,4755, 4706,4716,4726,4736,4746,4756, 4707,4717,4727,4737,4747,4757, 4708,4718,4728,4738,4748,4758, 4709, 4719, 4729, 4739, 4749, 4759;
  44. setarray .enc_stats_price[0],1500,1500,1500,1500,1500,1500, 2500,2500,2500,2500,2500,2500, 3500,3500,3500,3500,3500,3500, 4500,4500,4500,4500,4500,4500, 5500,5500,5500,5500,5500,5500, 6500,6500,6500,6500,6500,6500, 7500,7500,7500,7500,7500,7500, 8500,8500,8500,8500,8500,8500, 9500,9500,9500,9500,9500,9500, 10500,10500,10500,10500,10500,10500;
  45.  
  46. // Load shop items
  47. for(.@i = 0; .@i < getarraysize(.shop_name$); .@i++) {
  48. .@npc$ = .shop_name$[.@i];
  49. deletearray .@id[0],getarraysize(.@id);
  50. deletearray .@price[0],getarraysize(.@price);
  51. copyarray .@id[0], getd("."+.@npc$+"_id[0]"), getarraysize(getd("."+.@npc$+"_id"));
  52. copyarray .@price[0], getd("."+.@npc$+"_price[0]"), getarraysize(getd("."+.@npc$+"_price"));
  53. npcshopdelitem .@npc$,501;// Remove apple
  54. for(.@j = 0; .@j < getarraysize(.@id); .@j++) {
  55. npcshopadditem .@npc$, .@id[.@j], .@price[.@j];
  56. }
  57. }
  58. end;
  59.  
  60. OnSellItem:
  61. end;
  62.  
  63. OnBuyItem:
  64. .@bought_count = getarraysize(@bought_nameid);
  65. if(.@bought_count < 1) end;
  66. // Get shop data by @shop_name$
  67. .@shop_index = inarray(.shop_name$[0], @shop_name$);
  68. if(.@shop_index == -1 || getarraysize(.shop_name$) < 1) {
  69. message strcharinfo(0), "Shop was not found!";
  70. debugmes "Incorrect shop array detected in '"+@shop_name$+"'! FIXME!";
  71. end;
  72. }
  73. copyarray .@shop_id[0], getd("."+@shop_name$+"_id"), getarraysize(getd("."+@shop_name$+"_id"));
  74. copyarray .@shop_price[0], getd("."+@shop_name$+"_price"), getarraysize(getd("."+@shop_name$+"_price"));
  75.  
  76. for(.@i = 0; .@i < .@bought_count; .@i++) {
  77. .@index = inarray(.@shop_id[0], @bought_nameid[.@i]);
  78. if(.@index == -1) {
  79. message strcharinfo(0), "Price was not found!";
  80. debugmes "Incorrect price array detected in '"+@shop_name$+"'! FIXME!";
  81. end;
  82. }
  83. setarray .@bought_cost[getarraysize(.@bought_cost)],.@shop_price[.@index]*@bought_quantity[.@i];
  84. for (.@j = 0; .@j < @bought_quantity[.@i]; .@j++) {
  85. setarray .@enchant[getarraysize(.@enchant)],@bought_nameid[.@i];
  86. }
  87. }
  88.  
  89. // Count total cost
  90. for(.@i = 0; .@i < .@bought_count; .@i++) {
  91. .@total_cost = .@total_cost + .@bought_cost[.@i];
  92. }
  93.  
  94. // Currency check
  95. if(.shop_currency$[.@shop_index] == "Zeny" && Zeny < .@total_cost) {
  96. message strcharinfo(0), "("+.@total_cost+") Not enough "+.shop_currency$[.@shop_index]+"!";
  97. end;
  98. }
  99. // Other currency checks...
  100.  
  101. // Select equipment (EQI)
  102. mes "[ " + strnpcinfo(1) + " ]";
  103. mes "Please select which equipment you want me to enchant.";
  104. .@position = callsub(S_SelectPosition);
  105.  
  106. // Check if position has equipment
  107. if(!getequipisequiped(.@position)) {
  108. clear;
  109. mes "[ " + strnpcinfo(1) + " ]";
  110. mes "You don't have anything equipped there!";
  111. close;
  112. }
  113.  
  114. .@item_id = getequipid(.@position); //Equipped item id
  115. .@refine = getequiprefinerycnt(.@position); //Equipped refine value
  116. .@slots = getitemslots(.@item_id);
  117. setarray .@cards[0],
  118. getequipcardid(.@position,0),
  119. getequipcardid(.@position,1),
  120. getequipcardid(.@position,2),
  121. getequipcardid(.@position,3);
  122. .@cards_count = getarraysize(.@cards);
  123. .@enchant_count = getarraysize(.@enchant);
  124.  
  125. /*if(.@enchant_count > .max_enchant) {
  126. clear;
  127. mes "[ " + strnpcinfo(1) + " ]";
  128. mes "This item has been crafted or produced and cannot be enchanted.";
  129. close;
  130. }*/
  131. // Check for enabled refinement
  132. /*if(!getequipisenableref(.@position)) {
  133. clear;
  134. mes "[ " + strnpcinfo(1) + " ]";
  135. mes "I don't think I can enchant this item at all.";
  136. mes "Sorry...";
  137. close;
  138. }*/
  139.  
  140. // Add all card slots
  141. for(.@i = 0; .@i < .@slots; .@i++) {
  142. setarray .@item[getarraysize(.@item)], (.@cards[.@i] > 0 ? .@cards[.@i] : -1);
  143. }
  144. // Add previous enchants
  145. for(.@i = .@slots; .@i < .@cards_count; .@i++) {
  146. if(.@cards[.@i] > 0) {
  147. setarray .@item[getarraysize(.@item)], .@cards[.@i];
  148. }
  149. }
  150. // Add new enchants
  151. for(.@i = 0; .@i < .@enchant_count; .@i++) {
  152. setarray .@item[getarraysize(.@item)], .@enchant[.@i];
  153. }
  154.  
  155. // Check for produced/crafted items 254,255
  156. if(.@cards[0] == CARD0_FORGE || .@cards[0] == CARD0_CREATE) {
  157. clear;
  158. mes "[ " + strnpcinfo(1) + " ]";
  159. mes "This item has been crafted or produced and cannot be enchanted.";
  160. close;
  161. }
  162.  
  163. // Has card sockets 4 - slots
  164. if(.@enchant_count > (.max_enchant - .@slots)) {
  165. clear;
  166. mes "[ " + strnpcinfo(1) + " ]";
  167. mes "This equipment can hold "+(.max_enchant - .@slots)+" enchant.";
  168. close;
  169. }
  170.  
  171. // Has free sockets
  172. if((.@slots + .@enchant_count) > .max_enchant || getarraysize(.@item) > .max_enchant) {
  173. clear;
  174. mes "[ " + strnpcinfo(1) + " ]";
  175. mes "This item does not have enough free sockets to enchant.";
  176. close;
  177. }
  178.  
  179. // Confirm the setup
  180. clear;
  181. mes "[ " + strnpcinfo(1) + " ]^6E6E6E Setup^000000";
  182. for(.@i = 0; .@i < .@enchant_count; .@i++) {
  183. mes "Enchant: "+ getitemname(.@enchant[.@i]);
  184. }
  185. mes "Equipment: "+ getitemname(getequipid(.@position));
  186. mes "Cost: "+.@total_cost+" "+.shop_currency$[.@shop_index]+".";
  187. if (select("Create enchant:Cancel") != 1) {
  188. clear;
  189. mes "[ " + strnpcinfo(1) + " ]";
  190. mes "Farewell.";
  191. close;
  192. }
  193.  
  194. // Create selected enchant
  195. clear;
  196. mes "[ " + strnpcinfo(1) + " ]^6E6E6E Done^000000";
  197. mes "Here is your enchanted equipment!";
  198. delequip(.@position);
  199. specialeffect2 154;
  200.  
  201. if(.shop_currency$[.@shop_index] == "Zeny") {
  202. Zeny = Zeny - .@total_cost;
  203. }
  204.  
  205. getitem2 .@item_id, 1, 1, .@refine, 0,
  206. (.@item[0] > 0 ? .@item[0] : 0),
  207. (.@item[1] > 0 ? .@item[1] : 0),
  208. (.@item[2] > 0 ? .@item[2] : 0),
  209. (.@item[3] > 0 ? .@item[3] : 0);
  210. close;
  211.  
  212. S_Remove:
  213. // Select equipment (EQI)
  214. mes "[ " + strnpcinfo(1) + " ]";
  215. mes "Please select which equipment you want me to work on.";
  216. .@position = callsub(S_SelectPosition);
  217.  
  218. // Check if position has equipment
  219. if(!getequipisequiped(.@position)) {
  220. clear;
  221. mes "[ " + strnpcinfo(1) + " ]";
  222. mes "You don't have anything equipped there!";
  223. close;
  224. }
  225.  
  226. .@item_id = getequipid(.@position); //Equipped item id
  227. .@refine = getequiprefinerycnt(.@position); //Equipped refine value
  228. .@slots = getitemslots(.@item_id);
  229. setarray .@cards[0],
  230. getequipcardid(.@position,0),
  231. getequipcardid(.@position,1),
  232. getequipcardid(.@position,2),
  233. getequipcardid(.@position,3);
  234. .@cards_count = getarraysize(.@cards);
  235. .@enchant_count = getarraysize(.@enchant);
  236.  
  237. // Create selected item
  238. clear;
  239. mes "[ " + strnpcinfo(1) + " ]^6E6E6E Done^000000";
  240. mes "Here is your equipment back!";
  241. delequip(.@position);
  242. specialeffect2 169;
  243.  
  244. getitem2 .@item_id, 1, 1, .@refine, 0,0,0,0,0;
  245. for(.@i=0; .@i<.@slots; .@i++) {
  246. if(.@cards[.@i] > 0)
  247. getitem .@cards[.@i], 1;
  248. }
  249. close;
  250.  
  251. S_SelectPosition:
  252. setarray .@indices[1], EQI_HEAD_TOP, EQI_HEAD_MID, EQI_HEAD_LOW, EQI_ARMOR, EQI_HAND_L, EQI_HAND_R, EQI_GARMENT, EQI_SHOES, EQI_ACC_L, EQI_ACC_R;
  253. setarray .@position$[1], "Top", "Mid", "Low", "Armor", "Left Hand", "Right Hand", "Garment", "Shoes", "Accessory L", "Accessory R";
  254. setarray .@option[1], 1, 1, 1, 1, 1, 1, 1, 1, 1, 1; // 1=allow, 0=deny
  255. for(.@i=1; .@i<getarraysize(.@indices); .@i++) {
  256. if(.@option[.@i] && getequipisequiped(.@indices[.@i])) {
  257. .@menu$ = .@menu$ + .@position$[.@i] + "-[" + getequipname(.@indices[.@i]) + "]";
  258. }
  259. .@menu$ = .@menu$ + ":";
  260. }
  261. .@part = .@indices[select(.@menu$)];
  262. return .@part;
  263. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement