Page 1 of 1

Running a function on every player disconnect

Posted: May 1st, 2013, 10:07 am
by CHRLZ
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

Re: Running a function on every player disconnect

Posted: May 1st, 2013, 8:16 pm
by Drofder2004
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.

Re: Running a function on every player disconnect

Posted: May 4th, 2013, 9:52 am
by CHRLZ
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
//...
}

Re: Running a function on every player disconnect

Posted: May 5th, 2013, 12:06 am
by Drofder2004
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);
}

Re: Running a function on every player disconnect

Posted: May 5th, 2013, 4:08 am
by megazor
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.

Re: Running a function on every player disconnect

Posted: May 17th, 2013, 9:39 am
by CHRLZ
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.

Re: Running a function on every player disconnect

Posted: May 17th, 2013, 9:17 pm
by Drofder2004
The function is:

Code: Select all

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

cj_autoadmin
cj_adminguids

Re: Running a function on every player disconnect

Posted: May 18th, 2013, 6:39 am
by CHRLZ
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 :)

Re: Running a function on every player disconnect

Posted: May 27th, 2013, 2:14 am
by CynePhoba
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