Page 1 of 1

[ACS] Running script as soon as a player connects

Posted: Sun Oct 08, 2017 1:27 am
by Ivan
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?

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

Posted: Sun Oct 08, 2017 1:54 am
by Kaminsky
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.
}

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

Posted: Sun Oct 08, 2017 3:13 am
by Ivan
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.

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

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

code master c+++?

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

Posted: Sun Oct 08, 2017 7:09 am
by Fused
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.

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

Posted: Sun Oct 08, 2017 2:24 pm
by Kaminsky
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.

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

Posted: Sun Oct 08, 2017 3:48 pm
by Ivan
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.

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

Posted: Sun Oct 08, 2017 5:34 pm
by Fused
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.

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

Posted: Sun Oct 08, 2017 5:53 pm
by Ivan
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.

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

Posted: Sun Oct 08, 2017 6:22 pm
by jdagenet
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.