Disconnect script [HELP] (SOLVED)

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
Barny-kun
Posts: 14
Joined: Wed May 03, 2017 2:28 pm
Location: Inside your mind

Disconnect script [HELP] (SOLVED)

Post by Barny-kun »

Can someone help me? Why isn't this script working:

Code: Select all

script 5 (int playernum) DISCONNECT   //I didn't get this part.. How to identify if the one leaving is the seeker, only executing the other script if it is him? :x 

{
    if (ActivatorTID() == 1)   //The tid of the seeker is 1
    {    
         SetFont("BIGFONT");
         HudMessageBold(s:"\ciSeeker left the game! Choosing new one!"; HUDMSG_FADEOUT, 3, 0, 1.5, 0.4, 3.5);
         delay(35);
         ACS_Execute(3,0,0,0,0);   //here i choose a new seeker
    }
}
I suck at scripting, i tried reading the wiki, but i didn't get how to make it.. I wanted the script to activates another script only if a certain player (the seeker) leaves the game, so i could choose a new player to be the seeker, but it isn't working.. How to identify if the one leaveing has the tid required, the seeker tid, and if the one who left isn't the seeker, nothing happens? :(
Last edited by Barny-kun on Mon Dec 18, 2017 3:36 pm, edited 1 time in total.
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: Disconnect script [HELP]

Post by wildweasel »

This script doesn't outwardly have anything wrong with it; I'd imagine the problem lies in whatever mechanism is setting the tid on players (script 3, I'd imagine, since that's the one being ACS_Executed at the end of this one).
User avatar
phantombeta
Posts: 2084
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: Disconnect script [HELP]

Post by phantombeta »

DISCONNECT scripts have the world as the activator, so that won't work. That's what the "playernum" variable is there for.
The player's actor is already gone by the time DISCONNECT scripts run, I believe.

Edit:
The wiki wrote:[wiki=Script_types#DISCONNECT]A DISCONNECT script must be declared with a single argument. ZDoom will pass the number of the disconnecting player into this variable. Because the player has already left the game by the time this script is called, no actions can be taken on that player. The script is executed by the world itself.

Disconnect scripts activate immediately before the player actor is destroyed, setting the leaving player as the activator instead of the world. Note that any delays or waiting will cause the script to reset the activator back to the world.[/wiki]
The wiki is contradicting itself on this one. From my experience with DISCONNECT, though, I'd say the former is the correct one.
User avatar
Barny-kun
Posts: 14
Joined: Wed May 03, 2017 2:28 pm
Location: Inside your mind

Re: Disconnect script [HELP]

Post by Barny-kun »

This seems complexy :x I'm curious on how mods like AOW, Zombie Horde, Deathrun, WhoDunIt and the likes do to select a new pursuer when the actual one leaves while the match is running.. :o Here is the full script, just to complement, also in the hope that someone find the issue:
Spoiler:
If someone know another way to prevent the game from breaking when the a seeker leaves while the match is running by choosing another seeker among the remaining players, please tell me.
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: Disconnect script [HELP]

Post by Arctangent »

You could store the player number of the seeker ( obtained through [wiki]PlayerNumber[/wiki] ) in a variable when the seeker is chosen, then compare the player number passed through the DISCONNECT script with that rather than using TIDs.

Alternatively, if the player object is gone by the time the DISCONNECT script runs ( which is something you'll have to test ), you could use [wiki]ThingCount[/wiki] to check if an actor with the TID exists, and if not, pick out a new seeker. Though in this case, you'd definitely want to use a much higher TID than 1 - that's a number incredibly likely to be used by maps, so stuff could easily go awry.
User avatar
Barny-kun
Posts: 14
Joined: Wed May 03, 2017 2:28 pm
Location: Inside your mind

Re: Disconnect script [HELP]

Post by Barny-kun »

Thank you guys, and also, thank you, Arctangent! The last comment made by you enlightened me :idea: Personally the variable thing is complexy to me, then i used something based on the other way you showed, that is checking if something stills exist on the map, and that is where the custom weapon used by the Seeker takes place (And also removing the custom weapon when the seeker dies, reseting everyones tid again and putting a little delay before the check)

Code: Select all

script 4 DEATH
{
    delay(10);
	if (ActivatorTID() == 1)
	{
         ACS_Execute(1, 0);
		 delay(1);
		 ACS_Terminate(8, 0);
		 delay(1);
		 ACS_Terminate(9, 0);
		 delay(1);
		 HudMessageBold(s:""; HUDMSG_PLAIN, 2, 0, 0, 0, 0);
		 delay(1);
		 SetFont("BIGFONT");
		 HudMessageBold(s:"\cr<\cf!\cr> \cfSeeker died! Choosing new one! \cr<\cf!\cr>"; HUDMSG_FADEOUT, 3, 0, 1.5, 0.4, 3.5); 
         delay(35);
		 ACS_Execute(3,0,0,0,0); //Choosing new Seeker
    }
}

script 5 (int playernum) DISCONNECT
{
	delay(10);
	if (CheckActorInventory(1, "SeekerEyes"))
	    {
        //
        }
        else
		{
		ACS_Execute(1, 0);
		delay(1);
	    ACS_Terminate(8, 0);
		delay(1);
		ACS_Terminate(9, 0);
		delay(1);
		HudMessageBold(s:""; HUDMSG_PLAIN, 2, 0, 0, 0, 0);
		delay(1);
		SetFont("BIGFONT");
		HudMessageBold(s:"\ciSeeker left the game! Choosing new one!"; HUDMSG_FADEOUT, 3, 0, 1.5, 0.4, 3.5); 
        delay(35);
		ACS_Execute(3,0,0,0,0); //Choosing new Seeker
		}
}
Well, it's working now. I hope that there isn't something more disastrous waiting its time to appear :)
Post Reply

Return to “Scripting”