Author Topic: hate how the mouse works? have i got the script for you!  (Read 39386 times)

0 Members and 1 Guest are viewing this topic.

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: hate how the mouse works? have i got the script for you!
remember that ] bug, i dont think it had anything to do with the brackets. i think it has more to do with unused tabs floating around. if you got a bunch of tabs on a line and nothing else, it wont even run. this is bad cause i have a habbit of tabbing out to the current level of scope regaurdless if i use the line or not. of course i cant duplicate it. sometimes il get stummped adn cant figure out whats wrong, clean up the formatting (while not changing the actual code), and it will end up working. im still trying to figure out exactly whats causing it. maybe a combination of things.

*edit*

it seems i fixed a few problems and ive implemented a working menu. im not sure if i fixed the damping, but i think i may have. i still have 3 more features to finish up before i call this script done. one of which it the ability to save preferances. right now the menu comes on at start up. i want to make it so that if it sees a prefs file it will not load the menu but rather load the prefs instead. the player will set the options the first time they come up, the file will be saved and autoloaded on game start next time they play, and the menu will remain hidden. the player is presented with a countdown on game start, during this period he may hit left and right buttons to pull up the menu, should changes need to be made.i got too many loose ends open to put up a new version now. i should finish it by tomorrow.
« Last Edit: January 15, 2007, 07:44:32 am by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline neoterran

  • 210
Re: hate how the mouse works? have i got the script for you!
Umm, can someone explain to me how to get this to work ? I can't run P4 builds and I get a bunch of LUA errors with the january ones...

edit.. i have problems with the middle mouse button, causes LUA crashes on my system, and the script doesn't seem to work for me when my mouse is off.
« Last Edit: January 15, 2007, 09:38:42 pm by neoterran »
Official Taylor Fan Club Member.
Chief Grognard.
"How much code could a coder code if a coder could code code?"

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: hate how the mouse works? have i got the script for you!
-C

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: hate how the mouse works? have i got the script for you!
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

Code: [Select]
#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
« Last Edit: January 16, 2007, 04:28:36 pm by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline neoterran

  • 210
Re: hate how the mouse works? have i got the script for you!
Gosh I'd really like to get this to work, but i'm having all kinds of LUA issues. I have the mouse turned off, as requested in the top post. I have the january build. (b) and I have scripting.tbl in my data folder with this script in.

The best i can get is the stuff to show up on the hud, but i can't make any movements.

The worst is a bunch of LUA errors.
Official Taylor Fan Club Member.
Chief Grognard.
"How much code could a coder code if a coder could code code?"

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: hate how the mouse works? have i got the script for you!
i hope youre not running it on 3.6.9, you gotta use one of wmcs scripting builds.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline neoterran

  • 210
Re: hate how the mouse works? have i got the script for you!
no, i'm using the january non-p4 wmc build.
Official Taylor Fan Club Member.
Chief Grognard.
"How much code could a coder code if a coder could code code?"

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: hate how the mouse works? have i got the script for you!
looks like wmc changed the mouse functions, yet again. il post a fix in abit.

*edit*
fixed, try it again
« Last Edit: January 16, 2007, 04:30:09 pm by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline neoterran

  • 210
Re: hate how the mouse works? have i got the script for you!
cool ! works.

Wow, this is going to take some getting used to... thanks for the hard work tho !
Official Taylor Fan Club Member.
Chief Grognard.
"How much code could a coder code if a coder could code code?"

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: hate how the mouse works? have i got the script for you!
looks like wmc changed the mouse functions, yet again. il post a fix in abit.

*edit*
fixed, try it again

Sorry. :) I realized that "GetX()" might be a bit vague if/when joystick support is added.
-C

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: hate how the mouse works? have i got the script for you!
not a big deal. anyway to hilight this? it might be hella usefull for anyone who flys with a mouse :D
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: hate how the mouse works? have i got the script for you!
Ehm...possibly, I don't know if I have privs. I don't want to mess with it tonight though.
-C

 
Re: hate how the mouse works? have i got the script for you!
 Hi guys,
I'm a newb here, but 'd really like to use that new mouse behavior. So I have a couple of questions here:

* If I've understood correctly, I need the builds from wmc. Do I use C01142007 ? C01142007b ? c12172006 ? What exe inside the archive
  do I have to use ?
* I put the code that Nuke posted in scripting.tbl  Where do I put this file ?
* Nuke, u said that you changed your code for scripting.tbl when wmc changed the mouse functions. Where is the updated code ?
 
That's all for now! Thxs in advance guys!
N_D

 

Offline Taristin

  • Snipes
  • 213
  • BlueScalie
    • Skelkwank Shipyards
Re: hate how the mouse works? have i got the script for you!
All tbl files go in the Tables folder.
The updated code should be what you see on the page.

