DPS widget?

DPS widget?

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

DPS widget?

Post by smoth »

We still have this thing but it still only shows damage taken not damage dealt. Was there ever a version made that showed damage dealt?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: DPS widget?

Post by Argh »

Gadget-only, if you want to see damage to opponents. You could use a Widget to do the actual display, ofc.
User avatar
TheFatController
Balanced Annihilation Developer
Posts: 1177
Joined: 10 Dec 2006, 18:46

Re: DPS widget?

Post by TheFatController »

I was thinking of making a gadget version for Spring Skirmish at some point with a tiny dummy widget that just turns it on and off, but if someone else wants to write it that'd be cool :P
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: DPS widget?

Post by Argh »

Well, basically... all we need is to put a Spring.SendLuaUIMsg() in a UnitDamaged loop, and pass it to unsynced.

Only problem is, we need to send several variables over as one string.

Anybody have utility code for parsing a string where data is delimited by commas available?

IDK how to do that, off-hand, otherwise this is really easy and I'd be happy to write the display part. The other route is to use a Widget to merely tell LuaRules to quit displaying this data to a given Team, I suppose, but that is a lot messier and might cause problems.
User avatar
Petah
Posts: 426
Joined: 13 Jan 2008, 19:40

Re: DPS widget?

Post by Petah »

Code: Select all

-- Compatibility: Lua-5.1
function split(str, pat)
   local t = {}  -- NOTE: use {n = 0} in Lua-5.0
   local fpat = "(.-)" .. pat
   local last_end = 1
   local s, e, cap = str:find(fpat, 1)
   while s do
      if s ~= 1 or cap ~= "" then
	 table.insert(t,cap)
      end
      last_end = e+1
      s, e, cap = str:find(fpat, last_end)
   end
   if last_end <= #str then
      cap = str:sub(last_end)
      table.insert(t, cap)
   end
   return t
end

Code: Select all

split('foo/bar/baz/test','/')
--> {'foo','bar','baz','test'}
split('/foo/bar/baz/test','/')
--> {'foo','bar','baz','test'}
split('/foo/bar/baz/test/','/')
--> {'foo','bar','baz','test'}
split('/foo/bar//baz/test///','/')
--> {'foo','bar','','baz','test','',''}
split('//foo////bar/baz///test///','/+')
--> {'foo','bar','baz','test'}
split('foo','/+')
--> {'foo'}
split('','/+')
--> {}
split('foo','')  -- opps! infinite loop!
http://lua-users.org/wiki/SplitJoin
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: DPS widget?

Post by Argh »

OK, so I can send "unitID/damage", etc., and parse it out that way? Excellent.

Lemme look at the issue of security for a minute (kinda skipped that, sigh) and I'll bang something out.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: DPS widget?

Post by jK »

Why not just use:

Code: Select all

--//unsynced (this is missing the synced->unsynced wrapper!)
function gadget:UnitDamaged(...)
  if (Script.LuaUI.UnitDamaged) then
    Script.LuaUI.UnitDamaged(...)
  end
end
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: DPS widget?

Post by Argh »

IDK what that, "Script." means, for one thing. Does that mean "check to see if that LuaUI is running"?

Almost done with the Gadget-only version, it's displaying and stuff. Haven't worried about paralyzer yet.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: DPS widget?

Post by Argh »

Here's an all-Gadget version. Very simple but it works.

<snipped, this was badly-written junk anyhow>

I am still pondering how to deal with it securely on the other side of the Widget aisle. If I just send a message with the "a" parameter, that should work I guess.

But, now that I have it working all-Gadget, I'm more tempted to just write a "turn off this feature locally" Widget, frankly.
Last edited by Argh on 30 Oct 2009, 09:55, edited 1 time in total.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: DPS widget?

Post by zwzsg »

Argh wrote:IDK what that, "Script." means, for one thing.
Makes an unsynced gadget calls a function that is in a widget.

The extra "if" in jK exemple is because of course you should check that this function exists before calling it.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: DPS widget?

Post by Argh »

Ok, so:

Code: Select all

if (Script.LuaUI.fooBar) then
    Script.LuaUI.fooBar(...)
end
...calls the function fooBar in a Widget? Okie doke. Does Script.LuaRules.fooBar work, or is that one-way only?
User avatar
TheFatController
Balanced Annihilation Developer
Posts: 1177
Joined: 10 Dec 2006, 18:46

Re: DPS widget?

Post by TheFatController »

I've run a quick test and it seems quite a lot more CPU intensive than my original widget, there should be some way of just importing that code into unsynced
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: DPS widget?

Post by Argh »

Yeah, there are two big no-nos in that initial version: it's allowing multiple table entries per UnitID, which means rapid-fire weapons cause huge pain, and it was doing updates inefficiently. Sorry, orkish get-it-dun code and all that. This should be a considerable improvement:

<snipped, to shorten thread>
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: DPS widget?

Post by Argh »

OK, here's a Gadget that uses a Widget to control output. I need a brave couple of people to test it with a modified BA/CA or something, to make sure that the security part works OK.

It shows your damage in white, all other damage is in yellow. It fades and moves (and it could be made even fancier, but the main thing's to make it all work right).

Smoth, you asked for it, so I volunteer you to test data security. Things you should see:

1. If the other player attacks a third party (Gaia, say), you should see nothing. That is not a bug.

2. If you turn your display off, the other player should still see a display.

Let me know what bugs if any are found. It works in Stock World Builder, but I have no idea if the multiplayer aspect and security works right or not.
Attachments
dps_ControlWidget.lua
(443 Bytes) Downloaded 24 times
dps_Gadget.lua
(2.93 KiB) Downloaded 26 times
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: DPS widget?

Post by Argh »

Sooo... does it work for MP? Is it still inefficient? Any other goofs, wishlist things, etc., or am I done with this one?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: DPS widget?

Post by Argh »

<bumpity>

Hey Smoth... you asked for it, please test it in MP and report back...
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: DPS widget?

Post by smoth »

Busy.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: DPS widget?

Post by Argh »

NP, thanks for letting me know :-)
Post Reply

Return to “Lua Scripts”