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, 06:34 PM
Adddeeee Adddeeee is offline
Registered User
Join Date: Aug 2011
Posts: 30
Adddeeee is on a distinguished road
To start with I want to thank you all for your replies and good support We're closing in on the main goal!

We don't have a DB just yet, but we're close to it...I think!

This is what we've got so far:

Class shop
PHP Code:
function onCreated()
{
   
setShape(13232);
}

function 
onPlayerTouchsMe()
{
  
this.listofitems = {{"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}
                       };
                     
  
triggerclient("gui""-shopcontrol"this.listofitemsthis.xthis.y);
}

function 
onActionBuyItem()
{
   
this.chat "I received your request!";

Class shop serves as our temp DB. We will fix a DB to hold the information about the items. But for now it's just a class This class is joined to the NPC who is the shopkeeper. When a player touchs him/her it will send a triggerclient to the shopcontrol weapon:

Weapon -shopcontrol:

PHP Code:

//#CLIENTSIDE
function onActionClientSide(listofitemsnpcxnpcy)
{
  
this.npcx npcx;
  
this.npcy npcy;
  
this.listofitems listofitems;
  
  new 
GuiBitmapBorderCtrl("Shop_Window"
  {
    
this.profile GuiBitmapBorderProfile;
    
this.width screenwidth 2;
    
this.height screenheight 2;
    
this.screenwidth this.width 2;
    
this.screenheight this.height 2;
    
this.canmove false;
    
this.canresize false;
    
    new 
GuiButtonCtrl("Shop_Button")
    {
      
width 100;
      
height 40;
      
Shop_Window.width this.width 2;    
      
Shop_Window.height this.height 10;
      
text "Buy";
    } 
  }
  
  for(
0this.listofitems.size(); i++)
  {
    new 
GuiShowImgCtrl("Shop_Item_" thiso.listofitems[i][0]) 
    {
      
20 20 32;
      
20;
      
width 32;
      
height 32;
    
      
this.imageselected thiso.listofitems[i][3];
      
this.imagenotselected thiso.listofitems[i][2];
      
this.image this.imagenotselected;
      
thiso.catchevent(this.name"onMouseDown""onItemSelected");
    }
    
Shop_Window.addControl("Shop_Item_" thiso.listofitems[i][0]);
  }
 
  
Shop_Window.show();
}

function 
onMouseDown()
{
  if(!((
mousescreenx in |Shop_Window.xShop_Window.Shop_Window.width|)
      &&(
mousescreeny in |Shop_Window.yShop_Window.Shop_Window.height|)))
  {
    
Shop_Window.destroy();
  }
}

function 
Shop_Button.onMouseDown()
{
  
triggeraction(this.npcx 0.5this.npcy 0.5"BuyItem""Buy"this.itemselected.substring("Shop_Item_".length()));
  
Shop_Window.makefirstresponder(true);
}

function 
onItemSelected(selected
{
  for(
1Shop_Window.controls.size(); ++)
  {
    
temp.control Shop_Window.controls[i];
    
temp.control.image = (temp.control == selected temp.control.imageselected temp.control.imagenotselected);
  }

  
this.itemselected selected.name;

The shopcontrol weapon is basically just a gui interface which shows all the possible items to buy.

This is where the trouble starts. When I'm about to send the chosen item back to the npc something goes wrong. It seems like the triggeraction doesn't really do what I thought it would do. I thought it would trigger the npc closest to the coordinates given in the triggeraction (x, y, ...). But maybe I'm doing it all wrong?

Also, it seems as if the NPC's shape is out of synch. The player touches it when the player is positioned at the top left tile of the NPC. Maybe there's something I've done with setshape that doesn't work?

Thank you

EDIT: I managed to get the data back to the NPC! So there's no problem with the triggeraction(npcx, npcy, ...) command But the NPC PlayerTouchsMe is still troubeling us.

EDIT2: As stated above I managed to get the triggerserver and trigger client between the NPC and the weapon to work. I have now created a DB NPC named DB_Items:

PHP Code:
function onInitialized()
{
  
onCreated();
}

function 
onCreated()
{
  
/*
    Format:
    this.item_id = {Name, WeaponName, Image, ImageWhenSelected, Price};
   */

  
this.lisofitems = {{"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}
                    };


function 
getItems()
{
  return 
this.listofitems();

Is that a proper way of scripting the DB NPC? Or do I have to trigger the DB NPC and then trigger back to the level NPC in order to get the information the DB holds?

Last edited by Adddeeee; 08-09-2011 at 07:05 PM..
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 06:50 PM.


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