[ACS] Running script as soon as a player connects

Discuss all aspects related to modding Zandronum here.
Post Reply
User avatar
Ivan
Addicted to Zandronum
Posts: 2219
Joined: Mon Jun 04, 2012 5:38 pm
Location: Omnipresent

[ACS] Running script as soon as a player connects

#1

Post by Ivan » Sun Oct 08, 2017 1:27 am

I have a little problem with running a script on a client's end as soon as they connect to the server. The catch is that I can't use ENTER script because that implies they joined the game. I need this to run on connecting to server, which includes spectators as well.

Is this possible? If so how?
=== RAGNAROK DM ON ... uh... dead forever? ===
=== ALWAYS BET ON ... uh... dead forever? ===
=== Who wanta sum wang? ===
=== Death and Decay - A new Monster/Weapon replacer ===

User avatar
Kaminsky
Developer
Posts: 193
Joined: Sun Apr 14, 2013 7:17 pm
Location: Canada

Re: [ACS] Running script as soon as a player connects

#2

Post by Kaminsky » Sun Oct 08, 2017 1:54 am

You can define an OPEN CLIENTSIDE script, which should execute on the client's end as soon as they've connected to the server.

Code: Select all

Script "PlayerConnect" OPEN CLIENTSIDE
{
	// Execute code when client joins the server.
}

User avatar
Ivan
Addicted to Zandronum
Posts: 2219
Joined: Mon Jun 04, 2012 5:38 pm
Location: Omnipresent

Re: [ACS] Running script as soon as a player connects

#3

Post by Ivan » Sun Oct 08, 2017 3:13 am

Kaminsky wrote:
Sun Oct 08, 2017 1:54 am
You can define an OPEN CLIENTSIDE script, which should execute on the client's end as soon as they've connected to the server.

Code: Select all

Script "PlayerConnect" OPEN CLIENTSIDE
{
	// Execute code when client joins the server.
}
Server runs the open script. It wouldn't matter if it's clientside or not AFAIK.

EDIT: Nevermind, it works apparently.
EDIT 2: Although it works, it doesn't have what I need. I need the connecting player's playernumber.
EDIT 3: Ok, PlayerNumber() is meaningless apparently. ConsolePlayerNumber() however has meaning.
=== RAGNAROK DM ON ... uh... dead forever? ===
=== ALWAYS BET ON ... uh... dead forever? ===
=== Who wanta sum wang? ===
=== Death and Decay - A new Monster/Weapon replacer ===

User avatar
Combinebobnt
Retired Staff / Community Team Member
Posts: 1893
Joined: Mon Jun 04, 2012 3:37 am
Location: Erth
Contact:

Re: [ACS] Running script as soon as a player connects

#4

Post by Combinebobnt » Sun Oct 08, 2017 5:53 am

lol ivan he gave u the solution and u didnt even try it at first

code master c+++?

User avatar
Fused
Contributor
Posts: 658
Joined: Sat Nov 09, 2013 9:47 am
Location: Netherlands
Contact:

Re: [ACS] Running script as soon as a player connects

#5

Post by Fused » Sun Oct 08, 2017 7:09 am

Does that work? I'm almost 100% sure that isn't supposed to work, because this was asked before actually, and it should do the same as OPEN, but for clients.

Alternatively, you could loop a script that keeps checking if an unique id is taken, and should it, make it execute a script with that id as activator.
My mods
Image Image

My socials
Image Image

User avatar
Kaminsky
Developer
Posts: 193
Joined: Sun Apr 14, 2013 7:17 pm
Location: Canada

Re: [ACS] Running script as soon as a player connects

#6

Post by Kaminsky » Sun Oct 08, 2017 2:24 pm

Fused wrote:
Sun Oct 08, 2017 7:09 am
Does that work? I'm almost 100% sure that isn't supposed to work, because this was asked before actually, and it should do the same as OPEN, but for clients.

Alternatively, you could loop a script that keeps checking if an unique id is taken, and should it, make it execute a script with that id as activator.

I have used this method before and it has worked for me, but I should mention that just like OPEN scripts that are executed on the server, the activator of an OPEN CLIENTSIDE script is the world and not the client, which is why PlayerNumber() wasn't working before.

