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

0 Members and 1 Guest are viewing this topic.

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
hate how the mouse works? have i got the script for you!
ok youl need WMCoolmon's Pre-Commit build

and this in a scripting.tbl

Code: [Select]
#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()

if w >= 1024 then
wf = w / 1024
else
wf = w / 640
end

if h >= 768 then
hf = h / 768
else
hf = h / 480
end

dead = 15
--mousejoy function, returns a value from -100 to 100 depending on the mouse's position

mousejoy = function(deadzone)
local X = ((io.getX() * wf) - (w/2)) * (200/w)
local Y = ((io.getY() * hf) - (h/2)) * (200/h)

if X < deadzone and X > -deadzone then X=0 end
if Y < deadzone and Y > -deadzone then Y=0 end

return X, Y
end

--generic crosshair function

crosshair = function(x,y)
gr.setColor(0,255,0,200)
gr.drawGradientLine(x+20,y+20,x+10,y+10)
gr.drawGradientLine(x-20,y+20,x-10,y+10)
gr.drawGradientLine(x+20,y-20,x+10,y-10)
gr.drawGradientLine(x-20,y-20,x-10,y-10)
end
]

$HUD:
[

mX, mY = mousejoy(dead)

gr.setColor(0,255,0,255)
gr.drawCircle(5,mX+200,mY+200)
gr.setColor(100,100,255,100)
gr.drawRectangle(100,100,300,300)
gr.setColor(128,128,0,200)
gr.drawRectangle(200-dead,200-dead,200+dead,200+dead)

mX = mX / 100
mY = -mY / 100
mZ = 0

cornholio = mn.Ships["Alpha 1"]

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
end

]
#End




enjoy! :D

*edit*

be sure to leave the mouse off in the game settings
« Last Edit: January 13, 2007, 04:50:04 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 Taristin

  • Snipes
  • 213
  • BlueScalie
    • Skelkwank Shipyards
Re: hate how the mouse works? have i got the script for you!
cornholio o.'.o
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!
i see you like my var for alpha 1's ship object :D i still got to do a few things, like come up with some better indicaters, roll control on button 2+mousex, and the big one is to throw in some damp calculation, cause right now it ignores it. anyway when its done hopefully it will serve as a good interim solution till they implement it in c. it makes flying with a mouse a hella lot easyer.
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 DaBrain

  • Screensniper
  • 212
    • Shadows of Lylat board
Re: hate how the mouse works? have i got the script for you!
Wow... thanks man.

I told myself to be patient and wait for taylor's new control stuff, but now I don't have to use the crappy mouse control till then. I'll test it and give you some feedback. ;)
--------------------------------------------------
SoL is looking for a sound effect artist
Please PM me in case you want to apply
---------------------------------
Shadows of Lylat - A Freespace 2 total conversion
(hosted by Game-Warden)
----------------------------------

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: hate how the mouse works? have i got the script for you!
mint you thats the wow it worked i cant believe it quick post it version :D il have an updated version later tonight, just got the deadzone feature in, im gonna make a better looking gauge next.
« Last Edit: January 13, 2007, 08:36:33 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

 
Re: hate how the mouse works? have i got the script for you!
Nuke, this is fantastic!

For those curious, what this does is eliminate the need to keep moving the mouse to keep turning the ship, a problem which has caused a long thread elsewhere. Now the mouse works like a joystick! Move it a few inches and stop, and the ship keeps turning. It's no longer necessary to keep picking up the mouse and repositioning it! Awesome.

Umm, is the gauge even necessary? And if you use button 2 to roll (an idea I like), does that mean you can't fire missiles with it anymore?

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: hate how the mouse works? have i got the script for you!
new version

Code: [Select]
#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()

if w >= 1024 then
wf = w / 1024
else
wf = w / 640
end

if h >= 768 then
hf = h / 768
else
hf = h / 480
end

--mousejoy function, returns a value from -1 to 1 depending on the mouse's position

dead = 0.05 --factor of how much range of motion is dead, 1 is max 0 is min
mX=0
mY=0
mZ=0
rolltoggle = false

mousejoy = function(deadzone)
local X = io.getX()
local Y = io.getY()

