[People helped]Strange Invulnerability "Leaking"

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
User avatar
Xane123
Posts: 165
Joined: Tue Nov 24, 2015 1:58 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Inwood, WV
Contact:

[People helped]Strange Invulnerability "Leaking"

Post by Xane123 »

In my game, Mary's Magical Adventure, you can transform into an invulnerable super form, but I've noticed something odd; My character is supposed to be invulnerable (as I use SetPlayerProperty to enable it upon transformation), but occasionally, a hit from an enemy somehow hurts me. It happens more often if I wait a bit then get hit by an enemy. This isn't a suit, which in Doom had leaking for sector damage (and this is enemy damage, not that).

I modify my game's version of the source code to remove things I don't like, but I'm not sure where to look or what to change to remove this random "leaking" of enemy attacks through invulnerability. I know that stupidly telefrags bypass invulnerability, but none of these attacks go over that threshold. Additionally, no enemies use the FOILINVUL (or whatever) flag. If I never find it, I'll just make the game cheaply give back any damage done while super, as this is very illogical behavior. :roll:

This short video talks about and shows this oddity. I'm not sure if it's a "bug" (though it feels like it is), but in case this unwanted behavior is a bug, it occurs in the latest dev build from DRD Team, gzdoom-g3.5pre-81-ga5b4d9d9a. It also occurs if I give myself the PowerInvulnerable actor class, which also makes me invulnerable.

Here are the scripts that matter that are used for transformation:

Code: Select all

//Transformation scripts
script "Transform" (void)
{	//This script handles transforming into Magical Cutie Mary/Super Xane. It's messy because it originates from World of Kirbycraft, that bad game.
	force_detransform[PlayerNumber()] = FALSE;	//If a detransformation was queued, cancel that.
	int o1, o2;	//Store the player's current X/Y velocity in these variables. They'll be restored when transformation ends.
	o1 = GetActorVelX(GetCurrentPlayerTID());
	o2 = GetActorVelY(GetCurrentPlayerTID());
	
	AmbientSound("misc/transform",64);	//The "YEEEE-AAH!" background chord. It sounds better if a yell is heard over it.
	ACS_NamedExecuteAlways("PlayerMovement",0,1,0,0);
	SetActorProperty(GetCurrentPlayerTID(),PROP_FLY,ON);
	SetActorState(GetCurrentPlayerTID(),"Transform",1);
	ActivatorSound("*super_yell",127);
	
	a[PlayerNumber()] =  GetActorAngle (GetCurrentPlayerTID());
	mmx[PlayerNumber()] = GetActorX (GetCurrentPlayerTID());
	y[PlayerNumber()] = GetActorY (GetCurrentPlayerTID());
	z[PlayerNumber()] = GetActorZ (GetCurrentPlayerTID()) + VIEW_HEIGHT;
	xyr =  r * cos (p) >> 16;	//Below is the transformation "cutscene".
	ACS_NamedExecuteAlways("SpawnCGems",0,0,0,0);	//Spawn the Chaos Bridges.
	SpawnForced("ChaseCam",mmx[PlayerNumber()]-cos(a[PlayerNumber()])*xyr, y[PlayerNumber()]-sin(a[PlayerNumber()])*xyr, z[PlayerNumber()], C_TID+PlayerNumber(), a[PlayerNumber()] >> 8);
	ChangeCamera(C_TID+PlayerNumber(),0,0);
	
	SetActorAngle(GetCurrentPlayerTID(),GetActorAngle(GetCurrentPlayerTID())-0.5);
	int super1 = 0;
	While(super1<38)
	{
		SetActorVelocity(GetCurrentPlayerTID(),0,0,0,0,1);
		super1++;
		Delay(1);
	}
	
	ActivatorSound("*super_grunt",127);
	
	ACS_NamedExecuteAlways("Invulnerable",0,1,0,0);	//Remove invulnerability.
	GiveActorInventory(GetCurrentPlayerTID(),"SuperX",1);
	If(PlayerClass(PlayerNumber())==CHAR_MARY)
	{
		TakeInventory("WandType",2);
		GiveInventory("Wand_Type",2);	//Select the Heart Wand.
		GiveInventory("MaryWand",1);	//Give Magical Cutie Mary her wand.
		UseInventory("MaryWand");		//Force the wand out for every transformation.
	}
	
	While(super1<=78)
	{
		SetActorVelocity(GetCurrentPlayerTID(),0,0,0,0,1);
		super1++;
		Delay(1);
	}
	SetActorProperty(GetCurrentPlayerTID(),PROP_FLY,OFF);
	SetActorAngle(GetCurrentPlayerTID(),GetActorAngle(GetCurrentPlayerTID())+0.5);
	ChangeCamera(0,0,0);
	Thing_Remove(C_TID+PlayerNumber());
	ACS_NamedExecuteAlways("PlayerMovement",0,0,0,0);
	If(1/*cgem_count==7*/) SetActorState(0, "Transform_Reflect",FALSE);
	SetActorVelocity(GetCurrentPlayerTID(),o1,o2,0,0,1);
	ACS_NamedExecuteAlways("ShowTutorial",0,28,0,0);	//Display warning about high speed wall jump behavior.
}

