• 0
Sign in to follow this  
Chun3

Question about dynamic shop

Question

-    shop    custom_seller2    -1,501:-1
prontera,155,148,3    script    Poring Seller   476,{
    mes "I will sell you items for " + getitemname(.CoinID) + ".";
    callshop "custom_seller2",1;
    npcshopattach "custom_seller2";
    end;
    OnBuyItem:
    mes ""+.Price[[email protected]]+"";
    mes ""[email protected]_nameid[[email protected]]+"";
    for(set [email protected],0; [email protected]<getarraysize(.customs); set [email protected],[email protected]+1) {
        for(set [email protected],0; [email protected]<getarraysize(@bought_nameid); set [email protected],[email protected]+1) {
            if(@bought_nameid[[email protected]]==.customs[[email protected]]) {
                if(checkweight(@bought_nameid[[email protected]],@bought_quantity[[email protected]])) {
                    if(countitem(.CoinID) >= .Price[[email protected]]*@bought_quantity[[email protected]]) {
                        delitem .CoinID,.Price[[email protected]]*@bought_quantity[[email protected]];
                        getitem @bought_nameid[[email protected]],@bought_quantity[[email protected]];
                    } else dispbottom "You don't have enough "+getitemname(.CoinID)+" to purchase that item.";
                } else dispbottom "Purchasing these items will put you over the weight limit!";
            }
        }
    }
    deletearray @bought_quantity, getarraysize(@bought_quantity);
    deletearray @bought_nameid, getarraysize(@bought_nameid);
    close;

OnInit:
    setarray .customs[0],12028,607,678;// Enter the ID of customs here
    setarray .Price[0],10,3,5; // Price for each custom is set to 20 coins
    set .CoinID,7539; // Enter the ID of the coin here.
    npcshopitem "custom_seller2",0,0; // Don't touch any coding beyond here
    for(set .i,0; .customs[.i]; set .i,.i+1) npcshopadditem "custom_seller2",.customs[.i],.Price[.i];
    end;
}

 

 

My question is:

this line mes ""[email protected]_nameid[[email protected]]+""; shows the correct name when a item is bought

this line    mes ""+.Price[[email protected]]+""; doesn't show the right price. its always Price[0]

why? isn't [email protected] supossed to be a npc variable after the bought?

 

 

Edited by Chun3

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

[email protected] is the loop variable set by this :

Quote

 for(set [email protected],0; [email protected]<getarraysize(@bought_nameid); set [email protected],[email protected]+1) {

so anywhere above that it is zero. However if you bought only one item at a time, then @bought_nameid [0] does reference that item correctly. Otherwise it'll only show the first, as it's displayed outside the loop.

furthermore, the loop finds you which item in your Price array was bought - and that's in [email protected] So the correct price is .Price[[email protected]]  and again, only inside the loop, below the

Quote

 if(@bought_nameid[[email protected]]==.customs[[email protected]]) {

Line which ensures the variable [email protected] has the correct number.

  • Upvote 1

Share this post


Link to post
Share on other sites
  • 0

Oh i see, thanks! i thought it was a variable from bought_x functions.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this