Advertisement
johnlol

Dynamic Shop v1.1

May 19th, 2019
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VeriLog 14.14 KB | None | 0 0
  1. //===== rAthena Script =======================================
  2. //= Dynamic Shop
  3. //===== By ===================================================
  4. //= llchrisll
  5. //===== Version ==============================================
  6. //= 1.0 - Initial Version
  7. //      - Nearly forgot the "OnBuyItem" part (Q.Q)
  8. //      - Added the possibility to edit the price limit.
  9. //= 1.1 - Added more Currency options
  10. //      - Added possiblity to use pre-defined items + prices,
  11. //        which are always in the shop, see 'OnInit:' > $cash_pre_it and $cash_pre_p
  12. //      - Fixed an bug about the price limit
  13. //      - Changed all $cash variables to .cash
  14. //      - Added extra config for maximum items in the shop
  15. //      - Changed function ShopStuff
  16. //===== Tested With =========================================
  17. //= rAthena SQL 07/16-2017 Revision
  18. //===== Description ==========================================
  19. //= This Shop can be changed dynamically ingame and has four
  20. //  payment methods, to choose from: Zeny, Cash Points, Custom Variable and Item.
  21. //===== Comments =============================================
  22. //= Thanks to Elysium:
  23. //  > Bug about the price limit
  24. //  > Modification request about more currency options
  25. //===========================================================
  26. prontera,152,177,4  script  Cash Shop   100,{
  27. function ShopStuff;
  28.  
  29. // Reading Currency Display Name
  30. switch(.CR) {
  31.     case 0: set .Cur_N$,"None"; break;
  32.     case 1: set .Cur_N$,"Zeny"; set @Cur_O$,"Zeny"; break;
  33.     case 2: set .Cur_N$,"Cash Points"; set @Cur_O$,"#CASHPOINTS"; break;
  34.     case 3: set .Cur_N$,.CR_Name$; set @Cur_O$,""+.CR_Var$; break;
  35.     case 4: set .Cur_N$,getitemname(.CR_Item); break;
  36. }
  37. ShopStuff(4);
  38.  
  39. if(getgmlevel() >= .gm) {
  40.     set @shop,0;
  41.     mes .n$;
  42.     mes "Hello, "+strcharinfo(0)+".";
  43.     mes "Current Currency: "+.Cur_N$;
  44.     while(1) {
  45.         if(@shop) {
  46.             close2;
  47.             break;
  48.         }
  49.         next;
  50.         mes .n$;
  51.         mes "How can I help you?";
  52.         next;
  53.         switch(select("- Shop Settings:- Reset Shop:- Open Shop:- Nothing")) {
  54.  
  55.             case 1:
  56.             mes .n$;
  57.             mes "What do you want view?";
  58.             next;
  59.             if(select("- Shop Managment:- Currency Setting") - 1) {
  60.                 mes .n$;
  61.                 mes "What now?";
  62.                 mes "^FF0000Note: On currency change I will delete every entry in the shop you have made so far.^000000";
  63.                 switch(select("- Change currency (Current - "+.Cur_N$+"):- Set Price Limit:- Nothing")) {
  64.                     case 1:
  65.                     next;
  66.                     mes .n$;
  67.                     mes "Please choose from the menu below, which currency I should use:";
  68.                     switch(select("- Zeny:- Cash Points:- Custom Variable:- Items")) {
  69.                        
  70.                         default: set .CR,@menu; break;
  71.                        
  72.                         case 3:
  73.                         next;
  74.                         mes .n$;
  75.                         mes "Please write the name of the Custom Variable and the display name for the players:";
  76.                         mes "^FF0000Note: You have to be aware of the variable name itself, like PvPPoints.^000000";
  77.                         mes "^FF0000Note: Max letters for variable name: 10, 20 for display name!^000000";
  78.                         next;
  79.                         if(input(.@CR_Var$,1,10) != 0) {
  80.                             mes .n$;
  81.                             mes "Error: Either the variable name is too long or too short. Please try again.";
  82.                             continue;
  83.                         }
  84.                         if(input(.@CR_Name$,1,20) != 0) {
  85.                             mes .n$;
  86.                             mes "Error: Either the display name is too long or too short. Please try again.";
  87.                             continue;
  88.                         }
  89.                         mes .n$;
  90.                         mes "Variable Name: "+.@CR_Var$;
  91.                         mes "Variable Display Name: "+.@CR_Name$;
  92.                         mes "Is this correct?";
  93.                         if(select("- Yes:- No") - 1) continue;
  94.                         next;
  95.                         mes .n$;
  96.                         mes "Custom Variable will now be used as currency.";
  97.                         set .CR_Var$,.@CR_Var$;
  98.                         set .CR_Name$,.@CR_Name$;
  99.                         set .CR,3;
  100.                         break;
  101.                        
  102.                         case 4:
  103.                         next;
  104.                         mes .n$;
  105.                         mes "Please write the id of the item you want to use:";
  106.                         next;
  107.                         if(input(.@item,501,.last_id) != 0) {
  108.                             mes .n$;
  109.                             mes "The id you have put is either too low or too high.";
  110.                             continue;
  111.                         }
  112.                         if(getitemname(.@item) == "null" || getitemname(.@item) == "") {
  113.                             mes .n$;
  114.                             mes "The item you requested doesn't exist.";
  115.                             continue;
  116.                         }
  117.                         mes .n$;
  118.                         mes "Chosen Item: "+getitemname(.@item);
  119.                         mes "Is that correct?";
  120.                         if(select("- Yes:- No") - 1) continue;
  121.                         set .CR_Item,.@item;
  122.                         set .CR,4;
  123.                         break;
  124.                     }
  125.                     deletearray .cash_it[0],getarraysize(.cash_it);
  126.                     deletearray .cash_p[0],getarraysize(.cash_p);
  127.                     ShopStuff(4);
  128.                     continue;
  129.                
  130.                     case 2:
  131.                     next;
  132.                     mes .n$;
  133.                     mes "Current Setting: "+.limit;
  134.                     mes "Change?";
  135.                     if(select("- Yes:- No") - 1) continue;
  136.                     next;
  137.                     mes .n$;
  138.                     mes "Please type the new value:";                      
  139.                     mes "Note: But you can't go higher than 10,000,000.";
  140.                     next;
  141.                     if(input(@n_lim,1,10000000) != 0) {
  142.                         mes .n$;
  143.                         mes "Invalid Value, max 10,000,000.";
  144.                         continue;
  145.                     }
  146.                     mes .n$;
  147.                     mes "New Limit has been set.";
  148.                     set .limit,@n_lim;
  149.                     continue;
  150.                    
  151.                     case 3:
  152.                     continue;
  153.                 }
  154.             }
  155.             if(!.CR) {
  156.                 mes .n$;
  157.                 mes "I'm sorry, but I don't know with which Currency I should trade yet.";
  158.                 mes "Please choose an currency first.";
  159.                 continue;
  160.             }
  161.             if(!.limit) {
  162.                 mes .n$;
  163.                 mes "You haven't set an price limit yet.";
  164.                 continue;
  165.             }
  166.             mes .n$;
  167.             if(getarraysize(.cash_it) < 1) {
  168.                 mes "There is no item in the Shop yet.";
  169.             } else {
  170.                 mes "There are currently the following "+getarraysize(.cash_it)+" Items in the Shop:";
  171.                 mes "============================";
  172.                 for ( set .@i,0; .@i < getarraysize(.cash_it); set .@i,.@i + 1) {
  173.                     mes getitemname(.cash_it[.@i])+" (ID: "+.cash_it[.@i]+")";
  174.                     mes "Price:"+.cash_p[.@i]+" "+.Cur_N$;
  175.                     mes ( (.cash_it[.@i+1] != 0)?"---------------------------------":"============================");
  176.                 }
  177.             }
  178.             next;
  179.             switch(select("- Add Items:- Edit Items:- Delete Items:- Nothing")) {
  180.                 case 1:
  181.                 mes .n$;
  182.                 if(getarraysize(.cash_it) >= .max_items) {
  183.                     mes "The Shop is full, please remove an item first.";
  184.                     continue;
  185.                 }
  186.                 mes "Please type the Item ID you want to add:";
  187.                 mes "Max is "+.max_items+" Items.";
  188.                 next;
  189.                 if(input(.@item,501,.last_id) != 0) {
  190.                     mes .n$;
  191.                     mes "The id you have put is either too low or too high.";
  192.                     continue;
  193.                 }
  194.                 if(getitemname(.@item) == "null" || getitemname(.@item) == "") {
  195.                     mes .n$;
  196.                     mes "The item you requested doesn't exist.";
  197.                     continue;
  198.                 }
  199.                 mes .n$;
  200.                 mes "Chosen Item: "+getitemname(.@item);
  201.                 mes " ";
  202.                 mes "Now input the price it should have, the current currency is \""+.Cur_N$+"\".";
  203.                 mes "Maximum is "+.limit;
  204.                 next;
  205.                 if(input(.@price,1,.limit) != 0) {
  206.                     mes .n$;
  207.                     mes "You have put an invalid price.";
  208.                     mes "Maximum is "+.limit;
  209.                     continue;
  210.                 }
  211.                 mes .n$;
  212.                 mes "Price: "+.@price+" "+.Cur_N$;
  213.                 mes "Is that correct?";
  214.                 if(select("- Yes:- No") - 1) continue;
  215.                 ShopStuff(1,0,.@item,.@price);
  216.                 continue;
  217.                    
  218.                 case 2:
  219.                 mes .n$;
  220.                 if(getarraysize(.cash_it) < 1) {
  221.                     mes "There is no Item to edit.";
  222.                     mes "Please add one first :D.";
  223.                     continue;
  224.                 }
  225.                 mes "Please choose the item you want to edit:";
  226.                 mes "Format: Name (Current Price)";
  227.                 next;
  228.                 for ( set .@e,0; .@e < getarraysize(.cash_it); set .@e,.@e + 1)
  229.                     set .@ed_list$,.@ed_list$ + "- "+getitemname(.cash_it[.@e])+" ("+.cash_p[.@e]+")" + ( (.cash_it[.@e+1])?":":"");
  230.                    
  231.                 set .@ed,select(.@ed_list$) - 1;
  232.                
  233.                 mes .n$;
  234.                 mes "Chosen Item: "+ getitemname(.cash_it[.@ed]);
  235.                 mes "Price: "+ .cash_p[.@ed]+" "+.Cur_N$;
  236.                 mes "Correct?";
  237.                 if(select("- Yes:- No") - 1) continue;
  238.                 next;
  239.                 mes .n$;
  240.                 mes "What do you want to edit?";
  241.                 next;
  242.                 if(select("- Item ID:- Price") - 1) {
  243.                     mes .n$;
  244.                     mes "Input the new price:";
  245.                     next;
  246.                     if(input(.@price,1,.limit) != 0) {
  247.                         mes .n$;
  248.                         mes "You have put an invalid price.";
  249.                         mes "Maximum is "+.limit;
  250.                         continue;
  251.                     }
  252.                     mes .n$;
  253.                     mes "Chosen Price: "+.@price+" "+.Cur_N$;
  254.                     mes "Correct?";
  255.                     if(select("- Yes:- No") - 1) continue;
  256.                     ShopStuff(3,.@ed,.cash_it[.@ed],.@price);
  257.                    
  258.                 } else {
  259.                     mes .n$;
  260.                     mes "Input the new item id:";
  261.                     next;
  262.                     if(input(.@item,501,.last_id) != 0) {
  263.                         mes .n$;
  264.                         mes "The id you have put is either too low or too high.";
  265.                         continue;
  266.                     }
  267.                     if(getitemname(.@item) == "null" || getitemname(.@item) == "") {
  268.                         mes .n$;
  269.                         mes "The item you requested doesn't exist.";
  270.                         continue;
  271.                     }
  272.                     mes .n$;
  273.                     mes "Chosen Item: "+getitemname(.@item);
  274.                     mes "Correct?";
  275.                     if(select("- Yes:- No") - 1) continue;
  276.                     ShopStuff(3,.@ed,.@item,.cash_p[.@ed]);
  277.                 }  
  278.                 continue;
  279.                
  280.                 case 3:
  281.                 mes .n$;
  282.                 if(getarraysize(.cash_it) < 1) {
  283.                     mes "There is no Item to remove.";
  284.                     mes "Please add one first :D.";
  285.                     continue;
  286.                 }
  287.                 mes "Please choose the item you want to remove:";
  288.                 mes "Format: Name (Current Price)";
  289.                 next;
  290.                 set @r_list$,"";
  291.                 for ( set .@e,0; .@e < getarraysize(.cash_it); set .@e,.@e + 1)
  292.                     set .@r_list$,.@r_list$ + "- "+getitemname(.cash_it[.@e])+" ("+.cash_p[.@e]+")" + ( (.cash_it[.@e+1])?":":"");
  293.                    
  294.                 set .@re,select(.@r_list$) - 1;
  295.                
  296.                 mes .n$;
  297.                 mes "Chosen Item: "+ getitemname(.cash_it[.@re]);
  298.                 mes "Price: "+ .cash_p[.@re]+" "+.Cur_N$;
  299.                 mes "Correct?";
  300.                 if(select("- Yes:- No") - 1) continue;
  301.                 ShopStuff(2,@ed);
  302.                 continue;
  303.                
  304.                 case 4:
  305.                 continue;
  306.                 break;
  307.             }
  308.            
  309.             case 2:
  310.             mes .n$;
  311.             mes "Do you really want to reset the shop?";
  312.             if(select("- Yes:- No") - 1) continue;
  313.             ShopStuff(4);
  314.             continue;
  315.            
  316.             case 3:
  317.             set @shop,1;
  318.             continue;
  319.            
  320.             case 4:
  321.             close;
  322.         }
  323.     }
  324. }
  325. if(!.CR) {
  326.     mes .n$;
  327.     mes "I'm sorry, but I don't know with which Currency I should trade yet.";
  328.     close;
  329. }
  330. if(getarraysize(.cash_it) < 1) {
  331.     mes .n$;
  332.     mes "There are no items to purchase yet.";
  333.     mes "Please come back as soon as I have some.";
  334.     close;
  335. }
  336. dispbottom strnpcinfo(1)+": Accepted Payment Method: "+.Cur_N$;
  337. if(.CR < 4)
  338.     dispbottom strnpcinfo(1)+": You have "+getd(""+@Cur_O$)+" "+.Cur_N$;
  339. else
  340.     dispbottom strnpcinfo(1)+": You have "+countitem(.CR_Item)+" "+.Cur_N$;
  341. dispbottom strnpcinfo(1)+": Notice: Discount Skill won't work at me, you'll have to pay the full price.";
  342. callshop "Dynam_Shop",1;
  343. npcshopattach "Dynam_Shop";
  344. end;
  345.  
  346. OnBuyItem:
  347. for ( set .@b,0; .@b < getarraysize(@bought_nameid); set .@b,.@b + 1) {
  348.     for ( set .@l,0; .@l < getarraysize(.cash_it); set .@l,.@l + 1) {
  349.         if(@bought_nameid[.@b] == .cash_it[.@l]) {
  350.             if(checkweight(.cash_it[.@l],@bought_quantity[.@b]) == 1) {
  351.                 set @cost,.cash_p[.@l]*@bought_quantity[.@b];
  352.                 set @total,@total+@cost;
  353.             } else {
  354.                 dispbottom "Cash Shop: You would be overweight, please remove some items or buy less.";
  355.                 set @cost,0;
  356.                 set @total,0;
  357.                 deletearray @bought_nameid[0],getarraysize(@bought_nameid);
  358.                 deletearray @bought_quantity[0],getarraysize(@bought_quantity);
  359.                 end;
  360.             }
  361.         }
  362.     }
  363. }
  364. if(.CR < 4 && (@total > getd(""+@Cur_O$) ) ) set .@f,1;
  365. if(.CR == 4 && (@total > countitem(.CR_Item) ) ) set .@f,1;
  366. if(.@f) {
  367.     dispbottom strnpcinfo(1)+": You don't have the required "+.Cur_N$;
  368.     dispbottom strnpcinfo(1)+": You need "+@total +" "+.Cur_N$+".";
  369.     set @cost,0;
  370.     set @total,0;
  371.     deletearray @bought_nameid[0],getarraysize(@bought_nameid);
  372.     deletearray @bought_quantity[0],getarraysize(@bought_quantity);
  373.     end;
  374. }
  375.  
  376. if(.CR < 4)
  377.     setd(""+@Cur_O$),getd(""+@Cur_O$)  - @total;
  378. else
  379.     delitem .CR_Item,@total;
  380.  
  381. for ( set .@s,0; .@s < getarraysize(@bought_nameid); set .@s,.@s + 1) {
  382.     getitem @bought_nameid[.@s],@bought_quantity[.@s];
  383.     dispbottom strnpcinfo(1)+": You have succesfully purchased "+@bought_quantity[.@s]+"x "+getitemname(@bought_nameid[.@s])+".";
  384. }
  385. dispbottom strnpcinfo(1)+": You have paied "+@total+"x "+.Cur_N$+".";
  386.    
  387. set @cost,0;
  388. set @total,0;
  389. deletearray @bought_nameid[0],getarraysize(@bought_nameid);
  390. deletearray @bought_quantity[0],getarraysize(@bought_quantity);
  391. end;
  392.  
  393. function    ShopStuff   {
  394. // ==================================================== //
  395. // getarg(0):
  396. //  * 1 - Add
  397. //  * 2 - Remove
  398. //  * 3 - Edit
  399. //  * 4 - Shop Creation
  400. // getarg(1): Array Position for Edit & Remove
  401. // getarg(2): Item ID
  402. // getarg(3): Price
  403. // ==================================================== //
  404. //debugmes "getarg(0): "+getarg(0,0)+", getarg(1): "+getarg(1,0)+", getarg(2): "+getarg(2,0)+", getarg(3): "+getarg(3,0);
  405.     // =========== Item Adding ============ //
  406.     if(getarg(0) == 1) {
  407.         npcshopadditem "Dynam_Shop",getarg(2),getarg(3);
  408.         setarray .cash_it[getarraysize(.cash_it)],getarg(2);
  409.         setarray .cash_p[getarraysize(.cash_p)],getarg(3);
  410.        
  411.     // =========== Item Removal ============ //
  412.     } else if(getarg(0) == 2) {
  413.         npcshopdelitem "Dynam_Shop",.cash_it[getarg(1)];
  414.         deletearray .cash_it[getarg(1)],1;
  415.         deletearray .cash_p[getarg(1)],1;
  416.        
  417.     // =========== Item Edit ============ //
  418.     } else if(getarg(0) == 3) {
  419.         setarray .cash_it[getarg(1)],getarg(2);
  420.         setarray .cash_p[getarg(1)],getarg(3);
  421.         // Re-Create Shop after Edit
  422.         npcshopitem "Dynam_Shop",.cash_it[0],.cash_p[0];
  423.         for ( set .@s,1; .@s < getarraysize(.cash_it); set .@s,.@s + 1)
  424.                 npcshopadditem "Dynam_Shop",.cash_it[.@s],.cash_p[.@s];
  425.                
  426.     // =========== Shop Creation ============ //               
  427.     } else if(getarg(0) == 4) {
  428.         npcshopitem "Dynam_Shop",512,10;
  429.         npcshopdelitem "Dynam_Shop",512;
  430.         // Adding pre-defined items to the shop array
  431.         for ( set .@s,0; .@s < getarraysize(.cash_pre_it); set .@s,.@s + 1) {
  432.             setarray .cash_it[getarraysize(.cash_it)],.cash_pre_it[.@s];
  433.             setarray .cash_p[getarraysize(.cash_p)],.cash_pre_p[.@s];      
  434.         }
  435.         // Adding items to the shop
  436.         for ( set .@s,0; .@s < getarraysize(.cash_it); set .@s,.@s + 1)
  437.             npcshopadditem "Dynam_Shop",.cash_it[.@s],.cash_p[.@s];
  438.     }
  439.     return;
  440. }
  441.  
  442. OnInit:
  443. set .n$,"["+strnpcinfo(1)+"]";
  444. set .gm,80; // General Access Level
  445. set .last_id,30000; // Highest Item ID
  446. set .max_items,1000;
  447. // Pre-Defined Items in the Shop, they are always in it!
  448. setarray .cash_pre_it[0],2792,2793,2374,2375,2357,2524,2421,2115,2729;
  449. setarray .cash_pre_p[0],100,100,100,100,100,100,100,100,100;
  450. end;
  451. }
  452. -   shop    Dynam_Shop  -1,512:-1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement