Help with referencing weapon in Event Handler

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
JMaszk
Posts: 8
Joined: Sun Oct 30, 2022 2:01 pm
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Help with referencing weapon in Event Handler

Post by JMaszk »

I've been trying to reference the player's weapon through event handler with no success. What I'm trying to do is a weapon overlay via event handler for a key bind. I think I'm doing everything else right besides the reference to the weapon because it still prints out my test message but A_Overlay does nothing. I'm not sure what I'm doing wrong.

Attached file has a testable example, thanks.
You do not have the required permissions to view the files attached to this post.
Jarewill
Posts: 1422
Joined: Sun Jul 21, 2019 8:54 am

Re: Help with referencing weapon in Event Handler

Post by Jarewill »

Replace A_Overlay in your event handler with the following:

Code: Select all

player.player.SetPSprite(500,weap.FindState("VisorLayer"));
player.player is required as the player actor needs to be interpreted as a player instead of just as an actor.

For instance, players[e.Player] returns a player, while players[e.Player].mo returns a player actor.
Both have different uses.
User avatar
JMaszk
Posts: 8
Joined: Sun Oct 30, 2022 2:01 pm
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Re: Help with referencing weapon in Event Handler

Post by JMaszk »

Ahh yes! That was it, thank you. I'll also keep those differences in mind in the future.

Is it possible to keep the Visor state from deselecting after weapon switch??
Jarewill
Posts: 1422
Joined: Sun Jul 21, 2019 8:54 am

Re: Help with referencing weapon in Event Handler

Post by Jarewill »

As the weapon gets deselected, all of its overlays get cleared, so you will need to work around that.
You could try using CustomInventory items as they can have overlays, even if it might be a little hacky:
Spoiler:
User avatar
JMaszk
Posts: 8
Joined: Sun Oct 30, 2022 2:01 pm
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Re: Help with referencing weapon in Event Handler

Post by JMaszk »

CustomInventory should be ok. I just read on the Wiki:
"This class is unnecessary in ZScript outside of very specific use cases, like overlays."

Neat, I didn't know you could have overlays outside of weapons. The only issue now is I had weapons in mind because I wanted to be able to select and deselect the overlay. I'm not sure if that's possible through the CustomInventory method?
Jarewill
Posts: 1422
Joined: Sun Jul 21, 2019 8:54 am

Re: Help with referencing weapon in Event Handler

Post by Jarewill »

What exactly do you mean by "select and deselect the overlay"?
If you want it to be toggle-able, you could modify the item to this:
Spoiler:
User avatar
JMaszk
Posts: 8
Joined: Sun Oct 30, 2022 2:01 pm
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Re: Help with referencing weapon in Event Handler

Post by JMaszk »

Yeah, that's even better than what I was thinking initially! I realize how obvious the toggle was... I don't know why I didn't think of that! :lol:

Thank you so much for all your help on this, I appreciate it!

Return to “Scripting”