[Lua] OnEvent() Help

Come in here to talk about your sky-net style world-destroying super bots!

Moderator: Defcon moderators

User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

[Lua] OnEvent() Help

Postby Ace Rimmer » Tue Feb 23, 2010 5:34 pm

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
martin
level5
level5
Posts: 3210
Joined: Fri Nov 19, 2004 8:37 pm

Postby martin » Tue Feb 23, 2010 9:04 pm

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.
GENERATION 22:The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Tue Feb 23, 2010 10:00 pm

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"
User avatar
roflamingo
level3
level3
Posts: 404
Joined: Fri Jan 19, 2007 10:25 am

Postby roflamingo » Thu Feb 25, 2010 1:16 am

Let us know when you get an answer plz
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Thu Feb 25, 2010 2:22 am

Sure. So far, no response.
Smoke me a kipper, I'll be back for breakfast...

Return to “AI Bots”

Who is online

Users browsing this forum: No registered users and 3 guests