I would place the GUI display and action script within a weapon, have the NPC call a function to that weapon passing itself as a parameter, then store that reference within the GUI object, and refer to it upon the action.
Weapon:
PHP Code:
function onCreated(){
SomeWeaponReference = this;
}
public function displayBuyHat(temp.owner){
new GUIControl(BuyHat_Buy){
this.owner = temp.owner;
}
}
function BuyHat_Buy.onAction(){
BuyHat_Buy.owner.buyHatPressed();
BuyHat_Buy.destroy();
}
NPC:
PHP Code:
function onPlayerTouchsMe(){
SomeWeaponReference.displayBuyHat(this);
}
public function buyHatPressed(){
triggeraction(stuff);
}