entity under crosshair

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
c_los
Private
Posts: 7
Joined: Tue Jul 03, 2007 7:53 pm

entity under crosshair

Post by c_los »

Is there a way to get the $targetname of an entity under the crosshair (such as a cube script_object)? I know there is a command to get a shader under the crosshair :/
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Unfortunately no such command exists :(
Image
Condor
Colour Sergeant
Posts: 82
Joined: Mon Apr 09, 2007 3:19 pm
Location: Bavaria (Germany)

Post by Condor »

I have another question whichs similar to this one:

Is there any way to move the cursor over the screen independet from the players angle ingame and a function which returns the mousekeys pressed and the cursorposition?
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

test pointer

Post by tltrude »

Try this tutorial map.

Test Pointer Map
Image


Review: A new item has been added to your inventory! With this tutorial map you can add a pointer for selecting buttons on any control panel. The map has panels for a four story elevator, touchtone phone, and a fireworks rocket launcher. A .map file, a playable pk3, and a text version of the script are included.
Tom Trude,

Image
Condor
Colour Sergeant
Posts: 82
Joined: Mon Apr 09, 2007 3:19 pm
Location: Bavaria (Germany)

Post by Condor »

Ah, yes, thats what I need, thank you :)
c_los
Private
Posts: 7
Joined: Tue Jul 03, 2007 7:53 pm

Post by c_los »

But couldn't I do something along the lines of the 'flashlight' thing and just check what it isTouching and get the returned entity?
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

Well, there is a way. You can do a trace, but you need to have a list of objects that the trace can possibly collide with beforehand (in the example it's an array called local.entitieslist). It would go something along these lines (off the top of my head):

Code: Select all

local.start = local.player gettagposition "eyes bone" // this is not exactly the player's viewpoint, but it's pretty close
local.dir = angles_toforward local.player.angles
local.end = local.start + local.dir * 64 // change 64 to how far you want the trace to go; 16 units is 1 foot
local.hit = trace local.start local.end
local.ent = spawn script_origin origin local.hit
for (local.i = 1; local.i <= local.entitieslist.size; local.i++) {
	if (local.ent isTouching local.entitieslist[local.i]) {
		// got a hit, run your code here
		break // this exits the loop
	}
}
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
Post Reply