What happened to OC? - CLOSED Carnage?!
Sign in to follow this  
Followers 0
Devieth

SAPP's Intersect

Edit: I got it to detect if one player is aiming at another... Now my problem is getting it not think a player is aiming at themselves when they move forward or backward.

Here is what I have:

 

local standing_height = 0.64
local crouch_height = 0.35

function OnTick()
	for i = 1,16 do
		if player_present(i) and player_alive(i) then -- Avilible to aim at things?

			local m_object = getdynamicplayer(i)
			local x , y, z = read_float(m_object + 0x230), read_float(m_object + 0x234), read_float(m_object + 0x238) -- Player camera
			local hit, vic = Intersect(m_object, i, x, y, z)

			if hit then
				if vic then
					rprint(i, getname(i).. " is aiming at " .. getname(vic))
				end
			end
		end
	end
end

function Intersect(m_object, PlayerIndex, vx, vy, vz)
	local hit, vic = false, nil

	local crouch_state = read_float(m_object + 0x50C)
	local x, y, z = read_vector3d(m_object + 0x5c) -- Player Location

	if (crouch_state == 0) then -- We need to adjust for crouching and standing heights.
		z = z + standing_height
	else
		z = z + (crouch_height * crouch_state)
	end

	local hit, cx, cy, cz, ObjectID = intersect(x, y, z, vx*1000, vy*1000, vz*1000) -- Run it.

	for i = 1,16 do
		if player_present(i) and player_alive(i) and i ~= PlayerIndex then -- Can they be aimed at?
			if get_object_memory(ObjectID) == getdynamicplayer(i) then -- Are we aiming at a player?
				hit = true
				vic = i
			end
		end
	end
	return hit, vic
end
 
Edited by Devieth

Share this post


Link to post
Share on other sites

Tiddy-bits:

The intersect function has an optional parameter for an object to ignore.

Something like this should probably work:

local player_object_id = read_dword(get_player(PlayerIndex) + 0x34)
local hit, cx, cy, cz, ObjectID = intersect(x, y, z, vx*1000, vy*1000, vz*1000, player_object_id) -- Run it.
Devieth likes this

Share this post


Link to post
Share on other sites
Sign in to follow this  
Followers 0
  • Recently Browsing   0 members

    No registered users viewing this page.