if w >= 1024 then
X = (X / 511.5) - 1
Y = (Y / 383.5) - 1
else
X = (X / 319.5) - 1
Y = (Y / 239.5) - 1
end

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 cx = w/2
local cy = h/2
local rgx = cx+60
local rgy = cy+60

gr.setColor(150,255,150,200) --big hashes

for i=cx-67.5, cx+67.5, 15 do
gr.drawLine(i,cy - 140,i,cy - 125)
end
for i=cy-67.5, cy+67.5, 15 do
gr.drawLine(cx - 140,i,cx - 125,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*65,rgy+y*65,rgx+x*80,rgy+y*80)
end

gr.setColor(50,255,50,150) --small hashes

for i=cx-60, cx+60, 15 do
gr.drawLine(i,cy - 140,i,cy - 132)
end
for i=cy-60, cy+60, 15 do
gr.drawLine(cx - 140,i,cx - 132,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*70,rgy+y*70,rgx+x*80,rgy+y*80)
end

gr.setColor(200,200,255,255) --indicators
gr.drawCircle(8,cx+(eks*67.5),cy-135)
gr.drawCircle(8,cx-135,cy+(why*67.5))
zee = (-zee * 45) + 45
gr.drawCircle(8,rgx + (math.sin(zee*math.pi/180) * 75),rgy + (math.cos(zee*math.pi/180) * 75 ))
end
]

$HUD:
[
rolltoggle = io.isButtonDown(MOUSE_MIDDLE_BUTTON)

if rolltoggle then
mZ, mY = mousejoy(dead)
mX = 0
else
mX, mY = mousejoy(dead)
mZ = 0
end

cornholio = mn.Ships["Alpha 1"]

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
end

mousegauge(mX,mY,mZ)

]
#End



ive added some more astheticly pleasing gauges. ive also added deadzone support for the mouse, you may tweak the dead variable to your liking. bigger number means more deadzone,  1 is the full range of motion 0.5 is half. i find a low value like 0.05 works well, to give you a small snap to indicate you reached center. bigger deadzones can be harder to deal with, and if you have a steady hand you can just set it to zero to get a fluid range. no matter what setting you use it will always run a full smooth 0-1 gradient from the edge of the dead zone to the edge of the range max. to change the deadzone just change the number on this line to whatever you want:
dead = 0.05   --factor of how much range of motion is dead, 1 is max 0 is min

ive also added a roll mode, enabled by the middle button, if you dont have a middle button you can use your right (or left for that matter) my changing this line:
rolltoggle = io.isButtonDown(MOUSE_MIDDLE_BUTTON)
to
rolltoggle = io.isButtonDown(MOUSE_RIGHT_BUTTON)
i used middle so i could use my right for missiles.

now i still havent plugged in scale factors for different screen resolutions yet. it might be a little large cause i designed it for 1280*1024, but i intent to make it uniform, at any resolution. i also havent plugged damping values yet. not sure how yet, i might need to ask wmc about that. but theyre on my to do list.
« Last Edit: January 14, 2007, 02:20:24 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 Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: hate how the mouse works? have i got the script for you!
if you are using the new scripting system why aren't you using sv.Player - or whatever was the new 'direct' handle to player's ship - instead of mn.Ships["Alpha 1"]
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: hate how the mouse works? have i got the script for you!
im just finally getting the hang of the new system. that wasnt in the scripting.html, but il make note for future reference.

*edit*
just tried it and it doesnt work :D

commented out this line
cornholio = mn.Ships["Alpha 1"]
and changed all other cornholio references to sv.Player.
crashes straight to desktop at mission commit, no error.
« Last Edit: January 14, 2007, 02:48:39 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 Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: hate how the mouse works? have i got the script for you!
well... WMC's pre-commit build fails to run on my cpu (that is when trying without any mods or any kind of scripts)

EDIT: Hmmm... fs2_open_C12172006-P4 caused an Illegal Instruction in module fs2_open_C12172006-P4.exe at 001b:005ef547.

Your problems sounds awfully lot like the older 'plr' handle issue that dropped game immediately when encountered if the actual exe file was of certain type. That is it worked with debugs and IIRC also on some redmenace builds but failed on all 369RCs for example
« Last Edit: January 14, 2007, 03:03:20 am by Wanderer »
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: hate how the mouse works? have i got the script for you!
i found another strange bug. if theres a line of code on the line preceding the ]  at the end of a hook, the game will refuse to run. i hope wmc reads this thread.

