Page 1 of 1

[ACS] Temporary invicibility to applying to everyone as it should?

Posted: Sat May 06, 2017 5:08 pm
by FranckyFox2468
I'm currently making a script that makes the player temporarily invicible but unable to move just before a cutscene plays, and once the cutscene is done it disable these effects.
It works in single player but then i decided to try to make it work with bots and the cutscene works but the invicibility and froze effect is not applied to anyone when my goal is to make it work on every active players. Can you guys help?

Code: Select all

script 5 (void)
{
SetActivator(0,AAPTR_NULL);	
SetPlayerProperty(0,1,PROP_TOTALLYFROZEN);
SetActorProperty(0,APROP_Invulnerable,true);
ChangeCamera(18,0,0);
delay(35);
ACS_Execute(6, 0, 0, 0, 0);

*insert cutscene shit*

ChangeCamera(0,0,0);
SetActorProperty(0,APROP_Invulnerable,false);
SetPlayerProperty(0,0,PROP_TOTALLYFROZEN);
delay(1);

[ACS] Re: Temporary invicibility to applying to everyone as it should?

Posted: Sat May 06, 2017 8:28 pm
by Fused
There's a lot wrong with this, which I will explain.
First of all, here's all the code you should use.
(might contain errors, I never really tested this)

Code: Select all

// Maximum player cap in Zandronum
#define MAX_PLAYERS 64

// Unique TID
#define PLAYER_TID 600

script 5 (void)
{
	for (int i = 0; i < MAX_PLAYERS; ++i) {
		if (playeringame(i)) {
			SetActorProperty(i+PLAYER_TID, APROP_INVULNERABLE, TRUE);
		}
	}
	SetPlayerProperty(TRUE, TRUE, PROP_TOTALLYFROZEN);
	
	ChangeCamera(18, TRUE, 0);
	delay(35);
	ACS_Execute(6, 0, 0, 0, 0);

	// *insert cutscene shit*

	ChangeCamera(0, TRUE, 0);
	
	for (i = 0; i < MAX_PLAYERS; ++i) {
		if (playeringame(i)) {
			SetActorProperty(i+PLAYER_TID, APROP_INVULNERABLE, FALSE);
		}
	}
	SetPlayerProperty(TRUE, FALSE, PROP_TOTALLYFROZEN);
}

script 1 ENTER
{
	// Give our player his own TID, so we can distinguish him from other stuff.
	Thing_ChangeTid(0, PLAYER_TID + PlayerNumber());
}

script 2 RESPAWN
{
	ACS_ExecuteAlways(1, 0);
}

script 3 DEATH
{
	// Unsign our TID.
	Thing_ChangeTid(0, 0);
}

It looks like a lot, but it's really simple once you understand the logic behind it.

Firstly, you need to teach yourself to always give a unique id to your player. It's what the last three scripts do.
In short, your player has a TID of his playernumber+600. This is given when he enters, and respawns.
For safety reasons, your TID is removed when you die. Because corpses can have TIDs.

Secondly, remember you need to use a loop for almost anything when it comes to targetting multiple players.
Only ChangeCamera() and SetPlayerProperty() in this case has a boolean which allows you to target everyone.
Although to be honest you should give ChangeCamera() a seperate 1-tic script because you can just spy out of camera's...

SetPlayerProperty() is for players only. If you look on the wiki you notice it has a "who" argument, which is because it doesn't care about monsters or all that.
SetActorProperty() on the other hand allows you to set stuff on monsters and stuff aswell. The wiki also gives it an "tid" argument, hence the whole TID story.

[ACS] Re: Temporary invicibility to applying to everyone as it should?

Posted: Sat May 06, 2017 9:15 pm
by FranckyFox2468
My fucking head hurts now from all i already did today. Ill check this another day, and even then i prolly won't understand jack shit.

Also why is assigning TID a MUST? Doesn't that limit the ammount of TIDs you can use further and simply make things more complicated?

[ACS] Re: Temporary invicibility to applying to everyone as it should?

Posted: Sat May 06, 2017 10:56 pm
by Fused
FranckyFox2468 wrote:My fucking head hurts now from all i already did today. Ill check this another day, and even then i prolly won't understand jack shit.

Also why is assigning TID a MUST? Doesn't that limit the ammount of TIDs you can use further and simply make things more complicated?
You have pretty much an infinite amount of TIDs. If you really want to be sure, you could use UniqueTID(). You just need to be sure you remember it.
And yes, it's a must really. You cant have 100% reliable code otherwise. Player one will basically interfere with everything if not.

[ACS] Re: Temporary invicibility to applying to everyone as it should?

Posted: Sun May 07, 2017 3:39 pm
by FranckyFox2468
Okay, first question

Code: Select all

   for (int i = 0; i < MAX_PLAYERS; ++i)
What does this even mean or do. Its like a clusterfuck of single letters and values i have no idea of their meanings.
And not trying to sound mean, i'm legit curious.

[ACS] Re: Temporary invicibility to applying to everyone as it should?

Posted: Sun May 07, 2017 3:45 pm
by Fused
FranckyFox2468 wrote:Okay, first question

Code: Select all

   for (int i = 0; i < MAX_PLAYERS; ++i)
What does this even mean or do. Its like a clusterfuck of single letters and values i have no idea of their meanings.
And not trying to sound mean, i'm legit curious.
https://zdoom.org/wiki/FOR_and_WHILE_loops

MAX_PLAYERS in this case is a constant, which is defined at the top of the code. https://zdoom.org/wiki/Constants

You can also replace this with 64 if you want, but you should learn to place recurring values as constants, in case Zandronum increases the max player cap for example.

[ACS] Re: Temporary invicibility to applying to everyone as it should?

Posted: Sun May 07, 2017 3:56 pm
by FranckyFox2468
I'll give this a shot when i get around it and give ye some news on the result.

[ACS] Re: Temporary invicibility to applying to everyone as it should?

Posted: Sun May 07, 2017 11:04 pm
by Empyre
FranckyFox2468 wrote:Okay, first question

Code: Select all

   for (int i = 0; i < MAX_PLAYERS; ++i)
What does this even mean or do. Its like a clusterfuck of single letters and values i have no idea of their meanings.
And not trying to sound mean, i'm legit curious.
int i = 0 means that the integer variable I is starting the loop at 0.
i < MAX_PLAYERS means the the loop will continue until the the variable i is no longer less than MAX_PLAYERS.
++i adds 1 to i to get it ready for the next time through the loop.

[ACS] Re: Temporary invicibility to applying to everyone as it should?

Posted: Sat May 20, 2017 2:15 pm
by FranckyFox2468
So i tested it. It works perfectly except for one aspect i might perhaps need help on fixing.

So i tried summoning a bot to walk on the script's trigger, but i forgot to move before spawning it so i got insta killed. Which is normal. But here's the thing, if you died before the cutscene is played and trigger your respawn, you are not affected by the invincibility or freezing effect at all.

[ACS] Re: Temporary invicibility to applying to everyone as it should?

Posted: Sat May 20, 2017 7:18 pm
by Fused
Try this.

Code: Select all

// Maximum player cap in Zandronum
#define MAX_PLAYERS 64

// Unique TID
#define PLAYER_TID 600

bool cutsceneIsPlaying;

script 5 (void)
{
	for (int i = 0; i < MAX_PLAYERS; ++i) {
		if (playeringame(i)) {
			SetActorProperty(i+PLAYER_TID, APROP_INVULNERABLE, TRUE);
		}
	}
	SetPlayerProperty(TRUE, TRUE, PROP_TOTALLYFROZEN);
   
	ACS_Execute(4, 0);
	cutsceneIsPlaying = TRUE;
	
	delay(35);
	ACS_Execute(6, 0);

	// *insert cutscene shit*
   
	cutsceneIsPlaying = FALSE;
	
	for (i = 0; i < MAX_PLAYERS; ++i) {
		if (playeringame(i)) {
			SetActorProperty(i+PLAYER_TID, APROP_INVULNERABLE, FALSE);
		}
	}
	SetPlayerProperty(TRUE, FALSE, PROP_TOTALLYFROZEN);
}

script 1 ENTER
{
	// Give our player his own TID, so we can distinguish him from other stuff.
	Thing_ChangeTid(0, PLAYER_TID + PlayerNumber());
}

script 2 RESPAWN
{
	ACS_ExecuteAlways(1, 0);
   
	if (cutsceneIsPlaying)
	{
		SetActorProperty(0, APROP_INVULNERABLE, TRUE);
      		SetPlayerProperty(TRUE, TRUE, PROP_TOTALLYFROZEN);
	}
}

script 3 DEATH
{	
	// Unsign our TID.
	Thing_ChangeTid(0, 0);
}

script 4 (void)
{
	while (cutsceneIsPlaying)
	{
		ChangeCamera(18, TRUE, 0);
		delay(1);
	}
	ChangeCamera(0, TRUE, 0);
}
A boolean keeps track of the cutscene playing, and refreezes if needed.
I also fixed the camera which could be spyed out from before.
Although if your cutscene uses multiple cameras, it has to be improved.