Making player invulnerable via a script?
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.
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.
Making player invulnerable via a script?
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]
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.
Re: Making player invulnerable via a script?
How about you give the player an invulnerability powerup that autoactivates?
Re: Making player invulnerable via a script?
I'd need to give the player a tid for that and I don't want the inverted palette effect either.
Re: Making player invulnerable via a script?
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.
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.
Re: Making player invulnerable via a script?
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]?
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49234
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: Making player invulnerable via a script?
A better idea would be to define a new PowerupGiver, give that and when it is to be switched off take away the powerup.
Re: Making player invulnerable via a script?
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.

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.

Re: Making player invulnerable via a script?
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();
}
Re: Making player invulnerable via a script?
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.
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.
- 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?
As I was reading the thread, I was thinking the same thing Zippy was. I'm pretty certain that should work.
Re: Making player invulnerable via a script?
Dead on.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?
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.
Re: Making player invulnerable via a script?
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.
Thanks again.

- 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?
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.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.
Could you provide a working example if it is?
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49234
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: Making player invulnerable via a script?
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.
Re: Making player invulnerable via a script?
And to 3 to get Heretic's golden colormap?