Artillery firing flag - Page 2 - ED Forums
 


Notices

Reply
 
Thread Tools Display Modes
Old 04-23-2017, 08:11 PM   #11
Wrecking Crew
Senior Member
 
Wrecking Crew's Avatar
 
Join Date: Apr 2011
Location: Colorado
Posts: 1,705
Reputation power: 11
Wrecking Crew has a spectacular aura aboutWrecking Crew has a spectacular aura aboutWrecking Crew has a spectacular aura aboutWrecking Crew has a spectacular aura aboutWrecking Crew has a spectacular aura about
Default

Here's an event handler example. I made this with a lot of help from the folks here. Put this into a Once event, with Condition like Time More (5), and Action Do Script with this code in it.

Code:
do
 local function detectClientTakeoff(event)
  local function contains(tbl, val)
   for _,v in ipairs(tbl) do
    if v == val then return true end
   end
   return false
  end
  if(event.id == world.event.S_EVENT_TAKEOFF and event.initiator) then
   local airborneUnitName = event.initiator:getName()
   if(contains({'F-15C 01', 'F-15C 02', 'F-15C 03', 'F-15C 04', 'M-2000C 01', 'M-2000C 02', 'M-2000C 03', 'M-2000C 04', 'AJS37 Viggen 01', 'AJS37 Viggen 02', 'AJS37 Viggen 03', 'AJS37 Viggen 04'}, airborneUnitName)) then
    trigger.action.setUserFlag(50003, true)
    trigger.action.outText(airborneUnitName .. ' just tookoff!', 5)
   end
  end
 end
 mist.addEventHandler(detectClientTakeoff)
end
__________________
Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.
Wrecking Crew is offline   Reply With Quote
Old 04-26-2017, 10:34 AM   #12
Dave317
Member
 
Join Date: Jan 2009
Location: St Evenage. UK
Posts: 596
Reputation power: 11
Dave317 has a spectacular aura aboutDave317 has a spectacular aura aboutDave317 has a spectacular aura aboutDave317 has a spectacular aura about
Default

I've spent so much time on this and still can't get my head around it! Would someone please be kind enough to make a very simple script where if a 155mm HE shell is fired it will turn a flag to true.
Dave317 is offline   Reply With Quote
Old 04-26-2017, 10:52 AM   #13
Looney
Member
 
Looney's Avatar
 
Join Date: Mar 2011
Posts: 719
Reputation power: 9
Looney has a spectacular aura aboutLooney has a spectacular aura aboutLooney has a spectacular aura aboutLooney has a spectacular aura aboutLooney has a spectacular aura about
Default

There are at least two pages you should read up:

http://wiki.hoggit.us/view/DCS_func_addEventHandler

and

http://wiki.hoggit.us/view/DCS_event_shot

With those two, you should then find the ID which a 155mm shell has and note it down.

After that, start working on (pseudo) code

So, when a 155mm shell is fired, find out who fired it and if the side (blue or red) is correct, set a flag.

With Wrecking_crew's example and the above pages, coupled with some .LUA tutorial should give you enough tools to come up with a basic flow of LUA scripting. If that fails, post what you have and I'm sure the people here will help you out.
__________________
Looney is offline   Reply With Quote
Old 04-26-2017, 12:01 PM   #14
Dave317
Member
 
Join Date: Jan 2009
Location: St Evenage. UK
Posts: 596
Reputation power: 11
Dave317 has a spectacular aura aboutDave317 has a spectacular aura aboutDave317 has a spectacular aura aboutDave317 has a spectacular aura about
Default

This is all I could come up with. Pretty sure it is completely wrong.




Code:
do
 local function S_EVENT_SHOT:onEvent(event)
    if event.id == world.event.S_EVENT_SHOT then
        if wpnType == “155mm HE” then
            trigger.action.setUserFlag(10, true)
        end
    end
 end
 world.addEventHandler(S_EVENT_SHOT)
end
Attached Files
File Type: lua ARTY script test 3.lua (234 Bytes, 6 views)

Last edited by Dave317; 04-26-2017 at 12:06 PM.
Dave317 is offline   Reply With Quote
Old 04-26-2017, 01:24 PM   #15
Looney
Member
 
Looney's Avatar
 
Join Date: Mar 2011
Posts: 719
Reputation power: 9
Looney has a spectacular aura aboutLooney has a spectacular aura aboutLooney has a spectacular aura aboutLooney has a spectacular aura aboutLooney has a spectacular aura about
Default

You're getting there

The output of S_EVENT_SHOT is a table according to http://wiki.hoggit.us/view/DCS_event_shot

So, that table is filled and returned at every shot. What you need to do is check if an entry in that table matches the correct weapon.

Event = {
id = 1,
time = 14:00:25,
initiator = M109,
weapon = 155HE
}

Up front, I'm no LUA expert but from pseudo code, you can get a good idea of where you need to go with any code.

On S_EVENT_SHOT
Check the line weapon in the table to see if it matches 155mmHE (or whatever code used for artillery). Alternatively, you may want to check the initiator to see if it matches any artillery unit you want to track.

If that weapon or unit type matches what we want, set flag XX to YY
End

Alternatively, you can have the eventhandler cough up a number which you then use to set a flag so you can check wether that flag has already been set or, if you really want to, add that event to a flag via a counter.
__________________
Looney is offline   Reply With Quote
Old 04-27-2017, 03:54 AM   #16
Igneous01
Junior Member
 
Join Date: Dec 2014
Posts: 60
Reputation power: 3
Igneous01 is on a distinguished road
Default

Moose is easier to use for this

Code:
EHMortarShot = EVENTHANDLER:New() 
EHMortarShot:HandleEvent( EVENTS.Shot )

function EHMortarShot:OnEventShot( EventData )
        -- this checks if the group name that fired was called 'Mortar1' (defined in mission editor)
	if (EventData.IniDCSGroupName == "Mortar1") then
		--set your flag here, do whatever
	end
end
Igneous01 is offline   Reply With Quote
Old 04-27-2017, 07:00 AM   #17
Dave317
Member
 
Join Date: Jan 2009
Location: St Evenage. UK
Posts: 596
Reputation power: 11
Dave317 has a spectacular aura aboutDave317 has a spectacular aura aboutDave317 has a spectacular aura aboutDave317 has a spectacular aura about
Default

It looks like this checks which group fired rather than what weapon. Is this right?
Dave317 is offline   Reply With Quote
Old 04-28-2017, 04:14 AM   #18
Igneous01
Junior Member
 
Join Date: Dec 2014
Posts: 60
Reputation power: 3
Igneous01 is on a distinguished road
Default

Quote:
Originally Posted by Dave317 View Post
It looks like this checks which group fired rather than what weapon. Is this right?
yes in my case I'm handling the shot event for specific artillery groups.

If you want to check for any artillery group, there is a way to do so with Moose by checking the EventData.WeaponCategory or EventData.Weapon properties

you can read more about all the properties returned here:

http://flightcontrol-master.github.i...l##(EVENTDATA)
Igneous01 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 12:45 AM. vBulletin Skin by ForumMonkeys. Powered by vBulletin®.
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.