Jump to content
  • 0

Understanding Simple Sample Dynamic Shop


Nerks

Question


  • Group:  Members
  • Topic Count:  22
  • Topics Per Day:  0.01
  • Content Count:  135
  • Reputation:   4
  • Joined:  07/29/17
  • Last Seen:  

Hi can i request for a sample quest item a very very simple dynamic shop.

Thanks po.

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   381
  • Joined:  02/03/12
  • Last Seen:  

On 11/5/2017 at 9:23 PM, Nerks said:

Yes i know that NPC but i can't figure it out heheheee.

I need some very simple dynamic shop..

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;
}

 

Edited by Skorm
  • Upvote 2
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  255
  • Reputation:   232
  • Joined:  07/24/13
  • Last Seen:  

3 hours ago, Nerks said:

Hi can i request for a sample quest item a very very simple dynamic shop.

Thanks po.

Hi, all sample scripts you can find here: doc/sample
and sample dynamic shop.txt

Edited by Balfear
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  65
  • Reputation:   38
  • Joined:  11/15/11
  • Last Seen:  

Use the itemshop or pointshop command, it does all the work of a dynamic store but is much simpler.

Read for more info.

** Define a shop/cashshop/itemshop/pointshop NPC.

-%TAB%shop%TAB%<NPC Name>%TAB%<sprite id>,<itemid>:<price>{,<itemid>:<price>...}
<map name>,<x>,<y>,<facing>%TAB%shop%TAB%<NPC Name>%TAB%<sprite id>,<itemid>:<price>{,<itemid>:<price>...}

-%TAB%cashshop%TAB%<NPC Name>%TAB%<sprite id>,<itemid>:<price>{,<itemid>:<price>...}
<map name>,<x>,<y>,<facing>%TAB%cashshop%TAB%<NPC Name>%TAB%<sprite id>,<itemid>:<price>{,<itemid>:<price>...}

-%TAB%itemshop%TAB%<NPC Name>%TAB%<sprite id>,<costitemid>{:<discount>},<itemid>:<price>{,<itemid>:<price>...}
<map name>,<x>,<y>,<facing>%TAB%itemshop%TAB%<NPC Name>%TAB%<sprite id>,<costitemid>{:<discount>},<itemid>:<price>{,<itemid>:<price>...}

-%TAB%pointshop%TAB%<NPC Name>%TAB%<sprite id>,<costvariable>{:<discount>},<itemid>:<price>{,<itemid>:<price>...}
<map name>,<x>,<y>,<facing>%TAB%pointshop%TAB%<NPC Name>%TAB%<sprite id>,<costvariable>{:<discount>},<itemid>:<price>{,<itemid>:<price>...}

<map name>,<x>,<y>,<facing>%TAB%marketshop%TAB%<NPC Name>%TAB%<sprite id>,<itemid>:<price>:<quantity>{,<itemid>:<price>:<quantity>...}

This will define a shop NPC, which, when triggered (which can only be done by
clicking) will cause a shop window to come up. No code whatsoever runs in shop
NPCs and you can't change the prices otherwise than by editing the script
itself.

The Item ID is the number of item in the 'item_db.txt' database. If Price is set
to -1, the 'buy price' given in the item database will be used. Otherwise, the
price you gave will be used for this item, which is how you create differing
prices for items in different shops.

There are other types of shops available:
cashshop - use "cashshop" in place of "shop" to use the Cash Shop interface, allowing
you to buy items with special points that are stored as account variables
called  #CASHPOINTS and #KAFRAPOINTS. This type of shop will not allow you to sell
items at it, only make purchases. The layout used to define sale items still count, and
"<price>" refers to how many points will be spent purchasing the them.

"itemshop" and "pointshop" use the Shop interface, allowing you to buy items with a specific
item or special points from a variable. 'pointshop' only supports permanent character variables,
temporary character variables, permanent local account variables or permanent global account
variables. These variables must be of integer type, not string. 'discount' flag is an
optional value which makes the price at that shop become affected by discount skill.

** Define an warp/shop/cashshop/itemshop/pointshop/NPC duplicate.

warp/warp2: <map name>,<x>,<y>,<facing>%TAB%duplicate(<label>)%TAB%<NPC Name>%TAB%<spanx>,<spany>
shop/cashshop/itemshop/pointshop/npc: -%TAB%duplicate(<label>)%TAB%<NPC Name>%TAB%<sprite id>
shop/cashshop/itemshop/pointshop/npc: <map name>,<x>,<y>,<facing>%TAB%duplicate(<label>)%TAB%<NPC Name>%TAB%<sprite id>
npc: -%TAB%duplicate(<label>)%TAB%<NPC Name>%TAB%<sprite id>,<triggerX>,<triggerY>
npc: <map name>,<x>,<y>,<facing>%TAB%duplicate(<label>)%TAB%<NPC Name>%TAB%<sprite id>,<triggerX>,<triggerY>

This will duplicate an warp/shop/cashshop/itemshop/pointshop/NPC referred to by 'label'.
Warp duplicates inherit the target location.
Shop/cashshop/itemshop/pointshop duplicates inherit the item list.
NPC duplicates inherit the script code.
The rest (name, location, facing, sprite ID, span/trigger area)
is obtained from the definition of the duplicate (not inherited).

 

Edited by Pixel
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  22
  • Topics Per Day:  0.01
  • Content Count:  135
  • Reputation:   4
  • Joined:  07/29/17
  • Last Seen:  

On 11/4/2017 at 9:53 PM, Balfear said:

Hi, all sample scripts you can find here: doc/sample
and sample dynamic shop.txt

Yes i know that NPC but i can't figure it out heheheee.

I need some very simple dynamic shop..

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  22
  • Topics Per Day:  0.01
  • Content Count:  135
  • Reputation:   4
  • Joined:  07/29/17
  • Last Seen:  

12 hours ago, Skorm said:

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 out shop.
OnBuyItem:
	.@len = getarraysize(.customs); // Get the number of customs we're adding.
	.@b_len = getarraysize(@bought_nameid); // Get the number of purchased items.

	for( set @i, 0; @i < .@len; set @i, @i+1 ) {
		for( set @d,0; @d < .@b_len; set @d, @d+1 ) {
			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 out 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;
}

 

Thank you so much @Skorm

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  12
  • Topics Per Day:  0.00
  • Content Count:  625
  • Reputation:   188
  • Joined:  11/19/11
  • Last Seen:  

Lol, I even learned something new out of that: npcshopitem "Name",0,0; 

Didn't know that you can clear it entirely, haha. Thnx @Skorm for that.

Regards, 

Chris

Link to comment
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.

×
×
  • Create New...