Page 1 of 2
RPG/Worms style DPS display widget v1.1
Posted: 07 Aug 2007, 01:39
by TheFatController
Update: Version 1.1 - 07/08/07
New widget displays damage per second to your allies units or all units if you're speccing or watching a replay.
Paralyze damage is displayed in blue.
To install it extract the zip into
..spring/luaUI/ and you're good to go!
Changelog
Version 1.1
Small tweaks to text size etc.
Numbers now freeze when game paused.
No longer accumalates lots of numbers when you're alt tabbed into another window.
Optimized code a little.
Fixed a crash bug and a few other bugs.
Credit to trepan for getting the fading outlined text working :)
Posted: 07 Aug 2007, 01:51
by Neddie
If this keeps up, all the cool ideas will be widgets!
Posted: 07 Aug 2007, 02:22
by j5mello
OH crap u do know what this means right???
we are one step closer to being WoW... OH NOEZ TEH HORROR!!!!
Posted: 07 Aug 2007, 02:23
by Nemo
Would it be possible to change it so that all units display it (for balance testing)?
Posted: 07 Aug 2007, 02:30
by Ishach
this is a cool idea
Posted: 07 Aug 2007, 02:34
by Neddie
Ishach wrote:this is a cool idea
Isaac, can you play these days, or is your machine too feeble?
Posted: 07 Aug 2007, 03:35
by DavetheBrave
this is awesome....should really help to see the effects of flanking too.
Posted: 07 Aug 2007, 03:48
by Warlord Zsinj
Hmm, if you could colour code this, or replace it with text, this could be very useful for you, Nemo, to do CoH style effects to show when a unit has been hit by an armour piercing round, etc.
It'd also be really nice if your guys were supressed, and this lua widget made the words "suppressed" rise above your units, and then if they continue to be fired upon, the words "pinned" appear above their heads (but maybe do not go away?)
Posted: 07 Aug 2007, 08:53
by TheFatController
Nemo wrote:Would it be possible to change it so that all units display it (for balance testing)?
Unfortunatley you cant access enemies damage while playing (otherwise it would be easy to write a widget that showed enemies health bars). You have to use replays or lots of .cheat team switching in sandbox mode for useful stuff like that.
Posted: 07 Aug 2007, 14:33
by Maelstrom
TheFatController wrote:Nemo wrote:Would it be possible to change it so that all units display it (for balance testing)?
Unfortunatley you cant access enemies damage while playing (otherwise it would be easy to write a widget that showed enemies health bars). You have to use replays or lots of .cheat team switching in sandbox mode for useful stuff like that.
Or turn it into a LuaRule, that would work, but would require editing the mod instead of just adding in a LuaUI widget.
Posted: 07 Aug 2007, 17:25
by 1v0ry_k1ng
this is cool, but would it be possible to show the damage done by each projectile instead? if only it was possible to show enemy damage too
would it be possible to make the font half the size? atm it looks a bit clumsy
Posted: 07 Aug 2007, 18:52
by TheFatController
1v0ry_k1ng wrote:this is cool, but would it be possible to show the damage done by each projectile instead?
I tried that but if a flamethrower hits a group of units and it shows every hit there's horrible death 0fps lag.
1v0ry_k1ng wrote:would it be possible to make the font half the size? atm it looks a bit clumsy
I like it! :p I'll add some constants for customization tho in version 1.x
Posted: 07 Aug 2007, 18:57
by 1v0ry_k1ng
you could change it from dps to damage every 0.1 sec then it woud be just like damage per projectile except really rapid fire units would be capped at 10 readings a second etc, or do it at 0.2..
Posted: 19 Aug 2007, 16:43
by zwzsg
It gives me:
gl.DrawFuncAtUnit: error(2) = [string "LuaUI/headers/billboard.lua"]:19: gl.MultMatrix requires all 16 values
[string "LuaUI/headers/billboard.lua"]:19: gl.MultMatrix requires all 16 values
Removed widget: Display DPS
Why? Can you fix?
Posted: 19 Aug 2007, 17:10
by jK
zwzsg wrote:It gives me:
gl.DrawFuncAtUnit: error(2) = [string "LuaUI/headers/billboard.lua"]:19: gl.MultMatrix requires all 16 values
[string "LuaUI/headers/billboard.lua"]:19: gl.MultMatrix requires all 16 values
Removed widget: Display DPS
Why? Can you fix?
it was a mistake in my
healthbars widget in a previous version, please update it

