FreePie FPS Script by TQwando
Posted: Thu Jun 02, 2016 8:50 am
Hi,
I just got my Oculus Rift CV1 and wanted to use a WiiMote and Nunchuck to play FPS games, like Left 4 Dead 2 and Half Life 2 with this
.
I tried Tridef, but it does not support headtracking for CV1.
And also tried vireio versions (2/3/4), but they crash on startup with both games.
So I had to buy VorpX to get the 3D effect and headtracking working.
Mouse movement (Head Aiming) is therefore done VorpX.
Anyway I made this FreePIE script, which I currently use for Left 4 Dead 2.
It should be easily editable for other shooters.
I hope you guys enjoy the script and can help improve it.
Note: This is my first Python script ever
I just got my Oculus Rift CV1 and wanted to use a WiiMote and Nunchuck to play FPS games, like Left 4 Dead 2 and Half Life 2 with this
.
I tried Tridef, but it does not support headtracking for CV1.
And also tried vireio versions (2/3/4), but they crash on startup with both games.
So I had to buy VorpX to get the 3D effect and headtracking working.
Mouse movement (Head Aiming) is therefore done VorpX.
Anyway I made this FreePIE script, which I currently use for Left 4 Dead 2.
It should be easily editable for other shooters.
Code: Select all
# Author: TQwando
# Description: WII Mote + Nunchuck script for FPS (Currently mapped for Left 4 Dead 2)
# Required: WII Mote (I use it in a one handed gun) + loose Nunchuck (so not zapper)
# Date: 02 June 2016
# Version: 1.0
# How to use:
# 1. Connect wiimote using bluetooth. (assigned wiimote nr does not matter, all are mapped to same keys)
# 2. Script --> Start
# Notes:
# - Nunchuck acceleation sometimes bugged. Check in watch if nunchuck acceleration is showing data, else stop/start script.
# - Motion+ not (yet) needed.
# ==== Controls =====
# -- WII Mote --
# A --> P Key (vorpx anti-motion sickness/zoom out key)
# B --> Left click (fire)
# Dpad --> Arrow Keys (allows for menu navigation)
# Shake up --> r (reload)
# 1 --> enter/return
# 2 --> esc
# Home --> unused
# + --> unused
# - --> unused
# -- Nunchuck --
# Z --> E Key (use)
# Shake up -- > Right click (alt fire)
# Stick --> WASD Keys
# Hold C + Stick:
# - Up --> Wheel up (next weapon)
# - Down --> Wheel down (previous weapon)
# - Left --> Middle mouse (scope)
# - Right --> F (flashlight)
# Shake both WII Mote and Nunchuck --> Space (jump)
# ===== TODO =====
# - A wii mote key combination to toggle script running/pauze.
# - Home to reclibrate
# - Wii mote roll left/right perhaps better for Q/E key
# - Jump (space) support by real 'inplace' jump (requires Motion+?)
# - Crouch (c) support by real 'inplace' crouch (requires Motion+?) or hold Nunchuck Z key when roll implemented.
# - Inplace walking enables nunchuck stick to simulate walking. (requires additional wiimote/nunchuck)
# - Wii motion+ movement to mouse for additional aiming (induces sickness?)
# ===== Helper functions =====
# NOTE: 'down' fires button multiple times, pressed fire's only once.
def map_wiimote_to_keyDown(wiimote_index, wiimote_button, key):
if wiimote[wiimote_index].buttons.button_down(wiimote_button):
keyboard.setKeyDown(key)
else:
keyboard.setKeyUp(key)
def map_wiimote_to_keyPressed(wiimote_index, wiimote_button, key):
if wiimote[wiimote_index].buttons.button_pressed(wiimote_button):
keyboard.setPressed(key, True)
else:
keyboard.setPressed(key, False)
def map_nunchuck_to_keyDown(wiimote_index, nunchuck_button, key):
if wiimote[wiimote_index].nunchuck.buttons.button_down(nunchuck_button):
keyboard.setKeyDown(key)
else:
keyboard.setKeyUp(key)
def map_nunchuck_to_keyPressed(wiimote_index, nunchuck_button, key):
if wiimote[wiimote_index].nunchuck.buttons.button_down(nunchuck_button):
keyboard.setPressed(key, True)
else:
keyboard.setPressed(key, False)
def log_acceleration(wiimote_index):
diagnostics.watch(wiimote[wiimote_index].acceleration.x)
diagnostics.watch(wiimote[wiimote_index].acceleration.y)
diagnostics.watch(wiimote[wiimote_index].acceleration.z)
def configureWiiMote(wiimote_index, wiiMoteF, motionPlusF, nunchuckF):
# wiimote[wiimote_index].enable(WiimoteCapabilities.MotionPlus | WiimoteCapabilities.Extension)
wiimote[wiimote_index].buttons.update += wiiMoteF
# wiimote[wiimote_index].motionplus.update += motionPlusF
wiimote[wiimote_index].nunchuck.update += nunchuckF
# ===== Funtions per wiimote =====
def wiiMoteUpdate(wiimote_index):
# A button --> P (Edge Peek)
map_wiimote_to_keyDown(wiimote_index, WiimoteButtons.A, Key.P)
# B button --> Left Click (fire)
mouse.leftButton = wiimote[wiimote_index].buttons.button_down(WiimoteButtons.B)
# One button --> Enter/Return
map_wiimote_to_keyPressed(wiimote_index, WiimoteButtons.One, Key.Return)
# Two button --> Escape
map_wiimote_to_keyPressed(wiimote_index, WiimoteButtons.Two, Key.Escape)
# DPad to Arrow keys
map_wiimote_to_keyDown(wiimote_index, WiimoteButtons.DPadUp, Key.UpArrow)
map_wiimote_to_keyDown(wiimote_index, WiimoteButtons.DPadDown, Key.DownArrow)
map_wiimote_to_keyDown(wiimote_index, WiimoteButtons.DPadLeft, Key.LeftArrow)
map_wiimote_to_keyDown(wiimote_index, WiimoteButtons.DPadRight, Key.RightArrow)
# swing mote up --> R (reload)
# swing mote + nunchuck up --> Space (jump)
if wiimote[wiimote_index].acceleration.y > 20:
if wiimote[wiimote_index].nunchuck.acceleration.y > 20:
keyboard.setPressed(Key.Space)
else:
keyboard.setPressed(Key.R)
# Not supported :(
# wiimote[wiimote_index].Rumble = true
# wiimote[wiimote_index].Leds = 15
# else:
# keyboard.setPressed(Key.R, false)
# wiimote[wiimote_index].Rumble = false
# wiimote[wiimote_index].Leds = 0
log_acceleration(wiimote_index)
def nunChuckUpdate(wiimote_index):
# normal: nunchuck wasd
# alt: hold C +
# up --> wheel up (next weapon)
# down --> wheel down (previous weapon)
# left --> middle mouse (scope)
# right --> F (flashlight)
global pressedUp
global pressedDown
global pressedMiddle
global pressedRight
if wiimote[wiimote_index].nunchuck.stick.y > 40:
if wiimote[wiimote_index].nunchuck.buttons.button_down(NunchuckButtons.C):
if pressedUp == False:
mouse.wheelUp = True
pressedUp = True
else:
mouse.wheelUp = False
else:
pressedUp = False
keyboard.setPressed(Key.W)
else:
pressedUp = False
if wiimote[wiimote_index].nunchuck.stick.y < -40:
if wiimote[wiimote_index].nunchuck.buttons.button_down(NunchuckButtons.C):
if pressedDown == False:
mouse.wheelDown = True
pressedDown = True
else:
mouse.wheelDown = False
else:
pressedDown = False
keyboard.setPressed(Key.S)
else:
pressedDown = False
if wiimote[wiimote_index].nunchuck.stick.x > 40:
if wiimote[wiimote_index].nunchuck.buttons.button_down(NunchuckButtons.C):
if pressedMiddle == False:
mouse.middleButton = True
pressedMiddle = True
else:
mouse.middleButton = False
else:
pressedMiddle = False;
keyboard.setPressed(Key.D)
else:
pressedMiddle = False
if wiimote[wiimote_index].nunchuck.stick.x < -40:
if wiimote[wiimote_index].nunchuck.buttons.button_down(NunchuckButtons.C):
keyboard.setKeyDown(Key.F)
else:
keyboard.setPressed(Key.A)
keyboard.setKeyUp(Key.F)
else:
keyboard.setKeyUp(Key.F)
# Z nunchuck --> e (use)
map_nunchuck_to_keyPressed(wiimote_index, NunchuckButtons.Z, Key.E)
# Shake nunchuck up --> right click
# Shake nunchuck and wii mote up --> space (jump)
if wiimote[wiimote_index].nunchuck.acceleration.y > 20:
if wiimote[wiimote_index].acceleration.y > 20:
keyboard.setPressed(Key.Space)
else:
if pressedRight == False:
mouse.rightButton = True
pressedRight = True
else:
mouse.rightButton = False
else:
pressedRight = False
diagnostics.watch(wiimote[wiimote_index].nunchuck.acceleration.y)
def motionPlusUpdate(wiimote_index):
diagnostics.watch(wiimote[wiimote_index].ahrs.pitch)
diagnostics.watch(wiimote[wiimote_index].ahrs.roll)
diagnostics.watch(wiimote[wiimote_index].ahrs.yaw)
# ===== Update Funtions =====
def wiiMoteUpdate1():
wiiMoteUpdate(0)
def wiiMoteUpdate2():
wiiMoteUpdate(1)
def wiiMoteUpdate3():
wiiMoteUpdate(2)
def wiiMoteUpdate4():
wiiMoteUpdate(3)
def motionPlusUpdate1():
motionPlusUpdate(0)
def motionPlusUpdate2():
motionPlusUpdate(1)
def motionPlusUpdate3():
motionPlusUpdate(2)
def motionPlusUpdate4():
motionPlusUpdate(3)
def nunChuckUpdate1():
nunChuckUpdate(0)
def nunChuckUpdate2():
nunChuckUpdate(1)
def nunChuckUpdate3():
nunChuckUpdate(2)
def nunChuckUpdate4():
nunChuckUpdate(3)
# ===== Start function =====
# If we're starting up, then hook up our update function.
if starting:
global pressedUp
global pressedDown
global pressedMiddle
global pressedRight
pressedUp = False
pressedDown = False
pressedMiddle = False
pressedRight = False
# 500hz for nunchuck and motion plus.
system.setThreadTiming(TimingTypes.HighresSystemTimer)
system.threadExecutionInterval = 2
configureWiiMote(0, wiiMoteUpdate1, motionPlusUpdate1, nunChuckUpdate1)
configureWiiMote(1, wiiMoteUpdate2, motionPlusUpdate2, nunChuckUpdate2)
configureWiiMote(2, wiiMoteUpdate3, motionPlusUpdate3, nunChuckUpdate3)
configureWiiMote(3, wiiMoteUpdate4, motionPlusUpdate4, nunChuckUpdate4)
Note: This is my first Python script ever