Retrieving players' data when they join a server

Discussions about Coding and Scripting
Post Reply
User avatar
UTPe
Masterful
Posts: 584
Joined: Sun Jul 12, 2009 7:10 pm
Personal rank: Dude
Location: Trieste, Italy
Contact:

Retrieving players' data when they join a server

Post by UTPe »

Hi,
I would need to know how to retrieve players' basic data when they join a server.
I'm using the modifyLogin function of Mutator class.
By using playerName = Level.Game.ParseOption(Options, "Name") it's possible to retrieve the name of the players who connect to a server but I cannot find a method that can be used to know if those player are "real players" or spectators. Any ideas ?

thanks in advance,
Pietro


I started from this code:

Code: Select all

class ClassName extends Mutator config(configfile);

function preBeginPlay() {
   ...
}

function modifyLogin(out class<playerpawn> spawnClass, out string portal, out string options) {

   local string playerName;

   if (nextMutator != none) {
      nextMutator.modifyLogin(spawnClass, portal, options);
   }

   // get player name
   playerName = Level.Game.ParseOption(Options, "Name");

}
Personal map database: http://www.ut99maps.net

"These are the days that we will return to one day in the future only in memories." (The Midnight)
User avatar
Sp0ngeb0b
Adept
Posts: 376
Joined: Wed Feb 13, 2008 9:16 pm
Location: Cologne
Contact:

Re: Retrieving players' data when they join a server

Post by Sp0ngeb0b »

Code: Select all

ClassIsChildOf(SpawnClass, class'Spectator')
Have a look at the 'Login' event in GameInfo.
Website, Forum & UTStats

Image
******************************************************************************
Nexgen Server Controller || My plugins & mods on GitHub
******************************************************************************
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Retrieving players' data when they join a server

Post by JackGriffin »

Hey Mr. P, it's gopostal. Are you going to use this on an ACE server because there is simple ways of getting everything with that.
So long, and thanks for all the fish
User avatar
UTPe
Masterful
Posts: 584
Joined: Sun Jul 12, 2009 7:10 pm
Personal rank: Dude
Location: Trieste, Italy
Contact:

Re: Retrieving players' data when they join a server

Post by UTPe »

Sp0ngeb0b wrote:

Code: Select all

ClassIsChildOf(SpawnClass, class'Spectator')
Have a look at the 'Login' event in GameInfo.
Thanks for the infos, I'll take a look at it ! :tu:

JackGriffin wrote:Hey Mr. P, it's gopostal. Are you going to use this on an ACE server because there is simple ways of getting everything with that.
Yes, I know it's you :D
About ACE, I really dont' know at the moment, surely I'll do some tests on ISC server where ACE is not installed
Personal map database: http://www.ut99maps.net

"These are the days that we will return to one day in the future only in memories." (The Midnight)
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Retrieving players' data when they join a server

Post by JackGriffin »

About your original question, if you want to specifically look at spectators then you check their PRI assignments. This is a function from a HUD mutator that shows in the players screen a list of players and also spectators that Bob from dU and I wrote for monsterhunt2:

Code: Select all

simulated function DrawPlayerLists (Canvas C)
{
    local float XL, YL, YOffSetP, YOffSetS;
	 local PlayerReplicationInfo PRI;
	 local int PlayerCount, i;
    local string playerString;

    if (PlayerOwner.PlayerReplicationInfo == none || C == none) return;

	 C.Font=C.SmallFont;
	 C.DrawColor=HUDColor;

	 C.StrLen("[Player(LOCATION)] ", XL, YL);
	 C.SetPos(C.ClipX - XL, C.ClipY / 4);
	 C.DrawText("[Player(LOCATION)]",False);

	 C.StrLen("[Spectators] ",XL,YL);
	 C.SetPos(C.ClipX - XL,C.ClipY / 1.5);
	 C.DrawText("[Spectators] ",False);

	// Wipe everything.
	for ( i=0; i<ArrayCount(Ordered); i++ )
		Ordered[i] = None;
	for ( i=0; i<32; i++ )
	{
		if (PlayerPawn(Owner).GameReplicationInfo.PRIArray[i] != None)
		{
			PRI = PlayerPawn(Owner).GameReplicationInfo.PRIArray[i];
			if ( !PRI.bWaitingPlayer )
			{
				Ordered[PlayerCount] = PRI;
				PlayerCount++;
				if ( PlayerCount == ArrayCount(Ordered) )
					break;
			}
		}
	}

	SortScores(PlayerCount);

    YOffSetP = C.ClipY/4 + YL;
    YOffSetS = C.ClipY/1.5 + YL;

    for (i = 0; i < playerCount; ++i)
    {
        if (Ordered[i].PlayerName ~= "player")
        {
        }
        else
        {

            playerString = Ordered[i].PlayerName;
            if (!Ordered[i].bIsSpectator)
            {
                if (Ordered[i].PlayerLocation != none && Ordered[i].PlayerLocation.LocationName != "")
                    playerString = playerString@"("$Ordered[i].PlayerLocation.LocationName$")";
                else if (Ordered[i].PlayerZone != none && Ordered[i].PlayerZone.ZoneName != "")
                    playerString = playerString@"("$Ordered[i].PlayerZone.ZoneName$")";
            }

            if (len(playerstring) > 30)
               playerString = left(playerString, 30)$")"; // truncate if longer than 30 chars

            C.StrLen (playerString$" ", XL, YL);
            if (Ordered[i].bIsSpectator) {
                C.SetPos(C.ClipX - XL, YOffSetS);
                YOffSetS += YL;
            }
            else {
                C.SetPos(C.ClipX - XL, YOffSetP);
                YOffSetP += YL;
            }
            if (!Ordered[i].bIsSpectator && PlayerOwner.PlayerReplicationInfo.PlayerName == Ordered[i].PlayerName)
                C.DrawColor=GoldColor;
            else
                C.DrawColor=WhiteColor;

            C.DrawText (playerString, False);
        }
    }
}
You can see here that the simple switch of
if (!Ordered.bIsSpectator)
allows you to sort the players to different 'lists' easily. This is the most efficient way to do what you are wanting to do. Grab the array of players then sort them depending on the way you need them separated.
So long, and thanks for all the fish
User avatar
Sp0ngeb0b
Adept
Posts: 376
Joined: Wed Feb 13, 2008 9:16 pm
Location: Cologne
Contact:

Re: Retrieving players' data when they join a server

Post by Sp0ngeb0b »

I don't think checking the PRI is possible in this case, because he wants to retrieve the information before the player actually joins the server, and therefore no player data has been replicated to the server yet / no PRI is available.
Website, Forum & UTStats

Image
******************************************************************************
Nexgen Server Controller || My plugins & mods on GitHub
******************************************************************************
User avatar
UTPe
Masterful
Posts: 584
Joined: Sun Jul 12, 2009 7:10 pm
Personal rank: Dude
Location: Trieste, Italy
Contact:

Re: Retrieving players' data when they join a server

Post by UTPe »

Ok, I want to be more clear about the mutator, this is the code:

Code: Select all

class ClassName extends Mutator config(configfile);

function preBeginPlay() {
   ...
}

function modifyLogin(out class<playerpawn> spawnClass, out string portal, out string options) {

   local string playerName;

   if (nextMutator != none) {
      nextMutator.modifyLogin(spawnClass, portal, options);
   }

   // get player name
   playerName = Level.Game.ParseOption(Options, "Name");

   // at this point I've to understand ONLY if the player joining the server is a spectator or not...
   
   // ...now I know it and this info is stored someway in the code

   if (...the player joining the server is a spectator...) {
		for (aPawn = level.pawnList; aPawn != none; aPawn = aPawn.nextPawn) {
			if (aPawn.isA('PlayerPawn')) {

                                                        // do something for every playerpawn in the server
                       		}
		}
   } else {
		for (aPawn = level.pawnList; aPawn != none; aPawn = aPawn.nextPawn) {
			if (aPawn.isA('PlayerPawn')) {

                                                        // do something else for every playerpawn in the server
                       		}
		}
   }
}

// other functions...

Now I have to retrieve player type data (player or spectator) by using the "Login" event in GameInfo class...

Code: Select all

class ClassName extends GameInfo

event playerpawn Login (string Portal, string Options, out string Error, class<playerpawn> SpawnClass) {

        if (ClassIsChildOf(SpawnClass, class'Spectator')) {

             // set the value of a variable so I'm able to read it ?
        }
}
How can I bind the 2 classes in order to get the infos from the second class ? thanks :help:
Personal map database: http://www.ut99maps.net

"These are the days that we will return to one day in the future only in memories." (The Midnight)
User avatar
Sp0ngeb0b
Adept
Posts: 376
Joined: Wed Feb 13, 2008 9:16 pm
Location: Cologne
Contact:

Re: Retrieving players' data when they join a server

Post by Sp0ngeb0b »

There's no need to have two classes. By saying have a look at the Login event, I meant it more in the way that you can actually see how things work whenever a new player joins ;)

The event automatically calls the mutator chain

Code: Select all

event playerpawn Login (
	string Portal,
	string Options,
	out string Error,
	class<playerpawn> SpawnClass
) {

// Other stuff

BaseMutator.ModifyLogin(SpawnClass, Portal, Options);           <-------- here
Therefore, you are able to link yourself with your mutator into this function call whenever a new player joins. Thats what you did with your modifyLogin function. Now, you can simply add this check which I posted above right into your existing function, so it looks like this:

Code: Select all

// at this point I've to understand ONLY if the player joining the server is a spectator or not...  
// ...now I know it and this info is stored someway in the code

if (ClassIsChildOf(SpawnClass, class'Spectator')) {
     // Do your stuff
}
But note that this function is called during the login process, which could still fail in (unlikely) cases and as stated in my post above doesn't give you access to the player's PRI, but if you only want to check whether the new player is a spectator or not you can ignore that :)
Website, Forum & UTStats

Image
******************************************************************************
Nexgen Server Controller || My plugins & mods on GitHub
******************************************************************************
User avatar
UTPe
Masterful
Posts: 584
Joined: Sun Jul 12, 2009 7:10 pm
Personal rank: Dude
Location: Trieste, Italy
Contact:

Re: Retrieving players' data when they join a server

Post by UTPe »

Thanks for your comments Sp0ngeb0b :tu:
I'm moving my first steps into UScript and many things are not so clear :?

greetings,
Pietro
Personal map database: http://www.ut99maps.net

"These are the days that we will return to one day in the future only in memories." (The Midnight)
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Retrieving players' data when they join a server

Post by JackGriffin »

Get used to it, it doesn't get much better :loool:

Ask anything here, this is an active forum and chock full of good advice and people that will help.
So long, and thanks for all the fish
Post Reply