And using the most recent dated build is almost always advisable (In this case the c01 14 2007 build.) Try either that one or the b variant and see which works better for you, I guess.
Freelance Modeler | Amateur Artist

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: hate how the mouse works? have i got the script for you!
just use the last build posted in this thread and use the last script i posted in this post .
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 
Re: hate how the mouse works? have i got the script for you!
That's what I did. But it doesn't work. So I changed the function in your code: getMouseX => GetX , same for Y, and isMouseButtonDown => isButtonDown, then it works.  It even works like a charm! A few years ago, I was playing FS2 with the Trackpoint, the pointing device on IBM thinkpads, I was an ace with it! Then my laptop died. Then I played with the mouse, because I suck with a joystick, I don't know why. But the mouse also kinda sucks because you have to keep moving. So finally I played with both the keyboard and the mouse (using the keyboard while moving the mouse back), kinda sucks too.
 
================== >>   So I recommend Nuke's code for anyone that plays with a mouse or that sucks with a joystick! It rocks, thxs Nuke!


 The only drawback is that the roll function doesn't work (even with the middle mouse button), and it also doesn't work with the keyboard anymore (it works actually, but 100x times slower...). But it's really not a big issue, I hardly used the roll anyways...
 I found that a deadzone value of 0 works best for me, it's most responsive. What do u recommend for the CoordP/B value ?
   (thxs for your answer Taristin)

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: hate how the mouse works? have i got the script for you!
fixed some bugs. now all options should work together without conflict. you can now use coord with button toggles or both mode. changed the falloff math so that it compensates for framerate. changed the way 1337Mode and InvY are handled. fixed a bug that would coord your controls if you had elite mode on with a coord setting. also be sure to use one of theese builds, not the pre commit build as stated in my first post, in order to avoid trouble with the mouse functions.

Code: [Select]
#Global Hooks ;;nukemouse version 5
$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.2 --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 --flip z
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
fo = (falloff + 0.01) * ba.getFrametime() * 45

if (rollmode == "Mid" and io.isMouseButtonDown(MOUSE_MIDDLE_BUTTON)) or (rollmode == "Right" and io.isMouseButtonDown(MOUSE_RIGHT_BUTTON)) then
mZ, mY = mousejoy(dead)
emmzee = mZ * coord

if mX < -fo + emmzee then
mX = mX + fo
elseif mX > fo + emmzee then
mX = mX - fo
else
mX = emmzee
end
elseif rollmode == "Mid" or rollmode == "Right" then
mX, mY = mousejoy(dead)
emmzee = mX * coord

if mZ < -fo + emmzee then
mZ = mZ + fo
elseif mZ > fo + emmzee then
mZ = mZ - fo
else
mZ = emmzee
end
else
mX, mY = mousejoy(dead)
emmzee = mX * coord

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 - fo then
mZ = mZ + fo
else
mZ = 1
end
elseif io.isMouseButtonDown(MOUSE_MIDDLE_BUTTON) then
if mZ > -1 + fo then
mZ = mZ - fo
else
mZ = -1
end
else
if mZ < -fo + emmzee then
mZ = mZ + fo
elseif mZ > fo + emmzee then
mZ = mZ - fo
else
mZ = emmzee
end
end
end

cornholio = mn.Ships["Alpha 1"]

if cornholio:isValid() then
desrot = cornholio.Physics.RotationalVelocityMax

if latvert then
desrot['1'] = desrot['1'] * -mY
else
desrot['1'] = desrot['1'] * mY
end

if leetmode then
desrot['2'] = desrot['2'] * mZ
desrot['3'] = desrot['3'] * -mX
else
desrot['2'] = desrot['2'] * mX
desrot['3'] = desrot['3'] * -mZ
end

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

end

]
$HUD:
[

if usehud then
if leetmode then
mousegauge(mZ,mY,mX)
else
mousegauge(mX,mY,mZ)
end
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
« Last Edit: January 21, 2007, 04:23:21 am by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 
Re: hate how the mouse works? have i got the script for you!
 Guys,
I'm having trouble using Nuke's code with WMC scripting build and the 3.6.8 beta media VPs. The grame crashes at some point, usually when a large ship comes in. I have errors such as: "Malloc failed" or some error related to an entry in a table that couldn't be found, I don't remember. I installed the media VPs correctly with the 710 patches.
  An important point is that everything works fine with the 3.6.7 media VPs. So I guess that WMC builds are incompatible with 3.6.8 ?
N_D

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: hate how the mouse works? have i got the script for you!
this is experimental and needs the most recent scripting build to work. it doesnt use media vps at all cause all graphics are procedural.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline jr2

  • The Mail Man
  • 212
  • It's prounounced jayartoo 0x6A7232
    • Steam
Re: hate how the mouse works? have i got the script for you!
...based on that, I'd say that the scripting build has a beef with the VPs?