lfnetwork.com mark read register faq members calendar

Thread: Getting a Clients Location?
Thread Tools Display Modes
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Old 09-10-2009, 04:02 PM   #1
TJ01
Lurker
 
Join Date: Aug 2009
Posts: 7
Getting a Clients Location?

Hi.

Keeping it short and sweet ; how do i obtain a Client's Location in co-ordinates?

I looked up how the viewpos command gets the co-ords but that's a client-side command and the cg.refdef.vieworg doesn't work on a server side mod.

Surely there must be a struct somewhere or something that holds the client's location...

Nearly all mod's out there let you tele to a player so i know it can be done; i just don't know how

Thanks for your help
TJ01 is offline   you may: quote & reply,
Old 09-10-2009, 04:43 PM   #2
-=*Raz0r*=-
Rookie
 
-=*Raz0r*=-'s Avatar
 
Join Date: Oct 2006
Location: Australia
Posts: 243
Heh, mmk...

Here's a bit of code I used to teleport you roughly where you're looking at.
I'm sure you could tweak it around a bit for what you want =P

Code:
static void teleport( gentity_t *ent ) {
	trace_t	tr;
	vec3_t	fPos, telepos;
	int i;

	//We want to obtain where they're looking at - This does it for us =]
	AngleVectors(ent->client->ps.viewangles, fPos, NULL, NULL);
	for (i=0; i < 3; i++)
		fPos[i] = ent->client->ps.origin[i] + fPos[i]*Q3_INFINITE;

	//Perform the trace, the tr.endpos will hold the vec3_t of where it collided with something
	trap_Trace(&tr, ent->client->ps.origin, 0, 0, fPos, ent->s.number, MASK_OPAQUE|CONTENTS_SOLID|CONTENTS_BODY|CONTENTS_ITEM|CONTENTS_CORPSE );

	//If we teleported directly to tr.endpos, we'd end up in a wall, so do a bit of vector math and we're safe
	VectorMA(tr.endpos, 32, tr.plane.normal, telepos);

	//Beam me up, scotty!
	TeleportPlayer( ent, telepos, ent->client->ps.viewangles );
}

-=*Raz0r*=- is offline   you may: quote & reply,
Old 09-11-2009, 11:16 AM   #3
TJ01
Lurker
 
Join Date: Aug 2009
Posts: 7
Smile

Thanks a lot razor
That's a great help.

I'll have a poke around and see if i can find the clients location in ent client


Much Appreciated
TJ01 is offline   you may: quote & reply,
Old 09-11-2009, 02:20 PM   #4
TJ01
Lurker
 
Join Date: Aug 2009
Posts: 7
The command worked a treat; thanks razor.

But I'm still unable to create a command which prints the clients location.
I want the clients location in co-ordinates to be viewable to admins.

Any idea where i'd find the clients location/origin ?

Also i'm unsure how i would make a cmd which teleports any other client to co-ords; could anyone help me here?
TJ01 is offline   you may: quote & reply,
Old 09-12-2009, 03:00 AM   #5
-=*Raz0r*=-
Rookie
 
-=*Raz0r*=-'s Avatar
 
Join Date: Oct 2006
Location: Australia
Posts: 243
No problem

As you might have noticed, TeleportPlayer works the real magic.
It takes in a pointer to the gentity_t of the player you wish to teleport, then a vector (3d coordinates), and the angle you wish to face them in (as another vector).

