| View previous topic :: View next topic |
| Author |
Message |
xanfantasy
Joined: 06 Mar 2007 Posts: 13
Digg It |
Posted: Tue Mar 06, 2007 3:30 am Post subject: Script Request: Battlefield 2142 |
|
|
I have been trying to code a GlovePIE script for Battlefield 2142 with only some luck. I have everything working except for the aiming. When I onpen the menus it works fine but during the actual gameplay, Spawn Screen and squad screen it wont work at all. Here is the code I have so far.
| Code: |
//Xan Fantasy's BF 2142 basic controls
//Calibration: DO NOT EDIT
var.xtrim = 6
var.ytrim = 31
var.ztrim = 6
//
//Options:
var.deadzone = 5 //distance in pixels that you have to move the wiimote in
//order for it to register movement. Creates a "dead zone" around the pointer
//to make it easier to click. Higher = smoother but less accurate.
//Basic buttons that could be edited
Mouse.LeftButton = wiimote.B //Fire
Mouse.RightButton = wiimote.A //Scope Aim
key.space = Wiimote.Nunchuk.CButton //Jump
key.LeftControl = Wiimote.Nunchuk.ZButton //crouch
key.Minus = Wiimote.Minus //Zoom out/Next Weapon
key.Equals = Wiimote.Plus //zoom in/Prev weapon
key.Shift = Wiimote.1 //sprint
key.e = Wiimote.2 //use/enter
key.r = Wiimote.Down //reload
key.Tab = Wiimote.Right //Squad menu
key.enter = Wiimote.Left //spawn menu
wiimote.Leds = 1
//movement
key.w = Wiimote.Nunchuk.JoyY < -0.5
key.a = Wiimote.Nunchuk.JoyX < -0.5
key.s = Wiimote.Nunchuk.JoyY > 0.5
key.d = Wiimote.Nunchuk.JoyX > 0.5
//I am still a beginning programmer so
//I dont know how to correctly edit this to work
var.accx = wiimote.RawForceX + var.xtrim
var.accy = wiimote.RawForceY + var.ytrim
var.accz = wiimote.RawForceZ + var.ztrim
if wiimote.dot1vis and wiimote.dot2vis then
if var.accy > -7 then
var.orientation = 0
elseif var.accy > -45 then
if var.accx < 0 then
var.orientation = 3
else
var.orientation = 1
endif
else
var.orientation = 2
endif
if var.leftpoint = 0 then
if var.orientation = 0 then
if wiimote.dot1x < wiimote.dot2x then
var.leftpoint = 1
else
var.leftpoint = 2
endif
endif
if var.orientation = 1 then
if wiimote.dot1y > wiimote.dot2y then
var.leftpoint = 1
else
var.leftpoint = 2
endif
endif
if var.orientation = 2 then
if wiimote.dot1x > wiimote.dot2x then
var.leftpoint = 1
else
var.leftpoint = 2
endif
endif
if var.orientation = 3 then
if wiimote.dot1y < wiimote.dot2y then
var.leftpoint = 1
else
var.leftpoint = 2
endif
endif
endif
if var.leftpoint = 1 then
var.fix1x = wiimote.dot1x
var.fix1y = wiimote.dot1y
var.fix2x = wiimote.dot2x
var.fix2y = wiimote.dot2y
else
var.fix1x = wiimote.dot2x
var.fix1y = wiimote.dot2y
var.fix2x = wiimote.dot1x
var.fix2y = wiimote.dot1y
endif
var.dx = var.fix2x - var.fix1x
var.dy = var.fix2y - var.fix1y
var.cx = (var.fix1x+var.fix2x)/1024.0 - 1
var.cy = (var.fix1y+var.fix2y)/1024.0 - .75
var.d = sqrt(var.dx*var.dx+var.dy*var.dy)
var.dx = var.dx / var.d
var.dy = var.dy / var.d
var.ox = -var.dy*var.cy-var.dx*var.cx;
var.oy = -var.dx*var.cy+var.dy*var.cx;
var.ax = (var.ox * screen.desktopwidth) + (screen.desktopwidth / 2)
var.ay = (-var.oy * screen.desktopwidth) + (screen.desktopheight / 2)
var.dx = var.ax - mouse.cursorposx
var.dy = var.ay - mouse.cursorposy
var.d = sqrt((var.dx*var.dx)+(var.dy*var.dy))
var.a = 180 / (200 + var.d * var.d * var.d * .001)
if var.d <= var.deadzone then var.a = 1
debug = var.d + " " + var.a
var.finalx = mouse.cursorposx * var.a + var.ax * (1 - var.a)
var.finaly = mouse.cursorposy * var.a + var.ay * (1 - var.a)
mouse.cursorposx = var.finalx
mouse.cursorposy = var.finaly
else
var.leftpoint = 0
endif
|
Last edited by xanfantasy on Thu Mar 08, 2007 11:37 pm; edited 1 time in total |
|
| Back to top |
|
 |
