Author Topic: Zoom script  (Read 16003 times)

0 Members and 1 Guest are viewing this topic.

Offline m!m

  • 211
Something I always missed in FS is the ability to zoom in so I can snipe a few precise shots.
I also had 15 minutes left today so I put together this script.

Zoom in using the d key (it was the first key not occupied by default )

Just unzip the file either in its own folder or into the mediavps folder to use it.

Known issues:
  • Handling while in zoom is difficult because scripting is unable to manipulate sensitivity
  • I haven't tested it very much :P

m!m

EDIT: Find the recent version here: http://www.hard-light.net/wiki/index.php/Script_-_Zoom
« Last Edit: September 12, 2010, 08:08:15 am by m!m »

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Very nice. Couple of notes, though:

1. It's best to distribute scripts as un-vped versions, IMHO
2. Can you put it on the wiki's scripting examples category?

AFTER fixing these bugs, of course:
-If you press d, zoom in a bit, release it, then press it again while the fov is resetting itself, then release again, the zoom will not wind back properly.

EDIT: Here's the fix. In zoom_key_pressed, do this:
Code: [Select]
if runZoomScript then
if not zooming then
plr = hv.Player
if plr:isValid() then
if #gr.Cameras > 0 then
cam = gr.Cameras[1]
if cam:isValid() then
zooming = true
tempFOV = normalFOV
zoom = tempFOV * zoomValue
cam:setFOV(zoom,2,1,0.5)
end
end
end
end
end
« Last Edit: July 15, 2010, 08:45:08 am by The E »
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline m!m

  • 211
Thank you for your feedback The E.

Fixing the mentioned things here is an updated version.
Now it's in one tbm and un-vped.
I'll add it to the wiki once it is sure that the script works correctly (and once i figure out how to do that  :nervous:)

EDIT: look in the wiki for the script
« Last Edit: July 17, 2010, 11:13:01 am by m!m »

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Here, with a bit more cleanup:
Code: [Select]
#Conditional Hooks

$Application: FS2_Open
$On Mission Start:
[
runZoomScript = true
zoomValue = 0.1
normalFOV = 0.75
zooming = false
defaultZoomSet = false
]

$Application: FS2_Open
$On Mission End:
[
runZoomScript = false
]

$State: GS_STATE_GAME_PLAY
$KeyPress: d
$On Key Pressed: [
if runZoomScript then
if not zooming then
plr = hv.Player
if plr:isValid() then
if #gr.Cameras > 0 then
cam = gr.Cameras[1]
if cam:isValid() then
zooming = true
if not defaultZoomSet then
normalFOV = cam.FOV
defaultZoomSet = true
end
zoom = normalFOV * zoomValue
cam:setFOV(zoom,2,1,0.5)
end
end
end
end
end
]

$On Key Released: [
if runZoomScript then
if zooming then
plr = hv.Player
if plr:isValid() then
if #gr.Cameras > 0 then
cam = gr.Cameras[1]
if cam:isValid() then
zooming = false
cam:setFOV(normalFOV,2,1,0.5)
end
end
end
end
end
]

#End

As for the wiki, you need to make an account, then make a new page with your script, then link it to the scripting examples category. Take a look at the other scripting examples to see how it's done.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline Sushi

  • Art Critic
  • 211
Once we have the New Pilot Code and can create new keybindings, I would love to see a native in-code version of Zoom In/Out. We could even include the aforementioned sensitivity reduction. :)

 

Offline m!m

  • 211
Thanks for this advise. :)

Find the script in the wiki here:
http://www.hard-light.net/wiki/index.php/Script_-_Zoom

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
you could probably override the controls while in zoomed out and scale back the amount of turning that gets applied to the ship, thus solving the sensitivity problem. look in scripting.html under control info, also look for ba.getControlInfo(), and ba.setControlMode(). i forget how it works, and i dont feel like reading through my code base, but i think you call ba.setControlMode(LUA_STEERING_CONTROLS), then call ba.getControlInfo() (ci = ba.getControlInfo()), then you can edit the data in the ci table to make the ship yaw, pitch and roll.
« Last Edit: July 15, 2010, 09:46:18 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 blowfish

  • 211
  • Join the cult of KILL MY ROUTER!!!!!!!!!!1
