Oznerol256 Posted April 24, 2013 Posted April 24, 2013 I have a question about the event handler feature of the Simulator Scripting Engine. I have added an event handler to the world and i am able to receive events. Im even able to get their id. So my script is able to determine wheather the event was a death of a unit or not. However, im not able to work out what unit was been killed. I thought the target field or the initiator field contains the unit with the unitId, however, it doesnt. How can i get the unitId of the Unit that has been killed? [sIGPIC][/sIGPIC]
Grimes Posted April 24, 2013 Posted April 24, 2013 http://forums.eagle.ru/showthread.php?t=98616 Use Mist and search mist.DBs.deadObjects for the corresponding Id. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Oznerol256 Posted April 24, 2013 Author Posted April 24, 2013 http://forums.eagle.ru/showthread.php?t=98616 Use Mist and search mist.DBs.deadObjects for the corresponding Id. Really? The event handling stuff is useless? For what Id should i search? All my script knows is that some unit has been killed because the id of the event states the type of the event. [sIGPIC][/sIGPIC]
Oznerol256 Posted April 27, 2013 Author Posted April 27, 2013 Okay, problem got solved. I used runtimeID that i got from the event handler and looked it up in the database. I actually found a lot of stuff that is totally ridiculous to do in the scripting environment. Think of that: You know a unit name or unitId. How do you get out if it is dead or not? Yeah, you have to go through the whole database because it is indexed by runtimeID. No simply flag function available. Or this one: You know the unitID. How do you get to know on what position in the convoy the unit is? Yeah, you have to get through the whole convoy in the group database. No simple function available. Anyway, it is ugly but it works. I hope this is going to get better in the future. [sIGPIC][/sIGPIC]
Grimes Posted April 27, 2013 Posted April 27, 2013 If you know a units name its really easy to find out info on the unit. if Unit.getByName('unitName') then code end If that function returns nil then the unit is dead. If its alive you can get all sorts of data. Unit.getByName('unitName'):getPosition().p will return a table of the units pos3 position. If you know a units id, then you can search the static databases of Mist to find its name and then go from there. And no, event handlers are not useless. In fact they are incredibly useful. Its just better to use mist for the database of objects rather than waiting for a specific unit to be associated with an event action. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Oznerol256 Posted April 27, 2013 Author Posted April 27, 2013 If you know a units name its really easy to find out info on the unit. if Unit.getByName('unitName') then code end If that function returns nil then the unit is dead. If its alive you can get all sorts of data. Unit.getByName('unitName'):getPosition().p will return a table of the units pos3 position. If you know a units id, then you can search the static databases of Mist to find its name and then go from there. Oh yes, you are right! Thanks! And no, event handlers are not useless. In fact they are incredibly useful. Its just better to use mist for the database of objects rather than waiting for a specific unit to be associated with an event action. Why? I have found that once you know the runtimeID of the unit (which isnt easy, you have to go through the whole database instead of calling a simple function) the event handler works well. Why should i keep scanning the database instead of waiting for my function to get called with the right runtimeID ? [sIGPIC][/sIGPIC]
SNAFU Posted June 6, 2013 Posted June 6, 2013 Does anybody have any idea, why this little script part is not working?: ClearApronHandler = {} function ClearApronHandler:onEvent(event) if (world.event.S_EVENT_ENGINE_SHUTDOWN == event.id) then local arrivalgroup = event.initator:getGroup() arrivalgroup:destroy() trigger.action.outText( " (" .. arrivalgroup .. ") removed", 7) end end; world.addEventHandler(ClearApronHandler) AI is not removed. [sIGPIC][/sIGPIC] Unsere Facebook-Seite
SNAFU Posted June 6, 2013 Posted June 6, 2013 Neverminde, I found a workaround: ClearApron = {}; function ClearApron:onEvent(event) if (world.event.S_EVENT_ENGINE_SHUTDOWN == event.id) then trigger.action.outText("EVENT1",10) --local arrivalgroup = event.initiator:getPoint() arrivalgroupname = event.initiator:getName() arrivalgroup = Group.getByName(arrivalgroupname) trigger.action.outText("EVENT2",20) end end; world.addEventHandler(ClearApron); function clear() if arrivalgroup ~= nil then arrivalgroup:destroy() end end mist.scheduleFunction(clear, {}, timer.getTime() + 5, 10) [sIGPIC][/sIGPIC] Unsere Facebook-Seite
Recommended Posts