this script is becomming bloat, but hey, its a good demo. it also uses physics, io, string manipulation and control interfaces. good for a learning tool at least. new feature is the menu which is presented on script load. the vertical axis selects the option while horizontal will change options. some things like save and exit require a click, click on the slider to set its default position. your settings will be saved and you wont have to look at my ugly menu when next time you load your game. you are however presented with an option to open the menu, by holding left and right buttons simultaniously.

UseMouse needs to be on for the script to do anything usefull. its pretty much for multi, so people with joysticks dont get screwed. DrawHud enables and disables the hud gauges. DeadZone is obvous, clicking sets default. CoordP/B allows you to both pitch and yaw on the x axis, center is no coordination right is full positive coord and right is full negative, set center to use buttons for roll. FallOff is the ramping rate for button based roll right means faster. 1337Mode swaps yaw and roll, sorta like in elite. RollCtrl lets you pick which button to use for roll toggle, mid and right are toggles, set both for mid left roll and right right roll, just be sure you have coord set to mid or they probly wont work. InvPitch is obvious, flipps your y. save and exit saves your settings in a file called nukemouse.cfg. you can edit it in edit, notepad or wordpad corrupt it. the loader is pretty good at not crashing on a bad file. if the file is corrupt it will just ovver ride it with defaults.

*edit* fixed to work with newest builds

`#Global Hooks ;;nukemouse version 4 `

$GameInit:

[

--all this stuff is for multires support, for getting true width and height, centers, and for generating factors to scale coords by

--it just needs to run once so heres the place to do it, 8 vars in all

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

--couple functions for loading and saving config files

menusave = function(vars)

local config = cf.openFile("nukemouse.cfg","w+")

local b1 = 0

local b2 = 0

local b6 = 0

local b7 = 0

local b8 = 0

if vars[1] then b1 = 1 end --convert non-neumeric values to neumerics

if vars[2] then b2 = 1 end

if vars[6] then b6 = 1 end

if vars[7] == "Right" then

b7 = 0

elseif vars[7] == "Mid" then

b7 = 1

elseif vars[7] == "Both" then

b7 = 2

end

if vars[8] then b8 = 1 end

config:write(b1,"\r\n",b2,"\r\n",vars[3],"\r\n",vars[4],"\r\n",vars[5],"\r\n",b6,"\r\n",b7,"\r\n",b8)

config:close()

end

menuload = function(test)

local config = cf.openFile("nukemouse.cfg","r")

local V = {}

local error = false

if config:isValid() ~= true then

config:close()

error = true

return error

else

for i=1, 8 do

V[i] = config:read("*n")

end

config:close()

end

if test then

for i=1, 8 do --test mode to check if file is valid

if V[i] == nil then error = true end

end

return error

else

if V[1] == 1 then V[1] = true else V[1] = false end --convert imput back to the correct type

if V[2] == 1 then V[2] = true else V[2] = false end

if V[6] == 1 then V[6] = true else V[6] = false end

if V[7] == 0 then

V[7] = "Right"

elseif V[7] == 1 then

V[7] = "Mid"

else

V[7] = "Both"

end

if V[8] == 1 then V[8] = true else V[8] = false end

return V

end

end

--uservars, soon il set it up to check for a file to load

if menuload(true) == false then

showmenu = false

local settings = menuload(false)

usemouse = settings[1]

usehud = settings[2]

dead = settings[3]

coord = settings[4]

falloff = settings[5]

leetmode = settings[6]

rollmode = settings[7]

latvert = settings[8]

else

dead = 0.0 --factor of how much range of motion is dead, 1 is max 0 is min, this one is safe to change

coord = 0.0 --coordinates roll with yaw, factor from -1 to 1, negative nums anti-coordinate

falloff = 0.01 --how long it takes a setting such as roll to wear off after control mode was switched, also rampup for 2 button roll

leetmode = false --elite mode (swap roll and yaw)

usehud = true --draw the hud, if mouse is off will still display rotation forces being applied or latvert if its being used

usemouse = true --turn on mouse mode

latvert = false --use mouse for lateral and vertical thrusters, for saitek users with analog mouse sticks

showmenu = true --toggles menu

rollmode = "Right" --uses left button for roll

end

--some internal vars

mX=0

mY=0

mZ=0

Mx=0

My=0

countdown = 500

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

Mx = X --theese are for the menu, -1 to 1 without deadzone applied

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

end

--mouse hud

mousegauge = function(eks,why,zee) --just a bunch of loops to draw the various hashes for the gauges

local rgx = cx + (48 * awh)

local rgy = cy + (48 * awh)

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

for i=0, 90, 10 do --radial roll gauge

local x = math.sin(i*math.pi/180)

local y = math.cos(i*math.pi/180)

gr.drawLine(rgx+x*50*awh,rgy+y*50*awh,rgx+x*62*awh,rgy+y*62*awh)

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

for i=5, 85, 10 do --radial roll gauge

local x = math.sin(i*math.pi/180)

local y = math.cos(i*math.pi/180)

gr.drawLine(rgx+x*54*awh,rgy+y*54*awh,rgx+x*62*awh,rgy+y*62*awh)

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))