You can however return the local id of the client using ConsolePlayerNumber(), so using SetActivatorToPlayer(ConsolePlayerNumber()) should properly set the activator of the script to the client if necessary.

Fused's method will more or less get you to the same place, but then you would also have a script on the server with a while loop that constantly checks for clients every tic (through some combination of PlayerIsSpectator() and PlayerInGame() to see if the client wasn't playing the game before and actually just joined), which can be quite cumbersome. As far as I know, OPEN CLIENTSIDE scripts also execute only for the client that connected and not everyone, so no need to do an additional check to see whether the script needs to be terminated for certain clients or not.

User avatar
Ivan
Addicted to Zandronum
Posts: 2219
Joined: Mon Jun 04, 2012 5:38 pm
Location: Omnipresent

Re: [ACS] Running script as soon as a player connects

#7

Post by Ivan » Sun Oct 08, 2017 3:48 pm

Combinebobnt wrote:
Sun Oct 08, 2017 5:53 am
lol ivan he gave u the solution and u didnt even try it at first

code master c+++?
Yeah bob zandronum keeps amazing me that's why I plan to never touch it in the future :)
Fused wrote:
Sun Oct 08, 2017 7:09 am
Does that work? I'm almost 100% sure that isn't supposed to work, because this was asked before actually, and it should do the same as OPEN, but for clients.

Alternatively, you could loop a script that keeps checking if an unique id is taken, and should it, make it execute a script with that id as activator.
Yes, it does work with ConsolePlayerNumber. It makes some sense too, because the activator of the OPEN scripts is the server. So, PlayerNumber makes sense to return -1, but ConsolePlayerNumber returns the client's id, which does make sense. I had my usual "ConsolePlayerNumber() == PlayerNumber()" check for the script and that's why it wasn't working.
=== RAGNAROK DM ON ... uh... dead forever? ===
=== ALWAYS BET ON ... uh... dead forever? ===
=== Who wanta sum wang? ===
=== Death and Decay - A new Monster/Weapon replacer ===

User avatar
Fused
Contributor
Posts: 658
Joined: Sat Nov 09, 2013 9:47 am
Location: Netherlands
Contact:

Re: [ACS] Running script as soon as a player connects

#8

Post by Fused » Sun Oct 08, 2017 5:34 pm

No, I'm referring to OPEN CLIENTSIDE triggering when someone connects. Are you 100% sure it doesn't trigger when the map loads, like a regular OPEN script? Good thing it was the solution to your problem though.
My mods
Image Image

My socials
Image Image

User avatar
Ivan
Addicted to Zandronum
Posts: 2219
Joined: Mon Jun 04, 2012 5:38 pm
Location: Omnipresent

Re: [ACS] Running script as soon as a player connects

#9

Post by Ivan » Sun Oct 08, 2017 5:53 pm

Fused wrote:
Sun Oct 08, 2017 5:34 pm
No, I'm referring to OPEN CLIENTSIDE triggering when someone connects. Are you 100% sure it doesn't trigger when the map loads, like a regular OPEN script? Good thing it was the solution to your problem though.
Yep, connected multiple times in different instances, each got a different number on their screen and only once.
=== RAGNAROK DM ON ... uh... dead forever? ===
=== ALWAYS BET ON ... uh... dead forever? ===
=== Who wanta sum wang? ===
=== Death and Decay - A new Monster/Weapon replacer ===

User avatar
jdagenet
Forum Regular
Posts: 191
Joined: Tue Jun 05, 2012 8:08 am
Clan: Cube
Clan Tag: A3
Contact:

Re: [ACS] Running script as soon as a player connects

#10

Post by jdagenet » Sun Oct 08, 2017 6:22 pm

Fused wrote:
Sun Oct 08, 2017 5:34 pm
No, I'm referring to OPEN CLIENTSIDE triggering when someone connects. Are you 100% sure it doesn't trigger when the map loads, like a regular OPEN script? Good thing it was the solution to your problem though.
It triggers when the map loads on that specific client, the server never knows of the script.
<Dynamo_>uh
<Dynamo_>did you just take the thread away
<FusedQyou>Dunno
<FusedQyou>ask the thread

Post Reply