Advertisement
Sehrentos

rAthena NPC script refiner

Oct 10th, 2018
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.21 KB | None | 0 0
  1. //===== rAthena Script =======================================
  2. //= Refine
  3. //===== By: ==================================================
  4. //= Sehrentos
  5. //===== Current Version: =====================================
  6. //= 1.0
  7. //===== Compatible With: =====================================
  8. //= rAthena Project
  9. //===== Description: =========================================
  10. //= Refine NPC with account wide material storage.
  11. //===== Additional Comments: =================================
  12. //= 1.0 Initial script.
  13. //============================================================
  14. prontera,155,174,5 script Refine#prt1::zRef -1,{
  15. disable_items;
  16. mes "[" + strnpcinfo(1) + "]";
  17. mes "I am the Armsmith";
  18. mes "I can refine all kinds of weapons,";
  19. mes "armor and equipment, so let me";
  20. mes "know what you want to refine.";
  21.  
  22. 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;
  23. setarray .@position$[1], "Top", "Mid", "Low", "Armor", "Hand L", "Hand R", "Garment", "Shoes", "Accessory L", "Accessory R";
  24. setarray .@option[1], 1, 1, 1, 1, 1, 1, 1, 1, 1, 1; // 1=allow, 0=deny
  25.  
  26. for(.@i=1; .@i<getarraysize(.@indices); .@i++) {
  27. if(.@option[.@i] && getequipisequiped(.@indices[.@i])) {
  28. .@ref = getequiprefinerycnt(.@indices[.@i]);
  29. .@menu$ = .@menu$+"^3a4750"+.@position$[.@i]+"-[^000000"+(.@ref>0?"+"+.@ref+" ":"")+""+getequipname(.@indices[.@i])+"^3a4750]";
  30. }
  31. .@menu$ = .@menu$ + ":";
  32. }
  33. // Options menu
  34. .@menu$ = .@menu$ + "Store Materials";
  35. .@index = select(.@menu$);
  36. if(.@index >= getarraysize(.@indices)) goto L_MaterialStorage;
  37.  
  38. // Continue refine
  39. .@part = .@indices[.@index];
  40.  
  41. if(!getequipisequiped(.@part)) {
  42. clear;
  43. mes "[" + strnpcinfo(1) + "]";
  44. mes "But, there is nothing equiped...";
  45. close;
  46. }
  47.  
  48. if(!getequipisenableref(.@part)) {
  49. clear;
  50. mes "[" + strnpcinfo(1) + "]";
  51. mes "I don't think I can refine this item at all.";
  52. close;
  53. }
  54.  
  55. .@refineitemid = getequipid(.@part);
  56. .@refinerycnt = getequiprefinerycnt(.@part);
  57. setarray .@card[0], getequipcardid(.@part,0), getequipcardid(.@part,1), getequipcardid(.@part,2), getequipcardid(.@part,3);
  58. .@price = getequiprefinecost(.@part, REFINE_COST_NORMAL, REFINE_ZENY_COST);
  59. .@material = getequiprefinecost(.@part, REFINE_COST_NORMAL, REFINE_MATERIAL_ID);
  60. .@ms_material = getd("#MS_"+getitemname(.@material));
  61. .@level = getequipweaponlv(.@part);
  62. .@chance = getequippercentrefinery(.@part);
  63.  
  64. // Over +10 cost
  65. if(.@refinerycnt >= 10) {
  66. .@price = getequiprefinecost(.@part, REFINE_COST_OVER10, REFINE_ZENY_COST);
  67. }
  68.  
  69. // Max refine
  70. if(.@refinerycnt >= 20) {
  71. clear;
  72. mes "[" + strnpcinfo(1) + "]";
  73. mes "This item cannot be refined because it has already reached its maximum level...";
  74. close;
  75. }
  76.  
  77. clear;
  78. mes "[" + strnpcinfo(1) + "]";
  79. if(.@level > 0)
  80. mes "A level " + .@level + " weapon.";
  81. mes "To refine this, I need";
  82. mes ""+ callsub(S_ItemLink,.@material);
  83. mes .@price +" Zeny";
  84. if(getequippercentrefinery(.@part) < 100)
  85. mes .@chance +" % chance to success.";
  86. mes "Do you wish to continue?";
  87. if(select("Yes:No") != 1) {
  88. clear;
  89. mes "[" + strnpcinfo(1) + "]";
  90. mes "There's no need to rush.";
  91. mes "Take your time.";
  92. close;
  93. }
  94.  
  95. // Warn about change of failure
  96. if(getequippercentrefinery(.@part) < 100) {
  97. clear;
  98. mes "[" + strnpcinfo(1) + "]";
  99. mes "This equipment may ^ff0000break^000000 if you refine it again.";
  100. mes "And if it breaks, ^ff0000Item will be lost!^000000";
  101. mes .@chance +" % chance to success.";
  102. mes "Are you sure you still want to continue?";
  103. if(select("Yes:No") != 1) {
  104. clear;
  105. mes "[" + strnpcinfo(1) + "]";
  106. mes "I completely agree...";
  107. mes "I might be a great smith, but sometimes even I make mistakes.";
  108. close;
  109. }
  110. }
  111.  
  112. // Count materials from inventory first, then in material storage
  113. if(countitem(.@material) < 1 && .@ms_material < 1) {
  114. clear;
  115. mes "[" + strnpcinfo(1) + "]";
  116. mes "You don't seem to have enough";
  117. mes ""+ callsub(S_ItemLink,.@material) + "";
  118. close;
  119. }
  120.  
  121. // Count currency
  122. if(Zeny < .@price) {
  123. clear;
  124. mes "[" + strnpcinfo(1) + "]";
  125. mes "You don't seem to have enough";
  126. mes "Zeny";
  127. close;
  128. }
  129.  
  130. // Remove materials from inventory if exist, else in material storage
  131. if(countitem(.@material) > 0)
  132. delitem .@material, 1;
  133. else
  134. setd "#MS_"+getitemname(.@material), .@ms_material-1;
  135. set Zeny, Zeny - .@price;
  136.  
  137. // Anti-hack checks
  138. if(.@refineitemid != getequipid(.@part) || .@refinerycnt != getequiprefinerycnt(.@part) || (.@card[0] != getequipcardid(.@part,0) && .@card[1] != getequipcardid(.@part,1) && .@card[2] != getequipcardid(.@part,2) && .@card[3] != getequipcardid(.@part,3))) {
  139. clear;
  140. mes "[" + strnpcinfo(1) + "]";
  141. mes "Oh, almost refined wrong equipment.";
  142. mes "Please select again.";
  143. close;
  144. }
  145.  
  146. // Safe refine
  147. if(getequippercentrefinery(.@part) >= 100) {
  148. successrefitem .@part;
  149. clear;
  150. mes "[" + strnpcinfo(1) + "]";
  151. switch(rand(5)){
  152. case 1: mes "Here you are!"; break;
  153. case 2: mes "Here is your item!"; break;
  154. case 3: mes "A great work, don't you think!"; break;
  155. case 4: mes "Works every time!"; break;
  156. default: mes "What a great "+(isday()?"day":"night")+" to be a smith!"; break;
  157. }
  158. close;
  159. }
  160.  
  161. // Chance of success
  162. if(getequippercentrefinery(.@part) >= rand(100)) {
  163. successrefitem .@part;
  164. clear;
  165. mes "[" + strnpcinfo(1) + "]";
  166. mes "^009900Success^000000";
  167. mes "Here you are! It's done.";
  168. if(rand(100) <= 5) {
  169. mes "It's been a while since I've made such a fine refine!";
  170. emotion ET_BEST;
  171. }
  172. close;
  173. }
  174.  
  175. // Failure
  176. failedrefitem .@part;
  177. emotion ET_SWEAT;
  178. clear;
  179. mes "[" + strnpcinfo(1) + "]";
  180. mes "^ff0000Failed^000000";
  181. mes "What a shame...";
  182. mes "Your equipment ^ff0000broke^000000 during the refining process. I had told you earlier this might happen!";
  183. close;
  184.  
  185. L_MaterialStorage:
  186. // All materials to store
  187. setarray .@materials[0],
  188. 984/*Oridecon*/,
  189. 985/*Elunium*/,
  190. 1010/*Phracon*/,
  191. 1011/*Emvertarcon*/,
  192. 6224/*Bradium*/,
  193. 6223/*Carnium*/;
  194. clear;
  195. emotion ET_QUESTION;
  196. mes "[" + strnpcinfo(1) + "]";
  197. mes "Do you want to store the materials in my storage?";
  198. mes "Your current balance is:";
  199. for(.@i=0; .@i<getarraysize(.@materials); .@i++) {
  200. .@name$ = getitemname(.@materials[.@i]);
  201. .@amount = getd("#MS_"+.@name$);//#MS_Oridecon, #MS_Elunium
  202. // inventory
  203. //mes ""+ .@name$ +" x "+ countitem(.@materials[.@i]);
  204. // variable
  205. mes ""+ .@name$ +" x "+ .@amount;
  206. }
  207. switch(select("Store All:Withdraw All:Leave")) {
  208. case 1:
  209. clear;
  210. .@total = 0;
  211. mes "[" + strnpcinfo(1) + "]";
  212. for(.@i=0; .@i<getarraysize(.@materials); .@i++) {
  213. .@name$ = getitemname(.@materials[.@i]);
  214. .@amount = countitem(.@materials[.@i]);
  215. .@stored = getd("#MS_"+.@name$);
  216. if(.@amount > 0) {
  217. .@total = .@total + .@amount;
  218. setd "#MS_"+.@name$, .@stored+.@amount;
  219. delitem .@materials[.@i], .@amount;
  220. mes .@name$ + " x "+ .@amount;
  221. }
  222. }
  223. mes "Store ("+ .@total +") item.";
  224. emotion ET_MONEY;
  225. break;
  226. case 2:
  227. clear;
  228. .@total = 0;
  229. mes "[" + strnpcinfo(1) + "]";
  230. for(.@i=0; .@i<getarraysize(.@materials); .@i++) {
  231. .@name$ = getitemname(.@materials[.@i]);
  232. .@amount = getd("#MS_"+.@name$);
  233. if(.@amount > 0) {
  234. .@total = .@total + .@amount;
  235. setd "#MS_"+.@name$, 0;
  236. getitem .@materials[.@i], .@amount;
  237. mes .@name$ + " x "+ .@amount;
  238. }
  239. }
  240. mes "Withdraw ("+ .@total +") item.";
  241. emotion ET_CRY;
  242. break;
  243. default:
  244. clear;
  245. mes "[" + strnpcinfo(1) + "]";
  246. mes "Some other time.";
  247. break;
  248. }
  249. close;
  250.  
  251. S_ItemLink:
  252. // ^nItemIDXXXX^ where XXXX=ID or
  253. // client 2015+ uses ITEM and older use ITEMLINK
  254. return "<ITEM>"+getitemname(getarg(0))+"<INFO>"+getarg(0)+"</INFO></ITEM>";
  255.  
  256. S_RefineValidate:
  257. .@level = getarg(0);
  258. .@refineitemid = getarg(1);
  259. .@price = getarg(2);
  260. .@part = getarg(3);
  261. clear;
  262. mes "[" + strnpcinfo(1) + "]";
  263. if (.@level) mes "A level " + .@level + " weapon.";
  264. mes "To refine this, I need";
  265. mes ""+ callsub(S_ItemLink,.@refineitemid) + "";
  266. mes "and "+ .@price +" Zeny";
  267. mes "Do you wish to continue?";
  268. if(select("Yes:No") == 1) {
  269. if(getequippercentrefinery(.@part) < 100) {
  270. clear;
  271. mes "[" + strnpcinfo(1) + "]";
  272. mes "This equipment looks like it's been refined many times... It may ^ff0000break^000000 if you refine it again.";
  273. mes "And if it breaks,";
  274. mes "^ff0000Item will be lost!^000000";
  275. mes "Are you sure you still want to continue?";
  276. if(select("Yes:No") != 1) {
  277. clear;
  278. mes "[" + strnpcinfo(1) + "]";
  279. mes "I completely agree...";
  280. mes "I might be a great refiner, but sometimes even I make mistakes.";
  281. close;
  282. }
  283. }
  284. if(countitem(.@refineitemid) > 0 && Zeny > .@price) {
  285. delitem .@refineitemid, 1;
  286. set Zeny, Zeny - .@price;
  287. return;
  288. }
  289. clear;
  290. mes "[" + strnpcinfo(1) + "]";
  291. mes "You don't seem to have enough";
  292. mes ""+ callsub(S_ItemLink,.@refineitemid) + "";
  293. mes "or Zeny.";
  294. close;
  295. }
  296. clear;
  297. mes "[" + strnpcinfo(1) + "]";
  298. mes "There's no need to rush.";
  299. mes "Take your time.";
  300. close;
  301. }
  302. // NPC Duplicates
  303. prontera,155,174,5 duplicate(zRef) Refiner#prt1 826
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement