How do I get velocity in 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
Kzer-Za
Posts: 509
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

How do I get velocity in zscript?

Post by Kzer-Za »

I'm trying to recreate the Iron Lich's fire column attack. I got it mostly working, but I need to coordinate the velocity of the first projectile and those spawned from it, and for some reason GetActorVelX/Y/Z is causing errors. As I said, the rest of the code works, if I do without the variables for velocity and just use "10,0,0" for xvel, yvel, zvel of the spawned units. The problem piece of the code is this:

Code: Select all

	Spawn:
		FRFX AAAA 1 Bright
			{
				A_SpawnItemEx("PillarFireTrail",0,0,0,0,0,0,0, SXF_NOCHECKPOSITION | SXF_TRANSFERPOINTERS);
				A_SpawnItemEx("RedFlareMedium",0,0,3,0,0,0,0,SXF_NOCHECKPOSITION);
				PillarUnitVelX = GetActorVelX(0);
				PillarUnitVelY = GetActorVelY(0);
				PillarUnitVelZ = GetActorVelZ(0);
			}
GZDoom engine outputs this:

Code: Select all

Script error, ":zscript.proj_mon_lich" line 110:
Call to unknown function 'GetActorVelX'
Script error, ":zscript.proj_mon_lich" line 111:
Call to unknown function 'GetActorVelY'
Script error, ":zscript.proj_mon_lich" line 112:
Call to unknown function 'GetActorVelZ'
The full code of the projectile, if it's needed:

Code: Select all

Class FirePillarBase : BrutalWereDragonBall
{
	int PillarUnits;
	int PillarUnitZoffs;
	int PillarUnitVelX;
	int PillarUnitVelY;
	int PillarUnitVelZ;
	Array<Actor> hitList;
	
	override void PostBeginPlay()
	{
		// A_PrintBold("Pillar base");
		PillarUnits = 4;
		PillarUnitZoffs = -10;
		PillarUnitVelX = 0;
		PillarUnitVelY = 0;
		PillarUnitVelZ = 0;
		Super.PostBeginPlay();
	}
	
	override int SpecialMissileHit (Actor victim)
	{
		if (victim == target)
			return 1;
		if (victim.GetSpecies() == target.GetSpecies())
			return 1;
		if (hitList.Find (victim) == hitList.Size())
		{
			victim.DamageMobj (self, target, 5, 'Fire');
			hitlist.Push (victim);
		}
		A_PlaySound("world/lavasizzle", CHAN_AUTO);
		return 1;
	}
Default
{
	+DONTSPLASH;
	Radius 15;
	Height 22;
	Scale 2.5;
	Speed 10;
	SeeSound "";
	DeathSound "world/lavasizzle";
	Obituary "";
}
	States
	{
	Spawn:
		FRFX AAAA 1 Bright
			{
				A_SpawnItemEx("PillarFireTrail",0,0,0,0,0,0,0, SXF_NOCHECKPOSITION | SXF_TRANSFERPOINTERS);
				A_SpawnItemEx("RedFlareMedium",0,0,3,0,0,0,0,SXF_NOCHECKPOSITION);
				PillarUnitVelX = GetActorVelX(0);
				PillarUnitVelY = GetActorVelY(0);
				PillarUnitVelZ = GetActorVelZ(0);
			}
	Grow:
		FRFX AAAAAA 1 Bright
			{
				A_SpawnItemEx("PillarFireTrail",0,0,0,0,0,0,0, SXF_NOCHECKPOSITION | SXF_TRANSFERPOINTERS);
				A_SpawnItemEx("RedFlareMedium",0,0,3,0,0,0,0,SXF_NOCHECKPOSITION);
			}
		// Spawn units up
		TNT1 A 0
		{
			if(PillarUnits > 0)
				{
				PillarUnits--;
				PillarUnitZoffs = PillarUnitZoffs + 20;
				A_SpawnItemEx("FirePillarUnit", -10,0,PillarUnitZoffs, PillarUnitVelX,PillarUnitVelY,PillarUnitVelZ, 0, SXF_NOCHECKPOSITION | SXF_TRANSFERPOINTERS);
				}
		}
		Loop;
	Death:
		TNT1 A 0 A_SetScale(0.2);
		FIR3 ABCDEFGHIJKLMNOP 1 Bright A_SpawnItem("RedFlareMedium");
		Stop;
	}
}
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: How do I get velocity in zscript?

Post by Arctangent »

Well, for one, the GetActorVel functions aren't valid in either Decorate or ZScript. They're exclusively for ACS, mostly because they're completely pointless in the other two due to the fact that they have access to the data more directly.

Specifically, ZScript can directly access an actor's vel Vector3, while Decorate abstracts it into three variables ( velx, vely, and velz ) due to not having vector support. You can access a vector's values through their x, y, and z variables, i.e. vel.x, vel.y, and vel.z.

You'll find that an actor's position is stored similarly, with the pos Vector3.
Kzer-Za
Posts: 509
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: How do I get velocity in zscript?

Post by Kzer-Za »

Thanks!
Post Reply

Return to “Scripting”