Small note: If you zoom using the FOV, zooming out will cause a fish-eye effect; zooming in will cause backgrounds to be come blurry.  It might be preferable to actually move the camera rather than adjust the FOV.  I'm not familiar with how this might work in Lua, but the actual math involved isn't that complicated.

 

Offline m!m

  • 211
New version! Now with better sensitivity (thank you Nuke) and a visual indicator.
I also cleaned up the code so the default values can be modified easily.
And here it is!  :)

EDIT: look in the wiki for the script
« Last Edit: July 17, 2010, 11:13:16 am by m!m »

 

Offline Mongoose

  • Rikki-Tikki-Tavi
  • Global Moderator
  • 212
  • This brain for rent.
    • Minecraft
    • Steam
    • Something
Sweet...mass driver/railgun ahoy! :D

 

Offline m!m

  • 211
New version is in wiki. Now with correctly working progress gauge.

 

Offline qazwsx

  • POST DRUNK GET TITLE
  • 29
    • Minecraft
Small note: If you zoom using the FOV, zooming out will cause a fish-eye effect; zooming in will cause backgrounds to be come blurry.  It might be preferable to actually move the camera rather than adjust the FOV.  I'm not familiar with how this might work in Lua, but the actual math involved isn't that complicated.
wouldn't that allow you to see "through" objects though? and wouldn't it also increase the size of close things by a greater factor?
<Achillion> I mean, it's not like he's shoving the brain-goo in a usb slot and praying to kurzweil to bring the singularity

<dsockwell> idk about you guys but the reason i follow God's law is so I can get my rocks off in the afterlife

 

Offline blowfish

  • 211
  • Join the cult of KILL MY ROUTER!!!!!!!!!!1
wouldn't that allow you to see "through" objects though?

Just zoom out a little.

wouldn't that allow you to see "through" objects though? and wouldn't it also increase the size of close things by a greater factor?

Is that a problem?

 

Offline qazwsx

  • POST DRUNK GET TITLE
  • 29
    • Minecraft
yeah, because the point of the zoom script would be to zoom in on far away enemies, if we take an object 400m away (arbitrary figure) to be the shortest distance before an object could be considered too far away to see normally, then for that object to have a angular size 2x bigger, the camera would have to move 200m forwards.

Piloting that would screw with my head.
<Achillion> I mean, it's not like he's shoving the brain-goo in a usb slot and praying to kurzweil to bring the singularity

<dsockwell> idk about you guys but the reason i follow God's law is so I can get my rocks off in the afterlife

 

Offline m!m

  • 211
Small note: If you zoom using the FOV, zooming out will cause a fish-eye effect; zooming in will cause backgrounds to be come blurry.  It might be preferable to actually move the camera rather than adjust the FOV.  I'm not familiar with how this might work in Lua, but the actual math involved isn't that complicated.
This would also cause the problem that you can see your own ship when looking back because scripting can't check if the view is in the normal state or outside or whatever.
But the biggest problem is still the one mentioned by qazwsx.

 

Offline Droid803

  • Trusted poster of legit stuff
  • 213
  • /人 ◕ ‿‿ ◕ 人\ Do you want to be a Magical Girl?
    • Skype
    • Steam
Hmmm...is there a way to make this only work for specific ships? :P
EDIT: I guess there is, just have to figure out scripting :|
(´・ω・`)
=============================================================

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
if hv.player:isValid() and (hv.player.Class.Name == "some ship" or  hv.player.Class.Name == "some other ship") then

--run script

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

  

Offline m!m

  • 211
I also thought about this before and I want to implement it at some time along with some other things for example that the script reads its values and the allowed ship classes from a file so customizing will be easier.

Maybe tomorrow...

:warp:

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
if it were me id make the zoom available when specific weapons are selected in the loadout. essentially rail gund coil guns mass drivers and general sniper weapons.
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 blowfish

  • 211
  • Join the cult of KILL MY ROUTER!!!!!!!!!!1
Sniper scope for Freespace?