i revamped the script to run on current builds. fly a ship with a turret01a (medusa works) while using this script. switch to outside view. now you can manipulate and fire the turret with the mouse. now there is a problem im just not figuring out. so long as your ship is in its default orientation (its position as placed in fred) it works fine. but you roll or turn into some funky position and your aim goes way off. anyone have any ideas?
#Global Hooks
$GameInit:
[
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
mousejoy = function(deadzone) --mousejoy function, returns a value from -1 to 1 depending on the mouse's position
local X = io.getMouseX()
local Y = io.getMouseY()
if hires then
X = (X / 511.5) - 1
Y = (Y / 383.5) - 1
else
X = (X / 319.5) - 1
Y = (Y / 239.5) - 1
end
local Mx = X --theese are for the menu, -1 to 1 without deadzone applied
local My = Y
local tweak = 1 / (1 - deadzone)
if X < deadzone and X > -deadzone then
X=0
else
if X > 0 then
X = (X - deadzone) * tweak
elseif X < 0 then
X = (X + deadzone) * tweak
end
end
if Y < deadzone and Y > -deadzone then
Y=0
else
if Y > 0 then
Y = (Y - deadzone) * tweak
elseif Y < 0 then
Y = (Y + deadzone) * tweak
end
end
return X, Y, Mx, My
end
mousegauge = function(eks,why) --just a bunch of loops to draw the various hashes for the gauges
gr.setColor(150,255,150,200) --big hashes
for i=cx-(54*awh), cx+(54*awh), 12*awh do
gr.drawLine(i,cy - (108*awh),i,cy - (96*awh))
end
for i=cy-(54*awh), cy+(54*awh), 12*awh do
gr.drawLine(cx - (108*awh),i,cx - (96*awh),i)
end
gr.setColor(50,255,50,150) --small hashes
for i=cx-(48*awh), cx+(48*awh), 12*awh do
gr.drawLine(i,cy - (108*awh),i,cy - (100*awh))
end
for i=cy-(48*awh), cy+(48*awh), 12*awh do
gr.drawLine(cx - (108*awh),i,cx - (100*awh),i)
end
gr.setColor(200,200,255,255) --indicators
gr.drawCircle(7.5*awh,cx+(eks*54*awh),cy-(104*awh))
gr.drawCircle(7.5*awh,cx-(104*awh),cy+(why*54*awh))
end
]
$Simulation:
[
player = mn.Ships["Alpha 1"]
X,Y,U,V = mousejoy(0.1)
if player:isValid() then
pgun = player["turret01a"]
ori = pgun.Orientation
ori.h = ori.h + X *2*ba.getFrametime()
pgun.Orientation = ori
ori = pgun.GunOrientation
ori.p = ori.p + Y *2*ba.getFrametime()
if ori.p > 0 then
ori.p = 0
elseif ori.p < -math.pi/2 then
ori.p = -math.pi/2
end
pgun.GunOrientation = ori
if io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
pgun:fireWeapon(1, 1000)
end
end
]
$HUD:
[
mousegauge(X, Y)
]
#End