how to get unit ID of units attacking you (in a widget)

how to get unit ID of units attacking you (in a widget)

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

Moderator: Moderators

Post Reply
obliter8or
Posts: 3
Joined: 28 Jul 2009, 13:25

how to get unit ID of units attacking you (in a widget)

Post by obliter8or »

Hi all

Im interested in trying to make a widget that assists with some of the micro managment in Spring mods. at the moment Im just exploring what widgets are capable of with the call-ins and call-outs.

from what I can see there is no way of detecting who is attaching your units. the call-in I was hoping to use was:

widget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer)

but for all my efforts so fay I cannot get the unit ID that delt the damage.

dose any one know how I could do this?
User avatar
manolo_
Posts: 1370
Joined: 01 Jul 2008, 00:08

Re: how to get unit ID of units attacking you (in a widget)

Post by manolo_ »

hey,

what will your widget do?
obliter8or
Posts: 3
Joined: 28 Jul 2009, 13:25

Re: how to get unit ID of units attacking you (in a widget)

Post by obliter8or »

at the moment the plan is for it suply a basic group managing:
1 - a UI for creating groups and adding and removing selected units from the current groups.
2 - keeping the group together. ie when you order the group to move it mooves as one (as best it can) and it controls the range of unit movements when the group is stationary.
3 - when enemy units come into sight units attack the ones they are most effective against.

for my honours thesis at uni I'm making a basic unit group AI for RTS games. spring is by far the best place to test my architecture.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: how to get unit ID of units attacking you (in a widget)

Post by imbaczek »

obliter8or wrote:2 - keeping the group together. ie when you order the group to move it mooves as one (as best it can) and it controls the range of unit movements when the group is stationary.
try ctrl/alt+move.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: how to get unit ID of units attacking you (in a widget)

Post by hoijui »

i guess the reason you do not get the ID of the unit that dealt the damage is, that this is kind of... nothing you would know usually.
* your units do not have sensors that track all the projectiles all the time
* in heavy fire fights, humans would not know eihter where a shot came form that hit them, sometimes
* you can be shot at from outside LOS/Radar coverage

i don't know how hard it would be to change the event to include this info. before even considering this, we should think about if it is.. legal to know that.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: how to get unit ID of units attacking you (in a widget)

Post by Argh »

In the next release of Spring, I believe that Kloot's callouts for Projectiles + the stuff I explored on this topic about a month ago should allow for this. IOW, this is probably possible to do right now, but only with a developmental release from Buildbot.
User avatar
TheFatController
Balanced Annihilation Developer
Posts: 1177
Joined: 10 Dec 2006, 18:46

Re: how to get unit ID of units attacking you (in a widget)

Post by TheFatController »

Units can get the location of a unit outside of LOS / radar using the Guard command (guard sets them to attack the unit that did the damage to the thing that's been attacked even if its out of sight) not sure if this also attaches the unitId to their attack command or not tho.

I was trying to think of a way to abuse this but nothing really reliable aside from a LRPC finder widget of some type.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: how to get unit ID of units attacking you (in a widget)

Post by Niobium »

Spring.GetUnitLastAttacker(unitID) -> attackerID

Call this on :UnitDamaged, and there you go, the missing piece.

Note that it will only return the attackers ID if it can see the attacker (Los or radar), so you should nil check it.
obliter8or
Posts: 3
Joined: 28 Jul 2009, 13:25

Re: how to get unit ID of units attacking you (in a widget)

Post by obliter8or »

thats fine I dont want the widget to 'cheat'. just collect some stats on which units are effective against others.
User avatar
manolo_
Posts: 1370
Joined: 01 Jul 2008, 00:08

Re: how to get unit ID of units attacking you (in a widget)

Post by manolo_ »

mmmh, dunno if this will work.
e.g. u have a group of A, B and C, now u attack with D (A is good vs D), A will move forward (i assume all other back), now u attack with E (E is superb vs A, but bad vs B), now A will move back and B forward,...
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: how to get unit ID of units attacking you (in a widget)

Post by zwzsg »

(synced) function gadget:UnitDamaged(UnitID,UnitDefID,Team,Damage,Para,WeaponID,AttackerID,AttackerDefID,AttackerTeam)


function widget:UnitDamaged(UnitID,UnitDefID,Team,Damage,Para,WeaponID)


Same callin name, but as a gadget, it is passed the attacker, as a widget it isn't, even if the attacker is in los.

Personnaly, I fell back on assuming the attacker is the nearest enemy and using :
local AttackerID=Spring.GetUnitNearestEnemy(UnitID,400) -- where 400 is the radius to look for enemies
if AttackerID then ...

But Niobium proposition sounds better.
Post Reply

Return to “Lua Scripts”