rge75 Posted May 5, 2018 Posted May 5, 2018 I'm new to LUA but since it seems similar to other languages, I'll get used to it ;-) However, when doing some coding, the following questions came to my mind: - I'm using trigger.action.outText(table.concat(msg), 10) to display text. Is there also a similar function to display text to one group only? While googling, I noticed there's also trigger.action.OutTextForCoalition, so I guess there's something like trigger.action.OutTextForGroup? Is there a list of all the trigger.action commands somewhere? - How can I get e.g. aircraft/pilot name who triggered an event? - Are all variables variant by default? - Is there a way to read out the name of a trigger? I e.g. have several triggers labeled "Checkpoint1", "Checkpoint2", "Checkpoint3" and I'd like to use something like substr('trigger-name', 10,1) to get the number of the trigger name. - In Multiplayer, does the "Once" event happen once for every pilot or once global? I'm initializing some variables with "Time More 1 / Do Script", so is this triggered once the server starts. My DCS videos https://www.youtube.com/channel/UCJX2av4UE4xqWto3y8EZWMw [sIGPIC][/sIGPIC]
rge75 Posted May 5, 2018 Author Posted May 5, 2018 Looks like I found a solution for the first question ;-) http://wiki.hoggit.us/view/DCS_singleton_trigger My DCS videos https://www.youtube.com/channel/UCJX2av4UE4xqWto3y8EZWMw [sIGPIC][/sIGPIC]
Grimes Posted May 5, 2018 Posted May 5, 2018 - How can I get e.g. aircraft/pilot name who triggered an event? Can't use the events available in the UI, gotta us the scripting engine to do it. Event handlers return a table for each event. If applicable it will have an initiator object which is a unit that caused the event. For example the shot event has those values. initiator is the unit object and weapon is a weapon object. Likewise if you have the handler setup to return a table "event" for that then you can simply do something like: Unit.getPlayerName(event.initiator) to return a string of the players name - Are all variables variant by default? Not sure I understand the question. - Is there a way to read out the name of a trigger? I e.g. have several triggers labeled "Checkpoint1", "Checkpoint2", "Checkpoint3" and I'd like to use something like substr('trigger-name', 10,1) to get the number of the trigger name. Yes, but not in the way you are thinking of it. Whenever you run do script or a lua predicate it doesn't have any functionality to know where it is coming from. The only "self" type variable is found with tasks run via group command to do script. In those you can do something like: local groupObject = ... Anyways the whole mission file is accessible to the scripting engine via the env.mission table. This is how a lot of scripts parse the table to create a DB of all groups and units in the mission. Specifically the name of the trigger is stored in env.mission.trigrules, whereby each trigger is indexed numerically. [1] = { ["rules"] = { [1] = { ["seconds"] = 1, ["coalitionlist"] = "", ["predicate"] = "c_time_after", ["zone"] = "", }, -- end of [1] }, -- end of ["rules"] ["comment"] = "AI OFF", There is a very narrow middle ground where it is beneficial to use both triggers and scripting to accomplish your design goals. The events in the editor are extremely basic and frankly have limited utility. Events in the scripting engine are more complex, but offer a huge assortment of possibilities. - In Multiplayer, does the "Once" event happen once for every pilot or once global? I'm initializing some variables with "Time More 1 / Do Script", so is this triggered once the server starts. It happens once on the host machine. All code is run on the host, any actions from that code will be synced to the client where-ever applicable. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
rge75 Posted May 6, 2018 Author Posted May 6, 2018 Thanks a lot for your detailed and helpful reply. It doesn't look like I'll be able to solve my "problem" with the event handlers, therefore I'll probably leave my triggers the way they are. It simply means some adjustments when cloning some triggers and I was trying to avoid that. For the variables, I'm used to define them. In many languages, if you don't the datatype is variant. Thus, it can be integer, string, date or whatever depending on it's value. The reason I was asking is because I was using substr(string,1) to extract a number, but I think LUA did not interpret it as a number. Or in other words, x=5 is not the same as x="5" ;-) Long story short, I was looking for something like x = cint("5") to convert the string into an integer. I found the explanation in the LUA documentation though (2.1 values and types): http://www.lua.org/manual/5.3/manual.html The command is x = tonumber("5") I think I did not quite understand the part with the env.mission.table, but I'll have a deeper look into it. My DCS videos https://www.youtube.com/channel/UCJX2av4UE4xqWto3y8EZWMw [sIGPIC][/sIGPIC]
Grimes Posted May 6, 2018 Posted May 6, 2018 Ok so there is the env singleton, which contains a few functions, mostly for printing to DCS.log. The .miz file that contains your mission is basically an archive file like a zip or rar. Within it are at least 5 files. One of them, "mission" is contains most of the data like units, triggers, zones, etc and is basically a giant lua table. This table is accessible via env.mission. Which can be iterated like any other table. For example I have this code in MIST to organize trigger zones if env.mission.triggers and env.mission.triggers.zones then for zone_ind, zone_data in pairs(env.mission.triggers.zones) do if type(zone_data) == 'table' then local zone = mist.utils.deepCopy(zone_data) zone.point = {} -- point is used by SSE zone.point.x = zone_data.x zone.point.y = 0 zone.point.z = zone_data.y mist.DBs.zonesByName[zone_data.name] = zone mist.DBs.zonesByNum[#mist.DBs.zonesByNum + 1] = mist.utils.deepCopy(zone) --[[deepcopy so that the zone in zones_by_name and the zone in zones_by_num se are different objects.. don't want them linked.]] end end end The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
rge75 Posted May 6, 2018 Author Posted May 6, 2018 Ok, thank you. I think I understood it now :-) My DCS videos https://www.youtube.com/channel/UCJX2av4UE4xqWto3y8EZWMw [sIGPIC][/sIGPIC]
Recommended Posts