Hard Light Productions Forums
FreeSpace Releases => Scripting Releases => Topic started by: m!m on July 15, 2010, 08:27:50 am
-
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 (http://www.hard-light.net/wiki/index.php/Script_-_Zoom)
-
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:
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
-
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
-
Here, with a bit more cleanup:
#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.
-
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. :)
-
Thanks for this advise. :)
Find the script in the wiki here:
http://www.hard-light.net/wiki/index.php/Script_-_Zoom (http://www.hard-light.net/wiki/index.php/Script_-_Zoom)
-
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.
-
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.
-
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
-
Sweet...mass driver/railgun ahoy! :D
-
New version is in wiki. Now with correctly working progress gauge.
-
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?
-
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?
-
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.
-
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.
-
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 :|
-
if hv.player:isValid() and (hv.player.Class.Name == "some ship" or hv.player.Class.Name == "some other ship") then
--run script
end
-
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:
-
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.
-
Sniper scope for Freespace?
-
hmm...
Is it possible to blur the outer regions of the screen via scripting? Then it would be possible to get this "scope feeling" while zooming ;7.
When there's time I'll implement the weapon restriction...
-
Post processing effects like that are possible (I believe, anyway), but hideously expensive in terms of processing required. Better wait for a better shader management system that integrates shaders and lua.
-
it probibly might just work to take a large bitmap of some set dimension. essentially gray with a transparent blob in the middle and maybe a crosshair graphic on top of that. youd want to stretch it to cover the screen and then render the crosshair graphic as a polygon at the center. its not as polished as a shader but it should look pretty good if you do it right.
-
Yeah, that would work as well, I think
-
So, I implemented a config file system and an allowed/restricted Ship/Weapon system but now I have got a problem with the Weapon banks.
To check if the current selected weapon is allowed I need to access the primary/secondary weapon bank. Now here is my problem:
I want to access the weapon class but it seams that there is no operator or function that gives me access to these. The scripting documentation states something as followed:
weaponbank [] number Index
Array of weapon banks
Returns: Weapon bank, or invalid handle on failure
suggesting that the weaponbanktype itself is a table containing the weaponbank handles but when i access it like a table in a for-loop FreeSpace (or rather Lua) gives me an "attempt to call a userdata value" error.
Does anyone know how I can get the currently selected weapon class or what I'm doing wrong?
Thank you for your help,
m!m
-
weaponbank is a table (technically its userdata but it works like a table) you can use the # operator to figure out the length of the table, and iterate through them to determine what weapon is mounted and whether its armed or not.
--get the weapon bank type object, with this you can see if dual fire or linked mode is selected
pbanks = hv.player.PrimaryBanks
link = pbanks.Linked
--iterate through primary banks
numpbanks = #pbanks
for i=1, numpbanks do
--get a specific bank
pbank = pbanks[i]
--do stuff with bank here, like check to see if the weapon is armed or what it is or how much ammo there is
wep = pbank.WeaponClass
arm = pbank.Armed
ammo = pbank.AmmoLeft
end
*edited for sanity, errors*
*edited because lua starts indexing at 1 not 0*
-
Ahh, I tried to iterate throug it using a for i in bank do loop rather than using indexes.
Thank you Nuke :)
-
Soooo, new version with some new features including:
- A configuration file mechanism
- The ability to restrict (or allow) the use of zoom based on weapon and/or ship class
Here's the script, paste it into your data/tables directory in a file called zoom-sct.tbm:
#Conditional Hooks
$Application: FS2_Open
$On Game Init:
[
-------------------------------------------------------------
-------- utility functions --------
-------------------------------------------------------------
function trim(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
function isAllIdent(check)
check = check:lower()
if check == "**all**" then
return true
else
return false
end
end
-------------------------------------------------------------
---- defining functions used for parsing the config file ----
-------------------------------------------------------------
-- gets the next line out of the file
local function getNextLine(file)
if file:isValid() then
local line = file:read("*l")
return line
else
ba.warning("Invalid file handle pased to readLine function")
return nil
end
end
-- looks up the set function which is connected to the specified keyword
local function getSetFunc(keyword)
keyword = keyword:lower()
for i,v in pairs(setTable) do
index = i:lower()
if index == keyword then
return v
end
end
return nil
end
local function setZoomFactor(value)
local val = tonumber(value)
if val == nil then
ba.warning("Non numeric value given to 'Zoom Factor'. Skipping...")
return
end
zoomValue = val
end
local function setTransTime(value)
local val = tonumber(value)
if val == nil then
ba.warning("Non numeric value given to 'Transition Time'. Skipping...")
return
end
transitionTime = val
end
local function setSens(value)
local val = tonumber(value)
if val == nil then
ba.warning("Non numeric value given to 'Sensitivity'. Skipping...")
return
end
sensitivity = val
end
local function setLinkedZoom(value)
local yesKey = "yes"
value = value:lower()
if value == yesKey then
linkedZoom = true
else
linkedZoom = false
end
end
local function addAllowedShipClass(value)
if isAllIdent(value) then
allowedShips = {}
allowedShips[1] = value
return
end
if allowedShips[1] == nil or not isAllIdent(allowedShips[1]) then
local ship = tb.ShipClasses[value]
if ship ~= nil and ship:isValid() then
table.insert(allowedShips, value)
else
ba.warning("Specified ship class '" .. value .. "' does not exist.")
end
end
end
local function addRestrictedShipClass(value)
if isAllIdent(value) then
restrictedShips = {}
restrictedShips[1] = value
return
end
if restrictedShips[1] == nil or not isAllIdent(restrictedShips[1]) then
local ship = tb.ShipClasses[value]
if ship ~= nil and ship:isValid() then
table.insert(restrictedShips, value)
else
ba.warning("Specified ship class '" .. value .. "' does not exist.")
end
end
end
local function addAllowedWeaponClass(value)
if isAllIdent(value) then
allowedWeapons = {}
allowedWeapons[1] = value
return
end
if allowedWeapons[1] == nil or not isAllIdent(allowedWeapons[1]) then
local weapon = tb.WeaponClasses[value]
if weapon ~= nil and weapon:isValid() then
table.insert(allowedWeapons, value)
else
ba.warning("Specified weapon class '" .. value .. "' does not exist.")
end
end
end
local function addRestrictedWeaponClass(value)
if isAllIdent(value) then
restrictedWeapons = {}
restrictedWeapons[1] = value
return
end
if restrictedWeapons[1] == nil or not isAllIdent(restrictedWeapons[1]) then
local weapon = tb.WeaponClasses[value]
if weapon ~= nil and weapon:isValid() then
table.insert(restrictedWeapons, value)
else
ba.warning("Specified weapon class '" .. value .. "' does not exist.")
end
end
end
local function parseLine(line)
if line == nil or line == "" then -- Check if this line needs to be parsed
return
end
local comm_s, comm_e = line:find("--",1,true)
if comm_s ~= nil then
line = line:sub(1,(comm_s - 1))
end
if line == "" then -- was the line fully commented away?
return -- Nothing to be done...
end
local key_s, key_e = line:find(":",1,true)
local val_s, val_e = line:find("%a",key_e)
if key_s == nil then -- malformatted line
ba.warning("Malformatted line: " .. line .. "\nSkipping...")
return
end
local keyword = line:sub(1,(key_e - 1))
if val_s == nil then -- Maybe we_ve got a digit value
val_s, val_e = line:find("%d",key_e) -- search for them
if val_s == nil then
-- We have no value
ba.warning("Keyword '" .. keyword .. "' hasn't specified a value. Skipping...")
return
end
end
keyword = keyword:lower() -- make the keyword lowercase
local val = line:sub(val_s, line:len())
if val ~= nil then
val = trim(val)
local setFunc = getSetFunc(keyword)
if setFunc == nil then
ba.warning("Unknown keyword: " .. keyword)
return
end
setFunc(val)
else
return
end
end
local function initSetTable()
setTable = {}
setTable["Zoom Factor"]=setZoomFactor
setTable["Transition Time"]=setTransTime
setTable["Sensitivity"]=setSens
setTable["Allowed Ship Class"]=addAllowedShipClass
setTable["Restricted Ship Class"]=addRestrictedShipClass
setTable["Allowed Weapon Class"]=addWeaponClass
setTable["Restricted Weapon Class"]=addRestrictedWeaponClass
setTable["Linked Zoom"]=setLinkedZoom
end
local function readConfig()
if cf.fileExists(configFile) then
local config = cf.openFile(configFile)
if config:isValid() then
initSetTable()
local parse = true
while parse do
local line = getNextLine(config)
if line == nil then
parse = false
break
end
parseLine(line) -- parse the found line
end
else
ba.warning("Handle to config file is invalid. Is the file readable?")
end
else
ba.warning("No config file found. Returning to default")
end
end
-------------------------------------------------------------
------ defining functions used in the script ------
-------------------------------------------------------------
local function checkTables(allTbl,restrTbl, checkHandle)
if checkHandle == nil then
return false
end
if allTbl ~= nil and restrTbl ~= nil then
if #allTbl > 0 then
if isAllIdent(allTbl[1]) then
if #restrTbl > 0 then
if isAllIdent(restrTbl[1]) then
return true
end
end
for i,v in ipairs(restrTbl) do
if checkHandle.Name == v then
return false
end
end
return true
elseif isAllIdent(restrTbl[1]) then
if #allTbl > 0 then
if isAllIdent(allTbl[1]) then
return true
end
end
for i,v in ipairs(allTbl) do
if checkHandle.Name == v then
return true
end
end
return false
else
local allowed = false
for i,v in ipairs(allTbl) do
if checkHandle.Name == v then
allowed = true
break
end
end
for i,v in ipairs(restrTbl) do
if checkHandle.Name == v then
allowed = false
break
end
end
return allowed
end
end
end
return true
end
function isAllowedShip(shipClass)
return checkTables(allowedShips,restrictedShips,shipClass)
end
function isAllowedWeapon(weaponClass)
return checkTables(allowedWeapons,restrictedWeapons,weaponClass)
end
function getProgressString()
local progressString = "Zooming"
if zoomingIn then
progressString = progressString .. " in:"
elseif zoomingOut then
progressString = progressString .. " out:"
elseif zoomedIn then
progressString = "Zoomed in:"
elseif zoomedOut then
progressString = "Zoomed out:"
else
progressString = "Zoomed:"
end
return progressString
end
function handleControls()
if zoomingIn or zoomedIn then
if currentProgr > 0 then
local tempSensValue = sensitivity * 100 / currentProgr
if tempSensValue <= 1 then
local ci = ba.getControlInfo()
ci.Pitch = ci.Pitch * tempSensValue
ci.Heading = ci.Heading * tempSensValue
ci.Bank = ci.Bank * tempSensValue
end
end
end
end
function isAllowedToZoom()
local allowedShip = isAllowedShip(hv.Player.Class)
local allowedWeapon = true
local primWeaponBank = hv.Player.PrimaryBanks
if not linkedZoom and primWeaponBank.Linked then
allowedWeapon = false
else
for i=0, #primWeaponBank do
local v = primWeaponBank[i]
if v.Armed then
if isAllowedWeapon(tb.WeaponClasses[v.WeaponClass.Name]) then
allowedWeapon = true
break
else
allowedWeapon = false
end
end
end
if allowedWeapon then
local secWeaponBank = hv.Player.SecondaryBanks
for i=0, #secWeaponBank do
local v = secWeaponBank[i]
if v.Armed then
if isAllowedWeapon(tb.WeaponClasses[v.WeaponClass.Name]) then
allowedWeapon = true
break
else
allowedWeapon = false
end
end
end
end
end
return allowedShip and allowedWeapon
end
function zoomIn()
if not zooming then
if hv.Player:isValid() then
if cam:isValid() then
if isAllowedToZoom() then
if currentProgr > 0 and currentProgr < 100 then
stepWidth = width / currentProgr -- Setting the stepWidth in case the zoom may not have been completed
end
zoomEndProgress = 100
zooming = true
zoomingIn = true
zoomedIn = false
zoomedOut = false
zoomingOut = false
if not defaultZoomSet then
normalFOV = cam.FOV
defaultZoomSet = true
end
zoom = normalFOV * zoomValue
ba.setControlMode(LUA_FULL_CONTROLS)
cam:setFOV(zoom,transitionTime,transitionTime / 2,transitionTime / 4)
end
end
end
end
end
function zoomOut()
if zooming and not zoomOutOverride then
if hv.Player:isValid() then
if cam:isValid() then
stepWidth = width / 100
zoomingIn = false
zoomingOut = true
zoomedIn = false
zoomedOut = false
if currentProgr > 0 then
zoomEndProgress = currentProgr -- Save the progress we made as we begin to zoom back
end
cam:setFOV(normalFOV,transitionTime,transitionTime / 2,transitionTime / 4)
ba.setControlMode(NORMAL_CONTROLS)
end
end
end
end
function drawProgress()
progressString = getProgressString()
local stringWidth = gr.getStringWidth(progressString);
gr.drawString(progressString,30,70)
local realOffset_x = offset_x + stringWidth + 10
gr.drawRectangle(realOffset_x, offset_y,realOffset_x + width, offset_y + heigth, zoomedIn)
local frameTime = ba.getFrametime()
local progressLineOffset_x = realOffset_x + stepWidth * currentProgr
gr.drawLine(progressLineOffset_x, offset_y, progressLineOffset_x, offset_y + heigth)
if not isAllowedToZoom() and not zoomOutOverride then
if zoomingIn or zoomedIn then
zoomOut()
zoomOutOverride = true
end
end
local thisFrameProg = (frameTime / transitionTime) * zoomEndProgress
if zoomingIn then
currentProgr = currentProgr + thisFrameProg
if currentProgr >= 100 then
currentProgr = 100
zoomingIn = false
zoomedIn = true
end
elseif zoomingOut then
currentProgr = currentProgr - thisFrameProg
if currentProgr <= 0 then
currentProgr = 0
zoomOutOverride = false
zoomedOut = true
zoomingOut = false
zooming = false
end
end
end
local function init()
if useConfig then
readConfig() -- read the config file if exists
end
end
local function initVars()
-- Some things to tell the script to do something and some default values
runZoomScript = true
useConfig = true
zoomValue = 0.1
normalFOV = 0.75
transitionTime = 2
zooming = false
defaultZoomSet = false
cameraSet = false
configFile = "data/config/zoom_config.cfg"
zoomOutOverride = false
linkedZoom = true
-- Setting the values to be used in the $On Frame: hook
currentProgr = 0
zoomEndProgress = 100
zoomingIn = false
zoomedIn = false
zoomingOut = false
zoomedOut = true
-- Constants for drawing the progress
offset_x = 30
offset_y = 70
heigth = 8
width = 80
stepWidth = width / 100
-- Settings for the sensitivity
sensitivity = 0.25
-- The camera which is used for zooming (is initialized in the first $Key Pressed: hook)
cam = nil
-- Tables that hold the allowe/restricted informations
-- Ships
allowedShips = {"**all**"}
restrictedShips = {}
-- Weapons
allowedWeapons = {"**all**"}
restrictedWeapons = {}
end
-- Initialize the global variables
initVars()
-- Initialize the rest
init()
]
$Application: FS2_Open
$On Mission Start:
[
if not runZoomScript then
runZoomScript = true
end
]
$On Mission End:
[
if runZoomScript then
runZoomScript = false
if defaultZoomSet and cam:isValid() then
cam:setFOV(normalFOV) -- Resetting the FOV in case we have not zoomed out completely
end
end
]
$On Frame:
[
if runZoomScript then
if zooming then
handleControls()
drawProgress()
end
end
]
$State: GS_STATE_GAME_PLAY
$KeyPress: d
$On Key Pressed:
[
if runZoomScript then
if not cameraSet then
if #gr.Cameras > 0 then
cam = gr.Cameras[1]
end
end
zoomIn()
end
]
$On Key Released:
[
if runZoomScript then
zoomOut()
end
]
#End
The needed config file has to be placed in the data/config directory (create if not existing) and it has to be named zoom_config.cfg (this can be edited in the script)
-- Setting standart values
Zoom Factor: 0.1
Transition Time: 2
Sensitivity: 0.25
Linked Zoom: YES
-- Setting ship class options
Allowed Ship Class: **all**
-- Setting weapon class options
Allowed Weapon Class: **all**
Explanation of entries:
"--" Are comments
Zoom Factor: The zoom factor, given in fraction of normal FOV (0.1 will result in 10% FOV of normal)
Transition Time: How long should zooming in take
Sensitivity: The sensitivity will be reduced to this value where the normal flight mode is a sensitivity of 1
Linked Zoom: Should zooming be allowed even when the weapon banks are linked
Allowed Ship Class: This shipclass will be allowed to zoom (more than 1 statement is possible)
Restricted Ship Class: This shipclass will not be able to zoom (again more than 1 can be given)
Allowed Weapon Class: When this weapon is used zooming will be possible (more than 1 possible)
Restricted Weapon Class:Zooming will not be possible if this weaponclass is selected (more than 1 possible)
Giving "**all**" in the Class restriction section will result in allowing/restricting all classes to zoom
When a class is in allowed and in restricted it will be allowed to zoom
If there are no further bugs I'll update the wiki shortly.
-
Awesome stuff.
Just tested it out. Didn't find anything wrong, though I'm no scripter.
Hold D zooms in, let go, zoom out. :cool:
-
Is anyone else thinking of BP's Uriel and its Archer when they read this? *cue evil cackling*.
Hats off to you m!m, and everyone else whose contributed :yes:. I've always preferred precision over spamming shots (yeah i'm a sniper geek on FPSs :rolleyes:) so a feature like this is music to my ears. Some players might like it for observation missions or precision bombing runs too.
Would it be possible to add an option to drop the sensitivity of the player's controls as he zooms further in, so the ship turns less when you press the controls? I use the keyboard to play and i've found it quite hard to target guns at range, at sniper ranges with guns like the Archer or maxim it'd likely be impossible.
Hold D zooms in, let go, zoom out. :cool:
Sounds like a good system; quick and easy. Perhaps there could also be an 'alt-d' command that toggles a constant zoom mode, with maybe the directional buttons on the keyboard\mouse wheel/secondary joystick knob\etc) to zoom in and out. Then players could choose between the 'just d' quick zoom in/out system or a more focused 'sniper mode' depending on the situation.
*Still cackling thinking about the Archer :lol:*
-
I prefer Steve-O's original archer with this.
More range + kills fighters faster :P (and it bumps them severely off course if it doesn't kill them for extra lulz)
-
Some progress on this one. :nod:
I added more config options including the possibility to specify the key which will zoom in and I also added a zoom lock feature (as proposed by T-Man) that will lock the zoom.
But the bigger feature is the FRED interface for forcing zoom-in or -out and adding allowed/restricted classes on the (mission) fly.
They are used as following:
when
true
eval-script
function-name
where function-name is one of:
zoom_zoomIn():
Causes a zoom in. Locks all player zoom controls.
This is never automatically zoomed back so the FREDer has to take care of this!
zoom_zoomOut():
Causes a zoom out. Also gives back zoom controlls to the player.
zoom_alS(ship):
Allows the ship class specified with ship. For it to work specify the ship class escaped with ' because " crashes FRED.
Due to the SEXP string length restriction of FSO it may not be possible to use this with all ship classes.
zoom_alW(weapon):
Allows the specified Weapon class. Essentially the same as zoom_alS().
zoom_reS(ship):
Restricts the specified Ship class. Essentially the same as zoom_alS().
zoom_reW(weapon):
Restricts the specified Weapon class. Essentially the same as zoom_alS().
New version is in wiki: http://www.hard-light.net/wiki/index.php/Script_-_Zoom (http://www.hard-light.net/wiki/index.php/Script_-_Zoom)
Please report any bugs or unwanted side effect here.
-
Thank you a lot for adding these features! I hope to test them very soon and post feedback.
Potential addition: the possibility to choose a specific zooming time in FRED (via variable?), and/or setting different zooming times for each spacecraft/weapon (via config file?). :)
-
Thanks Mobius.
Setting individual values for each spacecraft/weapon is possible but it is overly complicated and another question is what value should be used? The one of the ship or the one of the weapon?
Specifying the zoom time via FRED would be easily implemented, I'll do that when I've got time.
But now for something different:
On a idea of Mobius I experimented with a tactical display showing when zooming and the current state is this:
(http://img46.imageshack.us/img46/1517/zoomtactical.jpg)
Please provide feedback and I'm open for some new ideas :)
-
That's...a bit cluttered.
Don't think you need the IFF words there (pretty apparent due to color, no?)
-
In addition, you are doing a LOT of drawing to the HUD. That's a significant resource drain right there.
-
Don't think you need the IFF words there (pretty apparent due to color, no?)
That's right but the problem is that I can't get the IFF color via scripting and I'm currently choosing the color from the name so it's limited to distinguish "Friendly", "Hostile" and all that's left over so it's only drawing in 3 colors. :(
My question is: Is there a way to get the IFF color of a team so the brackets can be drawn with the right colors?
Edit: I solved this... :)
In addition, you are doing a LOT of drawing to the HUD. That's a significant resource drain right there.
I agree with you and it is overkill in it's current state but I'm experimenting with things so I just showed all available objects (also debris). Drawing only ships is the best thing and like that the "cluttering" of the HUD will be reduced.
Thank you for the feedback and I hope I can show something new shortly...
-
I see the resource drain is considerable there, so it should definitely become optional so that FREDders will decide when to use it. :)
-
Just a small update that fixes bugs and adds new configuration values:
Progress Offset X: This specifies where the progress bar will be displayed on the x-axis (this means the top-left corner)
Progress Offset Y: Same as above but for Y-axis
Progress Height: Specifies the height of the bar
Progress Width: And the corresponding width...
New version is in the wiki. Get it (http://www.hard-light.net/wiki/index.php/Script_-_Zoom) while it's hot!
-
You're awesome! :yes:
-
Errr...I don't seem to be able to disable the script for ships I don't want using it.
what exactly is the correct syntax if I say, only want 2 ships to have zoom (and only when their weapon bank with the sniper-weapon is selected)?
-
Specify the two ships ass "Allowed Ship Class" (each ship gets it's own entry) and specify the "Restricted Ship Class" as "**all**". Then add the sniper weapon as "Allowed Weapon Class" and again use "**all**" as "Restricted Weapon Cass".
Due to a bug, I'm still trying to solve, the ship class restriction feature isn't working :(.
I'm trying hard to solve this and there should be some progress this week...
-
i usually cheat with this sort of thing and use a weapon name affix like "railgun#sniper" to tell the script to use the zoom mode while such a weapon is in use. you could also use a weapon named "railgun" with other ships, which would essentially be a copy of "railgun#sniper". that way script usage is dependent of loadout compatibility rules, instead of a config file. of course thats just the way i do things (i also kinda betted we would get weapon templates at some point, which i dont think we have yet).
-
But that would again need the FREDer to take care of what ship the player is using and then set the weapon.
I'll implement that system if there is someone who would use it :nod:.
-
Hm, that would do, actually. It'd do nicely.
-
So I got this script working (with the help of The E), its pretty neat!
Error in the wiki
#Conditional Hooks
$Application: FS2_Open
$On Game Init:[[zoom_init.lua]]
$On Key Pressed: [[zoom_KeyDn.lua]]
$On Key Released: [[zoom_KeyUp.lua]]
$Application: FS2_Open
$On Mission Start:
[
if not runZoomScript then
runZoomScript = true
end
The second $Application: FS2_Open apparantly needs to be deleted.
And there's this
(http://img684.imageshack.us/img684/2923/bugym.jpg)
if you quit the mission while you are zoomed in and then load an other mission the hud gauge will appear in the command and normal briefing.
-
Should be fixed in the wiki. Now the progress is only drawn when in State GS_STATE_GAME_PLAY.
-
Thanks!
-
Nice :)
So where's the updated version? :p
-
currenly is there somewhere a video that shows the zoom script?
please could you post it?
EDIT: i've implemented the code in my laptop....simply amazing guys!!!! GREAT JOB PILOTS!!!!!! :yes:
-
Nice :)
So where's the updated version? :p
FreeSpace Wiki FTW (http://www.hard-light.net/wiki/index.php/Script_-_Zoom)!! :p
currenly is there somewhere a video that shows the zoom script?
please could you post it?
EDIT: i've implemented the code in my laptop....simply amazing guys!!!! GREAT JOB PILOTS!!!!!! :yes:
Thank you! :)
-
ioy're welcome! :) the script is simply perfect....just one thing... i found (for my tastes) the zoom out a little bit slow...i think it must be more faster for better performance in gaming... however just my opinion... what do you think about this? thanks
-
yeah...you're right... :) mine was just a stupid question
-
You can specify the the zoom time using the configuration file. Just alter Transition Time: 2 to a time that is better for you.
-
thank you man!
EDIT: Higher number means faster?
-
That's the time in seconds it takes to do a full zoom-in/-out. So small numbers mean faster zoom.
-
do it....thanks again man... ;)
EDIT: after testing the real use in-game of the zoom...i think is more useful set zoom factor at 0.25 and Transition Time: 1... the zoom is faster and you can use it in short distance too... :)
-
zoom_config.cfg [19] : Unknown keyword: 'allowed weapon class'
getting this on debug
Also, whats the correct syntax to use when adding ships&weapons to the list of allowed class?
-
I can't reproduce that but the warning indicates that something is corrupt in your script. Could you try to paste the script from the wiki into the file and try again?
I also updated the wiki page (http://www.hard-light.net/wiki/index.php/Script_-_Zoom) with a new version that is now able to enable zooming based on the weapon end (just set the "Weapon End" option to the post-fix you want).
-
I'm reviving this topic because it is of great interest to me, and to discuss the creation of a general purpose adjustable FOV script, rather than a specialized weapon-dependant scope script.
The way things currently are, you can set up your field of view with a command line flag, but this is a static setting. This works well enough for situations where the cockpit is not drawn, but it seems that more and more community-built models are getting high quality interiors for the cockpits and head tracking equipment is increasing in numbers as well, it would be a shame not to make these features more approachable. Not to mention the full detail of high quality skyboxes...
The thing is, head tracking with cockpits increases the immersion factor about hundredfold. The problem is, without adjustable field of view, this is not as useful as it should be. For gaining true sense of being in the cockpit, field of view should usually be set to wider setting than is useful for using the weapons systems and observing targets outside the cockpit.
An excellent example of how to do this right is in IL-2 Sturmovik, which as three presets for the field of view (I think they're set to 30, 60 and 90 degrees), and the field of view can also be adjusted in notches between the presets.
This would take three buttons - let's say U, I and O.
U - wide FOV
I - middle FOV
O - narrow FOV
Shift+U - increase FOV
Shift+O - decrease FOV
(Of these buttons, only U is used by default - for Target Uninspected Cargo, which is most of the time fairly useless function).
Presets could well be 90,60 and 30 degrees, but it would be beneficial if it was possible to adjust the FOV in full range of let's say 120-20 degrees. Notched adjustment could be set to 5 or 10 degrees per notch.
This kind of setup in FS2_Open I think would be most sensible and beneficial for improving the gameplay with the new features of cockpits with head tracking.
Now, a specialized targeting scope for specific weapons could be useful as well, but I would seriously want to see a freely adjustable field of view script, independent of all bindings to ship and weapon classes.
What I'm asking is: How much work would be involved with modifying the current zoom script for this purpose?
-
Modifying the current script for this purpose would be more complicated than just writing a new script as the functionality you propose can be easily done using the existing scripting-API. I'll take a look at it tomorrow.
-
I haven't followed this for a while - may I know what its status is? Is there anything I should know except what I can find on this thread?
-
No sadly no new developments.
-
I can't reproduce that but the warning indicates that something is corrupt in your script. Could you try to paste the script from the wiki into the file and try again?
I also updated the wiki page (http://www.hard-light.net/wiki/index.php/Script_-_Zoom) with a new version that is now able to enable zooming based on the weapon end (just set the "Weapon End" option to the post-fix you want).
Could you explain the setup with the weapon end ? I don't understand where or what to do with this ? I don't find any sample on the wiki.
-
I can't reproduce that but the warning indicates that something is corrupt in your script. Could you try to paste the script from the wiki into the file and try again?
I also updated the wiki page (http://www.hard-light.net/wiki/index.php/Script_-_Zoom) with a new version that is now able to enable zooming based on the weapon end (just set the "Weapon End" option to the post-fix you want).
Could you explain the setup with the weapon end ? I don't understand where or what to do with this ? I don't find any sample on the wiki.
It works using by specifying a value let's say "zoom". After this the script will allow every weapon where the name ends with "#zoom" to use the zoom feature. That means that if you have the weapon "Subach HL-7" it will not be able to zoom but if you create a new weapon named "Subach HL-7#zoom" it will be able to zoom. This allows a quick setup if you do not want to got through all the more complicated configuration setup.
-
Sorry for the necro, but I have problem with the script. I want to use it in Shadow Genesis, but I have an error.
LUA ERROR: [string "zoom_KeyDn.lua"]:2: attempt to index global 'zoomLockKey' (a nil value)
------------------------------------------------------------------
ADE Debug:
------------------------------------------------------------------
Name: (null)
Name of: (null)
Function type: (null)
Defined on: 0
Upvalues: 0
Source: (null)
Short source:
Current line: 0
- Function line: 0
------------------------------------------------------------------
------------------------------------------------------------------
LUA Stack:
------------------------------------------------------------------
------------------------------------------------------------------
I've added version of the weapons with '#zoom" in the name. This error occuring during the putting any key. I'm not scripter and even experianced sctipt user. I have only basic knowledge of using it.
-
That is very weird... That piece of code should not be reached, are you sure that you have the latest version?
Try pasting the following code into your zoom_KeyDn.lua inside the scripts directory:
if runZoomScript and not fredOverride then
if zoomLockKey and hv.Key:lower() == zoomLockKey:lower() then
if lockedZoom then
zoomOut()
lockedZoom = false
return
else
zoomIn()
lockedZoom = true
return
end
end
if hv.Key:lower() == zoomKey:lower() then
zoomIn()
end
end
I hope that helps...
-
Now it's working, thanks. I copied the version from Wiki last time, I think it's buggy.
Great script :yes:.
-
I updated the wiki with my local version, sorry for the inconvenience :nervous:
-
I was thinking, would it be possible to tell this script(or a similar one) to tilt and zoom the camera(especially good with cockpit model) just a bit in the direction of big events? such as a capship going down? this can look pretty cool if done right... it should trigger only if the event if happening more or less in the field of view
-
That kind of effect would be very difficult to "feel" right. Most times it will simply interrupt the game, for example when you're just following an enemy on the upper-left side of your screen but a capship goes down at the lower-right and the camera focuses on this then the enemy will be gone when everything is back to normal.
Of course it would be possible to have a script that would enable the FREDer to manipulate the camera so it turns to an event he would like to focus.
-
well thats the idea, have it work only for major events, like completing an objective or failing it, this is much more important than losing an enemy fighter, as it means you already won/lost the battle...
I'm also sure a real pilot would also turn his head towards a friendly/hostile destroyer going down...
-
And I don't think so. Following an enemy is a matter of life and death, exploding capship is less so. A real pilot would pay attention to dogfight and focus on it.
-
This script apparently doesn't work correctly with the latest FSO builds, since the player's ship's turn rate isn't affected when you zoom in.
Nevermind, I was able to solve the problem. I think it had something to do with the mouse script, which I was also using at the same time.
However, if the config file has the Weapon End field, you won't be able to zoom in with any weapons other than those that have #zoom at the end. Is this behaviour intentional?
-
The functions which the script use to alter the turn rate didn't get modified and worked when I last tried it. Maybe you have a wrong value for your "Sensitivity" setting. Can you post your configuration file?
-
Posting here again because I'm having another problem with the script. The script only works once I start up a mission for the first time after I start up FSO, but if I quit the mission I'm playing and start up another mission, the script will not work.
I suspect there's a bug that's causing the On Mission Start and On Mission End hooks to run only once per game.
EDIT: Reported in Mantis (http://scp.indiegames.us/mantis/view.php?id=2662)
-
I fixed the bug, a changed version is available in the FS wiki.
The bug was indeed caused by the On Mission Start-hook but instead of only running once it didn't get run completely. That was caused by the absence of a hook option for it so I added a meaningless $Application: FS2_Open to it and that fixed the issue.