Quote:
Originally Posted by cbkbud
PHP Code:
new GuiShowImgCtrl( "InvItem_0" )
{
image = "x.png";
width = 32;
height = 32;
x = 10;
y = 10;
this.itemName = "Guns/KABOOM!!!111!!";
thiso.catchevent( name, "onMouseDown", "onItemSelected" );
}
and later something like this:
PHP Code:
function onItemSelected( obj )
{
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;
x = 10;
y = 10;
this.itemName = "Guns/KABOOM!!!111!!";
}
}
function onItemSelected(obj) {
for(temp.i=0; i < player.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

.