View Single Post
  #1  
Old 08-08-2011, 10:12 PM
Adddeeee Adddeeee is offline
Registered User
Join Date: Aug 2011
Posts: 30
Adddeeee is on a distinguished road
This is what we've got so far!

Although I'm interested in re-doing the shop with DB NPC's instead of putting all the item information in the shop class. Do you think that would be more efficient or is this a good solution? Don't really know how to set it all up using DB NPC's yet though.

PHP Code:
function onActionBuyItem(cmdselected)

  if(
cmd == "Buy")
  {
    for(
temp.itemthis.listofitems)
    {
      if(
temp.item[0] == selected)
      {
        if(
player.rupees temp.item[3])
        {
          
player.chat "Not enough rupees!";
        }
        else
        {
          
player.chat "Bought " temp.item[1] @ "!";
          
player.rupees player.rupees temp.item[3];
          
this.money this.money temp.item[3];
          
this.chat this.money;
          
player.addweapon(temp.item[2]);
        }
      }
    }
  }
}

function 
onCreated()
{
  
this.setShape(13232); 
  
this.listofitems = {{"Shop_Item_Fireball""Fireball""split_fireball"30}, 
                      {
"Shop_Item_Sword""Sword""split_sword"20},
                      {
"Shop_Item_Bow""Bow""split_bow"10}
                     };
}

//#CLIENTSIDE
function onPlayerTouchsMe()
{  
  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";
    }
        
    new 
GuiShowImgCtrl("Shop_Item_Fireball"
    {
      
20;
      
20;
      
width 32;
      
height 32;
      
      
this.imageselected "split_fireball_selected.png";
      
this.imagenotselected "split_fireball.png";
      
this.image this.imageselected;
      
thiso.catchevent(this.name"onMouseDown""onItemSelected");
    }
    
    new 
GuiShowImgCtrl("Shop_Item_Sword"
    {
      
Shop_Item_Fireball.Shop_Item_Fireball.width 20;
      
20;
      
width 32;
      
height 32;
      
      
this.imageselected "split_sword_selected.png";
      
this.imagenotselected "split_sword.png";
      
this.image this.imagenotselected;
      
thiso.catchevent(this.name"onMouseDown""onItemSelected");
    }
    
    new 
GuiShowImgCtrl("Shop_Item_Bow"
    {
      
Shop_Item_Sword.Shop_Item_Sword.width 20;
      
20;
      
width 32;
      
height 32;
      
      
this.imageselected "split_bow_selected.png";
      
this.imagenotselected "split_bow.png";
      
this.image this.imagenotselected;
      
thiso.catchevent(this.name"onMouseDown""onItemSelected");
    }
  }
  
Shop_Window.show();
  
this.listofitems = {Shop_Item_FireballShop_Item_SwordShop_Item_Bow};
  
this.itemselected this.listofitems[0].name;
}

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

function 
Shop_Button.onMouseDown()
{
  
triggeraction(this.0.5this.0.5"BuyItem""Buy"this.itemselected);
  
Shop_Window.makefirstresponder(true);
}

function 
onItemSelected(selected
{
  for(
tempi 0temp.this.listofitems.size();temp.++) 
  {
    
temp.item this.listofitems[i];
    
temp.item.image = (temp.item == selected temp.item.imageselected temp.item.imagenotselected);
  }
  
  
this.itemselected selected.name;

Reply With Quote