View Single Post
  #18  
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(cmd, selected)
{ 
  if(
cmd == "Buy")
  {
    for(
temp.item: this.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(1, 32, 32); 
  
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.x = screenwidth / 2 - this.width / 2;
    
this.y = screenheight / 2 - this.height / 2;
    
this.canmove = false;
    
this.canresize = false;
    
    new 
GuiButtonCtrl("Shop_Button")
    {
      
width = 100;
      
height = 40;
      
x = Shop_Window.width / 2 - this.width / 2;    
      
y = Shop_Window.height - this.height - 10;
      
text = "Buy";
    }
        
    new 
GuiShowImgCtrl("Shop_Item_Fireball") 
    {
      
x = 20;
      
y = 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") 
    {
      
x = Shop_Item_Fireball.x + Shop_Item_Fireball.width + 20;
      
y = 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") 
    {
      
x = Shop_Item_Sword.x + Shop_Item_Sword.width + 20;
      
y = 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_Fireball, Shop_Item_Sword, Shop_Item_Bow};
  
this.itemselected = this.listofitems[0].name;
}

function 
onMouseDown()
{
  if(!((
mousescreenx in |Shop_Window.x, Shop_Window.x + Shop_Window.width|)
      &&(
mousescreeny in |Shop_Window.y, Shop_Window.y + Shop_Window.height|)))
  {
    
Shop_Window.hide();
  }
}

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

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