Veteran66 Posted May 20, 2017 Share Posted May 20, 2017 Hi all I need a working script like: Bf109 shoot P51 = Flag1 or Group1 shoot Group2 = Flag1 how i can make this? http://wiki.hoggit.us/view/DCS_event_hit Event = {S_EVENT_HIT id = 2, time = Time, initiator = Unit, weapon = Weapon target = Object } German WW2 Radio calls Mod: https://www.digitalcombatsimulator.com/en/files/2161798/ Link to comment Share on other sites More sharing options...
Stonehouse Posted May 20, 2017 Share Posted May 20, 2017 (edited) You could do that in the mission editor triggers without having to do a script I'm pretty sure. <edit> looking at the editor you'd probably use the unit damaged condition and if you wanted to cover the whole group you would just add several unit damaged with OR operators and have the action be set either increment flag1 or give it the value you want it to be when the P51s get damaged. I did something similar in this old mission https://www.digitalcombatsimulator.com/en/files/348122/ where the 109s call for help when they get damaged and it triggers a scramble from a nearby friendly airfield. Edited May 20, 2017 by Stonehouse Link to comment Share on other sites More sharing options...
Veteran66 Posted May 20, 2017 Author Share Posted May 20, 2017 i will set a Radio call like "Horrido! Indianer go down" so when a AA shoot down the Enemy plane the Radio call will play, but only a german plane will shoot the radio call will play. (sorry for my bad english) German WW2 Radio calls Mod: https://www.digitalcombatsimulator.com/en/files/2161798/ Link to comment Share on other sites More sharing options...
Stonehouse Posted May 20, 2017 Share Posted May 20, 2017 (edited) Ok so it isn't just a P51 getting damaged then. You want it to be shot down and this to trigger a radio call? Still think you can do it with a mission trigger. Except instead of checking for unit damaged you would check for any one of the P51 units being destroyed and if that condition is satisfied trigger a radio call or a sound file. If you want an actual audio message rather than a text message you will need to record a message in ogg format if I remember correctly. Probably would use a ONCE trigger in conjunction with a UNIT DEAD condition (you would need to check each of the P51 units using a compound OR condition) and an action of SOUND TO GROUP or something similar or RADIO TRANSMISSION. Sorry I just noticed the mod in your signature. You already know all about recording stuff. The above suggestion should still work. Edited May 20, 2017 by Stonehouse Link to comment Share on other sites More sharing options...
Veteran66 Posted May 21, 2017 Author Share Posted May 21, 2017 Hi Stonehouse The damage sound is not the problem it work fine. The UNIT DAMAGE or UNIT DEAD trigger a Soundfile my problem is, AA (Flak) is shooting down a enemy plane and the DAMAGE or DEAD Sound file is play the Soundfile. I will have: only friend plane is shooting down enemy plane = UNIT DEAD Trigger is play sound file. UNIT SHOOT TRIGGER + UNIT DEAD TRIGGER = TRIGGER ACTION SOUND TO ALL So when the enemy plane crash on start or is shoot down by a AA, no sound is play. The sound will play only when the player group plane is shoot down the enemy plane. German WW2 Radio calls Mod: https://www.digitalcombatsimulator.com/en/files/2161798/ Link to comment Share on other sites More sharing options...
Stonehouse Posted May 22, 2017 Share Posted May 22, 2017 ah ok, I see what you mean now. Have to think about it a bit, you may be right in thinking you need a script after all now that you have described the full problem. Link to comment Share on other sites More sharing options...
Pikey Posted May 22, 2017 Share Posted May 22, 2017 So you want an event handler on the Unit to be hit. Design question, do you want the handler on multiple units or just one? If you run MOOSE first in your mission then add a do script with the below, changing the units name from "Tank" or "Plane" (case sensitive) it will display the message every time it's hit. If you need more complex, then start digging in. All the example missions are here: https://github.com/FlightControl-Master/MOOSE_MISSIONS NOTE: you NEED to swap out the MOOSE.lua from my mission attached into any of the sample missions as they are developer builds. Plane = UNIT:FindByName( "Plane" ) Tank = UNIT:FindByName( "Tank" ) Plane:HandleEvent( EVENTS.Hit ) Tank:HandleEvent( EVENTS.Hit ) function Plane:OnEventHit( EventData ) Plane:MessageToAll( "I just got hit!", 15, "Alert!" ) end function Tank:OnEventHit( EventData ) Tank:MessageToAll( "I just got hit!", 15, "Alert!" ) endEVT-101 - UNIT OnEventHit Example.miz ___________________________________________________________________________ SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING * Link to comment Share on other sites More sharing options...
Pikey Posted May 22, 2017 Share Posted May 22, 2017 Re-reading, you want more complex, so you need the event.initiator to be a certain unit as well. I don't have that to hand, but the examples will get your started to learn. ___________________________________________________________________________ SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING * Link to comment Share on other sites More sharing options...
Veteran66 Posted May 22, 2017 Author Share Posted May 22, 2017 So you want an event handler on the Unit to be hit. Design question, do you want the handler on multiple units or just one? If you run MOOSE first in your mission then add a do script with the below, changing the units name from "Tank" or "Plane" (case sensitive) it will display the message every time it's hit. If you need more complex, then start digging in. All the example missions are here: https://github.com/FlightControl-Master/MOOSE_MISSIONS NOTE: you NEED to swap out the MOOSE.lua from my mission attached into any of the sample missions as they are developer builds. Plane = UNIT:FindByName( "Plane" ) Tank = UNIT:FindByName( "Tank" ) Plane:HandleEvent( EVENTS.Hit ) Tank:HandleEvent( EVENTS.Hit ) function Plane:OnEventHit( EventData ) Plane:MessageToAll( "I just got hit!", 15, "Alert!" ) end function Tank:OnEventHit( EventData ) Tank:MessageToAll( "I just got hit!", 15, "Alert!" ) end Thx Pikey i make some tests and it work fine, can you add: Tank: Flag 10 Plane: Flag 20 German WW2 Radio calls Mod: https://www.digitalcombatsimulator.com/en/files/2161798/ Link to comment Share on other sites More sharing options...
Stonehouse Posted May 23, 2017 Share Posted May 23, 2017 (edited) Yeah but according to your post and as Pikey says the complication is that you want to only send a message/sound file when the target aircraft is destroyed by a particular set of attackers and no other ie any one of the P51s destroys one of the 109s. Pikey's example is essentially the script version of the mission trigger thing I'd already mentioned. You need to expand it slightly using some of the other things passed back in the event table entry by S_EVENT_HIT: http://wiki.hoggit.us/view/DCS_event_hit Event = { id = 2, time = Time, initiator = Unit, weapon = Weapon target = Object } So you'd be checking on each and every hit event whether the initiator was one of your P51s and whether the target was one of your 109s. This could be pretty expensive code to run if a lot of things are firing at a given moment as it applies to all hit events even no lethal ones. eg a ground machine gun fires at a truck 100 rounds and 20 hit so that is 20 hit events, at the same time a 109 attacks another plane and hits it 15 times so 15 hit events, likewise at the same time one of your P51s fires at one of the 109s we are interested in and scores 10 hits but doesn't kill it. Still 10 more hit events. I believe that from an event handling point of view all the hit events are the same and it is only when you look at the details you can differentiate between them. You might be able to make it less expensive by somehow linking it to S_EVENT_DEAD and S_EVENT_PILOT_DEAD (from memory if the pilot is killed the aircraft is not dead until it hits the ground so you need to check both although it has been awhile so I could be wrong) so that when something is destroyed you then check the hit events to see what killed it and issue your message accordingly. Tricky thing there is the hit event is likely fractionally before the dead event. A better way might be to hand off each hit event's details and every pilot death event's details to a scheduled function that runs every two or three secs and it checks the hit event to see if the initiator is one of the P51s and the target is one of the 109s. If it is you can then check to see if the 109 has a health of 0 or a corresponding pilot death for it and if has issue the message. You'd probably have to add the details of each event to a table and pass that table to scheduled function. Once the scheduled function had processed a table entry you'd need to remove it so it doesn't get looked at again and also to avoid the table getting too large and making things get slow accordingly. Anyway some flavour of this sort of thing might do what you want. @Pikey - does MOOSE already have that sort of thing built in? I'm behind on my reading and down with the flu as well today so my brain is complete mush. In fact the way I feel today I wouldn't be surprised if someone posts that my suggestion is complete rubbish and offers a much simpler approach. <edit> told you my brain was mush, just realised Pikey's example limits it to the unit in question so it isn't for each hit event after all so the performance issue may not be a problem. You would still need to check the initiator is one of your P51s and the health of the 109 = 0 before issuing the message. I think you still need to also check for a pilot kill too. Edited May 23, 2017 by Stonehouse Link to comment Share on other sites More sharing options...
Veteran66 Posted May 23, 2017 Author Share Posted May 23, 2017 Hi Stonehouse Look at my post above UNIT SHOOT TRIGGER + UNIT DEAD TRIGGER = TRIGGER ACTION SOUND TO ALL UNIT SHOOT TRIGGER = so the own Planes are in combat UNIT DEAD TRIGGER = the enemy is shoot down TRIGGER ACTION SOUND = the script make activ a Flag so i can set in Editor Flag1 trigger Play sound Pikey`s Moose script is the first script who will work for me (i am a script noob), not optimal but work :) German WW2 Radio calls Mod: https://www.digitalcombatsimulator.com/en/files/2161798/ Link to comment Share on other sites More sharing options...
Stonehouse Posted May 25, 2017 Share Posted May 25, 2017 (edited) Hi Veteran66, Sorry been very flu ridden last couple of days and still am pretty miserable. So you have sorted it out to your satisfaction? or are you asking if the UNIT SHOOT + UNIT DEAD method is ok? If the latter then it will probably work most of the time but there is nothing there that guarantees that the P51 didn't shoot at something else at the same time as flak blew the 109 to pieces. All it checks is that the P51 fired and that the 109 is dead. It doesn't check to see how the 109 died and whether it was the P51 that killed it. Anyway hope it works for you. PS make sure you use a ONCE type trigger or else once the 109 is dead you get the message every time the P51 fires. Edited May 25, 2017 by Stonehouse ONCE trigger type Link to comment Share on other sites More sharing options...
Veteran66 Posted May 26, 2017 Author Share Posted May 26, 2017 Hi Stonehouse Maybe i find a way, this time i work for a small script "FLAK1 true when PLANE1 SHOOTING" :) German WW2 Radio calls Mod: https://www.digitalcombatsimulator.com/en/files/2161798/ Link to comment Share on other sites More sharing options...
Veteran66 Posted May 26, 2017 Author Share Posted May 26, 2017 i try this script: -- event handlers: HitEventHandler = {}; -- function - event handler for aircraft: function HitEventHandler:onEvent(event) if event.id == world.event.S_EVENT_HIT then local _initiator = event.initiator local _initname = _initiator:getName() if _initname == "Unit1" then trigger.action.setUserFlag(1, true) end end end world.addEventHandler(HitEventHandler) i get the Flag1 whin the Unit1 is hit. better way is: PLANE1 SHOOT- UNIT1 IS HIT = FLAG1 TRUE http://wiki.hoggit.us/view/DCS_event_hit Initiator : The unit object the fired the weapon Target: The Object that was hit. but how i can this write in my script? German WW2 Radio calls Mod: https://www.digitalcombatsimulator.com/en/files/2161798/ Link to comment Share on other sites More sharing options...
Pikey Posted May 26, 2017 Share Posted May 26, 2017 EVENTS are pretty powerful and at the same time you can't always use them how you like. SHOT events have targets, weapons, initiators. All the remaining events only have the initiator and three have a 'place' (landing takeoff and base capture). EVENTS are also "Point in Time", and it's obvious, really, the limits of this because weapons have travel times. The SHOT comes way before the HIT and the last hit comes way before the DEATH. We've all seen it in scripting, where someone tries to connect these events and somehow it's muddled and the last person gets the kill. Dead event and "DCS dead" with the victim/initiator and weapon seems closer to accuracy but is still not great for "contribution kills" where multiple hits from different people go into one result. I think it takes the last HIT received to match it, but it's not the most accurate way. You really want to record all the hits by all the initiators and weapons and take all of them, then give a proportion of credit to the sum of all the largest warheads from one single player. And that....is not easy and way too complex, but very possible! ___________________________________________________________________________ SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING * Link to comment Share on other sites More sharing options...
Pikey Posted May 26, 2017 Share Posted May 26, 2017 SHOT and HIT and different events as described above. Two people can shoot at one player, one with bullets and one with an AMRAAM 15 seconds before. Whilst the bullets might clip the wing before and after the AMRAAM hit, who killed the player? i try this script: -- event handlers: HitEventHandler = {}; -- function - event handler for aircraft: function HitEventHandler:onEvent(event) if event.id == world.event.S_EVENT_HIT then local _initiator = event.initiator local _initname = _initiator:getName() if _initname == "Unit1" then trigger.action.setUserFlag(1, true) end end end world.addEventHandler(HitEventHandler) i get the Flag1 whin the Unit1 is hit. better way is: PLANE1 SHOOT- UNIT1 IS HIT = FLAG1 TRUE http://wiki.hoggit.us/view/DCS_event_hit Initiator : The unit object the fired the weapon Target: The Object that was hit. but how i can this write in my script? ___________________________________________________________________________ SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING * Link to comment Share on other sites More sharing options...
Veteran66 Posted May 26, 2017 Author Share Posted May 26, 2017 ok thx for your answer, so it is to complex for a SHOOT and HIT script. German WW2 Radio calls Mod: https://www.digitalcombatsimulator.com/en/files/2161798/ Link to comment Share on other sites More sharing options...
Stonehouse Posted May 26, 2017 Share Posted May 26, 2017 (edited) That's kind of what I have been saying. You would probably want to record any hit event on the aircraft you are interested in (ie the 109s) - Pikey's example gives you this sort of thing. But then you need to look at them in the order they happen in as soon as possible after the event happens and after each evaluate if the P51 was the initiator and if the target is 0% health (ie dead 109) and then if that is true send your message. To complicate matters I think that a pilot kill doesn't equate to the unit health being 0% but perhaps you could ignore that as in real life a plane with a dead pilot will fly on for a little while depending on a few factors and possibly the P51 pilot won't be sure that he's made a kill. However if he sees the plane on fire or blow up or the pilot bail out then he'd send the message that he has made a kill. It sounds like a simple thing but it is actually quite complex. From a script point of view the most straight forward would be for each hit event on the aircraft of interest, check the initiator. If the initiator is one of the P51s, check if the 109 is dead. If it is then issue the message. You may need to record the fact that you have sent a message about that 109 so that you can check for that being done and not send another. For instance if the P51 shot a burst of 30 rounds at the 109 and the 15th round destroyed it but more rounds of the same burst still hit the 109 you would not want to issue messages for rounds that hit after the 15th. <edit> maybe if the mission you are building is fairly simple then you can approach the problem from a different direction and apply a degree of abstraction to avoid building a complex script. Assuming you can manage where and when the engagement takes place, perhaps you could use two mission triggers - the first checks for a P51 shooting AND a 109 being hit. The second is only done if the first is true, this checks to see whether a 109 is dead. If it is then issue the message. You would want the second condition to be evaluated either switched or continuously (you'd need to experiment to figure out which) but the condition could only be allowed to be true once or else you would generate the message more than once for that 109. I think this could approximate what you want to have happen as long as you've managed the situation in the mission, it may take quite a bit of tweaking to get it doing what you want most of the time. I'd suggest trying to prototype it with a single P51 and a single 109 and if you get it working then expand it to cover the groups of planes. Edited May 26, 2017 by Stonehouse Link to comment Share on other sites More sharing options...
Recommended Posts