Activating script with an inventory item

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Activating script with an inventory item

Post by cocka »

Hello!

Is there a way to activate a script when I press enter on an inventory item?

Thanks for your reply.
User avatar
ChronoSeth
Posts: 1631
Joined: Mon Jul 05, 2010 2:04 pm
Location: British Columbia

Re: Activating script with an inventory item

Post by ChronoSeth »

First thing that comes to mind is calling [wiki]ACS_Execute[/wiki] or similar from a [wiki]CustomInventory[/wiki] item (it's usually easy to emulate the effects of a "normal" inventory item, so don't worry about that).
User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Re: Activating script with an inventory item

Post by cocka »

Thanks, but I'm not really familiar with decorate. :?
User avatar
Enjay
 
 
Posts: 27684
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: Activating script with an inventory item

Post by Enjay »

I don't know how good an example it is but here's what I did for the portable night vision goggles in my Burghead mod:

Code: Select all

ACTOR NJInfraRed2 : CustomInventory 22067
{
   Tag "Night Vision Goggles"
   Inventory.PickupMessage "Picked night vision goggles."
   inventory.maxamount 1
   inventory.icon ARTIGOGG
   inventory.usesound "misc/infrared"
   Mass 5
   +INVBAR
   +Floorclip
   Scale 0.5
   States
   {
     Spawn:
     PNVG AABB 4 Bright
     LOOP
     Use:
     TNT1 A 1 ACS_Execute (500, 0, 0, 0, 0) 
     Stop
   }
  }
User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Re: Activating script with an inventory item

Post by cocka »

I don't want to create new ones, just reuse the inventory items from Hexen. Perhaps it can be solved by using inheritance. Or I don't know.

And what if you just want to use this activation in one place in a map? So there is a place on the map where if you use the inventory item, it will activate a script, but if you are elsewhere, it won't.
User avatar
BloodyAcid
Posts: 372
Joined: Thu Jul 26, 2012 10:28 pm
Location: Canadia

Re: Activating script with an inventory item

Post by BloodyAcid »

Tag the sectors and use the script to run a check on whether or not you're there. I think that works.
User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Re: Activating script with an inventory item

Post by cocka »

I think it's easier to use thing executed specials such as: actor enters/leaves sector. OK, but if I use the CustomInventory decorate, how will I be able to remove the script execution from the inventory item or prevent the script being executed in other situations?
Blue Shadow
Posts: 5046
Joined: Sun Nov 14, 2010 12:59 am

Re: Activating script with an inventory item

Post by Blue Shadow »

User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Re: Activating script with an inventory item

Post by cocka »

Thank you very much. I understand the acs script quite well, but the decorate is a bit obscure for me. Why should be placed the Fail at the end of Use state? :?

If you learn the decorate, is it absolutely necessary to learn the parent actors' properties, states, flags and functions? I mean this one:

http://zdoom.org/wiki/Classes:Inventory
User avatar
Nightfall
Posts: 555
Joined: Thu Aug 06, 2009 4:00 am
Location: Finland

Re: Activating script with an inventory item

Post by Nightfall »

cocka wrote:If you learn the decorate, is it absolutely necessary to learn the parent actors' properties, states, flags and functions?
Learning is overrated. Just open up the reference when you need something. :P
User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Re: Activating script with an inventory item

Post by cocka »

OK, new problems arise with this decorate stuff. There would be two puzzle items on the map which would activate the script. So I think I cannot use Use state because zdoom gives me error.

I would like something similar to UsePuzzleItem, but with more than one item. For example: I use this special on a bishop. (Hexen) If I give him the blue gem by pressing enter on the blue gem in the inventory, he'll give me another inventory item. If I give him the green gem, he'll give me another item.

UsePuzzleItem won't let me use more than one puzzle item on the same bishop. :?
User avatar
BloodyAcid
Posts: 372
Joined: Thu Jul 26, 2012 10:28 pm
Location: Canadia

Re: Activating script with an inventory item

Post by BloodyAcid »

Make the bishop an object that can be activated. Then make him run a script to check for the appropriate gem colour and give the right item.
User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Re: Activating script with an inventory item

Post by cocka »

Make the bishop an object that can be activated
What do you mean by that? Do I have to use the Active-Inactive actor states or just give a script to the bishop? Or did you think of +USESPECIAL flag?
Blue Shadow
Posts: 5046
Joined: Sun Nov 14, 2010 12:59 am

Re: Activating script with an inventory item

Post by Blue Shadow »

cocka wrote:Why should be placed the Fail at the end of Use state?
The Fail keyword there will prevent the item from being removed from the player's inventory whenever the player uses it, since the script itself controls whether the item is removed or not upon execution.
User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Re: Activating script with an inventory item

Post by cocka »

Oh, I see now.

The only question is how you can apply your CustomInventory item if it is about a puzzle item?

Here is my decorate script for the modified gem:

Code: Select all

ACTOR kekgem : PuzzleItem 12000
{
  Game Hexen
  SpawnID 81
  PuzzleItem.Number 5
  Inventory.Icon ARTIGEMB
  Inventory.PickupMessage "$TXT_ARTIPUZZGEMBLUE1" // "SAPPHIRE PLANET"
  States
  {
  Spawn:
    AGMB A -1
    Stop
  Use:
	TNT1 A 0 ACS_Execute(5, 0, 1, 0, 0)
	Fail
  }
}
If I press enter on the item the program says "you cannot use this here" and completely ignores the Use state. If I write CustomInventory 12000 instead of PuzzleItem 12000 then program says:
Script error, "Forest2.wad:DECORATE" line 10:
Unexpected '5' in definition of 'kekgem'
This refers to the line: PuzzleItem.Number 5. So I don't know what's wrong with it. Hmm, but if I write this: +INVENTORY.INVBAR instead of PuzzleItem.Number 5 then it will work.

Return to “Editing (Archive)”