VectorMA(tr.endpos, 32, tr.plane.normal, telepos) is a macro for some funky vector math (Not sure exactly what it does) that basically takes in the end position of the trace (Where you're looking at), two numbers that work their magic in this case, and then stores it in telepos (A vector I created)

telepos now holds the exact location in 3d coordinates I wanted to teleport the player to, so I passed that as an argument to TeleportPlayer


So now you know how that works; here's how to do the same for teleporting to a player.

If we just teleport directly to them, we'll telefrag them, so we'll have to safeguard against that.
I also safeguarded against entering an invalid name.
This isn't the cleanest code, and I'm sure someone could offer a less ugly version of this, but here's what I got after playing around for a few minutes...
Code:
void TeleportToPlayer( gentity_t *ent ) {
	vec3_t		origin = {0, 0, 0};
	int			j = -1;
	char		name[32];

	//	If they didn't supply a name, don't let them teleport
	if (trap_Argc() < 2)
	{
		trap_SendServerCommand(ent->client->ps.clientNum, va("print \"^1You must provide a name\n\""));
		return;
	}

	//	Get the name they supplied, and we'll try to work out the clientNum
	strcpy( name, ConcatArgs(1) );
	j = G_ClientNumberFromName(name);

	//Because G_ClientNumberFromName will return -1 if they couldn't find anything,
	//	we have to safeguard, otherwise we'd teleport to some weird location
	if ( j<0 || j>=MAX_CLIENTS )
	{// 'j' wasn't between 0 <-> 32, so warn them and exit this function
		trap_SendServerCommand(ent->client->ps.clientNum, va("print \"^1Player %s is not on the server\n\"", name));
		return;
	}

	//	They're a valid client, so copy their coordinates into 'origin'
	VectorCopy(level.clients[j].ps.origin, origin);

	//	TODO: If we teleported straight to those coord's, we'd telefrag them, so play around with 'origin'

	//Teleport them to 'origin'
	TeleportPlayer(ent, origin, ent->client->ps.viewangles);
}
All that's left to do is play around with 'origin' so we won't teleport inside them.


If you just wanted to print the coords of the player, it's a bit simpler...

Code:
void TeleportToPlayer( gentity_t *ent ) {
	int			j = -1;
	char		name[32];
	char		theirOrigin[24];

	//	If they didn't supply a name, exit this function
	if (trap_Argc() < 2)
	{
		trap_SendServerCommand(ent->client->ps.clientNum, va("print \"^1You must provide a name\n\""));
		return;
	}

	//	Get the name they supplied, and we'll try to work out the clientNum
	strcpy( name, ConcatArgs(1) );
	j = G_ClientNumberFromStrippedName(name);

	//Because G_ClientNumberFromName will return -1 if they couldn't find anything,
	//	we have to safeguard, otherwise we'd teleport to some weird location
	if ( j<0 || j>=MAX_CLIENTS )
	{// 'j' wasn't between 0 <-> 32, so warn them and exit this function
		trap_SendServerCommand(ent->client->ps.clientNum, va("print \"^1Player %s is not on the server\n\"", name));
		return;
	}

	//	They're a valid client, so copy their coordinates into 'myStr'
	strcpy(theirOrigin, vtos(level.clients[j].ps.origin));

	//	Print out their coords
	trap_SendServerCommand(ent->client->ps.clientNum, va("print \"^1^5%s\n\"", theirOrigin));
}
I've heavily commented it all so you can understand it.
Hope I helped ^_^'


Last edited by -=*Raz0r*=-; 09-12-2009 at 03:16 AM.
-=*Raz0r*=- is offline   you may: quote & reply,
Old 09-12-2009, 11:58 AM   #6
TJ01
Lurker
 
Join Date: Aug 2009
Posts: 7
That's brilliant. Thanks Razor

I understood how tele'ing worked by looking at setviewpos

I just didn't know how to get a client ID or origin.

Thanks Alot; you've been a great help and i've learnt alot from your code snipets.

Oh and about not tele-fragging them, could i just add 100 to one of the axis. Would that work?

Last edited by TJ01; 09-12-2009 at 12:30 PM.
TJ01 is offline   you may: quote & reply,
Old 09-12-2009, 12:41 PM   #7
-=*Raz0r*=-
Rookie
 
-=*Raz0r*=-'s Avatar
 
Join Date: Oct 2006
Location: Australia
Posts: 243
Yeah, something like that - I just wanted a clean way to do it =P
You'd best put that in before trap_SendServerCommand is called

-=*Raz0r*=- is offline   you may: quote & reply,
Old 09-12-2009, 12:57 PM   #8
TJ01
Lurker
 
Join Date: Aug 2009
Posts: 7
Oh.

I thought i'd put it after this line
Code:
VectorCopy(level.clients[j].ps.origin, origin);
And then edit 'origin'.
TJ01 is offline   you may: quote & reply,
Old 09-12-2009, 02:13 PM   #9
-=*Raz0r*=-
Rookie
 
-=*Raz0r*=-'s Avatar
 
Join Date: Oct 2006
Location: Australia
Posts: 243
Ah, I meant before TeleportPlayer is called, so yeah =P
Bit tired here >_> <_<

-=*Raz0r*=- is offline   you may: quote & reply,
Old 09-13-2009, 07:05 AM   #10
TJ01
Lurker
 
Join Date: Aug 2009
Posts: 7
Hey

Theres a slight issue with the TeletoPlayer code but ive fixed it.

Code:
//	Get the name they supplied, and we'll try to work out the clientNum
	strcpy( name, ConcatArgs(1) );
	j = ClientNumberFromString  (ent, name );

	//Because G_ClientNumberFromName will return -1 if they couldn't find anything,
	//	we have to safeguard, otherwise we'd teleport to some weird location
	if ( j == -1 || j>=MAX_CLIENTS )
	{// 'j' wasn't between 0 <-> 32, so warn them and exit this function
		return;
I've used ClientNumberFromString instead as its more stable and You don't need to print an error message since that function does it for you

It also works with ClientNumbers; so /teletoplayer 2 would tele you to Client 2 no matter what their name is.

Last edited by TJ01; 09-13-2009 at 08:56 AM.
TJ01 is offline   you may: quote & reply,
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Go Back   LucasForums > Network > JediKnight Series > Editing Central > JA Coding > Getting a Clients Location?

Tags
client, coding, coordinates, location, mod, tele

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:46 PM.

LFNetwork, LLC ©2002-2011 - All rights reserved.
Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.