Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
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_idgetShopItems(), this.xthis.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
  #2  
Old 08-09-2011, 07:29 PM
Adddeeee Adddeeee is offline
Registered User
Join Date: Aug 2011
Posts: 30
Adddeeee is on a distinguished road
Thank you I tried something similar just now, but failed because I didn't make the function getItems in the DB NPC public. I suppose it has to be public?
Reply With Quote
  #3  
Old 08-09-2011, 07:37 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
Quote:
Originally Posted by Adddeeee View Post
Thank you I tried something similar just now, but failed because I didn't make the function getItems in the DB NPC public. I suppose it has to be public?
To call it from other scripts like in my class example, yes.
__________________
Quote:
Reply With Quote
  #4  
Old 08-09-2011, 08:27 PM
Adddeeee Adddeeee is offline
Registered User
Join Date: Aug 2011
Posts: 30
Adddeeee is on a distinguished road
Thank you very much! Now I think I understand the DB NPC

Although, I still have problems with the PlayerTouchsMe. It seems as if the player touches the NPC when the player is located to the top left of the NPC.

This is the NPC script:

PHP Code:
join("shop");

//#CLIENTSIDE

function onCreated()
{
  
showcharacter();
  
nick "Candy"//Sets the nickname of the character
  
ap 100//Sets the ap of the character. Also affects the colour of the nickname
  
headimg "head722.gif"//What head image to use
  
bodyimg "body8.png";   //What body image to use
  
colors[0] = "orange";     //Sets the skin colour
  
colors[1] = "lightblue";     //Sets the coat colour
  
colors[2] = "yellow";     //Sets the sleeves colour
  
colors[3] = "darkred";     //Sets the shoes colour
  
colors[4] = "lightgreen";     //Sets the belt colour
  
shieldimg "no-shield.gif"//Sets the shield image
  
shieldpower 1//Must have this or the shield won't show


and this is the shop class:

PHP Code:
function onCreated()
{
   
setShape(13232);
   
this.shop_id "basicshop";
}

function 
onPlayerTouchsMe()
{
  
this.listofitems DB_Items.getShopItems(this.shop_id);
  
triggerclient("gui""-shopcontrol"this.listofitemsthis.xthis.y);         

Am I missing something that causes the PlayerTouchsMe to fire when I'm located to the top left of the NPC?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:04 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.