 |
WiiLi.org a new revolution
|
| View previous topic :: View next topic |
| Author |
Message |
TaggeD
Joined: 27 Jan 2007 Posts: 2
Digg It |
Posted: Sat Jan 27, 2007 3:09 pm Post subject: Half-Life2 (and other FPS) Script by TaggeD |
|
|
Just found out you can use Wiimote's with the PC today, so I quickly got a hold of GlovePIE (Very easy scripting) and got to work.
This script is primarily for Half-Life 2, but other FPS games should work with a little modification. It's a modification of another script I found, well I would say more of a complete overhaul
It's heavily commented for users to learn from, and has some nice features that I haven't seen elsewhere such as:
The controls were all constructed by myself, I tried just use reflexes to think about the control mapping. Hopefully users find it very easy and intuitive to use.
On-The-Fly Sensitivity adjustments, press the home button then use the Minus and Plus buttons to adjust the X Axis while 1 and 2 buttons adjust the Y axis. The leds inform you of the sensitivity (no leds is lowest, 4 leds is highest).
Runtime Calibration. If you want to hold your Wiimote in a way to your liking then simply press both minus and plus together. This disables all input expect for the A button, align the wiimote to it's preferred center state and then press A to confirm.
The script is posted below, any comments are welcome but please, this is my first script.. It's even my first day with the Wiimote/PC, but knowing that constructive criticism is welcome
On a small note, I did have troubles with the nunchuk and it's calibration, which results in sometimes reload when flicking on the flashlight It's 1am so I will have to debug this a little more another time.
| Code: |
/////////////////////
//Modified By TaggeD
//Version 1.0
//
//Script for Wiimote and Nunchuk
//Primarily aimed at Half-Life2 + addons
//
//Heavily commented to provide help for others
//Seperate X and Y axis movement variables
//On-The-Fly Sensitivity settings (Toggle with Home Button, Minus/Plus for X Axis, 1/2 for Y Axis)
//Runtime Calibration Mode (Minus and Plus buttons pressed, then A button to Confirm Calibration)
//Prevented variables from being assigned continously (might save some resources?)
//
//
//Idea's and parts of Script obtained from:
//tjfear
//vkapadia
//deceased
/////////////////////
//Controls
//Move = Nunchuk Analog
//Jump = Z
//Crouch = C
//Shoot = B
//Aim = Move/Twist Wiimote
//Flashlight = Flick Nunchuk Left
//Reload = Shake Nunchuk Up and Down
//Weapon Down = -
//Weapon Up = +
//Sprint = C and Z
//Use = A
//
//Alt Fire = DPad Down
//
//
//Calibrate Wiimote = Plus and Minus (Then A once in place)
//
/////////////////////
//Precision
//Once-Off Assignment//
if var.RunOnce == 0 then
var.AimSensitivityX = 400
var.AimSensitivityY = 300
var.AimSensitivity_Modifier = 2
var.AimSensitivityX_1 = var.AimSensitivityX / var.AimSensitivity_Modifier
var.AimSensitivityY_1 = var.AimSensitivityY / var.AimSensitivity_Modifier
var.AimSensitivityX_2 = var.AimSensitivityX_1 / var.AimSensitivity_Modifier
var.AimSensitivityY_2 = var.AimSensitivityY_1 / var.AimSensitivity_Modifier
//
var.Cal_Wiimote_AxisX = 0
var.Cal_Wiimote_AxisY = -25
var.Cal_Wiimote_AxisZ = 1
//
//
var.thresh0_AxisX = 5
var.thresh0_AxisY = 2
var.thresh1_AxisX = 10
var.thresh1_AxisY = 4
var.thresh2_AxisX = 20
var.thresh2_AxisY = 8
//
var.Calibrate = 0 //Should intially Start at 0, then if user requires calibration...
var.Sensitivity = 0 //Not modifying Sensitivity
//
var.RunOnce = 1 //Ensures this only runs once
endif
/////////////////////////
//Globals
var.x = Wiimote.RawForceX + var.Cal_Wiimote_AxisX
var.y = Wiimote.RawForceY + var.Cal_Wiimote_AxisY
var.z = Wiimote.RawForceZ + var.Cal_Wiimote_AxisZ
/////////////////////////
/////////////////////////
//Calibration Explaination//
/*
I added this to ensure people can calibrate their wiimotes to their style of play
The idea is to hold the wiimote in the default/center position of your choosing
and pressing A.
*/
if var.Calibrate > 0 then //Prevents any controls from getting through until complete
//Checks first if Calibrate is at stage 1// -Calibrates X Axis on Wiimote-
if var.Calibrate == 1 then
var.Cal_Wiimote_AxisX = Wiimote.RawForceX
var.Cal_Wiimote_AxisY = Wiimote.RawForceY
var.Cal_Wiimote_AxisZ = Wiimote.RawForceZ
if Wiimote.A then
var.Calibrate = 0
endif
endif
else
/////////////////////////
//NunChuk
/////////////////////////
if Wiimote.Nunchuk.ZButton and not Wiimote.Nunchuk.CButton then
Keyboard.Space = true
else
Keyboard.Space = false
endif
//Nunchuk C Button// -Function- Croutch
if Wiimote.Nunchuk.CButton and not Wiimote.Nunchuk.ZButton then
Keyboard.Ctrl = true
else
Keyboard.Ctrl = false
endif
//NunChuk C and Z Buttons// -Function- Sprint/Walk
if Wiimote.Nunchuk.ZButton and Wiimote.Nunchuk.CButton then
Keyboard.Shift = true
else
Keyboard.Shift = false
endif
if Wiimote.nunchuk.joyy > .2
Keyboard.S = true
else if Wiimote.nunchuk.joyy < -.2
Keyboard.W = true
else
Keyboard.S = false
Keyboard.W = false
endif
if wiimote.nunchuk.joyx > .2
Keyboard.D = true
else if wiimote.nunchuk.joyx < -.2
Keyboard.A = true
else
Keyboard.D = false
Keyboard.A = false
endif
//Shake NunChuk Up/Down ONLY// -Function- Reload
//Code Breakdown:
// I found that shaking the Nunchuk side to side would produce enough Y axis acceleration that
//it would wrongly set off the reload script. I prevented this by making sure the gx value is
//within a certain range.
if Wiimote.Nunchuk.gy > 2 and Wiimote.Nunchuk.gx < 2 and Wiimote.NunChuk.gx > -1 then
key.r = true
Wiimote.Rumble = true
else
key.r = false
Wiimote.Rumble = false
endif
//Shake NunChuk left ONLY// -Function- Flashlight
if Wiimote.Nunchuk.gx > 1 and Wiimote.Nunchuk.gy < 2 and Wiimote.NunChuk.gy > -1 then
if var.Delay_Flashlight == 1 then
else
key.f = true
var.Delay_Flashlight = 1
key.f = false
wait 100 ms
var.Delay_Flashlight = 0
endif
endif
/////////////////////////
//WiiMote
/////////////////////////
//WiiMote A Button// -Function- Use
if Wiimote.A and not Wiimote.B then
Keyboard.E = true
else
keyboard.E = false
endif
//WiiMote B Button// -Function- Fire
if Wiimote.B and not Wiimote.A then
Mouse.LeftButton = true
wait 1 ms
Mouse.LeftButton = false
Wiimote.Rumble = true
wait 10 ms
Wiimote.Rumble = false
endif
//Wiimote DPad Down// -Function- Alt Fire
if Wiimote.Down then
Mouse.RightButton = true
endif
if var.Sensitivity == 0 and Wiimote.Minus and not Wiimote.Plus then
Mouse.WheelUp = true
wait 1 ms
Mouse.WheelUp = false
wait 200 ms //Slows down the scrolling through weapons
endif
if var.Sensitivity == 0 and Wiimote.Plus and not Wiimote.Minus then
Mouse.WheelDown = true
wait 1 ms
Mouse.WheelDown = false
wait 200 ms //Slows down the scrolling through weapons
endif
//Wiimote Minus and Plus buttons// -Enter Calibration Mode-
if Wiimote.Minus and Wiimote.Plus then
var.Calibrate = 1
var.Sensitivity = 0
endif
if Wiimote.Home then
if var.Sensitivity == 0 then
var.Sensitivity = 1
else
Wiimote.Leds = 0
var.Sensitivity = 0
endif
wait 300 ms
endif
//MODIFICATION SETTINGS//
if var.Sensitivity == 1 and Wiimote.Minus then //Decrease Sensitivity on X Axis
var.AimSensitivityX = var.AimSensitivityX + 10
//
var.AimSensitivityX_1 = var.AimSensitivityX / var.AimSensitivity_Modifier
var.AimSensitivityX_2 = var.AimSensitivityX_1 / var.AimSensitivity_Modifier
//
if var.AimSensitivityX > 150 and var.AimSensitivityX < 300 then Wiimote.Leds = 7
if var.AimSensitivityX > 300 and var.AimSensitivityX < 450 then Wiimote.Leds = 3
if var.AimSensitivityX > 450 and var.AimSensitivityX < 700 then Wiimote.Leds = 1
if var.AimSensitivityX > 700 then
Wiimote.Leds = 0
var.AimSensitivityX = 700
endif
endif
if var.Sensitivity == 1 and Wiimote.Plus then //Increase Sensitivity on X Axis
var.AimSensitivityX = var.AimSensitivityX - 10
//
var.AimSensitivityX_1 = var.AimSensitivityX / var.AimSensitivity_Modifier
var.AimSensitivityX_2 = var.AimSensitivityX_1 / var.AimSensitivity_Modifier
//
if var.AimSensitivityX < 450 and var.AimSensitivityX > 300 then Wiimote.Leds = 1
if var.AimSensitivityX < 300 and var.AimSensitivityX > 150 then Wiimote.Leds = 3
if var.AimSensitivityX < 150 and var.AimSensitivityX > 20 then Wiimote.Leds = 7
//
if var.AimSensitivityX < 20 then
Wiimote.Leds = 15
var.AimSensitivityX = 20
endif
endif
if var.Sensitivity == 1 and Wiimote.1 then //Increase Sensitivity on Y Axis
var.AimSensitivityY = var.AimSensitivityY - 10
//
var.AimSensitivityY_1 = var.AimSensitivityY / var.AimSensitivity_Modifier
var.AimSensitivityY_2 = var.AimSensitivityY_1 / var.AimSensitivity_Modifier
//
if var.AimSensitivityY < 450 and var.AimSensitivityY > 300 then Wiimote.Leds = 1
if var.AimSensitivityY < 300 and var.AimSensitivityY > 150 then Wiimote.Leds = 3
if var.AimSensitivityY < 150 and var.AimSensitivityY > 20 then Wiimote.Leds = 7
//
if var.AimSensitivityY < 20 then
Wiimote.Leds = 15
var.AimSensitivityY = 20
endif
endif
if var.Sensitivity == 1 and Wiimote.2 then //Decrease Sensitivity on Y Axis
var.AimSensitivityY = var.AimSensitivityY + 10
//
var.AimSensitivityY_1 = var.AimSensitivityY / var.AimSensitivity_Modifier
var.AimSensitivityY_2 = var.AimSensitivityY_1 / var.AimSensitivity_Modifier
//
if var.AimSensitivityY > 150 and var.AimSensitivityY < 300 then Wiimote.Leds = 7
if var.AimSensitivityY > 300 and var.AimSensitivityY < 450 then Wiimote.Leds = 3
if var.AimSensitivityY > 450 and var.AimSensitivityY < 700 then Wiimote.Leds = 1
if var.AimSensitivityY > 700 then
Wiimote.Leds = 0
var.AimSensitivityY = 700
endif
endif
//Wiimote Sensitivity Setting// -Function- MouseMovement/Viewpoint/Aiming
//X-axis
if var.x > var.thresh0_AxisX
mouse.x = mouse.x - 1/var.AimSensitivityX
endif
if var.x < -var.thresh0_AxisX
mouse.x = mouse.x + 1/var.AimSensitivityX
endif
//Y-axis
if var.z > var.thresh0_AxisY
mouse.y = mouse.y - 1/var.AimSensitivityY
endif
if var.z < -var.thresh0_AxisY
mouse.y = mouse.y + 1/var.AimSensitivityY
endif
//X-axis
if var.x > var.thresh1_AxisX
mouse.x = mouse.x - 1/var.AimSensitivityX_1
endif
if var.x < -var.thresh1_AxisX
mouse.x = mouse.x + 1/var.AimSensitivityX_1
endif
//Y-axis
if var.z > var.thresh1_AxisY
mouse.y = mouse.y - 1/var.AimSensitivityY_1
endif
if var.z < -var.thresh1_AxisY
mouse.y = mouse.y + 1/var.AimSensitivityY_1
endif
//X-axis
if var.x > var.thresh2_AxisX
mouse.x = mouse.x - 1/var.AimSensitivityX_2
endif
if var.x < -var.thresh2_AxisX
mouse.x = mouse.x + 1/var.AimSensitivityX_2
endif
//Y-axis
if var.z > var.thresh2_AxisY
mouse.y = mouse.y - 1/var.AimSensitivityY_2
endif
if var.z < -var.thresh2_AxisY
mouse.y = mouse.y + 1/var.AimSensitivityY_2
endif
endif //Ends Calibrate and Script
|
|
|
| Back to top |
|
 |
TylerK

Joined: 18 Dec 2006 Posts: 384 Location: Springfield, IL
Digg It |
Posted: Sat Jan 27, 2007 3:14 pm Post subject: Re: Half-Life2 (and other FPS) Script by TaggeD |
|
|
| TaggeD wrote: | On-The-Fly Sensitivity adjustments, press the home button then use the Minus and Plus buttons to adjust the X Axis while 1 and 2 buttons adjust the Y axis. The leds inform you of the sensitivity (no leds is lowest, 4 leds is highest).
Runtime Calibration. If you want to hold your Wiimote in a way to your liking then simply press both minus and plus together. This disables all input expect for the A button, align the wiimote to it's preferred center state and then press A to confirm. | I don't have HL2, so I can't test your script, but I just wanted to say that both of these ideas are awesome and I'm surprised no one else has been doing this. Very cool. |
|
| Back to top |
|
 |
plumpman
Joined: 28 Jan 2007 Posts: 8
Digg It |
Posted: Sun Jan 28, 2007 6:10 pm Post subject: |
|
|
| Hard to use but works great! |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|