Running a function on every player disconnect

Have a question about modding, modelling or skinning? Have a tutorial to post? Post here!

Moderator: Core Staff

Post Reply
CHRLZ
CJ Wannabe
CJ Wannabe
Posts: 10
Joined: July 9th, 2011, 1:06 pm

Running a function on every player disconnect

Post by CHRLZ » May 1st, 2013, 10:07 am

I'm attempting to write a script for my server to display player name and guid (8 digit only) on connect and disconnect.

It works fine on connect, but I can't get it to trigger disconnect.

Is the level notified on player disconnect?
Or what?

I'm so confused :P

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Running a function on every player disconnect

Post by Drofder2004 » May 1st, 2013, 8:16 pm

I would assume you would need to retrieve the GUID before the game "disconnects" the player, however the GUID is not a member of the entity.

You may be able to do (onConnect)
self._guid = self getGUID();

And then on disconnect, you can simply recall that value.
I have not tested it.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

CHRLZ
CJ Wannabe
CJ Wannabe
Posts: 10
Joined: July 9th, 2011, 1:06 pm

Re: Running a function on every player disconnect

Post by CHRLZ » May 4th, 2013, 9:52 am

Thanks for your reply Drof, I've had a busy few days and only was able to check this now.

I was more wondering what is notified when a player disconnects.

If I were to write a script to run on disconnect, I'd need

Code: Select all

for (;;) {
level/self waittill("<what do I put here?> ");
// code
//...
}

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Running a function on every player disconnect

Post by Drofder2004 » May 5th, 2013, 12:06 am

This is purely hypothetical and may not work, the disconnect code is mostly hard coded and I am not sure at what point entity information is cleared.

Code: Select all

onPlayerConnect()
{
        for(;;)
        {
                level waittill("connecting", player);
                player._guid = player getGuid();
                player thread onPlayerDisconnect();
        }
}
 
onPlayerDisconnect()
{
        self waittill("disconnect");
        iprintln(self._guid);
}
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: Running a function on every player disconnect

Post by megazor » May 5th, 2013, 4:08 am

Play around with maps\mp\gametypes\_callbacksetup.gsc

This is the part you will want to deal with:

Code: Select all

/*================
Called when a player drops from the server.
Will not be called between levels.
self is the player that is disconnecting.
================*/
CodeCallback_PlayerDisconnect()
{
        self notify("disconnect");
        [[level.callbackPlayerDisconnect]]();
}
you can add here

Code: Select all

level notify("disconnecting", self);
or another function. But I suggest to avoid modifying the stock file, better use the [[level.callbackPlayerDisconnect]]() function, which is defined in gametype script files.

CHRLZ
CJ Wannabe
CJ Wannabe
Posts: 10
Joined: July 9th, 2011, 1:06 pm

Re: Running a function on every player disconnect

Post by CHRLZ » May 17th, 2013, 9:39 am

Sorry about my lack of reply.

University work has kept be rather busy for a few weeks, and just general life stuff.

I haven't been able to get this working (mind you, I haven't had the time I'd like to put into it) but thank you Drofder and megazor for your help :)



Now I have another question (of course).

This is on a server level (but it's still modding so I guess it's in the right spot) for the cod4 CJ mod.

If I were to write a function to automatically promote someone from a list of people given by a dvar, what command do I use to actually promote them, as I (obviously) can't access the functions that would be defined in the scripts within the mod.ff from outside, what is used to promote someone outside of that?



A bit of background, I'm relatively new to scripting, but I've recently started studying Computer Science and I've only really got a few months of programming experience (and in Java, at that). Hence why my syntax may be off and I may miss some obvious functions.

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Running a function on every player disconnect

Post by Drofder2004 » May 17th, 2013, 9:17 pm

The function is:

Code: Select all

player codjumper\_cj_admins::promotePlayer(1);
The DVar you are suggesting already exists as:

cj_autoadmin
cj_adminguids
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

CHRLZ
CJ Wannabe
CJ Wannabe
Posts: 10
Joined: July 9th, 2011, 1:06 pm

Re: Running a function on every player disconnect

Post by CHRLZ » May 18th, 2013, 6:39 am

Thanks, I needed a way to read from other dvar lists to automatically promote players, as our clan is large and I can foresee the cj_adminguids string getting too long to be read.

So I need to read from multiple dvars.

Thanks Drof :)

CynePhoba
CJ Wannabe
CJ Wannabe
Posts: 5
Joined: May 25th, 2013, 5:04 am

Re: Running a function on every player disconnect

Post by CynePhoba » May 27th, 2013, 2:14 am

megazor wrote:Play around with maps\mp\gametypes\_callbacksetup.gsc

This is the part you will want to deal with:

Code: Select all

/*================
Called when a player drops from the server.
Will not be called between levels.
self is the player that is disconnecting.
================*/
CodeCallback_PlayerDisconnect()
{
        self notify("disconnect");
        [[level.callbackPlayerDisconnect]]();
}
you can add here

Code: Select all

level notify("disconnecting", self);
or another function. But I suggest to avoid modifying the stock file, better use the [[level.callbackPlayerDisconnect]]() function, which is defined in gametype script files.
How exactly do you use this function? This would be great for what i'm needing =P

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests