Difference between revisions of "DCS event shot"

From DCS World Wiki - Hoggitworld.com
m (1 revision imported)
 
Line 8: Line 8:
  
 
|desc= Occurs whenever any unit in a mission fires a weapon. But not any machine gun or autocannon based weapon, those are handled by [[DCS_event_shooting_start|shooting_start.]]  
 
|desc= Occurs whenever any unit in a mission fires a weapon. But not any machine gun or autocannon based weapon, those are handled by [[DCS_event_shooting_start|shooting_start.]]  
 
 
 
  
 
|form=  The shot event table is in the following format.  
 
|form=  The shot event table is in the following format.  
Line 17: Line 14:
 
   id = 1,
 
   id = 1,
 
   time = Time,
 
   time = Time,
   initiator = Unit,
+
   initiator = [[DCS_Class_Object|Object]],
   weapon = Weapon
+
   weapon = [[DCS_Class_Weapon|Weapon]]
 
  }
 
  }
 
   
 
   
  
|exam=
+
|exam= The following creates a message box stating the unit name has fired a weapon with the given name. If the weapon object returns a target then that target will also be displayed.
 +
    local e = {}
 +
    function e:onEvent(event)
 +
      if event.id == 1 then
 +
              local m = {}
 +
              m[#m+1] = event.initiator:getName()
 +
              m[#m+1] = ' has fired a '
 +
              m[#m+1] = event.weapon:getDisplayName()
 +
              local tgt = event.weapon:getTarget()
 +
              if tgt then
 +
                  m[#m+1] = ' at a target  '
 +
                  m[#m+1] = tgt:getTypeName()
 +
              end
 +
            trigger.action.outText(table.concat(m), 60)
 +
          end
 +
    end
 +
    world.addEventHandler(e)
  
 
|notes=
 
|notes=
 
 
 
  
 
}}
 
}}

Revision as of 01:39, 5 March 2022


Event: S_EVENT_SHOT Added with: 1.2.4
Enum ID: 1
Description: Occurs whenever any unit in a mission fires a weapon. But not any machine gun or autocannon based weapon, those are handled by shooting_start.
Table Format: The shot event table is in the following format.
Event = {
  id = 1,
  time = Time,
  initiator = Object,
  weapon = Weapon
}
Examples: The following creates a message box stating the unit name has fired a weapon with the given name. If the weapon object returns a target then that target will also be displayed.
   local e = {}
   function e:onEvent(event)
      if event.id == 1 then
             local m = {}
             m[#m+1] = event.initiator:getName()
             m[#m+1] = ' has fired a '
             m[#m+1] = event.weapon:getDisplayName()
             local tgt = event.weapon:getTarget()
             if tgt then
                 m[#m+1] = ' at a target  '
                 m[#m+1] = tgt:getTypeName()
             end
            trigger.action.outText(table.concat(m), 60)
          end
    end
    world.addEventHandler(e)
Notes:
Events: shot, hit, takeoff, land, crash, ejection, refueling, dead, pilot_dead, base_captured, mission_start, mission_end, took_control, refueling_stop, birth, human_failure, detailed_failure, engine_startup, engine_shutdown, player_enter_unit, player_leave_unit, player_comment, shooting_start, shooting_end, mark_added, mark_change, mark_remove, kill, score, unit_lost, landing_after_ejection, discard_chair_after_ejection, weapon_add, landing_quality_mark, ai_abort_mission, weapon_drop