Sleem Posted July 14, 2011 Posted July 14, 2011 After reading the thread about random spawning of units I've slightly modified this to allow spawning to be influenced by the number of players in the mission, and so adjust the difficulty. Essentailly I use a list of flags to represent a list of units. Everytime a player joins (using Once Unit Alive) I run a lua script which switches on each flag if math.random() is less than x. (x is usually the fraction of units to activate for each player e.g. 0.25 for 4 players, etc.) Hence if this script is run 4 times for each player most (but probably not all) flags should be on. You can obviously increase/dcrease x to modify the behaviour of this. (Also as the time of the player joining is used to seed there should be more variation in the randomness.) math.randomseed( os.time() ) math.random(); math.random() for i = 1, 10 do if math.random() < 0.25 then trigger.setUserFlag(100 + i, true) end end The above sets a list of ten flags 101-110 to on with a 25% chance and can be run repeatedly on the same set of flags. Each random unit can then be activated using a ONCE time since flag condition. No one has mentioned this sort of thing before so thought I'd share and hope someone finds it useful. 1
Ripcord Posted July 14, 2011 Posted July 14, 2011 This is perfect for use in MP missions.... essentially a force multiplier. Great stuff. [sIGPIC][/sIGPIC]
Ripcord Posted July 14, 2011 Posted July 14, 2011 Question that is related here...... if I may. Say I wanted to make an AI flight go away in the event that a second player joins a mission in MP -- in my example it would be a single A-10C AFAC flight. Could I do that using this ONCE UNIT ALIVE trigger command? To clarify, the HOST is flying as flight lead for a CAS flight and the CLIENT player flight would be AFAC. The AI AFAC flight would need to disappear or deactivate or whatever when the CLIENT player joints. No need for the AI AFAC if we now have a human player flight set up to do that. Alternatively I could just send the AI flight back to RTB..... could that be done? Will need to experiment a bit with this. Ripcord [sIGPIC][/sIGPIC]
Grimes Posted July 14, 2011 Posted July 14, 2011 It would be safer to force the AI AFAC to head to a holding waypoint where they can orbit and easily get fuel if needed. If the client aircraft disconnects at any time the AI AFAC is commanded to fly back to the target area. Just a thought. 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
Speed Posted July 15, 2011 Posted July 15, 2011 (edited) Oddly enoguh, when I used the math.randomseed(os.time()), it seemed I wasn't getting random numbers, and when I didn't seed at all, I got random numbers... anyway... that's all I remember about my experiments with math.random in Lua... I could easily be wrong, as that was a long time ago... several months. You're getting verified, random values? While we're talking about it, I was planning on a bunch of random functions to be included in a Lua function library mod I am working on. Anyone got some suggestions? My ideas are: rand_activate(group_name, probability) rand_deactivate(group_name, probability) rand_flag_on(flag_number, probability) rand_flagrange_on(flag_number_start, flag_number_end, probability) randvalue = rand_value(min, max) Anyone got any suggestions on some other basic functions while we're at it? I don't usually include much randomness in my missions because it's just too much damn work... so I'm not the best judge of this. Edited July 15, 2011 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.
104th_Crunch Posted July 15, 2011 Posted July 15, 2011 Nice idea! Too bad you must be a programmer or mathematician to understand how you did it lol. Triggers are great, but some of the more complex ideas are above common knowledge me thinks. At least my knowledge anyway.
Speed Posted July 15, 2011 Posted July 15, 2011 (edited) Nice idea! Too bad you must be a programmer or mathematician to understand how you did it lol. Triggers are great, but some of the more complex ideas are above common knowledge me thinks. At least my knowledge anyway. Well, the idea is to provide a simple set of functions that can be used by a wider audience. So to wrap this one into a more simple form: function rand_flag_range(flag_start, flag_end, prob) if randseeded == nil then math.randomseed( os.time() ) randseeded = true end math.random(); math.random() for i = 0, (flag_end - flag_start) do if math.random() < prob then trigger.setUserFlag(flag_start + i, true) end end end Have someone copy and paste that code and make it run just after mission start, and it creates a function called rand_flag_range. Now, the mission maker only has to have very minimal knowledge of Lua to use it- all they have to do is to call the rand_flag_range function in a unit's triggered action. The format is like this: rand_flag_range(100, 110, 0.25) Running this code (by using a "Run Script" triggered action) will make flags 100 through 110 each to have a probability of 0.25 of being set true. So by turning it into a function, you go from having to run this Lua code: math.randomseed( os.time() ) math.random(); math.random() for i = 1, 10 do if math.random() < 0.25 then trigger.setUserFlag(100 + i, true) end end to simply having to run this Lua code: rand_flag_range(100, 110, 0.25) The first is hard to understand if you don't know Lua. The second one isn't. And with the second one, you can re-use it over and over again more easily than the first, like this would also work: rand_flag_range(1, 50, 0.1) Now each flag from 1 through 50 has a 10% chance of being set true when the above Lua code is run. Turning your Lua scripts into function calls is the way to go if you want the easiest implementation for the average mission creator who doesn't know how to write any Lua... it also makes it easier even if you do know Lua. Edited July 15, 2011 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.
Sleem Posted July 15, 2011 Author Posted July 15, 2011 Speed is right - a function library would be a great addition. By the way, how's that lua function guide coming along? I've not tested how random the random numbers are. Come to think of it as os.time() only returns whole seconds you should probably only seed once or not at all. Meanwhile I've attached a mission so you can see what I mean. The random function is attached to a dummy unit. This also tests out Ripcord's idea of a flight switching on/off. Slot 3 Activates/Deactivates the F16s - this seems to crash A10 quite often, but not sure why. Slot 4 sends them home/calls them back.Test.miz
Grimes Posted July 15, 2011 Posted July 15, 2011 Activating and Deactivating a group only works once, so maybe the game gets a little unstable if those triggers keep running. I'd add a "Time more" to their activation trigger, so that if player 3 doesn't join for 5 minutes the group will activate. I'd remove the deactivate trigger entirely. All it takes is for someone to jump in the slot, spawn, realize they forgot to turn trackIR on and disconnect for the SEAD flight to be rendered completely useless. Honestly, just use deactivate group when you know said group has been "used." 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
theghost Posted July 15, 2011 Posted July 15, 2011 speed I hope that for once I understand what you write ... :) The 147 Squadron commander "The Goring Ram"
Speed Posted July 15, 2011 Posted July 15, 2011 Speed is right - a function library would be a great addition. By the way, how's that lua function guide coming along? Sending a PM on where you can download the unfinished first draft. It's 30+ pages of guide (with lots of code examples :) ), followed by 20 pages of notes to self/additional functions. I've not tested how random the random numbers are. Come to think of it as os.time() only returns whole seconds you should probably only seed once or not at all. Yea, when I packaged your script into a function a few posts above here, I did this check: if randseeded == nil then math.randomseed( os.time() ) randseeded = true end So if the global variable "randseeded" doesn't exist, then do a math.randomseed(os.time()) and create the global variable called "randseeded". This should make sure that math.randomseed(os.time()) only ever runs a single time. Which is another good reason to package this script up as a function like that, you can ensure that math.randomseed only ever operates a single time, without having to break it out into its own separate little script... though you could have done the same thing in the full script. This also tests out Ripcord's idea of a flight switching on/off. Slot 3 Activates/Deactivates the F16s - this seems to crash A10 quite often, but not sure why. Slot 4 sends them home/calls them back. Possibly a better way to do it is to create a Lua function or script that gets the time-averaged number of players flying the mission. So, if fifteen minutes into the mission, the time-averaged number of players flying the mission is less than three, then spawn the extra AI aircraft. With scripts like those, you can make 8 player missions that auto-scale in difficulty so that it is not any more challenging with two players than it is with eight. That's what I did in a Black Shark/FC2 mission I made, "Attack on Krasnodar", but it took A LOT of triggers. It is much more simple and easier to implement such things in Lua. I had it in mind to do the same thing with my most recent mission, "Kashuri CAS", but then patch 1.1.0.8 came out and broke artillery. 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.
Druid_ Posted July 15, 2011 Posted July 15, 2011 Oddly enoguh, when I used the math.randomseed(os.time()), it seemed I wasn't getting random numbers, and when I didn't seed at all, I got random numbers... anyway... that's all I remember about my experiments with math.random in Lua... I could easily be wrong, as that was a long time ago... several months. You're getting verified, random values? That was my experience. Hence my random number generator using tables. With regard to your functions, good effort but is it worth writing lua functions for 1 line triggers in ME. Don't think anyone will use it. e.g. rand_activate(group_name, probability) would be ONCE blah RANDOM(value%) GROUP ACTIVATE(groupname) randvalue = rand_value(min, max) however is a good one not easily done in GUI triggers. I completely agree on the adding of randomness to missions. Its so easy to overdo it and lose touch with the substance of the mission. A bit like watching a movie with great special effects but no storyline. In the time it takes to add so much randomness to a mission you could have written another 3 missions. i7-7700K : 16Gb DDR4 2800 Mhz : Asus Mobo : 2TB HDD : Intel 520 SSD 240gb : RTX 2080ti: Win10 64pro : Dx10 : TrackiR4 : TM Warthog : ASUS ROG SWIFT PG348Q
Speed Posted July 15, 2011 Posted July 15, 2011 (edited) That was my experience. Hence my random number generator using tables. With regard to your functions, good effort but is it worth writing lua functions for 1 line triggers in ME. Don't think anyone will use it. e.g. rand_activate(group_name, probability) would be ONCE blah RANDOM(value%) GROUP ACTIVATE(groupname) Incorrect, unfortunately. Once -> Random(%)-> Group activate will, over time, eventually activate a group with 100% probability (unless the probability % is set to 0) because the Random condition is evaluated once every second until it becomes true, at which point the group is activated and the trigger is removed from the internal Lua trigger table in the "mission" environment. The "Once" only refers to how many times the trigger actions execute, not how many times the trigger conditions are evaluated. Once, Continuous, and Switched triggers are all evaluated continuously. However, Once->(Conditions)->rand_activate(group, prob) will only run the probability function ONE time, and hence, will result in the correct behavior. However, something like this should also work to spawn a group at a certain point in the mission: Once->Random(%)AND Time More (x) and Time Less than (x+1)->Activate Group Depending on how Time more and Time less are evaluated, you should be able to set this trigger up so that it is only ever evaluated a single time. But at that point, due to uncertainties such as that, plus the general complexity (if you want this to evaluate not at a specific time but relative to some specific event you need to use flags and time since flag conditions) then I would argue that the Lua function is vastly more simple. I completely agree on the adding of randomness to missions. Its so easy to overdo it and lose touch with the substance of the mission. A bit like watching a movie with great special effects but no storyline. In the time it takes to add so much randomness to a mission you could have written another 3 missions. That is my opinion also, it ends up taking an incredible amount of time to do a lot of randomization, and in that time you could have just made another mission just like the first. Edited July 15, 2011 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.
Sleem Posted July 31, 2011 Author Posted July 31, 2011 After 1109 changes breaking the above method I've worked a way to do the same thing using just the triggers part of the ME. You need a flag to track the number of times to test each units random activation as follows: ONCE - UNIT ALIVE player1 - FLAG INCREASE 100 by 1 ONCE - UNIT ALIVE player2 - FLAG INCREASE 100 by 1 ... ONCE - UNIT ALIVE playerX - FLAG INCREASE 100 by 1 ONCE - FLAG 100 MORE 0 AND RANDOM(15) ACTIVATE GROUP 1 (can have any % desired) ONCE - FLAG 100 MORE 0 AND RANDOM(15) ACTIVATE GROUP 2 ... ONCE - FLAG 100 MORE 0 AND RANDOM(15) ACTIVATE GROUP X CONTINUOUS - FLAG 100 MORE 0 - FLAG DECREASE 100 by 1 Hopefully lua will become useful again in the future.
Recommended Posts