From JC2-MP Documentation
This function is available for the Player class, on both the server and client.
Each version returns a table containing the following:
- Vector3 position
- object entity
entity can be one of the following types:
To get the type of entity, you can use entity.__type, which returns a string, such as "Player".
Server: Print player Bob's results of GetAimTarget every second
timer = Timer() function Foo() if timer:GetSeconds() > 1 then timer:Restart() local results = Player.Match("Bob"):GetAimTarget() print("position: "..tostring(results.position)) print("entity: "..tostring(results.entity)) end end Events:Subscribe("PostTick", Foo)
Client: Print what you're aiming at when you hold fire
function Foo(args) if args.input == Action.FireRight then local results = LocalPlayer:GetAimTarget() if results.entity then local entityType = results.entity.__type Chat:Print("You are aiming at a "..entityType..": "..tostring(results.entity), Color(255, 255, 255)) end end end Events:Subscribe("LocalPlayerInput", Foo)
The player and vehicle table variables are deprecated in favor of a single entity variable. They both still work, however.