C6_Hellfrog Posted June 15, 2016 Posted June 15, 2016 (edited) hello I'm making first attempts to use scripting function in ME. I just need to have the group ID of the player aircraft it is (to stay more simple) solo mission no MP I made a event 'one time' ,rule is 'time more than > 5', action 'run script' with that code (no typo errors) env.setErrorMessageBoxEnabled(true) myGroupName = "GroupHellfrog" myPilot = "Hellfrog" myGroup = Group.getByName(myGroupName) myGroupID = Group.GetID(myGroup) I need only the unit name and its group ID for after. but that is already a problem I get an error message : Attempt to call field 'GetID' a nil value I suppose I have myGroup == nil but I don't know why... maybe the syntax is not the good one ? can someone help please ? Edited June 16, 2016 by C6_Hellfrog change title because evolution
Steggles Posted June 15, 2016 Posted June 15, 2016 (edited) Client groups are not accessible in multiplayer ATM. There is a work around using MIST. It's not your code. Check here for the workaround: http://forums.eagle.ru/showpost.php?p=2499638&postcount=5 If you check the first post of that thread all the current acknowledged scripting issues are listed. Edited June 15, 2016 by Steggles -16AGR- 16th Air Guards Regiment is always looking for pilots - http://www.16agr.com EWRS - Early Warning Radar Script Specs: Gigabyte Sniper Z5-S Intel i5-4670k 3.4GHz OC'd 3.9GHz w/ Thermaltake 120mm Water 3.0 Pro Liquid CPU Cooler 16GB RAM Gigabyte GTX 1080 TM Hotas Warthog: SN: 06976 Saitek Pro Flight Combat Rudder Pedals TrackIR5 with TrackClipPro & Oculus Rift 2x 28" 4k UHD Monitors (3840x2160 each) + 1280x1024
St3v3f Posted June 15, 2016 Posted June 15, 2016 env.setErrorMessageBoxEnabled(true) myGroupName = "GroupHellfrog" myPilot = "Hellfrog" myGroup = Group.getByName(myGroupName) myGroupID = Group.[color="Red"]g[/color]etID(myGroup) There's your error. Client groups are not accessible in multiplayer ATM. There is a work around using MIST. It's not your code. Check here for the workaround: http://forums.eagle.ru/showpost.php?p=2499638&postcount=5 If you check the first post of that thread all the current acknowledged scripting issues are listed. Not an issue here, as the OP only wants to run this in single player aka: Baron [sIGPIC][/sIGPIC]
C6_Hellfrog Posted June 15, 2016 Author Posted June 15, 2016 ouch, didn't thought it was so case sensitive. and difficult to see. many thanks. except that my code was ok ?
Steggles Posted June 15, 2016 Posted June 15, 2016 env.setErrorMessageBoxEnabled(true) myGroupName = "GroupHellfrog" myPilot = "Hellfrog" myGroup = Group.getByName(myGroupName) myGroupID = Group.[color="Red"]g[/color]etID(myGroup) There's your error. Not an issue here, as the OP only wants to run this in single player Well that's what I get for not reading the OP correctly. Thanks for the catch. -16AGR- 16th Air Guards Regiment is always looking for pilots - http://www.16agr.com EWRS - Early Warning Radar Script Specs: Gigabyte Sniper Z5-S Intel i5-4670k 3.4GHz OC'd 3.9GHz w/ Thermaltake 120mm Water 3.0 Pro Liquid CPU Cooler 16GB RAM Gigabyte GTX 1080 TM Hotas Warthog: SN: 06976 Saitek Pro Flight Combat Rudder Pedals TrackIR5 with TrackClipPro & Oculus Rift 2x 28" 4k UHD Monitors (3840x2160 each) + 1280x1024
C6_Hellfrog Posted June 15, 2016 Author Posted June 15, 2016 (edited) Hi again Still having some problems with the scripts I just want to have a scheduled check about my unit altitude above ground level to voice announcements to emulate a virtual copilot to help for training at low altitude here is what I have added in the mission editor 1st event : 2d event : here is the script : test_Alt = function() env.setErrorMessageBoxEnabled(true) timer_frequency = 1 myGroupName = "GroupHellfrog" myPilot = "Hellfrog" myGroup = Group.getByName(myGroupName) MyGroupID = Group.getID(myGroup) myUnit = myGroup:getUnit(1) if myUnit == nil then trigger.action.outText("nil unit", 900) end timer.scheduleFunction(CheckAltitude, myUnit, timer.getTime() + timer_frequency) end function CheckAltitude(myUnit, time) -- use the scheduleFunction's second argument local myPos = nil myPos = myUnit:getPosition() if myPos == nil then trigger.action.outText("nil pos", 900) end myALT_m_AGL = unit_Alt_meters_AGL(myPos) if myALT ~= nil then if myALT >= 1 then if myALT < 2 then trigger.action.outSoundForGroup(myGroupID, '1-end.wav') end end if myALT >= 3 then if myALT < 4 then trigger.action.outSoundForGroup(myGroupID, '3-end.wav') end end if myALT >= 5 then if myALT < 6 then trigger.action.outSoundForGroup(myGroupID, '5-end.wav') end end if myALT >= 10 then if myALT < 11 then trigger.action.outSoundForGroup(myGroupID, '10-end.wav') end end if myALT >= 15 then if myALT < 16 then trigger.action.outSoundForGroup(myGroupID, '15-end.wav') end end if myALT >= 20 then if myALT < 21 then trigger.action.outSoundForGroup(myGroupID, '20-end.wav') end end return time + timer_frequency else -- looping return nil end end function unit_Alt_meters_AGL(uPos) local uAGL = nil local GndAlt = nil if uPos ~= nil then GndAlt = land.getHeight({x = uPos.p.x, y = uPos.p.z}) -- gnd alt below unit uAGL = uPos.p.y - GndAlt -- unit feet alt above gnd uAGL = uAGL*0.3048 -- convert feet to m end end return uAGL end what I get is an error about a " <EOF> missing after 'end' " .... ????? I have no idea about what is the cause and how to correct. Edited June 15, 2016 by C6_Hellfrog img links updated
Chump Posted June 15, 2016 Posted June 15, 2016 Looks to me like you have one too many conditional terminators: function unit_Alt_meters_AGL(uPos) local uAGL = nil local GndAlt = nil if uPos ~= nil then GndAlt = land.getHeight({x = uPos.p.x, y = uPos.p.z}) -- gnd alt below unit uAGL = uPos.p.y - GndAlt -- unit feet alt above gnd uAGL = uAGL*0.3048 -- convert feet to m end [b][color=Red] end[/color][/b] return uAGL end
C6_Hellfrog Posted June 15, 2016 Author Posted June 15, 2016 ah shit... i'm sick with a sort of flue and my brain is not working as it should... should have noticed myself. sorry for asking so simple thing. But thanks anyway. will try if working... asap
C6_Hellfrog Posted June 15, 2016 Author Posted June 15, 2016 (edited) ok script seems to run fine, but no sound EDIT : in fact no : if i add trigger.action.outText("10", 700) if test is true, i have no display I have the sound files in miz l10n/DEFAULT/ I play them once after loading script in the same event trigger my script call for sound is trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/3-end.wav') what is wrong ? test_Alt = function() env.setErrorMessageBoxEnabled(true) timer_frequency = 1 myGroupName = "GroupHellfrog" myPilot = "Hellfrog" myGroup = Group.getByName(myGroupName) MyGroupID = Group.getID(myGroup) myUnit = myGroup:getUnit(1) if myUnit == nil then trigger.action.outText("nil unit", 900) end timer.scheduleFunction(CheckAltitude, myUnit, timer.getTime() + timer_frequency) end function CheckAltitude(myUnit, time) -- use the scheduleFunction's second argument local myPos = nil myPos = myUnit:getPosition() if myPos == nil then trigger.action.outText("nil pos", 900) end myALT_m_AGL = unit_Alt_meters_AGL(myPos) if myALT ~= nil then if myALT >= 1 then if myALT < 2 then trigger.action.outText("ONE", 700) trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/1-end.wav') end end if myALT >= 3 then if myALT < 4 then trigger.action.outText("3", 700) trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/3-end.wav') end end if myALT >= 5 then if myALT < 6 then trigger.action.outText("5", 700) trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/5-end.wav') end end if myALT >= 10 then if myALT < 11 then trigger.action.outText("10", 700) trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/10-end.wav') end end if myALT >= 15 then if myALT < 16 then trigger.action.outText("15", 700) trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/15-end.wav') end end if myALT >= 20 then if myALT < 21 then trigger.action.outText("20", 700) trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/20-end.wav') end end return time + timer_frequency else -- looping return nil end end function unit_Alt_meters_AGL(uPos) local uAGL = nil local GndAlt = nil if uPos ~= nil then GndAlt = land.getHeight({x = uPos.p.x, y = uPos.p.z}) -- gnd alt below unit uAGL = uPos.p.y - GndAlt -- unit feet alt above gnd uAGL = uAGL*0.3048 -- convert feet to m end return uAGL end Edited June 15, 2016 by C6_Hellfrog
C6_Hellfrog Posted June 16, 2016 Author Posted June 16, 2016 (edited) adding a trigger.action.outText at the start of CheckAlt function i see it is run only once and not timly repeated. why ? if i change the event trigger where i call test_alt() to continuously and not once, I have again nil value error in the call... EDIT : Ok, the call has to be continous, and after a delay of 7 sec to have time maybe for script to be interpreted. But still no sound neither outtext whatever is the altitude.... running without compiling error, but not working as intended... any idea ? Edited June 16, 2016 by C6_Hellfrog
Chump Posted June 16, 2016 Posted June 16, 2016 I do not think that timer.scheduleFunction() accepts a parameter for repetition. http://en.wiki.eagle.ru/wiki/Simulator_Scripting_Engine/DCS:_World/Part_1#timer FunctionId function timer.scheduleFunction(FunctionToCall functionToCall, any functionArgument, Time time)MiST does do this. http://wiki.hoggit.us/view/ScheduleFunction number mist.scheduleFunction(function f, table vars, number t, number rep, number st)
C6_Hellfrog Posted June 16, 2016 Author Posted June 16, 2016 I do not think that timer.scheduleFunction() accepts a parameter for repetition. http://en.wiki.eagle.ru/wiki/Simulator_Scripting_Engine/DCS:_World/Part_1#timer FunctionId function timer.scheduleFunction(FunctionToCall functionToCall, any functionArgument, Time time) OK, thanks for the advice, i realize I misunderstood and confused defered call and repetitive call... but any way with continous single call from trigger event it should work... and is not... with repetitive call once, it should work ... and is not... something with the code or a bug ?
C6_Hellfrog Posted June 16, 2016 Author Posted June 16, 2016 (edited) well, coming back at first question, still having the pb about groupID stay nil EDIT and delete ok found it, again typo error with myGroupID and MyGroupID.... that sucks !!! Edited June 16, 2016 by C6_Hellfrog
C6_Hellfrog Posted June 16, 2016 Author Posted June 16, 2016 (edited) ok, now it is working almost too good !!! any idea about how to reduce frequency of annoucements ? I prefer to avoid using mist if possible to avoid having heavier mission i already check not to announce without less than 10% change... i could increase for sure, but will lose precision for low altitudes i could use flags but will increase considerabily nb of "if" tests and would be better to limit that for performance but I still have some repetitions... as objective is to perform low level training to get used to gain better visual references... and refer to known altitude... therefore the annoucements... i think it s a good idea, and may work , but need some optimisation... current lua script is function test_Alt() myGroupName = "GroupHellfrog" myPilot = "Hellfrog" local oldAltRad = -1 local getAltRad = 0 env.setErrorMessageBoxEnabled(true) myGroup = Group.getByName(myGroupName) myGroupID = Group.getID(myGroup) myUnit = myGroup:getUnit(1) if myUnit ~= nil then myPos = myUnit:getPosition() GndAlt = land.getHeight({x = myPos.p.x, y = myPos.p.z}) -- gnd alt below unit uAGL = myPos.p.y - GndAlt -- unit feet alt above gnd uAGL = uAGL*0.3048 -- convert feet to m newAltRad = uAGL trigger.action.outText(string.format("%d", newAltRad), 1) ---- to dbg test ChangeTenPercentAbove = ( newAltRad > (1.1*oldAltRad) ) ChangeTenPercentBelow = ( newAltRad < (0.9*oldAltRad) ) AboveMinAlt = ( newAltRad > 0.5 ) -- 50 cm AGL if( ChangeTenPercentAbove or ChangeTenPercentBelow and AboveMinAlt )then -- don't send if below 50 cm AGL or less than 10% change in RAlt if( newAltRad >= 22 ) then return 0 -- no announcement above elseif(newAltRad >= 20) then trigger.action.outText("20", 1) ---- to dbg test trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/20-end.wav') elseif(newAltRad >= 16 ) then return 0 elseif(newAltRad >= 15 ) then trigger.action.outText("15", 1) ---- to dbg test trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/15-end.wav') elseif(newAltRad >= 11 ) then return 0 elseif(newAltRad >= 10 ) then trigger.action.outText("10", 1) ---- to dbg test trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/10-end.wav') elseif(newAltRad >= 6 ) then return 0 elseif(newAltRad >= 5 ) then trigger.action.outText("5", 1) ---- to dbg test trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/5-end.wav') elseif(newAltRad >= 3.5 ) then return 0 elseif(newAltRad >= 3 ) then trigger.action.outText("3", 1) ---- to dbg test trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/3-end.wav') elseif(newAltRad >= 2 ) then return 0 elseif(newAltRad >= 1 ) then trigger.action.outText("1", 1) ---- to dbg test trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/1-end.wav') else -- ".....land or CRASHED !!! \xa" end end end end EDIT : I have that idea : could be efficient defining a timed delay between announcemnts independant from altitude changes and only one more "if" timer_New = os.time() if checkTimerDelay(timer_Old, timer_New, VOICE_TIMER_DELAY) then -- Timer function function checkTimerDelay(timer_Old, timer_New, timer_delay) -- compare delay between time old and new (new supposed to be > old), return true / false return (os.difftime(timer_New, timer_Old))>= timer_delay) end Edited June 16, 2016 by C6_Hellfrog
C6_Hellfrog Posted June 16, 2016 Author Posted June 16, 2016 (edited) finally had it do env.setErrorMessageBoxEnabled(true) flag_LastAnnouce = 0 myGroupName = "GroupHellfrog" myPilot = "Hellfrog" oldAltRad = -1 AltMin = 0.5 myGroup = Group.getByName(myGroupName) myGroupID = Group.getID(myGroup) myUnit = myGroup:getUnit(1) flag_UpDn_Now = 0 flag_UpDn_Last = 0 end function test_Alt() local myPos = myUnit:getPosition() local GndAlt = land.getHeight({x = myPos.p.x, y = myPos.p.z}) -- gnd alt below unit local newAltRad = myPos.p.y - GndAlt -- unit feet alt above gnd newAltRad = newAltRad*0.3048 -- convert feet to m if( newAltRad > oldAltRad ) then flag_UpDn_Now = 1 elseif( newAltRad == oldAltRad ) then flag_UpDn_Now = 0 elseif( newAltRad < oldAltRad ) then flag_UpDn_Now = -1 end local ChangeTenPercentAbove = ( newAltRad > (1.1*oldAltRad) ) local ChangeTenPercentBelow = ( newAltRad < (0.9*oldAltRad) ) local AboveMinAlt = ( newAltRad > AltMin ) -- 50 cm AGL if( ChangeTenPercentAbove or ChangeTenPercentBelow and AboveMinAlt )then -- don't send if below 50 cm AGL or less than 10% change in RAlt if( newAltRad >= 22) then -- no announcement above elseif( (newAltRad >= 20 and flag_LastAnnouce ~= 20 ) or ( (newAltRad >= 20 and flag_LastAnnouce == 20) and (flag_UpDn_Last ~= flag_UpDn_Now)) ) then trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/20-end.wav') flag_LastAnnouce = 20 elseif( newAltRad >= 16) then elseif( (newAltRad >= 15 and flag_LastAnnouce ~= 15) or ( (newAltRad >= 15 and flag_LastAnnouce == 15) and (flag_UpDn_Last ~= flag_UpDn_Now)) ) then trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/15-end.wav') flag_LastAnnouce = 15 elseif( newAltRad >= 11) then elseif( (newAltRad >= 10 and flag_LastAnnouce ~= 10) or ( (newAltRad >= 10 and flag_LastAnnouce == 10) and (flag_UpDn_Last ~= flag_UpDn_Now)) ) then trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/10-end.wav') flag_LastAnnouce = 10 elseif( newAltRad >= 6) then elseif( (newAltRad >= 5 and flag_LastAnnouce ~= 5) or ( (newAltRad >= 5 and flag_LastAnnouce == 5) and (flag_UpDn_Last ~= flag_UpDn_Now)) ) then trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/5-end.wav') flag_LastAnnouce = 5 elseif( newAltRad >= 3.5) then elseif( (newAltRad >= 3 and flag_LastAnnouce ~= 3) or ( (newAltRad >= 3 and flag_LastAnnouce == 3) and (flag_UpDn_Last ~= flag_UpDn_Now)) ) then trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/3-end.wav') flag_LastAnnouce = 3 elseif( newAltRad >= 2) then elseif( (newAltRad >= 1 and flag_LastAnnouce ~= 1) or ( (newAltRad >= 1 and flag_LastAnnouce == 1) and (flag_UpDn_Last ~= flag_UpDn_Now)) ) then trigger.action.outSoundForGroup(myGroupID, 'l10n/DEFAULT/1-end.wav') flag_LastAnnouce = 1 else -- ".....land or CRASHED !!! \xa" end end oldAltRad = newAltRad flag_UpDn_Last = flag_UpDn_Now end that one seems to be not so bad... a few questions : - why do i have an error if i don't place the definitions of global vars between do/end in the predicate ? EDIT I think it is a known bug : found that http://forums.eagle.ru/showthread.php?t=148364 - why DCS seems sometimes not reloading the script even after modification ? I tried reediting the field of input in mission editor where you choose the lua script file, with or wihtout changing directory level to update, not forgetting to save before launching mission i tried editing and updating a copy of the miz file opened in winzip/rar with the new lua script, then save taking care of file names, then reload , no way, the miz file behaves as if i never had changed the script ; although if i open again the miz file in winrar everything is up to date... i even add to close DCS and open it again, but at a point the error occured anyway ; and i am sure : it was a verbose version running with outtext indicating alitutde although script file was different with a new name and without any verbosing... and i checked many times for no errors... everything was ok... i even started creating a brand new mission, and even had the same strange behavior... absolutely non logical... and after some time making other work and relaunching dcs it stopped... strange that is very very annoying when you edit relatively often to debug... anyway to avoid that ? if someone want to test i attach the miz , you have the lua script and wav files in l10n/DEFAULTSA342 batumi altitude script test.miz Edited June 17, 2016 by C6_Hellfrog
C6_Hellfrog Posted June 19, 2016 Author Posted June 19, 2016 (edited) made some progress analysing others's scripts i think i succeeded in compiling mist, my previous script and a part from helicopter script you find in nevada helicopter war mission to regain copilot voicing for incoming and sink rate in a simple mission to test, ( I removed anything else from helo war) seems to work, except incoming detection i am not sure is efficient if someone can have a look... i claim no credit for work from others i used, it is just for me to study and understand scripting. created in 202 caucasus map - sa342 chopper - batumi airfield - some tanks and sams to eliminate (you'll need rearm and refuel) - north of the city along the right river side - you can use nadir points for prudent approach or can go as you want, but advise it is best to stay LOW to survive and stay prudent for launching, tanks have missiles - choose a good launch point... EDIT may have some unit not displaing because using mods i don't remember if all units are vanilla or some are modded... not very complex mission, units are not moving. it was intended for practice. therefore the sounds, that can help beginners. having a option with radiomenu to have it on or off could be something to add... a future step maybe... next step will be playing with cargos as soon as bugs are removed and an update arrives... would like to success adding voice guidance to forestry operation mission by example from CTLD script or helicargo or helo script... then being more comfortable with editor fucntions and tables use in lua to generate much more complicated missions... because it is more immersive... it is hard to begin scripting because of lack of guides and examples, but is very interesting for the perspectives you have once you understand.SA342.batumi convoi training.2.snd.zip Edited June 19, 2016 by C6_Hellfrog
Recommended Posts