It took me a bit to understand dynamic shops when I was first learning too. This is the npc I used to understand dynamic shops but I added a bunch of comments hopefully it helps. ( Disclaimer: This npc is old and doesn't have all the necessary weight checks and mumbo-jumbo I'm providing it as an example because it's simple. )
- shop custom_seller2 -1,501:20 // Create our dummy shop.
prontera.gat,95,99,5 script WoE Shop 100,{
// This code runs when the user clicks our npc.
mes "I will sell you items for " + getitemname(.CoinID) + "."; // Let the user know about our shop.
callshop "custom_seller2",1; // Summon our dummy shop filled with custom items.
npcshopattach "custom_seller2"; // Attach the shop to this npc.
end;
// This code runs when a user purchases an item from our shop.
OnBuyItem:
.@len = getarraysize(.customs); // Get the number of customs we've added.
.@b_len = getarraysize(@bought_nameid); // Get the number of purchased items.
for( set @i, 0; @i < .@len; set @i, @i+1 ) { // Loop through all our custom items.
for( set @d,0; @d < .@b_len; set @d, @d+1 ) { // Loop through all the purchased items.
if( @bought_nameid[@d] == .customs[@i] ) { // Check if the purchased item equals our custom item.
if( countitem(.CoinID) >= .Price[@i] * @bought_quantity[@d] ) { // Check if the user has the correct funds.
delitem .CoinID,.Price[@i]*@bought_quantity[@d];
getitem @bought_nameid[@d],@bought_quantity[@d];
}
}
}
}
deletearray @bought_quantity, getarraysize(@bought_quantity); // Remove the array.
deletearray @bought_nameid, getarraysize(@bought_nameid); // Remove the array.
close;
// This code runs first. When the server is started.
OnInit:
setarray .customs[0],12103,607,678; // An array of our custom items.
set .CoinID,7227; // Currency used for the transaction.
setarray .Price[0],20,40,300; // The amount of coins needed for our items. (For example: Item 12103 = 20 coins)
npcshopitem "custom_seller2",0,0; // Remove all items from our dummy shop.
for( set .@i, 0; .customs[.@i]; set .@i, .@i+1 ) // Loop through our custom items.
npcshopadditem "custom_seller2",.customs[.@i],.Price[.@i]; // Add our custom items to the cleared dummy shop.
end;
}