View topic - Attacker Information



All times are UTC + 1 hour


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Attacker Information
PostPosted: 06 Jun 2011, 17:23 

Joined: 10 Feb 2011, 03:00
Hey everyone!

I have this portion of the code that write who is being attack in the game.

Code:
function widget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer)
   local txt = "TakingFire unitTeam ".. unitTeam.. " unit".. unitDefID.. " id"..unitID
   write(txt)
end


Anyone knows if I could find out through this widget which unit is attacking my unit?

Desire outcome will be Unit 123 from Team 0 is attacking Unit 456 from Team 1 at x y z location.
Instead of the current> TakingFire unitTeam 0 unit 123.


Top
 Offline Profile  
 
 Post subject: Re: Attacker Information
PostPosted: 06 Jun 2011, 19:46 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
you are missing half the parameters:
UnitDamaged() --> "unitID, unitDefID, unitTeam, damage, paralyzer, weaponID, attackerID, attackerDefID, attackerTeam"


Top
 Online Profile  
 
 Post subject: Re: Attacker Information
PostPosted: 06 Jun 2011, 19:59 
Kernel Panic Co-Developer
User avatar

Joined: 16 Nov 2004, 13:08
What knorke said. However.... maybe that's gadget only!

As using widgets to know who's attacking through the fog of war could theorically be considered some sort of cheating, it might have been disabled in widgets. Try and see!


Top
 Offline Profile  
 
 Post subject: Re: Attacker Information
PostPosted: 07 Jun 2011, 08:53 

Joined: 10 Feb 2011, 03:00
Thanks knorke and zwzsg!

Yup, I confirm it only works in gadget!

I got this portion of the code in a gadget:
Code:
function gadget:UnitDamaged(unitID,unitDefID,unitTeam,damage,paralyzer,weaponID,attackerID,attattackerDefID,attackerTeam)
local x,y,z=Spring.GetUnitPostion(unitID)
local txt = "Unit "..unitID.." from Team"..unitTeam.." is being attacked by Unit "..attackerID.." from Team "..attackerTeam.."at"..x..y..z

Spring.SendLuaUIMsg(txt)
end



Thanks! =)
Which sends the information to a widget to write it in a txt.
The portion that contains of the widget that receive the information:
Code:
function widget:RecLuaMsg(txt,playerID)
write(txt)
end


My questions here:
1. The information is successfully written in a txt file.
But I randomly I will have this error message:
Code:
LuaRules::RunCallIn:error=2, unitDamged, [string "LuaRules/Gadgets/logger.lua"]:16: attemot to concatenate local 'attackerTeam'(a nil value)

How should I ensure this error is prevented?


Top
 Offline Profile  
 
 Post subject: Re: Attacker Information
PostPosted: 07 Jun 2011, 19:52 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
you can nil-check the attackerTeam (it can be nil if e.g. a unit is hit by falling debris) or you could do something like

Code:
" from Team ".. (attackerTeam or "no team") .."at".


but that's a bit ugly.

i'd probably just do:

Code:
local txt = "Unit "..unitID.." from Team"..unitTeam.." is being attacked by Unit "..attackerID

if attackerTeam then
  txt .. " from Team "..attackerTeam
end
txt .."at"..x..y..z


of course it might be very sensible to nil-check other arguments too!


Top
 Offline Profile  
 
 Post subject: Re: Attacker Information
PostPosted: 08 Jun 2011, 02:53 

Joined: 10 Feb 2011, 03:00
It works like magic! Thanks lot! =)


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: knorke and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Site layout created by Roflcopter et al.