[ACS] retain a playernumber in a DISCONNECT script?

Discuss all aspects related to modding Zandronum here.
Post Reply
User avatar
FranckyFox2468
Forum Regular
Posts: 180
Joined: Sat May 07, 2016 8:30 pm

[ACS] retain a playernumber in a DISCONNECT script?

#1

Post by FranckyFox2468 » Fri Sep 11, 2020 10:23 pm

does anyone know how would you retain a playernumber in a DISCONNECT script? Cause im trying to make a script that destroy all of that player's summon upon switching team, class or leaving the game but only the last part doesnt seem to work and i dont want players to be harassed by a turret of a player that doesnt exist anymore.

If you can provide exemples it would really help cause the DISCONNECT section of the zdoom wiki isnt very clear on its function and INT.

If you wanna see my pathetic attempt without much knowledge:
script "Disconnectz" (int playernum) DISCONNECT
{
ACS_NamedExecuteWithResult("BreakShit", 0);
}

script "BreakShit" (void)
{
///This scripts destroy all active summons of the player when called.
///or well, atleast those that are meant to remain alive if their owner is dead.
int pnum = PlayerNumber();
SetActorState ((pnum + 1600), "Death", TRUE);
SetActorState ((pnum + 1700), "Death", TRUE);
SetActorState ((pnum + 1800), "Death", TRUE);
SetActorState ((pnum + 12000), "Death", TRUE);
SetActorState ((pnum + 12100), "Death", TRUE);
}
I also tried to directly make the "breakshit" script a disconnect script but it didnt change anything.

User avatar
Kaminsky
Forum Regular
Posts: 159
Joined: Sun Apr 14, 2013 7:17 pm
Location: Somewhere...

[ACS] Re: retain a playernumber in a DISCONNECT script?

#2

Post by Kaminsky » Sat Sep 12, 2020 12:37 am

The activator of any "Disconnect" script is always the world (except in (G)ZDoom where the activator is the player who left until after one tic), not the player who left. What you could do is pass the player ID as a parameter in "BreakShit" like so:

Code: Select all

Script "Disconnectz" (int playernum) Disconnect
{
	ACS_NamedExecuteWithResult("BreakShit", playernum);
}

Script "BreakShit" (int pnum)
{
	SetActorState((pnum + 1600), "Death", TRUE);
	SetActorState((pnum + 1700), "Death", TRUE);
	SetActorState((pnum + 1800), "Death", TRUE);
	SetActorState((pnum + 12000), "Death", TRUE);
	SetActorState((pnum + 12100), "Death", TRUE);
}
Alternatively, you could also paste the code from the "BreakShit" script into the disconnect script and keep only the first script.
Last edited by Kaminsky on Sat Sep 12, 2020 3:24 am, edited 1 time in total.

User avatar
FranckyFox2468
Forum Regular
Posts: 180
Joined: Sat May 07, 2016 8:30 pm

[ACS] Re: retain a playernumber in a DISCONNECT script?

#3

Post by FranckyFox2468 » Sat Sep 12, 2020 1:35 am

hm, thanks. Also i must ask, i assume i gotta establish playernum first or is this an automatic value of sort?

And i guess that with that in mind, i'm better off making a script that checks if the 64 players are active and those who arent has their stuff destroyed...

User avatar
Kaminsky
Forum Regular
Posts: 159
Joined: Sun Apr 14, 2013 7:17 pm
Location: Somewhere...

[ACS] Re: retain a playernumber in a DISCONNECT script?

#4

Post by Kaminsky » Sat Sep 12, 2020 3:22 am

As with any disconnect-type script, the ID of the player who left (in this case it's "playernum") is automatically passed as a parameter, which you always need to define with the script. You can do whatever you want with this number except returning any information specific to the player actor that left (In Zandronum 3.0 the script is still executed after the player actor has already been destroyed, whereas (G)ZDoom changed it so that the script's executed before it happens).

