Jump to content

Recommended Posts

Posted

I'm trying to get the category of weapons for the event "S_EVENT_SHOT", with no results..

 

I tried with: event.weapon:getDesc().category and event.weapon:getCategory()

 

from wiki https://wiki.hoggitworld.com/view/DCS_Class_Weapon

 

:helpsmilie:

PC: i7-13700K - Gigabyte RTX 5080 GAMING OC - 64GB DDR5 6400 - VPC MongoosT-50CM3 - VKB GF pro - MFG Crosswind - Msi MPG321UR-QD + LG OLED 32GS95UE - TrackIR5 - Quest 3

Posted (edited)

I just wrote this code to figure out if an Unit is an Aircraft:

 

unit:getDesc().category

 

the getDesc() returns a table with the following data structure, I guess the missile does the same:

{
   Hmax=12247,
   Kab=0,
   Kmax=4,
   NyMax=2.5,
   NyMin=0.5,
   RCS=80,
   VyMax=10,
   _origin="",
   attributes={
       AWACS=true,
       Air=true,
       All=true,
       NonAndLightArmoredUnits=true,
       NonArmoredUnits=true,
       Planes=true,
       Refuelable=true
   },
   box={
       max={x=21.821313858032, y=11.463214874268, z=26.033617019653},
       min={x=-27.208490371704, y=-3.3296194076538, z=-25.958759307861}
   },
   category=0,
   displayName="a-50",
   fuelMassMax=70000,
   life=60,
   massEmpty=90000,
   massMax=190000,
   range=7300,
   speedMax=236.11000061035,
   speedMax0=167.11000061035,
   speedMax10K=236.11000061035,
   tankerType=1,
   typeName="A-50"
}

Edited by tigair
Posted

I do not see anything wrong, assuming that event.weapon is not nil.

 

One thing to note is the difference between the two:

 

event.weapon:getDesc().category returns Weapon.Category enum

event.weapon:getCategory() returns Object.Category enum

Posted
I do not see anything wrong, assuming that event.weapon is not nil.

 

This is the script:

 

EventHandler = {}
function EventHandler:onEvent(event)
       if event.id == world.event.S_EVENT_SHOT and event.initiator == Unit.getByName('Player') then

		local arma = event.weapon:getDesc().guidance
		local categoria = event.weapon:getDesc().category

           if arma == 4 then
                   trigger.action.outTextForCoalition(coalition.side.BLUE, "FOX 1", 8)
				trigger.action.outSoundForCoalition(coalition.side.BLUE, 'walkietalkie2.ogg')
           end
           if arma == 2 then
                   trigger.action.outTextForCoalition(coalition.side.BLUE, "FOX 2", 8)
				trigger.action.outSoundForCoalition(coalition.side.BLUE, 'walkietalkie2.ogg')
           end
           if arma == 3 then
                   trigger.action.outTextForCoalition(coalition.side.BLUE, "FOX 3", 8)
				trigger.action.outSoundForCoalition(coalition.side.BLUE, 'walkietalkie2.ogg')
				
		if categoria == 3 then
                   trigger.action.outTextForCoalition(coalition.side.BLUE, "PICKLE", 8)
				trigger.action.outSoundForCoalition(coalition.side.BLUE, 'walkietalkie2.ogg')
		end		
       end
   end
end
world.addEventHandler(EventHandler)

 

It's working for the missiles but not for the bombs....

 

Weapon.Category

SHELL 0

MISSILE 1

ROCKET 2

BOMB 3

PC: i7-13700K - Gigabyte RTX 5080 GAMING OC - 64GB DDR5 6400 - VPC MongoosT-50CM3 - VKB GF pro - MFG Crosswind - Msi MPG321UR-QD + LG OLED 32GS95UE - TrackIR5 - Quest 3

Posted (edited)

Did you mean to nest

if categoria == 3 then

inside

if arma == 3 then

?

 

Instead of testing for an integer, you might think about testing against the enum value (ie. if categoria == Weapon.Category.BOMB then).

 

Also recommend using elseif since only one condition can apply for a single event.

Edited by Chump
Posted

I found the mistake, I forgot an "end" before the last "if", now it's working.

 

EventHandler = {}
function EventHandler:onEvent(event)
       if event.id == world.event.S_EVENT_SHOT and event.initiator == Unit.getByName('Player') then

		local arma = event.weapon:getDesc().guidance
		local categoria = event.weapon:getDesc().category

           if arma == 4 then
                   trigger.action.outTextForCoalition(coalition.side.BLUE, "FOX 1", 8)
	    trigger.action.outSoundForCoalition(coalition.side.BLUE, 'walkietalkie2.ogg')
           end
           if arma == 2 then
            trigger.action.outTextForCoalition(coalition.side.BLUE, "FOX 2", 8)
     trigger.action.outSoundForCoalition(coalition.side.BLUE, 'walkietalkie2.ogg')
           end
           if arma == 3 then
                   trigger.action.outTextForCoalition(coalition.side.BLUE, "FOX 3", 8)
	    trigger.action.outSoundForCoalition(coalition.side.BLUE, 'walkietalkie2.ogg')
     end
	    if categoria == 3 then
                   trigger.action.outTextForCoalition(coalition.side.BLUE, "PICKLE", 8)
	    trigger.action.outSoundForCoalition(coalition.side.BLUE, 'walkietalkie2.ogg')
     end		
     end
end
world.addEventHandler(EventHandler)

PC: i7-13700K - Gigabyte RTX 5080 GAMING OC - 64GB DDR5 6400 - VPC MongoosT-50CM3 - VKB GF pro - MFG Crosswind - Msi MPG321UR-QD + LG OLED 32GS95UE - TrackIR5 - Quest 3

  • Recently Browsing   0 members

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