zee = (-zee * 45) + 45

gr.drawCircle(7.5*awh,rgx + (math.sin(zee*math.pi/180) * 58 * awh),rgy + (math.cos(zee*math.pi/180) * 58 * awh))

end

mousemenu = function(sel,val,button)

local mtext = {"UseMouse","DrawHud","DeadZone","CoordP/B","FallOff","1337Mode","RollCtrl","InvPitch","Save and Exit"}

local ops = 9

local snum = math.ceil((sel+1.25)*4)

for i=1,ops do --draw menu and set settings

if i == snum then

gr.setColor(192,255,255,255)

else

gr.setColor(64,192,128,200)

end

gr.drawString(mtext[i], cx-(85*awh), cy+(((i-1)-(ops/2))*(15*awh)))

if i == 1 or i == 2 or i == 6 or i == 8 then --draw radio butons

gr.drawCircle(8*awh, cx+(81*awh), (cy+(4*awh))+(((i-1)-(ops/2))*(15*awh)))

if i == 1 then

if usemouse then

gr.setColor(0,192,255,255)

else

gr.setColor(0,0,0,255)

end

if snum == 1 and val >= 0 then

usemouse = true

elseif snum == 1 and val < 0 then

usemouse = false

end

gr.drawCircle(6.5*awh, cx+(81*awh), (cy+(4*awh))+(((i-1)-(ops/2))*(15*awh)))

elseif i == 2 then

if usehud then

gr.setColor(0,192,255,255)

else

gr.setColor(0,0,0,255)

end

if snum == 2 and val >= 0 then

usehud = true

elseif snum == 2 and val < 0 then

usehud = false

end

gr.drawCircle(6.5*awh, cx+(81*awh), (cy+(4*awh))+(((i-1)-(ops/2))*(15*awh)))

elseif i == 6 then

if leetmode then

gr.setColor(0,192,255,255)

else

gr.setColor(0,0,0,255)

end

if snum == 6 and val >= 0 then

leetmode = true

elseif snum == 6 and val < 0 then

leetmode = false

end

gr.drawCircle(6.5*awh, cx+(81*awh), (cy+(4*awh))+(((i-1)-(ops/2))*(15*awh)))

elseif i == 8 then

if latvert then

gr.setColor(0,192,255,255)

else

gr.setColor(0,0,0,255)

end

if snum == 8 and val >= 0 then

latvert = true

elseif snum == 8 and val < 0 then

latvert = false

end

gr.drawCircle(6.5*awh, cx+(81*awh), (cy+(4*awh))+(((i-1)-(ops/2))*(15*awh)))

end

elseif i == 3 or i == 4 or i == 5 then --draw sliders

for j = 0, 10 do

gr.drawLine( (cx-(j*5*awh))+(85*awh), cy+(((i-1)-(ops/2))*(15*awh)),(cx-(j*5*awh))+(85*awh), (cy+(6*awh))+(((i-1)-(ops/2))*(15*awh)) )

end

gr.setColor(192,255,255,255)

if i == 3 then

