Help trying to convert PickActor from an old ACS Script to ZScript

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!)
Post Reply
loydthebartender
Posts: 1
Joined: Mon Aug 05, 2024 5:25 pm

Help trying to convert PickActor from an old ACS Script to ZScript

Post by loydthebartender »

I'm trying to convert one of my old ACS Scripts to ZScript. Basically there's a custom keybinding that when a player presses it, the script grabs the actor in front of the players crosshair or in the area (using ACSs PickActor method) and if it's an actor of a certain type, something happens. Basically i'm looking for a Zscript equivalent to PickActor. I checked the docs, source code and this thread right here which I thought would have my answer:
viewtopic.php?t=55073&hilit=Zscript+A_P ... rt=240#top

Basically I'm creating a NetworkProcess for a custom keypress and if you are standing in front of a Sygil (custom Actor class), stuff happens. Here is the code I have tried to adapt from that thread

Code: Select all

	override void NetworkProcess(ConsoleEvent e) {
		if (e.Name == "pray") {
			double useDist = 64.f,
					vDist = 35.f;

			// Replacement for A_PickActor
			FTranslatedLineTarget t;
			players[0].mo.AimLineAttack(
				players[0].mo.Angle,
				useDist,
				t,
				vDist,
				ALF_FORCENOSMART | ALF_CHECKCONVERSATION | ALF_PORTALRESTRICT
			);

			bool isSygil = (t.linetarget!= null && t.linetarget is "Sygil");
			if(isSygil){
				// do stuff
			}
		}
	}
Problem is nothing happens. I'm not really sure where to start debugging either. I know it returns a double, but what of? What is linetarget exactly? How can I view what its returning, console.printf doesn't work becasue it can't be converted to a string. Obviously measuring it against a string won't work, but I'm kind of flying blind here.
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Help trying to convert PickActor from an old ACS Script to ZScript

Post by Player701 »

First, if this is a network event, why are you using players[0]? This will always cause the first player to perform the action regardless of who actually sends the event. You should probably use players[e.Player] instead.

Now, regarding the issue in question: I suspect your problem is likely that the actor you're trying to find with AimLineAttack is non-shootable. By default, this function only checks for shootable actors, but there is a flag called ALF_CHECKNONSHOOTABLE to override this behavior. Also, unless your "Sygil" actor has a dialogue attached to it, you don't need ALF_CHECKCONVERSATION.

Finally, the is operator already checks for null, so the t.linetarget!= null part is redundant.

You might also consider a somewhat easier way to implement this: make your actor usable by overriding Used, and put the "do stuff" part there:

Code: Select all

class Sygil : Actor
{
    ...
    
    override bool Used (Actor user)
    {
        // do stuff
        return true;
    }
}
Post Reply

Return to “Scripting”