Check if an actor exists?

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.

Check if an actor exists?

Postby Enjay » Mon Oct 11, 2021 7:04 am

I can see a few threads on this topic, but I can't find anything that definitively answers the question.

Is there a way in ACS to check if an actor actually exists and then only do stuff if the actor is actually real?

Specifically, I'm looking to manipulate the player's inventory and, depending on which mods are loaded, I want it to do different things. However, if mods are not loaded, then certain actors won't even exist as far as the game is concerned, so I don't want to perform operations on non-existant actors.

Code: Select allExpand view
if (CheckActorExists("CoolHealthItem") == 1)
      {
            SetHUDSize (640, 480, 0);
            HUDMessageBold (s:"You look like you could use this.";
                  HUDMSG_PLAIN, 44, CR_GREEN, 320.4, 340.0, 3.0);      
            GiveInventory ("CoolHealthItem", 1);
      }
else
      {
            SetHUDSize (640, 480, 0);
            HUDMessageBold (s:"Here, let me patch you up a bit.";
                  HUDMSG_PLAIN, 44, CR_GREEN, 320.4, 340.0, 3.0);      
            HealThing(20);
      }

or something like that.

Possible?
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
 
 
Joined: 15 Jul 2003
Location: Scotland

Re: Check if an actor exists?

Postby Blue Shadow » Mon Oct 11, 2021 7:44 am

Last edited by Blue Shadow on Mon Oct 11, 2021 8:50 pm, edited 1 time in total.
User avatar
Blue Shadow
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: Check if an actor exists?

Postby Enjay » Mon Oct 11, 2021 8:21 am

Works perfectly, thank you. :)

[edit] And example added to the Wiki https://zdoom.org/wiki/CheckClass_(ACS) [/edit]
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
 
 
Joined: 15 Jul 2003
Location: Scotland


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests