Jump to content

Recommended Posts

Posted

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]

Posted

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]

Posted

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 ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Posted
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]

  • 1 month later...
Posted

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

Posted

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...