I still recommend that you continue using your current script to remove the extra actors bound to the player(s), because it would be inefficient to have another script that needs to run every tic and check all 64 players to see which are active or not.

User avatar
FranckyFox2468
Forum Regular
Posts: 180
Joined: Sat May 07, 2016 8:30 pm

[ACS] Re: retain a playernumber in a DISCONNECT script?

#5

Post by FranckyFox2468 » Sat Sep 12, 2020 4:44 am

Well not necessarily, cause if it is a world script only triggered if someone disconnects or goes spectator, then the script will only run when that happens.
Also going by your way i guess that means i have to define/assign it to a map parameter rather than inside a script then.

Also, i'm curious on your script, what would assinging playernum to arg1 do concidering it uses a different term "pnum" on the "breakshit" script?

Lastly, if i assign the ID to a parameter/int, will it be individual to all players? Because im worried it gets a bit fucky when it comes to having multiple people running the script.

User avatar
Kaminsky
Forum Regular
Posts: 159
Joined: Sun Apr 14, 2013 7:17 pm
Location: Somewhere...

[ACS] Re: retain a playernumber in a DISCONNECT script?

#6

Post by Kaminsky » Sat Sep 12, 2020 12:55 pm

FranckyFox2468 wrote: Well not necessarily, cause if it is a world script only triggered if someone disconnects or goes spectator, then the script will only run when that happens.
I don't know what you mean by this. According to your OP, you want to remove the actors only when the player leaves/spectates, or if they switch teams (the latter requires a RESPAWN script to work by the way). You can learn more about the different types of scripts here: https://zdoom.org/wiki/Script_types
FranckyFox2468 wrote: Also going by your way i guess that means i have to define/assign it to a map parameter rather than inside a script then.
You must always declare a single argument in a DISCONNECT script, this represents the disconnecting player's ID. Otherwise, ACC will throw an error upon compilation.
FranckyFox2468 wrote: Also, i'm curious on your script, what would assinging playernum to arg1 do concidering it uses a different term "pnum" on the "breakshit" script?
I was passing playernum as a parameter into the "BreakShit" script, which was named as pnum, just to be consistent with your code in the OP. As mentioned before, unless you plan on doing more with this "BreakShit" script, it's better to keep only the DISCONNECT script and use it like this:

Code: Select all

Script "Disconnectz" (int playernum) Disconnect
{
	// Kills the actors connected to the player.
	Thing_Destroy(playernum + 1600, 1, 0);
	Thing_Destroy(playernum + 1700, 1, 0);
	Thing_Destroy(playernum + 1800, 1, 0);
	Thing_Destroy(playernum + 12000, 1, 0);
	Thing_Destroy(playernum + 12100, 1, 0);
}
FranckyFox2468 wrote: Lastly, if i assign the ID to a parameter/int, will it be individual to all players? Because im worried it gets a bit fucky when it comes to having multiple people running the script.
Multiple DISCONNECT scripts can be executed at the same time but the ID passed into them will be specific to each player(s) that leaves/spectates, so you don't need to worry about any conflicts between players.

User avatar
FranckyFox2468
Forum Regular
Posts: 180
Joined: Sat May 07, 2016 8:30 pm

[ACS] Re: retain a playernumber in a DISCONNECT script?

#7

Post by FranckyFox2468 » Sat Sep 12, 2020 4:35 pm

Ah so the int/parameter on a disconnect script is ALWAYS the player ID? Is it their TID or simply their playernumber?

Thanks a lot for the help. Will keep you updated on if it worked.

User avatar
FranckyFox2468
Forum Regular
Posts: 180
Joined: Sat May 07, 2016 8:30 pm

[ACS] Re: retain a playernumber in a DISCONNECT script?

#8

Post by FranckyFox2468 » Sun Sep 13, 2020 9:37 pm

Yeah it works pretty great, thanks. Main issue is that as you said, im gonna have to make a copy of the script to run in different circumstances and as i add new summons and such its gonna be a bit of a pain to work with lol.

Post Reply