Advertisement
Emistry

[RO] Euphy Quest Shop - Allow Purchase using Points.

Dec 30th, 2015
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.02 KB | None | 0 0
  1. // https://rathena.org/board/topic/103895-little-modification-on-euphys-quest-shop/
  2.  
  3.  
  4. // Shop NPCs -- supplying no argument displays entire menu.
  5. //  callfunc "qshop"{,<shop ID>{,<shop ID>{,...}}};
  6. //============================================================
  7. prontera,164,203,6  script  Quest Shop#1    998,{ callfunc "qshop"; }
  8.  
  9.  
  10. // Script Core
  11. //============================================================
  12. -   script  quest_shop  -1,{
  13. function Add; function Chk; function Slot;
  14. OnInit:
  15.     freeloop(1);
  16.  
  17. // -----------------------------------------------------------
  18. //  Basic shop settings.
  19. // -----------------------------------------------------------
  20.  
  21.     set .Announce,1;    // Announce quest completion? (1: yes / 0: no)
  22.     set .ShowSlot,1;    // Show item slots? (2: all equipment / 1: if slots > 0 / 0: never)
  23.     set .ShowID,0;      // Show item IDs? (1: yes / 0: no)
  24.     set .ShowZeny,0;    // Show Zeny cost, if any? (1: yes / 0: no)
  25.     set .MaxStack,100;  // Max number of quest items purchased at one time.
  26.  
  27. // -----------------------------------------------------------
  28. //  Points variable -- optional quest requirement.
  29. //  setarray .Points$[0],"<variable name>","<display name>";
  30. // -----------------------------------------------------------
  31.  
  32.     setarray .Points$[0],"#CASHPOINTS","Cash Points";
  33.  
  34. // -----------------------------------------------------------
  35. //  Shop IDs -- to add shops, copy dummy data at bottom of file.
  36. //  setarray .Shops$[1],"<Shop 1>","<Shop 2>"{,...};
  37. // -----------------------------------------------------------
  38.  
  39.     setarray .Shops$[1],"Headgears","Weapons","Other";
  40.  
  41. // -----------------------------------------------------------
  42. //  Quest items -- do NOT use a reward item more than once!
  43. //  Add(<shop ID>,<reward ID>,<reward amount>,
  44. //      <Zeny cost>,<point cost>,<donation cost>,
  45. //      <required item ID>,<required item amount>{,...});
  46. // -----------------------------------------------------------
  47.  
  48.     Add(1,5022,1,0,1000,7086,1,969,10,999,40,1003,50,984,2);
  49.     Add(1,5032,1,0,1000,1059,250,2221,1,2227,1,7063,600);
  50.     Add(1,5027,1,0,1000,2252,1,1036,400,7001,50,4052,1);
  51.     Add(1,5045,1,0,1000,2252,1,1054,450,943,1200);
  52.  
  53.     Add(2,1224,1,0,1000,7297,30,969,10,999,50,714,10);
  54.     Add(2,1225,1,0,1000,7292,30,969,10,999,50,714,10);
  55.  
  56.     Add(3,531,1,3,1000,512,1,713,1);
  57.     Add(3,532,1,3,1000,513,1,713,1);
  58.     Add(3,533,1,3,1000,514,1,713,1);
  59.     Add(3,534,1,3,1000,515,1,713,1);
  60.  
  61. // -----------------------------------------------------------
  62.  
  63.     freeloop(0);
  64.     set .menu$,"";
  65.     for(set .@i,1; .@i<=getarraysize(.Shops$); set .@i,.@i+1) {
  66.         set .menu$, .menu$+.Shops$[.@i]+":";
  67.         npcshopdelitem "qshop"+.@i,909;
  68.     }
  69.     end;
  70.  
  71. OnMenu:
  72.     set .@size, getarraysize(@i);
  73.     if (!.@size) set @shop_index, select(.menu$);
  74.     else if (.@size == 1) set @shop_index, @i[0];
  75.     else {
  76.         for(set .@j,0; .@j<.@size; set .@j,.@j+1)
  77.             set .@menu$, .@menu$+.Shops$[@i[.@j]]+":";
  78.         set @shop_index, @i[select(.@menu$)-1];
  79.     }
  80.     deletearray @i[0],getarraysize(@i);
  81.     if (.Shops$[@shop_index] == "") {
  82.         message strcharinfo(0),"An error has occurred.";
  83.         end;
  84.     }
  85.     dispbottom "Select one item at a time.";
  86.     callshop "qshop"+@shop_index,1;
  87.     npcshopattach "qshop"+@shop_index;
  88.     end;
  89.  
  90. OnBuyItem:
  91.     // .@q[] : RewardID, BoughtAmt, RewardAmt, BaseAmt, ReqZeny, ReqPts, { ReqItem, ReqAmt, ... }
  92.     setarray .@q[0],@bought_nameid[0],((@bought_quantity[0] > .MaxStack)?.MaxStack:@bought_quantity[0]);
  93.     copyarray .@q[3],getd(".q_"+@shop_index+"_"+.@q[0]+"[0]"),getarraysize(getd(".q_"+@shop_index+"_"+.@q[0]));
  94.     set .@q[2],.@q[1]*.@q[3];
  95.     if (!.@q[2] || .@q[2] > 30000) {
  96.         message strcharinfo(0),"You can't purchase that many "+getitemname(.@q[0])+".";
  97.         end;
  98.     }
  99.     mes "[Quest Shop]";
  100.     mes "Reward: ^0055FF"+((.@q[2] > 1)?.@q[2]+"x ":"")+Slot(.@q[0])+"^000000";
  101.     mes "Requirements:";
  102.     disable_items;
  103.     if (.@q[4]) mes " > "+Chk(Zeny,.@q[4]*.@q[1])+(.@q[4]*.@q[1])+" Zeny^000000";
  104.     // if (.@q[5]) mes " > "+Chk(getd(.Points$[0]),.@q[5]*.@q[1])+(.@q[5]*.@q[1])+" "+.Points$[1]+" ("+getd(.Points$[0])+"/"+(.@q[5]*.@q[1])+")^000000";
  105.     if (.@q[6]) for(set .@i,6; .@i<getarraysize(.@q); set .@i,.@i+2)
  106.         mes " > "+Chk(countitem(.@q[.@i]),.@q[.@i+1]*.@q[1])+((.ShowID)?"{"+.@q[.@i]+"} ":"")+Slot(.@q[.@i])+" ("+countitem(.@q[.@i])+"/"+(.@q[.@i+1]*.@q[1])+")^000000";
  107.     next;
  108.     setarray @qe[1], getiteminfo(.@q[0],5), getiteminfo(.@q[0],11);
  109.     if (@qe[2] > 0 && ((@qe[1] & 1) || (@qe[1] & 256) || (@qe[1] & 512) || (@qe[1] & 1024) || (@qe[1] & 2048) || (@qe[1] & 4096) || (@qe[1] & 4) || (@qe[1] & 8192)))
  110.         set .@preview,1;
  111.     addtimer 1000, strnpcinfo(0)+"::OnEnd";
  112.     while(1) {
  113.         switch(select(" ~ Purchase ^0055FF"+getitemname(.@q[0])+"^000000",
  114.             ((.@q[5])? "~ Purchase using "+(.@q[5]*.@q[1])+" "+.Points$[1] : ""),
  115.             ((.@preview && !@qe[7])?" ~ Preview...":""),
  116.             "~ ^777777Cancel^000000"
  117.         )) {
  118.         case 1:
  119.             if (@qe[0]) {
  120.                 mes "[Quest Shop]";
  121.                 mes "You're missing one or more quest requirements.";
  122.                 close;
  123.             }
  124.             if (!checkweight(.@q[0],.@q[2])) {
  125.                 mes "[Quest Shop]";
  126.                 mes "^FF0000You need "+(((.@q[2]*getiteminfo(.@q[0],6))+Weight-MaxWeight)/10)+" additional weight capacity to complete this trade.^000000";
  127.                 close;
  128.             }
  129.             if (.@q[4]) set Zeny, Zeny-(.@q[4]*.@q[1]);
  130.             // if (.@q[5]) setd .Points$[0], getd(.Points$[0])-(.@q[5]*.@q[1]);
  131.             if (.@q[6]) for(set .@i,6; .@i<getarraysize(.@q); set .@i,.@i+2)
  132.                 delitem .@q[.@i],.@q[.@i+1]*.@q[1];
  133.             getitem .@q[0],.@q[2];
  134.             if (.Announce) announce strcharinfo(0)+" has created "+((.@q[2] > 1)?.@q[2]+"x "+getitemname(.@q[0]):callfunc("F_InsertArticle",getitemname(.@q[0])))+"!",0;
  135.             specialeffect2 EF_FLOWERLEAF;
  136.             close;
  137.         case 2:
  138.             if ( getd(.Points$[0]) < (.@q[5]*.@q[1]) ) {
  139.                 mes "didnt have enough "+.Points$[1];
  140.             }
  141.             else {
  142.                 setd .Points$[0], getd(.Points$[0])-(.@q[5]*.@q[1]);
  143.                 getitem .@q[0],.@q[2];
  144.                 if (.Announce) announce strcharinfo(0)+" has created "+((.@q[2] > 1)?.@q[2]+"x "+getitemname(.@q[0]):callfunc("F_InsertArticle",getitemname(.@q[0])))+"!",0;
  145.                 specialeffect2 EF_FLOWERLEAF;
  146.             }
  147.             close;
  148.         case 3:
  149.             setarray @qe[3], getlook(LOOK_HEAD_BOTTOM), getlook(LOOK_HEAD_TOP), getlook(LOOK_HEAD_MID), getlook(LOOK_ROBE), 1;
  150.             if ((@qe[1] & 1) || (@qe[1] & 4096)) changelook LOOK_HEAD_BOTTOM, @qe[2];
  151.             else if ((@qe[1] & 256) || (@qe[1] & 1024)) changelook LOOK_HEAD_TOP, @qe[2];
  152.             else if ((@qe[1] & 512) || (@qe[1] & 2048)) changelook LOOK_HEAD_MID, @qe[2];
  153.             else if ((@qe[1] & 4) || (@qe[1] & 8192)) changelook LOOK_ROBE, @qe[2];
  154.             break;
  155.         case 4:
  156.             close;
  157.         }
  158.     }
  159.  
  160. OnEnd:
  161.     if (@qe[7]) {
  162.         changelook LOOK_HEAD_BOTTOM, @qe[3];
  163.         changelook LOOK_HEAD_TOP, @qe[4];
  164.         changelook LOOK_HEAD_MID, @qe[5];
  165.         changelook LOOK_ROBE, @qe[6];
  166.     }
  167.     deletearray @qe[0],8;
  168.     end;
  169.  
  170. function Add {
  171.     if (getitemname(getarg(1)) == "null") {
  172.         debugmes "Quest reward #"+getarg(1)+" invalid (skipped).";
  173.         return;
  174.     }
  175.     setarray .@j[0],getarg(2),getarg(3),getarg(4);
  176.     for(set .@i,5; .@i<getargcount(); set .@i,.@i+2) {
  177.         if (getitemname(getarg(.@i)) == "null") {
  178.             debugmes "Quest requirement #"+getarg(.@i)+" invalid (skipped).";
  179.             return;
  180.         } else
  181.             setarray .@j[.@i-2],getarg(.@i),getarg(.@i+1);
  182.     }
  183.     copyarray getd(".q_"+getarg(0)+"_"+getarg(1)+"[0]"),.@j[0],getarraysize(.@j);
  184.     npcshopadditem "qshop"+getarg(0),getarg(1),((.ShowZeny)?getarg(3):0);
  185.     return;
  186. }
  187.  
  188. function Chk {
  189.     if (getarg(0) < getarg(1)) {
  190.         set @qe[0],1;
  191.         return "^FF0000";
  192.     } else
  193.         return "^00FF00";
  194. }
  195.  
  196. function Slot {
  197.     set .@s$,getitemname(getarg(0));
  198.     switch(.ShowSlot) {
  199.         case 1: if (!getitemslots(getarg(0))) return .@s$;
  200.         case 2: if (getiteminfo(getarg(0),2) == 4 || getiteminfo(getarg(0),2) == 5) return .@s$+" ["+getitemslots(getarg(0))+"]";
  201.         default: return .@s$;
  202.     }
  203. }
  204. }
  205.  
  206. function    script  qshop   {
  207.     deletearray @i[0],getarraysize(@i);
  208.     for(set .@i,0; .@i<getargcount(); set .@i,.@i+1)
  209.         set @i[.@i],getarg(.@i);
  210.     doevent "quest_shop::OnMenu";
  211.     end;
  212. }
  213.  
  214.  
  215. // Dummy shop data -- copy as needed.
  216. //============================================================
  217. -   shop    qshop1  -1,909:-1
  218. -   shop    qshop2  -1,909:-1
  219. -   shop    qshop3  -1,909:-1
  220. -   shop    qshop4  -1,909:-1
  221. -   shop    qshop5  -1,909:-1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement