Jump to content

How to pass triggering Unit to script?


Recommended Posts

Posted

I am a total n00b regarding scripting in LUA/DCS. I have sort of a script that spawns survivors where a Huey crashes. It is not complete.

 

How the h*ll do I make this generic? So that within a very large trigger zone any crashing or emergency landing Huey triggers this scripts and spawns survivors (vanilla soldiers)?

1 How do I get the Huey that crashes or makes an emergency landing(damaged)?

2 How do I pass that Huey to my script as a parameter or ref somehow?

Posted

I think you want to use the EventHandler. I have not tried, but I think it should kinda look like that:

 

function CrashedUnit(event)
    if event.id == world.event.S_EVENT_CRASH then
        UnitDead = world.Event.initiator
        -- this will be your unit that crashedn not sure in what format, though; you can then check if it is a Huey and everything
    end
end
 
world.addEventHandler(CrashedUnit)

 

You might want to take a look at MiST also, they have a mist.addEventHandler (I'm not actually sure to get the difference with the default one though) and a small example in the documentation.

Posted

Thank you very much. I will try this path.

 

I think you want to use the EventHandler. I have not tried, but I think it should kinda look like that:

 

function CrashedUnit(event)
    if event.id == world.event.S_EVENT_CRASH then
        UnitDead = world.Event.initiator
        -- this will be your unit that crashedn not sure in what format, though; you can then check if it is a Huey and everything
    end
end
 
world.addEventHandler(CrashedUnit)

You might want to take a look at MiST also, they have a mist.addEventHandler (I'm not actually sure to get the difference with the default one though) and a small example in the documentation.

Posted

Where do I add the code that registers the event handler?

world.addEventHandler(CrashedUnit)

 

At the moment I can't get my function to fire, doesn't seem to be registered as an event handler.

 

I think you want to use the EventHandler. I have not tried, but I think it should kinda look like that:

 

function CrashedUnit(event)
    if event.id == world.event.S_EVENT_CRASH then
        UnitDead = world.Event.initiator
        -- this will be your unit that crashedn not sure in what format, though; you can then check if it is a Huey and everything
    end
end
 
world.addEventHandler(CrashedUnit)

You might want to take a look at MiST also, they have a mist.addEventHandler (I'm not actually sure to get the difference with the default one though) and a small example in the documentation.

Posted

Gotta be something linke this:

 


e.event_handler = {}

function e.event_handler:onEvent(event)
e.logger('e.event_handler: handling event with id: ' .. tostring(event.id))
if event.id == world.event.S_EVENT_LAND then
	e.logger('e.event_handler: handling a LANDING event')
	-- do something
end
if event.id == world.event.S_EVENT_SHOT then
	e.logger('e.event_handler: handling a SHOT event')
	-- do something
end
end

do
world.addEventHandler(e.event_handler)
end

[sIGPIC][/sIGPIC]

Posted

I'll test this, but where do I trigger this part to be registered? In a trigger? If so what kind of trigger? I need to register this event handler somehow.

 

Gotta be something linke this:

 


e.event_handler = {}

function e.event_handler:onEvent(event)
   e.logger('e.event_handler: handling event with id: ' .. tostring(event.id))
   if event.id == world.event.S_EVENT_LAND then
       e.logger('e.event_handler: handling a LANDING event')
       -- do something
   end
   if event.id == world.event.S_EVENT_SHOT then
       e.logger('e.event_handler: handling a SHOT event')
       -- do something
   end
end

do
   world.addEventHandler(e.event_handler)
end

Posted
I'll test this, but where do I trigger this part to be registered? In a trigger? If so what kind of trigger? I need to register this event handler somehow.

 

Events are automatically triggered. Every time a world event happens, all event handlers are run.

 

If you're asking where you run the Lua script itself, then you run it anywhere in the mission scripting environment. You can do it on mission start, on a once trigger, etc. You can use the DO SCRIPT trigger action, DO SCRIPT FILE, you can do the DO SCRIPT AI triggered action or waypoint action, etc. I prefer the DO SCRIPT trigger action.

Intelligent discourse can only begin with the honest admission of your own fallibility.

Member of the Virtual Tactical Air Group: http://vtacticalairgroup.com/

Lua scripts and mods:

MIssion Scripting Tools (Mist): http://forums.eagle.ru/showthread.php?t=98616

Slmod version 7.0 for DCS: World: http://forums.eagle.ru/showthread.php?t=80979

Now includes remote server administration tools for kicking, banning, loading missions, etc.

Posted

OK, I have tried to execute it in a MISSION START -> TIME MORE trigger. I will output debug info to see whether it executes the script(registration) or not.

 

Events are automatically triggered. Every time a world event happens, all event handlers are run.

 

If you're asking where you run the Lua script itself, then you run it anywhere in the mission scripting environment. You can do it on mission start, on a once trigger, etc. You can use the DO SCRIPT trigger action, DO SCRIPT FILE, you can do the DO SCRIPT AI triggered action or waypoint action, etc. I prefer the DO SCRIPT trigger action.

  • Recently Browsing   0 members

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