how to remove actor spawned by eventhandler

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
ramon.dexter
Posts: 1241
Joined: Tue Oct 20, 2015 12:50 pm
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

how to remove actor spawned by eventhandler

Post by ramon.dexter »

So, how do I remove/destroy an actor, spawned by eventhandler? I'm using the zscript footsteps solution by Da_Zombie_Killer and vsonnier. Works great, but I found out that it causes bugs in hub based maps. When I start in map01, then go to map02, everything's fine. But when I return to map01, the footsteps sound is doubled. I think it's because the eventhandler attaches the soundactor twice, first when player first enters the first map, and second when returns to first map. I wanted to fix this, but since it's not a inventory item, but an attached actor, I don't know how to remove it when player left map.

The footsteps actor is attached to player in eventhandler:

Code: Select all

override void PlayerEntered(PlayerEvent e) {
		let player = PlayerPawn(players[e.PlayerNumber].mo);
		//BEGIN VSO : Some Wads crash here with VM Abort because player can be NULL
		if (player == NULL) {
			return;
		}
		//END VSO
        //VSO: Attach footsteps to player:
		Footsteps fsteps = Footsteps(Actor.Spawn("Footsteps",player.pos));
        fsteps.Init(player);
	}
I assume the action 'player leaves map' is handled by 'PlayerDisconnected(PlayerEvent e)'. So I did:

Code: Select all

override void PlayerDisconnected(PlayerEvent e) {
		Footsteps fsteps = footsteps(Actor.Destroy());
	}
But gzdoom tells me:

Code: Select all

Script error, "D:/DOOM/WoS/WoS-Base/:zscript/woshandler.zs" line 160:
Cannot call non-static function Actor::Destroy from here

So, how do I remove/destroy the 'footsteps' actor? I just don't know how to refer the footsteps actor and ho to define the destroy() thing... Or if there is some better solution that is oblivious to me... Would someone help?

edit:
Oh, and the overall footsteps code is here:
Spoiler:
JaedenDuhreis
Posts: 8
Joined: Sun Jan 02, 2022 7:19 am

Re: how to remove actor spawned by eventhandler

Post by JaedenDuhreis »

I would suggest not destroying the actor; instead disable spawning another one when you return to the map, by checking e.IsReturn in the PlayerEntered event.

Code: Select all

override void PlayerEntered(PlayerEvent e) {
      let player = PlayerPawn(players[e.PlayerNumber].mo);
      //BEGIN VSO : Some Wads crash here with VM Abort because player can be NULL
      if (player == NULL) {
         return;
      }
      //END VSO
        //VSO: Attach footsteps to player:

      if (e.IsReturn) return;

      Footsteps fsteps = Footsteps(Actor.Spawn("Footsteps",player.pos));
        fsteps.Init(player);
   }
User avatar
ramon.dexter
Posts: 1241
Joined: Tue Oct 20, 2015 12:50 pm
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: how to remove actor spawned by eventhandler

Post by ramon.dexter »

JaedenDuhreis wrote:

Code: Select all


      if (e.IsReturn) return;

Yep, that does the trick.Many thanks, JaedenDuhreis ;)

Return to “Scripting”