Making player invulnerable via a script?

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
User avatar
Enjay
 
 
Posts: 27081
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Making player invulnerable via a script?

Post by Enjay »

I know that this is probably phenomenally easy and has probably been done 100 times before but I can't see how to do it. So...

How do I use a script to make the player invulnerable for a while? The script in question is an OPEN (it needs to be Open, not enter or void) script which sits and monitors conditions in the level and activates the invulnerability once certain conditions have been met - ie it could happen at any time and anywhere on the level. I would have used SetPlayerProperty with PROP_INVULNERABILITY but it looks from the Wiki as if this is supposed to be like the invulnerability sphere effect (although that may be bugged) and it has been deprecated anyway. Alternatively, I could use SetActorProperty but that requires the player to have a tid and, in this particular instance, I'd rather not have the player be allocated a tid.

So, is there a way of doing this other than the methods that I mentioned?

[edit]Fixed silly, but critical, typo[/edit]
Last edited by Enjay on Mon Sep 21, 2009 12:03 pm, edited 1 time in total.
User avatar
Ichor
Posts: 1784
Joined: Wed Jul 23, 2003 9:22 pm

Re: Making player invulnerable via a script?

Post by Ichor »

How about you give the player an invulnerability powerup that autoactivates?
User avatar
Enjay
 
 
Posts: 27081
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Making player invulnerable via a script?

Post by Enjay »

I'd need to give the player a tid for that and I don't want the inverted palette effect either.
User avatar
Enjay
 
 
Posts: 27081
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Making player invulnerable via a script?

Post by Enjay »

Ironically, the deprecated "SetPlayerProperty (1, 1, PROP_INVULNERABILITY);" does exactly what I want. The bug with it makes it act perfectly for me (the bug means that the inverted palette effect doesn't happen).

If nothing better comes along, I'll use this and just keep my fingers crossed that it won't be changed at any point. However, I'd prefer to "future proof" things and use a better method if it exists.
Gez
 
 
Posts: 17946
Joined: Fri Jul 06, 2007 3:22 pm

Re: Making player invulnerable via a script?

Post by Gez »

Can you use [wiki]GiveInventory[/wiki] to the players a custom PowerInvulnerability (not a powerupgiver) with a long duration, and take it back with [wiki]TakeInventory[/wiki]?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49234
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Making player invulnerable via a script?

Post by Graf Zahl »

A better idea would be to define a new PowerupGiver, give that and when it is to be switched off take away the powerup.
User avatar
Enjay
 
 
Posts: 27081
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Making player invulnerable via a script?

Post by Enjay »

However, with the script in question being an OPEN one I don't think it will work. GiveInventory and TakeInventory apply to the activator of the script which, of course, would be the world, not the player :?:


It does seem that SetPlayerProperty is the ideal command to use, it's just that it doesn't have an appropriate unbugged, non-deprecated property to set. :?
User avatar
Zippy
Posts: 3302
Joined: Wed Mar 23, 2005 5:31 pm
Location: New Jersey

Re: Making player invulnerable via a script?

Post by Zippy »

Why exactly does the script need to be open? Anything that you could put in an OPEN script could just be flagged to start in an ENTER script so I don't see why it needs to be like that.

Code: Select all

bool flag = FALSE;

script 1 OPEN
{
   while( !flag )
   {
      if( condition )
      {
         flag = TRUE;
      }
      delay(1);
   }
}

script 2 ENTER
{
   while( !flag )
   {
      delay(1);
   }

   MakeInvulnerable();
}
User avatar
Enjay
 
 
Posts: 27081
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Making player invulnerable via a script?

Post by Enjay »

The script is an OPEN type because it shouldn't be run per player. However, your post has shown me the way (I think).

I think what you are suggesting is that an enter script does nothing other than sit and wait for a variable to be set. The OPEN script can set the variable then the enter script will detect that and do the invulnerability stuff. Is that right?

It sounds like it should work. Unfortunately it's getting a bit late for me to try it tonight.
User avatar
Project Shadowcat
Posts: 9369
Joined: Thu Jul 14, 2005 8:33 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support
Location: Blacksburg, SC USA
Contact:

Re: Making player invulnerable via a script?

Post by Project Shadowcat »

As I was reading the thread, I was thinking the same thing Zippy was. I'm pretty certain that should work.
User avatar
Zippy
Posts: 3302
Joined: Wed Mar 23, 2005 5:31 pm
Location: New Jersey

Re: Making player invulnerable via a script?

Post by Zippy »

Enjay wrote:I think what you are suggesting is that an enter script does nothing other than sit and wait for a variable to be set. The OPEN script can set the variable then the enter script will detect that and do the invulnerability stuff. Is that right?
Dead on.

If you're loathe to give the player a TID, the only way you're really going to be able to direct actions towards the player is if they are the script activator. That means either make sure it's a script only the player can start (they cross a line or hit a switch, etc.) or make an ENTER script. If the conditions can't possibly be fulfilled by just the usual activation methods you're pretty much stuck with the ENTER script, or using the same exact concept as the ENTER script snippet above but in a regular script which you can guarantee will be run beforehand and therefore waiting for the flag at the right moment. But you can always guarantee an ENTER script will be running, so might as well go that route.
User avatar
Enjay
 
 
Posts: 27081
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Making player invulnerable via a script?

Post by Enjay »

OK, thanks, yeah, that all makes sense. It's just a pity that the slightly simpler option of SetPlayerProperty having a suitable property to set did not exist but it's no big deal.

Thanks again. :)
User avatar
Cutmanmike
Posts: 11353
Joined: Mon Oct 06, 2003 3:41 pm
Operating System Version (Optional): Windows 10
Location: United Kingdom
Contact:

Re: Making player invulnerable via a script?

Post by Cutmanmike »

Graf Zahl wrote:A better idea would be to define a new PowerupGiver, give that and when it is to be switched off take away the powerup.
Does that work? I tried like mad to get that working, even requested help here but I could NOT get it work. If it does work, that sucks because I trashed a HUGE idea for it.

Could you provide a working example if it is?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49234
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Making player invulnerable via a script?

Post by Graf Zahl »

Enjay wrote: I would have used SetPlayerProperty with PROP_INVISIBILITY but it loooks from the Wiki as if this is supposed to be like the invulnerability sphere effect (although that may be bugged) and it has been deprecated anyway.

I reinstated the invulnerability effect here because it was clearly an unintentional omission. However, it was quite easy to extend it so if you set PROP_INVULNERABLE to 2 instead of 1 it doesn't apply its colormap anymore.
Gez
 
 
Posts: 17946
Joined: Fri Jul 06, 2007 3:22 pm

Re: Making player invulnerable via a script?

Post by Gez »

And to 3 to get Heretic's golden colormap?
Locked

Return to “Editing (Archive)”