Jump to content

[RESOLVED] Get target, check if superclass & get superclass fields


Recommended Posts

Posted (edited)

I have a pretty basic logic that I'm struggling to implement in either ZScript or ACS.  I've sunk about 6 solid hours of searching through forums, existing mods, and the wiki.  Here's what I'd like to do:

 

1) get the player's current target

2) check whether the target's class extends from a particular superclass

3) If it IS an instance of the superclass, pull 2 fields from it which are defined in that superclass.

 

In ACS, I can accomplish step 1 (sort of) with SetActivatorToTarget(playerTid).  But step 2 seems out of reach, and for step 3, I've only found GetActorProperty, which helps with generic properties like "health", but not custom ones.

 

Meanwhile, in ZScript, the "is" keyword makes step 2 simple, and an answer to step 3 seems likely, but I can't find anything to help with step 1.

 

I feel like I've exhausted my research options for this.  If anyone can provide some insight, I'd be very grateful.

Edited by violgamba

Share this post


Link to post

In ZScript:

 

1) You can use AimTarget or AimLineAttack to get what the player is aiming at (or manually do a hitscan check through LineTrace).

2)3) You can use "is" keyword, but if you want to pull fields from a class, it is better to cast a pointer to the superclass and check if the casted pointer is valid.

 

Assuming "pl" is pointer to the player, "Superclass" is class name of the superclass, this code should access fields if the aiming target is extended from the superclass (or is the superclass itself):

Actor tgt = pl.AimTarget();
let casted = Superclass(tgt);
if (casted)
{
	casted.field1 = ...
	int result = casted.field2;
}

 

(untested)

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...