Posted: 19 Aug 2007, 17:21
by zwzsg
Yes, indeed, installing your health bar widget fixes this one. Thanks.
Posted: 20 Aug 2007, 02:57
by zwzsg
However, I found that then when I use this widget in Kernel Panic, it shows lots of 0 when building. This is most probably due to the beam laser that are used to replace nano, and are actually real weapon with very low power.
From a general standpoint, I am torn about whether 0 damage should be shown or not.
But for KP I have to disable it or have "0" comes out of everything under construction. So far I disable the showing of 0 damage like that:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- . file: . . gui_display_dps.lua
-- . brief: . Displays DPS done to your allies units
-- . author: . Owen Martindell
--
-- . Copyright (C) 2007.
-- . Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:GetInfo()
. return {
. . name . . . = "Display DPS",
. . desc . . . = "Displays damage per second done to your allies units v1.1",
. . author . . = "TheFatController",
. . date . . . = "August 05, 2007",
. . license . = "GNU GPL, v2 or later",
. . layer . . = 0,
. . enabled . = true . -- . loaded by default
. }
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Speed Up
local GetUnitDefID . . . . = Spring.GetUnitDefID
local GetUnitDefDimensions = Spring.GetUnitDefDimensions
local AreTeamsAllied . . . = Spring.AreTeamsAllied
local GetMyTeamID . . . . . = Spring.GetMyTeamID
local GetGameSpeed . . . . = Spring.GetGameSpeed
local glTranslate . . . = gl.Translate
local glColor . . . . . = gl.Color
local glBillboard . . . = gl.Billboard
local glText . . . . . = gl.Text
local glDepthMask . . . = gl.DepthMask
local glDepthTest . . . = gl.DepthTest
local glAlphaTest . . . = gl.AlphaTest
local glBlending . . . = gl.Blending
local glDrawFuncAtUnit = gl.DrawFuncAtUnit
local GL_GREATER . . . . . . = GL.GREATER
local GL_SRC_ALPHA . . . . . = GL.SRC_ALPHA
local GL_ONE . . . . . . . . = GL.ONE
local GL_ONE_MINUS_SRC_ALPHA = GL.ONE_MINUS_SRC_ALPHA
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local damageTable = {}
local unitParalyze = {}
local unitDamage = {}
local countDown = 0
local paused = false
local update = false
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:Initialize()
. for udid, ud in ipairs(UnitDefs) do
. . ud.show_dps_height = (GetUnitDefDimensions(udid).height * 0.9)
. end
end
local function getTextSize(damage, paralyze)
. local sizeMod = 3
. if paralyze then sizeMod = 2.25 end
. return math.floor(8 * (1 + sizeMod * (1 - (200 / (200 + damage)))))
end
local function calcDPS(inTable, paralyze)
. for unitID,damage in pairs(inTable) do
. . local unitDefID . = GetUnitDefID(unitID)
. . local unitDef . . = UnitDefs[unitDefID]
. . if (unitDef ~= nil) then
. . . local textSize = getTextSize(damage, paralyze)
. . . if (damage >= 1) then
. . . . table.insert(damageTable, {
. . . . . unitID,
. . . . . math.floor(damage),
. . . . . unitDef.show_dps_height,
. . . . . (6 - math.random(0,12)),
. . . . . textSize,
. . . . . 0,
. . . . . 1,
. . . . . paralyze
. . . . })
. . . . inTable[unitID] = 0
. . . else
. . . . inTable[unitID] = nil
. . . end
. . end
. end
end
function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
. unitDamage[unitID] = nil
. unitParalyze[unitID] = nil
. for i, damage in pairs(damageTable) do
. . if (damage[1] == unitID) then
. . . table.remove(damageTable, i)
. . end
. end
end
function widget:UnitTaken(unitID, unitDefID, oldTeam, newTeam)
. if (AreTeamsAllied(oldTeam, newTeam)) then
. . return
. else
. . widget:UnitDestroyed(unitID, unitDefID, newTeam)
. end
end
function widget:Update(DeltaTime)
if paused then return end
if (countDown > 1) then
. countDown = 0
. update = true
else
. countDown = countDown + DeltaTime
end
end
local function addDamage(inTable, damage, unitID, ud, paralyze)
. for uID,_ in pairs(inTable) do
. . if (uID == unitID) then
. . . inTable[uID] = inTable[uID] + damage
. . . return
. . end
. end
.
. if not update then
.
. . inTable[unitID] = 0
.
. . local textSize = getTextSize(damage, paralyze)
.
. . table.insert(damageTable, {
. . . unitID,
. . . math.floor(damage),
. . . ud.show_dps_height,
. . . (6 - math.random(0,12)),
. . . textSize,
. . . 0,
. . . 1,
. . . paralyze
. . })
.
. . table.sort(damageTable, function(m1,m2) return m1[2] < m2[2]; end)
. .
. end
end
function widget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer)
. local ud = UnitDefs[unitDefID]
. if (ud == nil) then
. . return
. end
.
. if paralyzer then
. . addDamage(unitParalyze, damage, unitID, ud, true) .
. else
. . addDamage(unitDamage, damage, unitID, ud, false) .
. end
end
local function DrawUnitFunc(yshift, xshift, damage, textSize, alpha, paralyze)
. if(damage>=1) then
. . glTranslate(xshift, yshift, 0)
. . glBillboard()
. . gl.MultiTexCoord(1, 0.25 + (0.5 * alpha))
. . if paralyze then
. . . glColor(0, 0, 1)
. . . glText(damage, 0, 0, textSize, 'cnO')
. . else
. . . glColor(1, 1, 1)
. . . glText(damage, 0, 0, textSize, 'cno')
. . end
. end
end
function widget:DrawWorld()
. if update then
. . if next(unitDamage) then calcDPS(unitDamage, false) end
. . if next(unitParalyze) then calcDPS(unitParalyze, true) end
. . table.sort(damageTable, function(m1,m2) return m1[2] < m2[2]; end)
. . update = false
. end
.
. if (next(damageTable) == nil) then
. . return
. end
.
. _,_,paused = GetGameSpeed()
. .
. glDepthMask(true)
. glDepthTest(true)
. glAlphaTest(GL_GREATER, 0)
. glBlending(GL_SRC_ALPHA, GL_ONE)
. gl.Texture(1, LUAUI_DIRNAME .. "Images/gradient_alpha_2.png")
. for i, damage in pairs(damageTable) do
. . if (damage[7] <= 0) then
. . . table.remove(damageTable,i)
. . else
. . . glDrawFuncAtUnit(damage[1], false, DrawUnitFunc,
. . . . . . . . . . . . (damage[3] + damage[6]),
. . . . . . . . . . . . damage[4], damage[2], damage[5],
. . . . . . . . . . . . damage[7], damage[8])
. . . if not paused then
. . . . if damage[8] then
. . . . . damage[7] = damage[7] - 0.05
. . . . . damage[5] = damage[5] + 0.2
. . . . else
. . . . . local fadeTime = math.max(0.03 - (damage[2] / 333333), 0.015)
. . . . . local riseTime = 1 + math.min((damage[2] / 2500), 2)
. . . . . damage[6] = damage[6] + riseTime
. . . . . if (damage[6] > 25) then
. . . . . . damage[7] = damage[7] - fadeTime
. . . . . end
. . . . end
. . . end
. . end
. end
. gl.Texture(1, false)
. glBlending(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
. glAlphaTest(false)
. glDepthTest(false)
. glDepthMask(false)
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
But I don't understand most of that code, so I hope it wasn't a too awful method of removing the zeroes.
Posted: 20 Aug 2007, 08:57
by imbaczek
A better (faster) solution would be to condition calls to Draw... function, but your isn't wrong.
Posted: 20 Aug 2007, 21:42
by zwzsg
Yes, but the only other line that mention the function DrawUnitFunc is:
glDrawFuncAtUnit(damage[1], false, DrawUnitFunc,(damage[3] + damage[6]), damage[4], damage[2], damage[5], damage[7], damage[8])
And I just do not understand that kind of syntax. I mean, the function name, without filling its argument, is passed a an argument to another function, while I would be expecting something more like DrawUnitFunc(arg1,arg2,arg3,arg4,arg5,arg6).
Posted: 20 Aug 2007, 22:08
by Kloot
glDrawFuncAtUnit() is a function which takes as its
third argument a pointer to a custom Lua function
(called "DrawUnitFunc" in this script) that performs
some user-defined drawing task at a unit's location,
like showing rank icons or DPS values. The other
arguments (4 through n, there's no limit to how
many can be provided) are passed to the custom
function, DrawUnitFunc() takes 6 here. When it
(glDrawFuncAtUnit()) is called, it in turn calls
DrawUnitFunc() with those 6 values, so you can
control what the drawing task does.