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.
Help with referencing weapon in Event Handler
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!)
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!)
-
- 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
You do not have the required permissions to view the files attached to this post.
-
- Posts: 1450
- Joined: Sun Jul 21, 2019 8:54 am
Re: Help with referencing weapon in Event Handler
Replace A_Overlay in your event handler with the following:
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.
Code: Select all
player.player.SetPSprite(500,weap.FindState("VisorLayer"));
For instance, players[e.Player] returns a player, while players[e.Player].mo returns a player actor.
Both have different uses.
-
- 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
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??
Is it possible to keep the Visor state from deselecting after weapon switch??
-
- Posts: 1450
- Joined: Sun Jul 21, 2019 8:54 am
Re: Help with referencing weapon in Event Handler
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:
You could try using CustomInventory items as they can have overlays, even if it might be a little hacky:
Spoiler:
-
- 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
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?
"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?
-
- Posts: 1450
- Joined: Sun Jul 21, 2019 8:54 am
Re: Help with referencing weapon in Event Handler
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:
If you want it to be toggle-able, you could modify the item to this:
Spoiler:
-
- 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
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!
Thank you so much for all your help on this, I appreciate it!

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