 |
WiiLi.org a new revolution
|
| View previous topic :: View next topic |
| Author |
Message |
kiddo7
Joined: 05 Feb 2007 Posts: 42
Digg It |
Posted: Sat Jul 26, 2008 9:51 pm Post subject: AirRivals script (nunchuk, no IR) |
|
|
This is my first script And i would really like to get some feed back on this.
If you use this please let me know how it feels.
| Code: | /*
Air rivals script
Inspired by Maxadam5
Rewritten by kiddo7
Script to controll the MMORPG "AirRivals" with a wiimote and nunchuck.
Instructions:
Fly using the analog stick as your mouse replacement and keep in mind that
I inverted the y axis, and bank by tilting the nunchuk. You can easily preform
barrelrolls with the d-pad left and right.
Slow down by pulling back on the wiimote untill it is pointing straight up,
airstop by doing the same with the nunchuck.
Land with d-pad down and boost with nunchuck Z.
Fire primary with the b trigger, advanced with the A button and switch targets
by fliping the wiimote on it's side or shaking it a little.
I also assigned rear view to d-pad up, the mouse wheel to the plus and minus
buttons enter to nunchuk c and escape to home.
I decided to leave the 1 & 2 buttons without assignment because they are hard
to reach. You might be a little confused by this explanation but try it in game
and most of it should become clear.
Also if you get stuck, I tried to leave enough comment in my code so that you
can at least search for key words and find the snippet of code tha pretains to
it. One last thing, I have left the original script that I started out from in
a comment at the end. I do not have a sensor bar so my script has no IR
functionality, but the original apparently does. You can try it out by
uncommenting Maxadam5's script and putting mine into comments. Or you can try
to splice the IR parts to my script and toggle between the two modes using the
1 and 2 buttons.
*/
/*
Mouse controls:
I used the "+=" operator to increment a value of "Nunchuk.Joy"
then added a multiplier(in my case 55 & 35. I added the negative sign to
invert the Y axis) to get it to a usable speed
(change this value if the mouse feels sluggish or too fast),
finnaly I added a deadzone to keep the cursor from drifting
*/
Mouse.DirectInputX += (55 * DeadZone(Nunchuk1.JoyX, 0.025))
Mouse.DirectInputY += -(35 * DeadZone(Nunchuk1.JoyY, 0.025))
//I use the plus and minus keys to SCROLL (ZOOM IN & OUT)
if Wiimote1.Plus then
Mouse.Wheelup = true
endif
if Wiimote1.Minus then
Mouse.Wheeldown = true
endif
//the B-triger is my PRIMARY weapon and the A-button fires my SECONDARY,
//while the d-pad up activates the REAR VIEW
Mouse.LeftButton = Wiimote1.B
Mouse.RightButton = Wiimote1.A
Mouse.MiddleButton = Wiimote1.up
//Remaining flight controls:
//BARRELROLLS...
if pressed(wiimote1.left) then
DoubleClicked(a)=true
wait 2s
elseif pressed(wiimote1.right) then
DoubleClicked(d)=true
wait 2s
endif
//...and BANKing(you might have to adjust the threshold values)
if nunchuk.gX > 0.50 then
a = true
endif
if nunchuk.gX < -0.50 then
d = true
endif
//SLOWing DOWN(same as with banking)...
if pressed(nunchuk.gZ) > 0.50 then
s = true
endif
//...AIRSTOPping(you guessed it)...
if pressed(wiimote1.gZ) > 0.50 then
b = true
endif
//...BOOSTing...
if nunchuk.ZButton then
space = true
endif
//...and LANDING
if pressed(wiimote1.down) then
c = true
endif
//SWITCH TARTEG
if pressed(wiimote1.gX) > |0.5| then
tab = true
endif
//confirm
if pressed(nunchuk.CButton) then
pressed(enter) = true
wait 1s
endif
//back off
if pressed(wiimote1.home) then
pressed(esc) = true
endif
///////////////////////////////////////////////////////////////////////
//Thank you for cheking out my script.
/*
if var.irpointer = false then
Mouse.x = MapRange(Wiimote1.Pitch, -90 degrees,90 degrees, 0,1)
Mouse.y = MapRange(Wiimote1.Roll, 90 degrees,-90 degrees, 0,1)
endif
if var.A = true then
mouse.x = wiimote.PointerX
mouse.Y = wiimote.PointerY
endif
var.A = Wiimote1.A
var.B = Wiimote1.B
var.home = Wiimote1.Home
var.plus = Wiimote1.Plus
var.minus = Wiimote1.Minus
var.Cbutton = wiimote.Nunchuk.CButton
var.Zbutton = wiimote.Nunchuk.ZButton
var.one = wiimote.One
var.two = wiimote.Two
var.up = wiimote.Up
var.down = wiimote.Down
var.left = wiimote.Left
var.right = wiimote.right
var.nunchukswing = (wiimote.Nunchuk.RawAccX > 25 or < -25) or (wiimote.Nunchuk.RawAccY > 25 or < -25) or (wiimote.Nunchuk.RawAccZ > 25 or < -25)
var.nunchukx = (wiimote.Nunchuk.RawAccX > 25 or < -25)
var.nunchuky = (wiimote.Nunchuk.RawAccY > 25 or < -25)
var.nunchukz = (wiimote.Nunchuk.RawAccZ > 25 or < -25)
var.wiimoteswing = (wiimote.RawAccX > 25 or < -25) or (wiimote.RawAccY > 25 or < -25) or (wiimote.RawAccZ > 25 or < -25)
var.wiimoteX = (wiimote.RawAccX > 25 or < -25)
var.wiimoteY = (wiimote.RawAccY > 25 or < -25)
var.wiimoteZ = (wiimote.RawAccZ > 25 or < -25)
var.wiimoteXforward = (wiimote.rawaccX > 10)
/////////////////////////////////////
if pressed(var.wiimoteXforward) then
key.Space = true
wait 3 seconds
key.space = false
endif
if var.irpointer = false
mouse.LeftButton = var.two
mouse.rightbutton = var.one
key.B = var.b
key.shift = var.A
key.Escape = var.home
key.W = var.right
key.S = var.left
key.A = var.up
key.D = var.down
key.C = var.minus
endif
if var.plus = true then
var.irpointer = true
mouse.x = wiimote.PointerX
mouse.Y = wiimote.PointerY
else
var.irpointer = false
endif
if var.irpointer = true then
mouse.LeftButton = var.B
mouse.RightButton = var.A
endif
*/
// COMPILED CODE, PLEASE DELETE BEFORE COMPILING!
|
NOTE: this code is untested and buggy to the point of being unusable!!!!
I will upload the working version soon. |
|
| Back to top |
|
 |