gr.drawCircle(7*awh, cx+(85*awh)-(50*awh)+(dead*100*awh), (cy+(4*awh))+(((i-1)-(ops/2))*(15*awh)))

if snum == 3 then

dead = (val+1)*0.25

if button then dead = 0 end

end

elseif i == 4 then

gr.drawCircle(7*awh, cx+(85*awh)-(25*awh)+(coord*25*awh), (cy+(4*awh))+(((i-1)-(ops/2))*(15*awh)))

if snum == 4 then

coord = val

if button then coord = 0 end

end

elseif i == 5 then

gr.drawCircle(7*awh, cx+(85*awh)-(50*awh)+(falloff*100*awh), (cy+(4*awh))+(((i-1)-(ops/2))*(15*awh)))

if snum == 5 then

falloff = (val+1)*0.25

if button then falloff = 0.2 end

end

end

elseif i == 7 then --draw string settings

if val <= -0.666 and snum == 7 then

rollmode = "Right"

elseif val <= 0.666 and snum == 7 then

rollmode = "Mid"

elseif val <=1 and snum == 7 then

rollmode = "Both"

end

gr.drawString(rollmode, (cx+(85 * awh)) - gr.getStringWidth(rollmode), cy+(((i-1)-(ops/2))*(15*awh)))

elseif i == 9 then --exit command

if snum == 9 and button then

savevars = {usemouse,usehud,dead,coord,falloff,leetmode,rollmode,latvert}

menusave(savevars)

showmenu = false

end

end

end

end

]

$Simulation:

[

if showmenu then

mousejoy(dead)

elseif usemouse then

if (rollmode == "Mid" and io.isMouseButtonDown(MOUSE_MIDDLE_BUTTON)) or (rollmode == "Right" and io.isMouseButtonDown(MOUSE_RIGHT_BUTTON)) then

mZ, mY = mousejoy(dead)

if mX < -falloff then

mX = mX + falloff

elseif mX > falloff then

mX = mX - falloff

else

mX = 0

end

elseif rollmode == "Mid" or rollmode == "Right" then

mX, mY = mousejoy(dead)

if mZ < -falloff then

mZ = mZ + falloff

elseif mZ > falloff then

mZ = mZ - falloff

else

mZ = 0

end

else

mX, mY = mousejoy(dead)

if io.isMouseButtonDown(MOUSE_MIDDLE_BUTTON) and io.isMouseButtonDown(MOUSE_RIGHT_BUTTON) then

mZ = 0

elseif io.isMouseButtonDown(MOUSE_RIGHT_BUTTON) then

if mZ < 1 - falloff then

mZ = mZ + falloff

else

mZ = 1

end

elseif io.isMouseButtonDown(MOUSE_MIDDLE_BUTTON) then

if mZ > -1 + falloff then

mZ = mZ - falloff

else

mZ = -1

end

else

if mZ < -falloff then

mZ = mZ + falloff

elseif mZ > falloff then

mZ = mZ - falloff

else

mZ = 0

end

end

end

cornholio = mn.Ships["Alpha 1"]

if coord ~= 0 then mZ = mX * coord end

if leetmode then

local temp = mX

mX = mZ

mZ = temp

end

if latvert then mY = -mY end

if cornholio:isValid() then

desrot = cornholio.Physics.RotationalVelocityMax

desrot['1'] = desrot['1'] * mY

desrot['2'] = desrot['2'] * mX

desrot['3'] = desrot['3'] * -mZ

cornholio.Physics.RotationalVelocity = desrot + cornholio.Physics.RotationalVelocityDamping * ba.getFrametime()

end

end

]

$HUD:

[

if usehud then

mousegauge(mX,mY,mZ)

end

if showmenu then

mousemenu(My,Mx,io.isMouseButtonDown(MOUSE_LEFT_BUTTON))

end

if countdown > 1 and showmenu == false then

countdown = countdown - 1

if io.isMouseButtonDown(MOUSE_RIGHT_BUTTON) and io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then

showmenu = true

end

gr.setColor(192,255,255,255)

gr.drawString("press left and right mouse buttons to configure mouse", cx-(gr.getStringWidth("press left and right mouse buttons to configure mouse")/2), cy - (150*awh) )

end

]

#End