try this
#Global Hooks
$GameInit:
[
--all this stuff is for multires support, for getting true width and height, and for generating factors to scale coords by
w = gr.getScreenWidth()
h = gr.getScreenHeight()
cx = w/2
cy = h/2
if w >= 1024 then
wf = w / 1024
hf = h / 768
awh = (wf + hf) / 2
hires = true
else
wf = w / 640
hf = h / 480
awh = ((wf + hf) / 2) * 0.625
hires = false
end
--now that were done with that ****, we can define some more important vars
xtarg = cx --this is where our crosshair will want to be
ytarg = cy --same thing but a bit more vertical
wepvel = 450 --set for thrasher for testing, wel do what wanderer did later
chr = 50
chg = 50
chb = 50
cha = 50
--now a crosshair, il make this much more detailed later, with target direction and orientation, target iff and maybe ammo gauge and locked/locking indicators
drawgunsight = function(x,y,r,g,b,a)
gr.setColor(r,g,b,a)
gr.drawCircle(25,x,y)
gr.setColor(r,g,b,255)
gr.drawGradientLine(x+18,y+18,x+5,y+5)
gr.drawGradientLine(x-18,y+18,x-5,y+5)
gr.drawGradientLine(x+18,y-18,x+5,y-5)
gr.drawGradientLine(x-18,y-18,x-5,y-5)
end
--and finally lets jack wanderers code, because i really dont feel like plotting vectors in 3d space
leadreticle = function(weaponvel)
local targetpos = target.Position --tweak theese
local targetvel = target.Physics.Velocity --looks like nothing else needs to be tweaked here
local lenghttargetvel = targetvel:getMagnitude()
local playerpos = player.Position
local plrtotrg = playerpos - targetpos
local lenghtplrtotrg = plrtotrg:getMagnitude()
local trgangle = plrtotrg:getDotProduct(targetvel)
local a = (( weaponvel * weaponvel ) - ( lenghttargetvel * lenghttargetvel ))
local b = ( 2 * trgangle )
local c = -( lenghtplrtotrg * lenghtplrtotrg )
local discrim = ((b * b) - 4 * a * c)
local leadx = 0
local leady = 0
if discrim >= 0 and a ~= 0 then
multipl1 = (( -b + math.sqrt(discrim)) / ( 2 * a))
multipl2 = (( -b - math.sqrt(discrim)) / ( 2 * a))
if multipl1 >=0 and multipl1 <= multipl2 and multipl2 >= 0 then
targetmult = multipl1
elseif multipl1 >=0 and multipl2 < 0 then
targetmult = multipl1
elseif multipl2 >=0 then
targetmult = multipl2
else
targetmult = nil
end
if targetmult ~= nil then
local leadvel = targetvel/(1/targetmult)
local leadpos = targetpos + leadvel
if leadpos:getScreenCoords() ~= false then
leadx, leady = leadpos:getScreenCoords() --rather than just simply draw the coords, il scale and return them so my code can **** with them
leadx = leadx * wf --drawleadreticle(leadx,leady) pft, my way is better :D
leady = leady * hf --theese factors make things so much easyer
return leadx, leady --yep, thats what i need there
else
return -1, -1 --return -1-1 if this all fails, so it doesnt tweak my math
end
end
end
end
]
$HUD:
[
player = mn.Ships["Alpha 1"]
if player:isValid() then
target = player.Target
banks = player.PrimaryBanks --work on this
wep1 = banks['1']
wepvel = wep1.WeaponClass.Speed
end
if target:isValid() and player:isValid() then
if target.Position:getScreenCoords() ~= false then
xship, yship = target.Position:getScreenCoords()
xship = xship * wf
yship = yship * hf
xtarg, ytarg = leadreticle(wepvel)
if xtarg >= 0 or ytarg >= 0 then
xtarg = cx + (xship - xtarg)
ytarg = cy + (yship - ytarg)
else
xtarg = cx
ytarg = cy
end
else
xtarg = cx
ytarg = cy
end
else
xtarg = cx
ytarg = cy
end
if target:isValid() == false then
if chr > 50 then
chr = chr - 1
elseif chr < 50 then
chr = chr + 1
end
if chg > 50 then
chg = chg - 1
elseif chg < 50 then
chg = chg + 1
end
if chb > 50 then
chb = chb - 1
elseif chb < 50 then
chb = chb + 1
end
elseif target.Team.Name == "Hostile" or target.Team.Name == "Traitor" then
if chr < 255 then
chr = chr + 1
end
if chg > 0 then
chg = chg - 1
end
if chb > 0 then
chb = chb - 1
end
elseif target.Team.Name == "Friendly" then
if chr > 0 then
chr = chr - 1
end
if chg < 255 then
chg = chg + 1
end
if chb > 0 then
chb = chb - 1
end
elseif target.Team.Name == "Unknown" then
if chr < 255 then
chr = chr + 1
end
if chg > 0 then
chg = chg - 1
end
if chb < 255 then
chb = chb + 1
end
elseif target.Team.Name == "Neutral" then
if chr > 0 then
chr = chr - 1
end
if chg > 0 then
chg = chg - 1
end
if chb < 255 then
chb = chb + 1
end
else
if chr > 128 then
chr = chr - 1
elseif chr < 128 then
chr = chr + 1
end
if chg > 128 then
chg = chg - 1
elseif chg < 128 then
chg = chg + 1
end
if chb > 128 then
chb = chb - 1
elseif chb < 128 then
chb = chb + 1
end
end
drawgunsight(xtarg, ytarg, chr, chg, chb, cha)
]
#End
this should work in recent head builds