Page 1 of 1

[Lua] OnEvent() Help

Posted: Tue Feb 23, 2010 5:34 pm
by Ace Rimmer
I'm trying to work out what to do with 'unitType', or rather how to use it properly.

Code: Select all

function OnEvent(eventType, sourceID, targetID, unitType, longitude, latitude)
   if (eventType == "Destroyed") then
      SendChat(tostring(sourceID:GetUnitType()) .. " killed a " .. unitType .. " " .. tostring(targetID:GetUnitType()))
....
end


This

Code: Select all

SendChat(tostring(sourceID:GetUnitType()) .. " killed a " .. unitType

outputs "Gunshot killed a Invalid"

while this

Code: Select all

SendChat(tostring(sourceID:GetUnitType()) .. " killed a " .. tostring(targetID:GetUnitType()))

outputs "Gunshot killed a Fighter"

What's up with unitType (not GetUnitType)? 'Invalid' isn't a normal Lua error, (e.g. 'trying to index a nil value', 'expected string got userdata') so I'm lost.

Image

Posted: Tue Feb 23, 2010 9:04 pm
by martin
The documentation says that "Invalid" is a unit type, it looks like this is a bug, for now I would stick with using targetID:GetUnitType() which seems to get the result you want.

Posted: Tue Feb 23, 2010 10:00 pm
by Ace Rimmer
Wow, I missed the "Invalid" type. :P

Sent this through:

Mailing list wrote:I'm curious to whether or not this is an intended output (and perhaps if unitType "Invalid" is only for events such as CeaseFire, Votes, ect)?

function OnEvent(eventType, sourceID, targetID, unitType, longitude, latitude)
if (eventType == "Destroyed") then

This SendChat(tostring(sourceID:GetUnitType()) .. " killed a " .. unitType) outputs "Gunshot killed a Invalid"
This SendChat(tostring(sourceID:GetUnitType()) .. " killed a " .. tostring(targetID:GetUnitType())) outputs "Gunshot killed a Fighter"

Posted: Thu Feb 25, 2010 1:16 am
by roflamingo
Let us know when you get an answer plz

Posted: Thu Feb 25, 2010 2:22 am
by Ace Rimmer
Sure. So far, no response.