nc
Joined: 20 Jan 2007 Posts: 50
Digg It |
Posted: Tue Mar 06, 2007 1:08 pm Post subject: |
|
|
| You need to use directinput, not cursorpos |
|
| Back to top |
|
 |
xanfantasy
Joined: 06 Mar 2007 Posts: 13
Digg It |
Posted: Tue Mar 06, 2007 3:54 pm Post subject: |
|
|
| But like I said I am a newb at all of this so I have no Idea about a lot of this. I will look around some more at other scripts to see If I can get it |
|
| Back to top |
|
 |
nc
Joined: 20 Jan 2007 Posts: 50
Digg It |
Posted: Wed Mar 07, 2007 12:34 am Post subject: |
|
|
I haven't tried this one myself yet. But this looks like a good simple direct-input script for ir.
link |
|
| Back to top |
|
 |
xanfantasy
Joined: 06 Mar 2007 Posts: 13
Digg It |
Posted: Wed Mar 07, 2007 12:49 am Post subject: |
|
|
| They don't work. The bottom one gets extreamly jittery. The right mouse look (Looking to the right) doesn't seam to work for it either. Also when I try to add the movement controls It throws it out of wack. Although it does work fine on the desktop. |
|
| Back to top |
|
 |
xanfantasy
Joined: 06 Mar 2007 Posts: 13
Digg It |
Posted: Thu Mar 08, 2007 11:36 pm Post subject: |
|
|
So after searching and testing for a week, I have found some code by Dr_Zoidberg that works for most of my games, Although right now I have it tailored to Battlefield 2142. here it is
| Code: |
//BattleField 2142 Script
//Everything besides the IR Mouse
//By Xan Fantasy
//IR FPS Mouse Script by Dr_Zoidberg
//Basic Buttons (Can be edited to fit the Game
Mouse.LeftButton = wiimote.B //Fire
Mouse.RightButton = wiimote.A //Scope Aim
key.space = Wiimote.Nunchuk.CButton //Jump
key.LeftControl = Wiimote.Nunchuk.ZButton //crouch
key.Minus = Wiimote.Minus //Zoom out/Next Weapon
key.Equals = Wiimote.Plus //zoom in/Prev weapon
key.Shift = Wiimote.1 //sprint
key.e = Wiimote.2 //use/enter
key.r = Wiimote.Down //reload
key.Tab = Wiimote.Right //Squad menu
key.enter = Wiimote.Left //spawn menu
wiimote.Leds = 1
//movement
key.w = Wiimote.Nunchuk.JoyY < -0.5
key.a = Wiimote.Nunchuk.JoyX < -0.5
key.s = Wiimote.Nunchuk.JoyY > 0.5
key.d = Wiimote.Nunchuk.JoyX > 0.5
//FPS IR Script beta 1.3
//By Dr_Zoidberg
pie.FrameRate = 125
//rotation deadzone
var.rn = 0.5
pie.MouseDPI = 1600
//deadzone for just one dot visible
var.deadzone = 0.0001
//deadzone for both dots visible
var.deadzone0 = 0.0001
//var.dd = var.deadzone0*var.dead
//adjust sensitivty mousedpi/100 works best
var.scrmult = 16
//areas for IR pointing ----------------
//direct pointing area
var.czonex = (screen.Width/1.5)/var.scrmult
var.czoney = (screen.Height/1.5)/var.scrmult
//faster direct pointing area
var.izonex = (screen.Width/3)/var.scrmult
var.izoney = (screen.Height/3)/var.scrmult
//continous movment around inner area
//-------------------------------------
//speed factors-----------------------
var.cfactor = 1
var.ifactor = 1/32
var.0factor = 1/80
//y-axis adjustment
var.factory = 1/1.1
//acceleration adjust
var.cpower = 0.02
var.ipower = 1.2
var.0power = 0.1
//-------------------------------------
//wiimoteroll convert
var.roll = 0 - wiimote.roll
if var.roll < 0 then
var.roll = var.roll + 360
endif
var.cos = cos(var.roll)//-var.dcos
var.sin = -sin(var.roll)//-var.dsin
var.cos = smooth(var.cos,25)
var.sin = smooth(var.sin,25)
var.sinpitch = sin(wiimote.Pitch)
var.sinpitch = smooth(var.sinpitch,5)
if wiimote.dot1vis or wiimote.dot2vis then
//phantomdot creation if only one dot is visible
if (not wiimote.dot1vis) or (not wiimote.dot2vis) then
if wiimote.dot1vis then
var.d0x = (1024/2)- wiimote.dot1x
var.d0y = (768/2) - wiimote.dot1y
else
var.d0x = (1024/2)- wiimote.dot2x
var.d0y = (768/2) - wiimote.dot2y
endif
//check which dot is which
if sqrt(sqr(var.d0x-var.d1x)+sqr(var.d0y-var.d1y)) > sqrt(sqr(var.d0x-var.d2x)+sqr(var.d0y-var.d2y)) then
var.d3x = var.d1x
var.d3y = var.d1y
else
var.d3x = var.d2x
var.d3y = var.d2y
endif
//var.roll = var.roll - var.dr
var.distf = 1+((abs(var.y)^0.5/768-0.5)*((abs(var.sinpitch)^1)*(var.dist-1))/(1024-1))*sign(var.sinpitch)*sign(var.y)
var.px = var.cos*var.dist*var.distf
var.py = var.sin*var.dist*var.distf
if sqrt(sqr(var.d0x+var.px-var.d3x)+sqr(var.d0y+var.py-var.d3y)) > sqrt(sqr(var.d0x-var.px-var.d3x)+sqr(var.d0y-var.py-var.d3y)) then
var.px = var.px*(-1)
var.py = var.py*(-1)
endif
var.d1x = var.d0x
var.d1y = var.d0y
if abs((sqrt(sqr(var.d0x + var.px)+sqr(var.d0y + var.py)))-sqrt(sqr(var.d2x)+sqr(var.d2y))) > var.deadzone then
var.d2x = var.d0x + var.px
var.d2y = var.d0y + var.py
endif
//var.distp = sqrt(sqr(var.d1x-var.d2x)+sqr(var.d1y-var.d2y))
else
//read IR if both dots are visible
var.d2x = (1024/2)- wiimote.dot2x
var.d2y = (768/2) - wiimote.dot2y
var.d1x = (1024/2)- wiimote.dot1x
var.d1y = (768/2) - wiimote.dot1y
var.dist = sqrt(sqr(var.d1x-var.d2x)+sqr(var.d1y-var.d2y))
var.dsin = sin(var.roll) + ((var.d1y-var.d2y)/sqrt(sqr(var.d1x-var.d2x)+sqr(var.d1y-var.d2y)))
var.dcos = cos(var.roll) - ((var.d1x-var.d2x)/sqrt(sqr(var.d1x-var.d2x)+sqr(var.d1y-var.d2y)))
var.dsin = smooth(var.dsin,5)
var.dcos = smooth(var.dcos,5)
endif
//rotation neutralization
if abs(((var.d1x-var.d2x)/sqrt(sqr(var.d1x-var.d2x)+sqr(var.d1y-var.d2y)))-cos(var.roll)) > var.rn or abs(((var.d1y-var.d2y)/sqrt(sqr(var.d1x-var.d2x)+sqr(var.d1y-var.d2y)))+sin(var.roll)) > var.rn then
var.d0x = var.d1x
var.d0y = var.d1y
var.d1x = var.d2x
var.d1y = var.d2y
var.d2x = var.d0x
var.d2y = var.d0y
endif
//var.dr = -acos(((var.d1x-var.d2x)/sqrt(sqr(var.d1x-var.d2x)+sqr(var.d1y-var.d2y)))) - var.roll
//
//var.rots = asin((var.d1y-var.d2y)/sqrt(sqr(var.d1x-var.d2x)+sqr(var.d1y-var.d2y)))
//smooth movement
var.d1x = smooth(var.d1x,2)
var.d1y = smooth(var.d1y,2)
var.d2x = smooth(var.d2x,2)
var.d2y = smooth(var.d2y,2)
//temp dot
var.0x = var.x
var.0y = var.y
//coordinate calculation
if abs(sqrt(sqr(((var.d1y*var.d2x)-(var.d1x*var.d2y)) / (sqrt(sqr(var.d2x-var.d1x) + sqr(var.d2y-var.d1y)))/((1024))*screen.Width/var.scrmult)+sqr((sqr(var.d1x)-sqr(var.d2x)+sqr(var.d1y)-sqr(var.d2y)) / (2*(sqrt(sqr(var.d2x-var.d1x) + sqr(var.d2y-var.d1y))))/(768)*screen.Height/var.scrmult))-sqrt(sqr(var.x)+sqr(var.y))) > var.deadzone then
var.y = ((var.d1y*var.d2x)-(var.d1x*var.d2y)) / (sqrt(sqr(var.d2x-var.d1x) + sqr(var.d2y-var.d1y)))/((1024))*screen.Width/var.scrmult
var.x = (sqr(var.d1x)-sqr(var.d2x)+sqr(var.d1y)-sqr(var.d2y)) / (2*(sqrt(sqr(var.d2x-var.d1x) + sqr(var.d2y-var.d1y))))/(768)*screen.Height/var.scrmult
var.x = smooth(var.x,2)
var.y = smooth(var.y,2)
if var.input = 0 then
if abs(var.x) > var.czonex
var.x = var.x*abs(1+(abs(abs(var.x)-var.czonex)/abs(var.x))*var.cpower)*var.cfactor
endif
if abs(var.y) > var.czoney
var.y = var.y*abs(1+(abs(abs(var.y)-var.czoney)/abs(var.y))*var.cpower*var.factory)*var.cfactor
endif
endif
endif
if var.input = 1 then
mouse.x = smooth(((var.x/screen.Width*var.scrmult)*1.5 + 1/2),0)
mouse.y = smooth(((var.y/screen.Height*var.scrmult)*1.2 + 1/2),0)
endif
//fps mouse movement
if var.input = 0 then
if abs(var.x) > var.izonex then
var.inputx = var.inputx + var.x*abs((abs((abs(var.x)-var.izonex)^var.ipower)/abs(abs(var.x)^var.ipower)))*var.ifactor
endif
if abs(var.y) > var.izoney then
var.inputy = var.inputy + var.y*abs((abs((abs(var.y)-var.izoney)^var.ipower)/abs(abs(var.y)^var.ipower)))*var.ifactor
endif
var.inputx = var.inputx + var.x - var.0x
var.inputy = var.inputy + var.y - var.0y
mouse.DirectInputX = var.inputx
mouse.DirectInputY = var.inputy
endif
else
//continue mouse movement if no IR visible
if var.input = 0 then
if abs(var.x) > var.izonex then
var.InputX = var.InputX + var.x*abs((abs((abs(var.x)-var.izonex)^var.ipower)/abs(abs(var.x)^var.ipower)))*var.ifactor
else
var.InputX = var.InputX + var.x*abs(1+abs(var.x)*var.0power)*var.0factor
endif
if abs(var.y) > var.izoney then
var.InputY = var.InputY + var.y*abs((abs(abs(abs(var.y)-var.izoney)^var.ipower)/abs(abs(var.y)^var.ipower)))*var.ifactor
else
var.InputY = var.InputY + var.y*abs(1+abs(var.y)*var.0power*var.factory)*var.0factor
endif
mouse.directinputX = var.inputx
mouse.directinputY = var.inputy
endif
endif
mouse.RightButton = wiimote.A
mouse.leftbutton = wiimote.B
debug = ("dot1x: " + wiimote.dot1x+ " dot1y: " +wiimote.dot1y + " dot2x: " +wiimote.dot2x + " dot2y: " + wiimote.dot2y +" var.x: " +var.x + " var.y: " +var.y + " distf: " + var.distf + " mouse: " + mouse.DirectInputPos +" batt: " +wiimote.Battery)
|
Last edited by xanfantasy on Fri Mar 09, 2007 1:33 am; edited 1 time in total |
|
| Back to top |
|
 |
Dr_Zoidberg
Joined: 29 Dec 2006 Posts: 60
Digg It |
Posted: Fri Mar 09, 2007 12:14 am Post subject: |
|
|
My Script has been updated to Version 1.9 beta, mostly glitch fixes and i have also included nunchuk acceleration support mapped as buttons.
I recommend changing var.ifactor and var.0factor to adjust the rotation speed for each game.
ifactor determines the speed if you point to the edge of the screen and 0factor is responsible for the speed if no dot is visible. |
|
| Back to top |
|
 |
|