beynesairforce Posted December 14, 2012 Posted December 14, 2012 (edited) I try to find a way, in lua, to get the unit name who just enter in a trigger zone (no need to activatea flag) and put it in a "variable" who's call playername. It's my try for a Air race top get only 1 lua script file instead of 1 per player for the scoring. I know that the code inside the scoremission function is working because i test it in an other lua script file (no function and fixed value instead of #playername Thank's for the guy who understand my problem (English is not my motherlanguage) and i continue my search in the lua mystic world. do --when player x reach the finish line zone, we get is name (unit name in game are 1,2,3,4,5,6,7 or 8 ) in playername local playername = function scoreMission() local Time = trigger.misc.getUserFlag('.. #playername ..'1'') --DRAFT get flag1x value player x (player 1 -> flag11, player 2 -> flag21) local Validgate = trigger.misc.getUserFlag('.. #playername ..'0'')--DRAFT get flag1x value player x (player 1 -> flag10, player 2 -> flag20) local Score = 0 --init score value local Penality = 20 --init penality value local Reqpoint = 900 --init reqpoint value local ScoreMsg = 'Votre score joueur '.. #playername .. ':\n' local Invalgate = 70 - Validgate --init nb of invalid gates ScoreMsg = ScoreMsg .. 'Nombres de portes franchies durant la course: ' .. Validgate .. '\n' Score = Invalgate * Penality --score temp score ie just global penality value ScoreMsg = ScoreMsg .. Invalgate .. 'portes loupees soit un malus de ' .. Score .. 'points.\n' Score = Score + Time --final score ScoreMsg = ScoreMsg .. 'Votre score pour cette course: est de ' .. Score .. 'points.\n' if Score <= Reqpoint then ScoreMsg = ScoreMsg .. 'Module valide!' else ScoreMsg = ScoreMsg .. 'Module invalide!' end trigger.action.outText(ScoreMsg, 25) end scoreMission() end Edited December 14, 2012 by beynesairforce [sIGPIC][/sIGPIC] Intel I7-960 / 12Gb Corsair DDR3 Ram / Asus GTX980 Ti Strix / Asus PB287Q / TIR 5+Clip Pro Logitech G13/ TM Warthog N°01295 / Saitek Combat Rudder Pedals / Win Seven 64bits/ TM Cougar MFDs (Vers. 1) / 1 Syncmaster 206BW running Helios
Speed Posted December 14, 2012 Posted December 14, 2012 (edited) At this time, the scripting engine cannot get a player's name. It can get the unit's name. The ability to get a player's name *might* be added in a future patch, as there is a definite need to have this function, in my opinion. What I mean by this is the following: my multiplayer name is "Speed". Pretend I join the unit named "P-51 #1". The scripting engine can only get the "P-51 #1" name- the scripting engine cannot get "Speed". If just getting unit name is OK, why not use the mist.getUnitsInZones function? 1) Include mist into your mission: http://forums.eagle.ru/showthread.php?t=98616 2) Place a mission editor zone. Use the mist.getUnitsInZone function: table in_zone_units = mist.getUnitsInZones(table unit_names, table zone_names, string zone_type) in_zone_units is returned by mist.getUnitsInZones, and contains all the units from unit_names that are in the zones listed in zone_names. Remember that in_zone_units contains the actual Unit object for each unit, not a string name. So to get the names, you would need to do an additional step: do local names = {} local bluePlanes = mist.makeUnitTable( {'[blue][plane]'} ) -- make a UnitNameTable containing all blue planes. local inZoneUnits = mist.getUnitsInZones(bluePlanes, {'victory zone'}) -- let zone_type default to 'cylinder' if #inZoneUnits > 0 then for i = 1, #inZoneUnits do names[#names + 1] = inZoneUnits[i]:getName() end end -- now, the "names" table should contain all the unit names of all the in-zone units. -- Now, insert your code to do whatever you want with the "names" table. end Additionally, keep in mind: the continuous trigger only operates once per second. For an air race mission, you may need higher precision- imagine if the Olympics could only time contestants' times to the nearest second! To get higher precision, you can use the mist.scheduleFunction function. mist.scheduleFunction can operate up to 100 times per second. Check out the Mist manual that is included with the download for a full list of functions and how to use them. Oh and if you wanted to see what is actually inside mist.getUnitsInZones, function mist.getUnitsInZones(unit_names, zone_names, zone_type) zone_type = zone_type or 'cylinder' if zone_type == 'c' or zone_type == 'cylindrical' or zone_type == 'C' then zone_type = 'cylinder' end if zone_type == 's' or zone_type == 'spherical' or zone_type == 'S' then zone_type = 'sphere' end assert(zone_type == 'cylinder' or zone_type == 'sphere', 'invalid zone_type: ' .. tostring(zone_type)) local units = {} local zones = {} for k = 1, #unit_names do local unit = Unit.getByName(unit_names[k]) if unit then units[#units + 1] = unit end end for k = 1, #zone_names do local zone = trigger.misc.getZone(zone_names[k]) if zone then zones[#zones + 1] = {radius = zone.radius, x = zone.point.x, y = zone.point.y, z = zone.point.z} end end local in_zone_units = {} for units_ind = 1, #units do for zones_ind = 1, #zones do if zone_type == 'sphere' then --add land height value for sphere zone type local alt = land.getHeight({x = zones[zones_ind].x, y = zones[zones_ind].z}) if alt then zones[zones_ind].y = alt end end local unit_pos = units[units_ind]:getPosition().p if unit_pos then if zone_type == 'cylinder' and (((unit_pos.x - zones[zones_ind].x)^2 + (unit_pos.z - zones[zones_ind].z)^2)^0.5 <= zones[zones_ind].radius) then in_zone_units[#in_zone_units + 1] = units[units_ind] break elseif zone_type == 'sphere' and (((unit_pos.x - zones[zones_ind].x)^2 + (unit_pos.y - zones[zones_ind].y)^2 + (unit_pos.z - zones[zones_ind].z)^2)^0.5 <= zones[zones_ind].radius) then in_zone_units[#in_zone_units + 1] = units[units_ind] break end end end end return in_zone_units end But Mist is not converted into byte code anyway, so it's all in there if you want to look. Edited December 14, 2012 by Speed Intelligent discourse can only begin with the honest admission of your own fallibility. Member of the Virtual Tactical Air Group: http://vtacticalairgroup.com/ Lua scripts and mods: MIssion Scripting Tools (Mist): http://forums.eagle.ru/showthread.php?t=98616 Slmod version 7.0 for DCS: World: http://forums.eagle.ru/showthread.php?t=80979 Now includes remote server administration tools for kicking, banning, loading missions, etc.
beynesairforce Posted December 15, 2012 Author Posted December 15, 2012 wouaaa .... have to check and remember how to use a table now ..... (8 years i didn't touch C, and it's my first try with lua). yes, i just want to get the "ingame" unit name and not the "multiplayer" name Many thanks :thumbup: [sIGPIC][/sIGPIC] Intel I7-960 / 12Gb Corsair DDR3 Ram / Asus GTX980 Ti Strix / Asus PB287Q / TIR 5+Clip Pro Logitech G13/ TM Warthog N°01295 / Saitek Combat Rudder Pedals / Win Seven 64bits/ TM Cougar MFDs (Vers. 1) / 1 Syncmaster 206BW running Helios
Speed Posted December 16, 2012 Posted December 16, 2012 (edited) wouaaa .... have to check and remember how to use a table now ..... (8 years i didn't touch C, and it's my first try with lua). yes, i just want to get the "ingame" unit name and not the "multiplayer" name Many thanks :thumbup: You can't really do anything in Lua if you don't know how tables work, so you would have to learn them extremely soon anyway :) The official Lua manual is extremely well written, informative, full of useful examples, and available in English, German, Korean, Japanese, and Chinese. The first edition is available for free on the internet (in English only, though). However, it's for Lua 5.0 and DCS uses Lua 5.1, so some of what the Lua 5.0 manual says does not apply for DCS. Edited December 16, 2012 by Speed Intelligent discourse can only begin with the honest admission of your own fallibility. Member of the Virtual Tactical Air Group: http://vtacticalairgroup.com/ Lua scripts and mods: MIssion Scripting Tools (Mist): http://forums.eagle.ru/showthread.php?t=98616 Slmod version 7.0 for DCS: World: http://forums.eagle.ru/showthread.php?t=80979 Now includes remote server administration tools for kicking, banning, loading missions, etc.
beynesairforce Posted December 16, 2012 Author Posted December 16, 2012 after a lot of search and remembering how C language work i finally got something working. do local names = {} local bluePlanes = mist.makeUnitTable( {'[blue][plane]'} ) local inZoneUnits = mist.getUnitsInZones( bluePlanes, {'finish'} ) if #inZoneUnits > 0 then for i = 1, #inZoneUnits do names[#names + 1] = inZoneUnits:getName() end end for i = 0 , #names do if names == 'Player1' then a = 11 b = 21 elseif names == 'Player2' then a = 12 b = 22 elseif names == 'Player3' then a = 13 b = 23 elseif names == 'Player4' then a = 14 b = 24 elseif names == 'Player5' then a = 15 b = 25 elseif names == 'Player6' then a = 16 b = 26 elseif names == 'Player7' then a = 17 b = 27 elseif names == 'Player8' then a = 18 b = 28 end local Time = trigger.misc.getUserFlag(tostring(a)) local Validgate = trigger.misc.getUserFlag(tostring(b)) local Score = 0 local Penality = 20 local Reqpoint = 900 local ScoreMsg = 'Votre score joueur ' .. tostring(names) .. ':\n' local Invalgate = 70 - Validgate ScoreMsg = ScoreMsg .. 'Nombres de portes franchies durant la course: ' .. Validgate .. '\n' Score = Invalgate * Penality ScoreMsg = ScoreMsg .. Invalgate .. ' portes loupees soit un malus de: ' .. Score .. 'points.\n' Score = Score + Time ScoreMsg = ScoreMsg .. 'Votre score pour cette course est de: ' .. Score .. 'points.\n' ScoreMsg = ScoreMsg .. 'Etat du module N114: ' if Score <= Reqpoint then ScoreMsg = ScoreMsg .. ' valide!' else ScoreMsg = ScoreMsg .. ' invalide!' end trigger.action.outText(ScoreMsg, 25) end endAble to print on screen the name of plane who finish the route, getting his score ..... everything to get a valid exam to our squadron. Race is a big word, much close to an air rally. I will apply this to Dragon Air race but with A-10C (no P51D in our squad): a really good challenges to our "cadets" After learning more about lua, i think i will be able to optimize this code (in 2 or 3 month). Thank's for your help Speed. MIST i a really powerfull tool (and you are a good "explainer") [sIGPIC][/sIGPIC] Intel I7-960 / 12Gb Corsair DDR3 Ram / Asus GTX980 Ti Strix / Asus PB287Q / TIR 5+Clip Pro Logitech G13/ TM Warthog N°01295 / Saitek Combat Rudder Pedals / Win Seven 64bits/ TM Cougar MFDs (Vers. 1) / 1 Syncmaster 206BW running Helios
Recommended Posts