trace

Engine Trace Library, loaded by requiring "gamesense/trace"

Functions

trace.line

trace.line(from: vector, to: vector[, options: table]): table (trace info)

Returns a table, structured as Trace

trace.hull

trace.hull(from: vector, to: vector, mins: vector, maxs: vector[, options: table]): table (trace info)

Returns a table, structured as Trace

Trace

Description

  • This is simply the structure of the output table.

  • plane is a table that consists of values, indexed as normal, dist, type and sign_bits.

  • surface is a table that consists of values, indexed as name, props and flags.

Values

Mask

Description

  • Mask is an optional value in the "options" table.

  • The default mask is MASK_PLAYERSOLID.

  • You can pass either a string, a number or a table with strings or numbers.

  • If it's a table, all the masks will be combined by using the bitwise OR.

  • These enumerations are simply combinations of Contents which you can use just like the masks.

Values

Skip

Description

  • Skip is an optional value in the "options" table.

  • It can be either an entindex, a table with entindices or a function, like a "reverse" ShouldHitEntity callback.

  • If you're using it as a callback, entindex and contents_mask can be accessed by adding them to the arguments of a function.

Type

Description

  • Type is an optional value in the "options" table, indexed by "type".

  • The default trace type is TRACE_EVERYTHING.

  • You can pass either a string or a number.

Values

Contents

Description

  • This is what masks are combined with, meaning it can be used the same way.

  • This is mostly for rebuilding stuff when Valve doesn't use the masks that already exist.

Values

Examples

Plane visualizer

  • A demonstration how you can create a crosshair used in many other cheat providers, if you ever found it cool-looking of course.

  • I'm not entirely good at math so I'm sure there's a better way to make it!

local vector = require "vector"
local trace = require "gamesense/trace"

client.set_event_callback("paint", function()
	local local_player = entity.get_local_player()

	local src = vector(client.eye_position())
	local dest = src + vector():init_from_angles(client.camera_angles()) * 4096

	local tr = trace.line(src, dest, { skip = local_player, mask = "MASK_SHOT" })

	local end_pos = tr.end_pos
	local right, up = tr.plane.normal:vectors()

	local size = 8

	local upper_left = end_pos + up * size + right * size
	local upper_right = end_pos + up * size - right * size
	local bottom_right = end_pos - up * size - right * size
	local bottom_left = end_pos - up * size + right * size

	local x1, y1 = renderer.world_to_screen(upper_left:unpack())
	local x2, y2 = renderer.world_to_screen(upper_right:unpack())
	local x3, y3 = renderer.world_to_screen(bottom_right:unpack())
	local x4, y4 = renderer.world_to_screen(bottom_left:unpack())

	renderer.line(x1, y1, x2, y2, 255, 255, 255, 255)
	renderer.line(x2, y2, x3, y3, 255, 255, 255, 255)
	renderer.line(x3, y3, x4, y4, 255, 255, 255, 255)
	renderer.line(x4, y4, x1, y1, 255, 255, 255, 255)

	renderer.triangle(x1, y1, x2, y2, x3, y3, 255, 255, 255, 100)
	renderer.triangle(x1, y1, x3, y3, x4, y4, 255, 255, 255, 100)
end)

Skip & mask capabilities

  • This example shows what skip & mask values are capable of.

local vector = require "vector"
local trace = require "gamesense/trace"

client.set_event_callback("setup_command", function()
    local from = vector(client.eye_position())
    local to = from + vector():init_from_angles(client.camera_angles()) * 1024
    
    -- number example
    -- skip the specified entindex
    local local_player = entity.get_local_player()
    
    local tr_n = trace.line(from, to, {
        skip = local_player,
        
        -- mask as a number
        mask = 0xFFFFFFFF
    }
    
    -- table example
    -- skip every teammate
    local teammates = {}
    
    local players = entity.get_players()
    for i, entindex in ipairs(players) do
        if not entity.is_enemy(entindex) then
            table.insert(teammates, entindex)
        end
    end
    
    local tr_t = trace.line(from, to, {
        skip = teammates,
        
        -- mask as a string
        mask = "MASK_PLAYERSOLID"
    }
    
    -- function example
    -- skip every "CCSPlayer" entity
    local skip_classname = "CCSPlayer"
    
    local tr_f = trace.line(from, to, {
        skip = function(entindex, contents_mask)
            return entity.get_classname(entindex) == skip_classname
        end,
        
        -- mask as a table with strings and numbers
        -- a combination that results in "MASK_BLOCKLOS"
        mask = {"CONTENTS_SOLID", "CONTENTS_MOVEABLE", 0x40}
    })
end)

Last updated