View Single Post
  #14  
Old 05-12-2008, 11:26 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Quote:
Originally Posted by cbkbud View Post
PHP Code:
new GuiShowImgCtrl"InvItem_0" )
{
  
image "x.png";
  
width 32;
  
height 32;
  
10;
  
10;
  
  
this.itemName "Guns/KABOOM!!!111!!";
  
thiso.catcheventname"onMouseDown""onItemSelected" );

and later something like this:

PHP Code:
function onItemSelectedobj )
{
    for(
temp.i=0;temp.i<player.weapons.size();temp.i++;)
    {
      if(
player.weapons[temp.i].name == obj.itemName)
      {
        
player.selectedweapon temp.i;
        return;
      }
    }

I believe that will work.
Another way to do that would be like:

PHP Code:
function onCreated() {
  
catchevent(InvItem_0"onMouseDown""onItemSelected");

  new 
GuiShowImgCtrl"InvItem_0" ) {
    
image "x.png";
    
width 32;
    
height 32;
    
10;
    
10;
    
this.itemName "Guns/KABOOM!!!111!!";
  }
}

function 
onItemSelected(obj) {
  for(
temp.i=0player.weapons.size(); ++i) {
    if (
player.weapons[i].name == obj.itemName) {
      
player.selectedweapon i;
      break;
    }
  }

Basically, catchevent can be called outside of the object (the object that actually gets the "catchevent" call is most likely going to be the WNPC that you are in which is why Chris used thiso.), the first parameter is the object that you are catching and it can be called before the object is even created .
__________________
Do it with a DON!
Reply With Quote