script "CheckSuper" ENTER
{	//Checks for transformation. If the player is transformed, spawns sparkles and handles detransformation.
While(1)
	{
		If(CheckActorInventory(GetCurrentPlayerTID(),"SuperX")==1)
		{	//If transformed, check for forced detransform requests and spawn sparkles behind the player.
			Spawn("SparkleSpawner",GetActorX(GetCurrentPlayerTID()),GetActorY(GetCurrentPlayerTID()),GetActorZ(GetCurrentPlayerTID())+24,0,GetActorAngle(GetCurrentPlayerTID())>>8);
			
			If(force_detransform[PlayerNumber()]==TRUE)
			{	//Time to detransform? Fine, revert the player to their normal form.
				TakeActorInventory(GetCurrentPlayerTID(),"SuperX",1);
				ACS_NamedExecuteAlways("Invulnerable",0,0,0,0);	//Remove invulnerability.
				If(1/*cgem_count==7*/) SetActorState(0, "Revert",FALSE);
			}
			Delay(1);
		}
		Else
		{	//Otherwise, await the next transformation.
			Delay(35);
		}
	}
}

script "Invulnerable" (int enable)
{
	If(enable<-1||enable>1) { Log(s:"Invalid invulnerability command ", d:enable, s:"!"); Terminate; }
	If(enable==TRUE)
	{	//If enabling invulnerability, no checks are necessary, just turn it on and increment the counter.
		invulnerable[PlayerNumber()]++;
		SetPlayerProperty(FALSE, ON, PROP_INVULNERABILITY);
	}
	If(enable==-1) { invulnerable[PlayerNumber()] = 1; enable = FALSE; }	//-1 guarantees invulnerability is disabled.
	If(enable==FALSE)
	{	//If disabling invulnerability, decrement the counter then if it's zero disable the invulnerability.
		If(invulnerable[PlayerNumber()]>0) invulnerable[PlayerNumber()]--;
		If(invulnerable[PlayerNumber()]==0) SetPlayerProperty(FALSE, OFF, PROP_INVULNERABILITY);
	}
}
Also, here's the "states" within Mary's player class that enable the reflective flags, just in case. (I don't know what I should provide.)

Code: Select all

  Transform_Reflect:	//If all seven Chaos Bridges are collected (final boss/replays), Mary will reflect all projectiles automatically.
    GIRL A 0 A_Log("It's working.")
    GIRL A 0 A_ChangeFlag("REFLECTIVE",TRUE)
    GIRL A 0 A_ChangeFlag("MIRRORREFLECT",TRUE)
	Goto See
  Revert:	//When reverting to normal cutie Mary, she can't keep reflecting anything that tries to hit her!
    SUPA A 0 A_ChangeFlag("MIRRORREFLECT",FALSE)
    SUPA A 0 A_ChangeFlag("REFLECTIVE",FALSE)
	Goto See
Last edited by Xane123 on Sun Jul 22, 2018 8:18 am, edited 2 times in total.
User avatar
Xane123
Posts: 165
Joined: Tue Nov 24, 2015 1:58 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Inwood, WV
Contact:

Re: Please help! Strange Invulnerability "Leaking"

Post by Xane123 »

:evil: Well, here's a bump! Seems no one came to help, but my game is just set to give back health any time the player is marked as "invulnerable", which seems to work. It would be nice if there was an explanation from a developer or something about this odd, random behavior. :roll:
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: [No one helped]Strange Invulnerability "Leaking"

Post by wildweasel »

I wonder if it'd help if this thread were in Scripting instead of General. I've gone ahead and moved it there.
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: [No one helped]Strange Invulnerability "Leaking"

Post by _mental_ »

Please post a ready to run sample.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49066
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [No one helped]Strange Invulnerability "Leaking"

Post by Graf Zahl »

Nobody here is willing to get your code into a working state, especially if you just post fragments. And few people will ask you to do it. Posting stuff like this one is a surefire way not to get help.
You will have to give people something to check and a video won't do!

Seconding _mental here: If you want help, post some example mod which people can run, test and change.
User avatar
Xane123
Posts: 165
Joined: Tue Nov 24, 2015 1:58 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Inwood, WV
Contact:

Re: [No one helped]Strange Invulnerability "Leaking"

Post by Xane123 »

Oh, I should've done that...

Anyways, I'm not sure what caused the random invulnerability leaking (as afterwards the invulnerability would resume) but I discovered that when SetPlayerProperty is used to give the player PROP_INVULNERABILITY, which should just set the player object's INVULNERABLE flag, instead it gives you PowerInvulnerability. Problem is this powerup only lasts 30 seconds, so after that the player resumes taking damage. This is odd behavior, but this WAD demonstrates it. Observe how the first 30 seconds you don't get hurt by the demons but after that, they begin to hurt you! This may be the cause.
Attachments
invulnerability_flaw.wad
This demonstration WAD shows off how GZDoom gives you a limited time powerup item rather than making the player permanently invulnerable until disabled.
(6.44 KiB) Downloaded 27 times
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: [No one helped]Strange Invulnerability "Leaking"

Post by wildweasel »

Xane123 wrote:PROP_INVULNERABILITY, which should just set the player object's INVULNERABLE flag
This was never true; the wiki page says it simply gives the sphere:
5 — PROP_INVULNERABILITY (deprecated) — Invulnerability sphere. Using a "set" value of 1 makes the player(s) invulnerable and applies the inverted greyscale invulnerable palette. Using a "set" value of 2 makes the player(s) invulnerable but does not apply the invulnerability palette. SetActorProperty with APROP_Invulnerable or APROP_DamageFactor is a valid substitution.
True to its word, SetActorProperty on the script's activator, to APROP_Invulnerable, should be proper invulnerability without it being the powerup effect.
User avatar
Xane123
Posts: 165
Joined: Tue Nov 24, 2015 1:58 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Inwood, WV
Contact:

Re: [No one helped]Strange Invulnerability "Leaking"

Post by Xane123 »

:? Oh...wow! I don't think I read that wiki page; If I did, this topic wouldn't have happened! I guess I should read the wiki more before making a topic in the future. It's strange how there are two invulnerability methods, but I guess PROP_INVULNERABILITY is there for very old mods that may still use it.

Still, thanks for helping! If this was in the bugs forum, it'd be marked [Not a Bug]!
Post Reply

Return to “Scripting”