How to change actor's scale on the fly?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

How to change actor's scale on the fly?

Post by ramon.dexter »

So, BlueShadow helped me with setting damage on the fly. I tried using the same method for setting scale on the fly, but gzdoom returns error "call to unknown function getScale()", but, the function IS defined in the class. So I clearly don't understand this error. How should I do that so gzdoom works?
I have to note that the 'getPwrupDamage()' is recognized and works, so I don't understand why the 'getScale()' is ignored.

Here is the projectile code:

Code: Select all


class shadowGunPoweredupProjectile : FastProjectile
{
	int getScale()
	{
		int scl = 0.8;
		if(target && target.CountInv("pwrLevel") == 8)
		{
			scl = 0.8;
		}
		if(target && target.CountInv("pwrLevel") == 7)
		{
			scl = 0.8;
		}
		if(target && target.CountInv("pwrLevel") == 6)
		{
			scl = 0.6;
		}
		if(target && target.CountInv("pwrLevel") == 5)
		{
			scl = 0.6;
		}
		if(target && target.CountInv("pwrLevel") == 4)
		{
			scl = 0.4;
		}
		if(target && target.CountInv("pwrLevel") == 3)
		{
			scl = 0.4;
		}
		if(target && target.CountInv("pwrLevel") == 2)
		{
			scl = 0.2;
		}
		if(target && target.CountInv("pwrLevel") == 1)
		{
			scl = 0.2;
		}
		return scl;
	}
	
	int getPwrupDamage()
	{
		int dmg = 16; //base damage, when player is on level 0 & level 1
		if(target && target.CountInv("pwrLevel") == 8)
		{
			dmg = 72;
		}
		else if(target && target.CountInv("pwrLevel") == 7)
		{
			dmg = 64;
		}
		else if(target && target.CountInv("pwrLevel") == 6)
		{
			dmg = 56;
		}
		else if(target && target.CountInv("pwrLevel") == 5)
		{
			dmg = 48;
		}
		else if(target && target.CountInv("pwrLevel") == 4)
		{
			dmg = 40;
		}
		else if(target && target.CountInv("pwrLevel") == 3)
		{
			dmg = 32;
		}
		else if(target && target.CountInv("pwrLevel") == 2)
		{
			dmg = 24;
		}
		else if(target && target.CountInv("pwrLevel") == 1)
		{
			dmg = 16;
		}
		return dmg;
	}
	
	Default
    {
        +RANDOMIZE
        +FORCEXYBILLBOARD
        +BLOODSPLATTER
		+SpawnSoundsource
		+NoExtremeDeath
		
        Projectile;
		DamageType "Extreme";
        Radius 2;
        Height 2;
        Speed 184;
        DamageFunction (getPwrupDamage() * random(1, 6));
        Decal "redShotScorch";
        Renderstyle "Add";
        Alpha 0.90;
        Scale (getScale());        
        MissileType "WCPRJ_TrailSpawner";
        MissileHeight 8;        
		SeeSound "weapons/shdwgnPRJ";
		DeathSound "weapons/shdwgnPRJD";
    }
	
	States
	{
        Spawn:
            SKPR ABCB 1 Bright A_SpawnItem("WCPRJ_Flare",0,0); //FX99 AA 1
            SKPR ABCB 1 Bright A_SpawnItem("WCPRJ_Flare",0,0); //FX99 AA 1
            Loop;
        Death:
            TNT1 A 0;
            TNT1 AAAAAAAAAAAAAAAAAAAAA 0 A_SpawnItemEx("WCPRJ_Particle2",0,0,0,frandom(-6,6),frandom(-6,6),frandom(-6,6),0,SXF_NOCHECKPOSITION);
			TNT1 A 0 A_SpawnItemEx("WCPRJ_Flash", 0, 0, 0, 0);				
			TNT1 A 0 A_SpawnItemEx("WCPRJ_Explosion", 0, 0, 0, 0);
			TNT1 A 0 A_SpawnItemEx("WCPRJ_shotDeath", 0, 0, 0, 0);
			//TNT1 A 0 A_SpawnItemEx("WCPRJ_shotDeath2", 0, 0, 0, 0);
            TNT1 A 2 Light("WRSTCANNONDEATHLIGHT2");
            TNT1 A 2 Light("WRSTCANNONDEATHLIGHT3");
            TNT1 A 2 Light("WRSTCANNONDEATHLIGHT4");
            TNT1 A 2 Light("WRSTCANNONDEATHLIGHT5");
            Stop;
	}
}
Blue Shadow
Posts: 5046
Joined: Sun Nov 14, 2010 12:59 am

Re: How to change actor's scale on the fly?

Post by Blue Shadow »

DamageFunction is a special case. You'll want to change the actor's scale somewhere else, maybe in a PostBeginPlay() override.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: How to change actor's scale on the fly?

Post by Matt »

You can change the actor's scale anytime, e.g.:

Code: Select all

scale=(-1.1,1.1); 
which would make the thing 10% bigger on each dimension and flipped horizontally.

Or you can use the scale as a variable:

Code: Select all

tracer.damagemobj(self,target,100*scale.y,... //inflict damage multiplied by Y scale  

Code: Select all

scale*=0.9; //reduce scale to 90% of whatever it was before  
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: How to change actor's scale on the fly?

Post by ramon.dexter »

Oh, that's cool :) Many thanks!

Return to “Scripting”