View Single Post
  #28  
Old 08-09-2011, 07:17 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Here's one way of doing it, you assign a shop id to your npc.

I.e: this.shop_id = "basicshop";

PHP Code:
function onCreated() {
  
this.shop_id = "basicshop";
  
this.join("shopkeeper");
} 
DB-NPC: DB_Shops (For this example)

PHP Code:
function onCreated() {
  
// Setup Basic Shop's Item List
  
this.shop_basicshop = {
    {
"Fireball", "split_fireball", "split_fireball.png", "split_fireball_selected.png", 30}, 
    {
"Sword", "split_sword", "split_sword.png", "split_sword_selected.png", 20},
    {
"Bow", "split_bow", "split_bow.png", "split_bow_selected.png", 10}
  };
}

// Public method to retrieve the items for a specific shop
public function getShopItems(shop_id) {
  return 
this.("shop_" @ shop_id);
} 
then in your NPC:

PHP Code:
// other code..

function getShopItems() {
  return 
DB_Shops.getShopItems(this.shop_id);
}

function 
onPlayerTouchsMe() {
  
// You don't need to specify "gui", you can just use the weapon's name.
  
player.triggerclient("-shopcontrol", this.shop_id, getShopItems(), this.x, this.y);
} 
Then in your script you can just store the shop id, and display the items, and then trigger your DB-NPC, verify the purchase against the list of items for that shop, and allow the player to purchase the item.
__________________
Quote:
Reply With Quote