[Solved] Taking a weapon away doesn't play Deselect state!

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.
Locked
User avatar
Nash
 
 
Posts: 17439
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

[Solved] Taking a weapon away doesn't play Deselect state!

Post by Nash »

Okay DECORATE weapon gods, I need your help. When a weapon is taken away, it seems that the Deselect state is not played... the PSprite just disappears instantly. Is there any way to force the Deselect state to play when taking a weapon away?

(The weapon being taken away is scripted to happen via a keybind. Think of the Fallout / Elder Scrolls system of pressing R to toggle between readying the weapon and holstering it... holstering in my case is to just take the weapon away from the player)
Last edited by Nash on Tue Sep 19, 2017 12:03 am, edited 1 time in total.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Taking a waepon away doesn't play the Deselect state!

Post by Matt »

One thing I've been wondering is if it's possible to call AttachToOwner inside DetachFromOwner (subject to some conditions) to force a weapon back onto the player so that it can do some stuff before finally detaching itself properly (with those conditions marked as fulfilled).

Conversely, would it be possible for DetachFromOwner to just set an overlay on the player?


But why do you want to take away the weapon in this particular situation, though, instead of just selecting something else?


(One workaround that I know works for sure: select some other weapon, then have that other weapon take away the first weapon in its select state.)
User avatar
Voros
Posts: 151
Joined: Fri Feb 03, 2017 11:47 pm

Re: Taking a waepon away doesn't play the Deselect state!

Post by Voros »

When changing weapons, it always jumps to the Deselect state by default. I don't see why it wouldn't now.

Did you write up anything specific/not-normal code? Eg using the Select state to play a "readying" animation, using AltFire as a reloading mechanism, etc.

Edit: nvm, I thought you were talking about something else.
User avatar
Nash
 
 
Posts: 17439
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: Taking a waepon away doesn't play the Deselect state!

Post by Nash »

Solved. It's very hard to go into details because my implementation is very abstracted (I am not using Inventory and Weapons in the way most people do here) but I solved the problem by deferring the weapon's Destroy() to after the Deselect animation has finished.

This required me checking for the PSprite's Y coordinate.

To answer Vaecrius' question on why I am Destroy()ing the weapon - the "Weapon" in this sense is merely a pawn. The actual item book keeping is done from a completely custom LADItem class I made, and the Weapon that's given to the player is a mere representation (It contains a pointer to a particular instance of LADItem).

Weapon slots in my project don't work the same way as Doom... the slots 1 to 8 are "hotkeyed" LADItems so it's kind of clumsy to allow Weapon instances on the player. I might as well just Destroy them all and manage them manually.

(again, it's an Elder Scrolls/Fallout-like weapon and inventory management system)

Anyway, everything works now. Thanks!
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [Solved] Taking a weapon away doesn't play Deselect stat

Post by Graf Zahl »

Nash wrote:Okay DECORATE weapon gods, I need your help. When a weapon is taken away, it seems that the Deselect state is not played...

Think abou it. To play the deselect state your player needs to own the weapon. If you take it away there's nothing left to play in the player's inventory.
User avatar
Nash
 
 
Posts: 17439
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: [Solved] Taking a weapon away doesn't play Deselect stat

Post by Nash »

Graf Zahl wrote:
Nash wrote:Okay DECORATE weapon gods, I need your help. When a weapon is taken away, it seems that the Deselect state is not played...

Think abou it. To play the deselect state your player needs to own the weapon. If you take it away there's nothing left to play in the player's inventory.
Yeah, it dawned on me (basically telling myself "duuhhhh no shit Sherlock!") when I thought the better way is to play the Deselect animation first before destroying it. =P
Locked

Return to “Editing (Archive)”