pengion 1 Posted March 2, 2020 I'm working on MetaMod_2.00 by Mjjstra, and I want to create a tower defense map using lua. And I have to evaluate whether timer equal to a specific value to excute some actions .I have found the lua function to judge whether timer equals to a spcific value like this function TimerCounterRefresh(self) for counter,value in TimerTable do if counter~="n" then if value == 0 then ExecuteAction("HIDE_COUNTER", counter) --tremove(TimerTable, counter) TimerTable[counter] = nil NumberTimers = NumberTimers - 1 if NumberTimers <= 0 then ExecuteAction("NAMED_DELETE", self) end break elseif value == 1201 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerMin[20]) elseif value == 901 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerMin[15]) elseif value == 601 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerMin[10]) elseif value == 301 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerMin[5]) elseif value == 181 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerMin[3]) elseif value == 61 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerMin[1]) elseif value == 31 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerSec[30]) elseif value == 11 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerSec[10]) elseif value == 4 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerCount[3]) elseif value == 3 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerCount[2]) elseif value == 2 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerCount[1]) end ExecuteAction("COUNTER_MATH_COUNTER", counter, MathOpTable["Subtract"], CounterTable[1]) TimerTable[counter] = TimerTable[counter] - 1 end end end But I can't figure out how to execute the function every second in the game loop to .Can someone help me? Share this post Link to post
Mjjstral 25 Posted May 5, 2020 (edited) Hi pengion, sorry for the late reply ! So I'm not sure how exactly you make the tower defense map and if you use the in the meta mod sdk pdf described procedure to make special meta mod tower defense maps or some variant of your own so I have to give you a general answer: First you set your function that gets executed every second and checks for the timer (assuming you have only one timer set). TIME_THRESHOLD = 120 function Coroutine() for counter,time in TimerTable do if time <= TIME_THRESHOLD then --your action here end end end Next step is to give it to the script timer so that this function above gets executed every second: SetScriptTimer(1,Coroutine,-1) The last argument is the number of executions. -1 means execute infinitely. The first argument is the time intervall between each execution. Note you can also create custom gamemode luas as descibed in the meta mod manual. Btw I'm working on a new successor project that will come as a dll mod and will in particular support new custom gamemodes by a new skirmish setup submenu (news on the sage modding discord). Edited May 5, 2020 by Mjjstral 1 Share this post Link to post
pengion 1 Posted May 6, 2020 1 hour ago, Mjjstral said: Hi pengion, sorry for the late reply ! So I'm not sure how exactly you make the tower defense map and if you use the in the meta mod sdk pdf described procedure to make special meta mod tower defense maps or some variant of your own so I have to give you a general answer: First you set your function that gets executed every second and checks for the timer (assuming you have only one timer set). TIME_THRESHOLD = 120 function Coroutine() for counter,time in TimerTable do if time <= TIME_THRESHOLD then --your action here end end end Next step is to give it to the script timer so that this function above gets executed every second: SetScriptTimer(1,Coroutine,-1) The last argument is the number of executions. -1 means execute infinitely. The first argument is the time intervall between each execution. Note you can also create custom gamemode luas as descibed in the meta mod manual. Btw I'm working on a new successor project that will come as a dll mod and will in particular support new custom gamemodes by a new skirmish setup submenu (news on the sage modding discord). Thank you for reply! Well I have figured out that you use a "coroutine dummy" that repeatetedly kills itself and spawns another dumm and calls the function. Now I'm curious about these functions work in your lua: 1.set the counter to a specific value 2.SpawnAtPosition I found that whatever value I pass,the counter is set to 0 and the position is always bottom left corner. Btw what does custom gamemode means?Does the new skirmish setup submenu means a new UI in the game? Share this post Link to post
Mjjstral 25 Posted May 6, 2020 11 hours ago, pengion said: I found that whatever value I pass,the counter is set to 0 and the position is always bottom left corner. You first need to initialize the global counters by using InitializeGCounters(). This will setup 10 counters with values 1 to 10. SetCounter will then do math with these global counters to get your desired counter value. This is because the regular counter commands for some reason don't work. So this is a workaround that works great. 11 hours ago, pengion said: 2.SpawnAtPosition This is a compilcated monster that fortunately gets replaced in the sage meta tool project with a muuuch faster and more convenient solution. This old method works like that in short: Spawns ocl dummy anchors with positional offsets (defined in ocl) on itself again and again until the desired position is reached. Then it uses "CREATE_NAMED_ON_TEAM_AT_OBJECTTYPE" to spawn the actual object on the invisible anchor. It also uses a self made lua stack system to process multiple spawn requests because that whole method gets not executed between two frames. The new method will work like that with a COORD3D lua table {x,y,z}: ExecuteAction("UNIT_SPAWN_NAMED_LOCATION_ORIENTATION", ObjectName, ObjectType, Team, {PositionX, PositionY, PositionZ}, Orientation) 12 hours ago, pengion said: Btw what does custom gamemode means?Does the new skirmish setup submenu means a new UI in the game? Yes completely new UI and a parser to show infos about these gamemodes + update functionality (pastebin dl based). Share this post Link to post
pengion 1 Posted May 7, 2020 (edited) 14 hours ago, Mjjstral said: Yes completely new UI and a parser to show infos about these gamemodes + update functionality (pastebin dl based). Well,that is attractive to me. I wish I could participate in it (my major is software) Btw the lua seems unable to handle situation when players save game or load game, because a game can be save many times and the same with load game ps:I try to use lua to spawn object but fail.....like this ExecuteAction("UNIT_SPAWN_NAMED_LOCATION_ORIENTATION", "nw", "SovietAntiAirShip", "Player_1/teamPlayer_1", {200.00, 200.00, 0.00}, 45) Edited May 7, 2020 by pengion Share this post Link to post
Mjjstral 25 Posted May 7, 2020 8 hours ago, pengion said: Well,that is attractive to me. I wish I could participate in it (my major is software) Nice ! Will probably put it on github at some point 8 hours ago, pengion said: Btw the lua seems unable to handle situation when players save game or load game, because a game can be save many times and the same with load game Yes see this question. In the long run extending the actual savegame routine would be the way to go I admit. 8 hours ago, pengion said: ps:I try to use lua to spawn object but fail.....like this ExecuteAction("UNIT_SPAWN_NAMED_LOCATION_ORIENTATION", "nw", "SovietAntiAirShip", "Player_1/teamPlayer_1", {200.00, 200 As I have written this is how it will work in sage meta tool (unreleased yet). The game is not able to handle coord3d parameters from lua in any way so I had to write a new parameter parser for it. Until then use the old method but keep in mind it depends on objects and ocls (not pure lua). Share this post Link to post