kiddo7
Joined: 05 Feb 2007 Posts: 42
Digg It |
Posted: Tue Jul 29, 2008 1:43 pm Post subject: |
|
|
I know double posting is EV-IL and I should be burned at the stake and then hanged. I made so many changes to my script That I wanted to have a reference for where I started from preserved. Also seeing the difference between an untested and extensively tested script could help a lot of people who are still learning (like myself.)
I now ceremonially repost only the sections of code that belong to me (with a lot more comments):
| Code: | //Air rivals script 0.1.2
//Inspired by Maxadam5
//Rewritten by kiddo7
//Script to controll the MMORPG "AirRivals" with a wiimote and nunchuck only, no IR.
//Instructions:
//Fly using the analog stick as your mouse replacement and bank by tilting the
//nunchuk.
//You can easily preform barrelrolls with the d-pad left and right.
//Slow down by pulling back on the wiimote untill it is pointing straight up,
//Airstop by doing the same with the nunchuck.
//Land with d-pad down and boost with nunchuck C.
//Fire primary with the Z trigger (nunchuk), advanced with the B Trigger and
//switch targets by fliping the wiimote on it's side or shaking it a little.
//I also assigned rear view to d-pad up, the mouse wheel to the plus and minus
//buttons, enter to the A Button and escape to home
//(wiimote! not on your keyboard, that would not make any sense lol).
//I decided to leave the 1 & 2 buttons without assignment because they are hard
//to reach.
//You might be a little confused by this explanation but try it in game and most
//of it should become clear. Also if you get stuck, I tried to leave enough
//comments in my code so that you can at least search for key words and find the
//snippet of code tha pretains to it.
//One last thing, I have left the original script that I started out from, in a
//comment(/*code */) at the end. I do not have a sensor bar so my script has no
//IR functionality, but the original apparently does. You can try it out by
//uncommenting Maxadam5's script and putting mine into comments. Or you can try
//to splice the IR parts to my script and toggle between the two modes using the
//1 and 2 buttons.
//Mouse controls:
cursor.X = smooth(EnsureMapRange(4000*DeadZone(Nunchuk1.JoyX, 0.055), -720,720, 0,1), 7)
cursor.Y = smooth(EnsureMapRange(4000*DeadZone(Nunchuk1.JoyY, 0.055), -450,450, 0,1), 7)
//I am sorry and ashamed of the mess that was supposed to be the mouse controls
//in my first attempt. Since then I have introduced some significant
//fixes/upgrades: I orriginally used some direct input that was incrementally
//added to the current possition of the mouse.while this was a very precise and
//reactive mouse script(for analog stick anyways) it worked terribly in-game. I
//then copied and modified the tilt controls from Maxadam5's script untill I
//had something that worked for me(took quite a few tries). Finnaly I decided
//to upgrade the script by replacing mouse.X/Y with cursor.X/Y this allows you
//to still be able to use your mouse while the script is running(quite a
//usefull thing especially when you are not flying in the game). I also changed
//the constants from the EnsuremapRange funtion from my screen
//ratio(aproximately) to my screen resolution. I found this makes the cursor
//lagg less. If you are using this script you probably should adjust these
//values to your own resolution. Remember the multiplier before the Deadzone
//function has to be a little bigger than our resolution if you want to reach
//the corners of your screen (they also control the sensitivity of your cursor),
//and the first two arguments of the range function
//have to go from negative to positive ann add upto your screen resolution.
//I use the plus and minus keys to SCROLL (ZOOM IN & OUT)
if Wiimote1.Plus then
Mouse.Wheelup = true
endif
if Wiimote1.Minus then
Mouse.Wheeldown = true
endif
//The Z-trigger(nunchuck) is my PRIMARY weapon and the B-trigger fires my SECONDARY,
//(you might want to switch this so it feels more natural).
//while the d-pad up activates the REAR VIEW
Mouse.LeftButton = nunchuk.ZButton
Mouse.RightButton = Wiimote1.B
Mouse.MiddleButton = Wiimote1.up
//Remaining flight controls:
//BARRELROLLS...
//simply press left or right on the d-pad
if pressed(wiimote1.left) then
DoubleClicked(a)=true
wait 15ms
Clicked(a)=true
wait 5ms
(a)=false
elseif pressed(wiimote1.right) then
Clicked(d)=true
wait 15ms
Clicked(d)=true
wait 5ms
(d)=false
endif
//...and BANKing(you might have to adjust the threshold values)
//twist the chuk on its sides
if nunchuk.gX > 0.50 then
a = true
wait 50ms
else a = false
endif
if nunchuk.gX < -0.50 then
d = true
wait 50ms
else d = false
//This was really messed up in my original code. Instead of keeping the buttons
//pressed it kept pressing them repeatedly. Took me a long while to figure out
//a solution for this and I had many crazy and complicated ideas. Problem was I
//assumed that every state that you do not designate as true will automatically
//be false. I learned my lesson: Make No Assumptions!
//The wait is because, as we know, for every action ther is an equal and
//opposite reaction therefore in the instant following the twisting of the chuk
//to one side, a force will appear in the other direction also, thereby
//inurrupting the press of the buttun for a short while causing the gear to
//barrelroll.
endif
//SLOWing DOWN(same as with banking)...
//Tilt the chuck back(analog stick facing you)
if nunchuk.gZ > 0.63 then
s = true
wait 100ms
s = false
endif
//...SPEEDing UP(same as with banking)...
//Tilt the chuk forwards (c & z buttons facing ground)
if nunchuk.gZ < -0.30 then
w = true
wait 100ms
w = false
endif
//...AIRSTOPping(you guessed it)...
//Tilt wiimote up (IR facing roof)
if wiimote1.gZ > abs(0.75) then
clicked(b) = true
b = false
wait 500ms
//I wanted to make this a flicking motion but I have not been able to get it to
//work reliably yet, so for the time being this is it.
endif
//...BOOSTing...
//press C on the chuck
if nunchuk.CButton then
space = true
wait 50ms
space = false
endif
//...and LANDING
//press D-pad down
if released(wiimote1.down) then
c = true
wait 50ms
c = false
endif
//SWITCH TARTEG
//Turn Wiimote on it's side
//(or shake it a little, though this does not always work for me)
if pressed(wiimote1.gX) > |0.5| then
shift = true
wait 100ms
shift = false
endif
//I thought it would be nice to have the ENTER key at my fingertips.
//press the A button
if wiimote1.A = true then
clicked(enter) = true
enter = false
wait 1s
endif
//ESCAPE comes in handy quite often too!
//press the home button.
if clicked(wiimote1.home) then
clicked(esc) = true
wait 1s
esc = false
endif
//never forget to code a KILL SWITCH!
// press end on your keyboard to stop the script.
ExitProgram = End
//Thank you for cheking out my script.
///////////////////////////////////////////////////////////////////////
| [/list] |
|
| Back to top |
|
 |
Maxadam5

Joined: 23 May 2008 Posts: 37
Digg It |
Posted: Sun Aug 10, 2008 8:09 pm Post subject: |
|
|
| Thank you very much for being inspired by my script. I guess that if you need another script i might write it for you, i have nothing better to do lol. |
|
| 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
|