yep, confirmed, there's a bug going on in GG somewhere.
local U = require "scriptbank\\utillib"
local P = require "scriptbank\\physlib"
local target = {}
local target_dist = 100
local textypos = 70
local place = 1
local hit = {}
function raycast_init(e)
--lazy way to assign the entity numbers
--my placement in editor = front / left / right / back
target[1] = 3
target[2] = 4
target[3] = 5
target[4] = 6
for a = 1, 4 do
hit[a] = 0
end
end
function raycast_main(e)
--get the player position
local x1,y1,z1 = g_PlayerPosX,g_PlayerPosY,g_PlayerPosZ
--do this in 1 frame so we know the target object is in the correct place when we ray cast to it later
if place == 1 then
--get the player rotation
local xa1,ya1,za1 = g_PlayerAngX,g_PlayerAngY,g_PlayerAngZ
local x2,y2,z2 = 0,0,0
--get and update the target object position based on the player position & angle
for a = 1, 4 do
CollisionOff(target[a])
if a == 1 then
--infront
x2,y2,z2 = U.Rotate3D( 0, 0, target_dist, 0, math.rad(ya1), 0 )
elseif a == 2 then
--left
x2,y2,z2 = U.Rotate3D( -target_dist, 0, 0, 0, math.rad(ya1), 0 )
elseif a == 3 then
--right
x2,y2,z2 = U.Rotate3D( target_dist, 0, 0, 0, math.rad(ya1), 0 )
elseif a == 4 then
--behind
x2,y2,z2 = U.Rotate3D( 0, 0, -target_dist, 0, math.rad(ya1), 0 )
end
local x3,y3,z3 = x1+x2,y1+y2,z1+z2
SetPosition(target[a],x3,y3,z3)
SetRotation(target[a],0,0,0)
end
place = 0
--do this in the other frame so we have already positioned the target object
else
--just helps for third person debugging
--TextCenterOnX(50,65,3,ignore)
for a = 1, 4 do
local ignore = g_Entity[11]['obj'] --g_Entity[target[a]]['obj'] --ignore target object or thirdperson
--get the target position (we updated before)
local x3,y3,z3 = GetEntityPosAng(target[a])
--check for obstalces
hit[a] = IntersectAll(x1,y1,z1,x3,y3,z3,ignore)
if hit[a] == nil then
hit[a] = 0
--convert from object number to entity number if it was dynamic
else
hit[a] = P.ObjectToEntity(hit[a])
if hit[a] == nil then
hit[a] = 0
end
end
--if no obstalces found we check for static obstalces next
if hit[a] == 0 then
hit[a] = IntersectStatic(x1,y1,z1,x3,y3,z3,ignore)
if hit[a] == nil then
hit[a] = 0
end
end
end
place = 1
end
--show the results on screen
textypos = 70
for a = 1, 4 do
local text = ""
if a == 1 then
text = "front = "..hit[a]
elseif a == 2 then
text = "left = "..hit[a]
elseif a == 3 then
text = "right = "..hit[a]
elseif a == 4 then
text = "back = "..hit[a]
end
local text2 = ""
--this is just a quick way to differentiate between static and dynamic as we converted the dynamic numbers earlier
if hit[a] > 70000 then
text2 = " (static)"
elseif hit[a] > 0 then
text2 = " (dynamic)"
else
text2 = " (nothing)"
end
TextCenterOnX(50,textypos,3,text..text2)
textypos = textypos + 5
end
end
@3com you can use the projectile commands to make the houses explode more accurately
g_projectileevent_explosion = 0
g_projectileevent_name = ""
g_projectileevent_x = 0
g_projectileevent_y = 0
g_projectileevent_z = 0
g_projectileevent_radius = 0
g_projectileevent_damage = 0
g_projectileevent_entityhit = 0
or make a script that tracks their HP (if you want non-projectile weapons to also destroy them)