somone should hilight this, mousies might want :D
« Last Edit: January 14, 2007, 03:25:22 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 WMCoolmon

  • Purveyor of space crack
  • 213
Re: hate how the mouse works? have i got the script for you!
Yeah, I did, both that and the +override bug should be fixed in this build, although I couldn't reproduce the ] bug so I have no way for telling if it's been fixed for sure.

I also fixed some code that just looked completely wrong relating to the script-eval SEXP. I haven't tested that, but it's in the build + CVS anyway so it doesn't get forgotten.

EDIT: Oh, and this thread should really be moved to the proper forum. :D
« Last Edit: January 14, 2007, 06:28:41 am by WMCoolmon »
-C

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: hate how the mouse works? have i got the script for you!
hell yea, i was wondering when the scripting forum would come to be.
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 Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: hate how the mouse works? have i got the script for you!
new version. ive added support for multiple resolutions (all have been tested of course) in the gauge function. only thing left to do is factor in damp:

Code: [Select]
#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()

if w >= 1024 then
wf = w / 1024
else
wf = w / 640
end

if h >= 768 then
hf = h / 768
else
hf = h / 480
end

--mousejoy function, returns a value from -1 to 1 depending on the mouse's position

dead = 0.0 --factor of how much range of motion is dead, 1 is max 0 is min
mX=0
mY=0
mZ=0
rolltoggle = false

mousejoy = function(deadzone)
local X = io.getX()
local Y = io.getY()

if w >= 1024 then
X = (X / 511.5) - 1
Y = (Y / 383.5) - 1
else
X = (X / 319.5) - 1
Y = (Y / 239.5) - 1
end

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 cx = w/2
local cy = h/2
local awh = (wf + hf) / 2

if w < 1024 then
awh = awh * 0.625
end

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

]

$HUD:
[
rolltoggle = io.isButtonDown(MOUSE_MIDDLE_BUTTON)

if rolltoggle then
mZ, mY = mousejoy(dead)
mX = 0
else
mX, mY = mousejoy(dead)
mZ = 0
end

cornholio = mn.Ships["Alpha 1"]

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
end

mousegauge(mX,mY,mZ)

]
#End



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!
Can this be included in the new build, maybe as an option in the launcher?

  

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: hate how the mouse works? have i got the script for you!
no, id advise agaisnt that for a few reasons. first being it breaks the other control modes. you notice while running the script you can no longer turn with the keypad, and id assume the joystick wouldnt work either. secondly it breaks the way the ships manuver, ignoring rotdamp (for now). it should respect the maximum turn rates for your ship though. while i may be able script in some fixes to theese problems. however sence theyr gonna do the same thing in c later on down the line, its better just to think of this as an interim solution for mousers. i really just did it to play with physics handles and the mouse interface.
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!
OK, thanks. I'll think of it as a great proof of concept then.

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: hate how the mouse works? have i got the script for you!
im currently coding in some new features. the first being a config menu to allow you to configure things like deadzone and which button to use for roll. i think il mess with the file stuff and try to get it to save a config, which it will check for on load.
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 Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: hate how the mouse works? have i got the script for you!
I got WMC's new builds to run... it seems that there is some issues with it currently...

Code: [Select]
#Global Hooks

$Global:
[

gr.setColor(255,255,0)
gr.drawString(#sv.Globals,100,80)
for h=1,#sv.Globals do
    gr.drawString(sv.Globals[h],100,20*h+80)
end

]
#End

This shows the number of sv.Glovals to be -1.. continously. So no wonder the sv.Player didnt function as AFAIK it doesnt even exists at the moment.
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: hate how the mouse works? have i got the script for you!
Well I've made a change in CVS that should allow the Globals array to work properly. Pain in the ass to implement though.

ScriptingVariables is also now moving to HookVariables(hv) for another possible future feature, and clarity of purpose.

Code: [Select]
#Global Hooks

$Global: [
gr.setColor(255,255,0)
gr.drawString(#hv.Globals,100,80)
for h=1,#hv.Globals do
    gr.drawString(hv.Globals[h],100,20*h+80)
end
]
#End
-C