Jump to content

Recommended Posts

Posted

Hey guys & gals,

I am working on getting respawning on a timer to work, using Mist script.

I have instant respawn working with the following script:

if not Group.getByName('RUS-T72B-6') then
   mist.respawnGroup('RUS-T72B-6', true)
 end

 

but now I want certain groups to respawn after a certain amount of minutes so they dont respawn in your face right away.

I used:

if not Group.getByName('RUS-T72B-6') then
   mist.respawnGroup('RUS-T72B-6', 120)
 end

 

but they keep respawning instantly, the timer doesn't work and I cant find anything that will work with this simple script. I do have to say, this is my first time using anything like Mist, the coding is new to me, I get the basics but I cant do anything fancy with it yet.

Could I get some help with just a simple respawn timer script?

Best Regards & Thanks in advance.

Posted

Using a number for the 2nd parameter in mist.respawnGroup isn't a delay in respawning the group. It is a delay for when the group task gets assigned. At first glance you could schedule mist.respawnGroup to occur at a later point in time, however I assume you are constantly checking if not Group.getByName, as a result it'd just schedule mist.respawnGroup however many times between when its dead and when the group actually respawns. 

 

 One way would be to add extra conditions. 

if not Group.getByName('RUS-T72B-6') then
   if not rusB6Respawn then     --- checks if a time was saved when the group was killed
      rusB6Respawn = timer.getTime()             --- creates a global variable for that group
   elseif rusB6Respawn + 120 < timer.getTime()         -- checks if the time the group died + 120 seconds is less than the current time
    	 mist.respawnGroup('RUS-T72B-6', true)      -- respawn
         rusB6Respawn = nil      -- delete value so it can be created again with the initial check
   end
  
end

At that point it might be easier to just create a function that checks and manages the groups you want to check. Maybe it has a table of the group group names and each time they died at, which iterates the table to respawn them as needed. Basically the above lua example is fine for a few groups, but gets annoying fast because you need a unique global variable for when each respawns. 

  • Like 1

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Posted

Thank you for your example, I am not a 100% clear on the last line:

         rusB6Respawn = nil      -- delete value so it can be created again with the initial check

The rest I understand and it should work for what I am trying to do but I have to be honest, I understand the code and what it does, but to write my own is still something I am unable to do. My coding skills are, let's say, lacking. It's like reading German, I know what it says and I can generally follow, but to speak the language is something else, it that makes sense.

Posted

I currently have this:

if not Group.getByName('RUS-RESPW-TEST-1') then
    trigger.action.outText("Russian T90 Destroyed. Reinforcements incoming in 120 seconds...", 6, true)
    timer.scheduleFunction(myRespawnGroup, 'RUS-RESPW-TEST-1', timer.getTime() + 120)
end


With an function in a seperate trigger:

function myRespawnGroup(groupName)
  mist.respawnGroup(groupName, true)
end

 

This code works, However, the message that it gives, saying, they died stays in screen for 120 seconds, or for as long as I set the timer to... which can fill up the screen rapidly when several groups are being killed close together.

Posted
50 minutes ago, DCS.Tyrant said:

This code works, However, the message that it gives, saying, they died stays in screen for 120 seconds, or for as long as I set the timer to...

Remember that 

if not Group.getByName('RUS-RESPW-TEST-1') then
	... do something ...

the condition "not Group.getByName('RUS-RESPW-TEST-1') remains true until the respawn happens. So if you regularly (say every second) invoke the check, and the test returns true the first time, it will also return true the second time, and every other second until the first scheduled respawn happens. This may account for the many messages that you receive. You'll also respwn the same group some 120 times in the next 120 seconds - something that luckily has few consequences since you replace the newly spawned group with an even newer one each time you respawn.

Please do not post the same subject in multiple threads.

Posted
4 hours ago, cfrag said:

the condition "not Group.getByName('RUS-RESPW-TEST-1') remains true until the respawn happens. So if you regularly (say every second) invoke the check, and the test returns true the first time, it will also return true the second time, and every other second until the first scheduled respawn happens. This may account for the many messages that you receive. You'll also respwn the same group some 120 times in the next 120 seconds - something that luckily has few consequences since you replace the newly spawned group with an even newer one each time you respawn

I havent noticed a lot of respawns, that is not what I meant with the messages. The issue is, the message stays in the screen for as long as I set the respawn timer at, so if I say, respawn a group after 5 minutes, the message will stay in screen for 5 minutes.

Now lets say, People on the server kill 10 groups, all with a respawn timer, the screen will get cluttered with those messages that wont go away until the respawn actually happens.

 

I tried adding:

msg.displayTime = 15

but for some reason I cant get it to work, or my implementation of it  in the code line is faulty... it's not giving me an error message.

Posted
8 minutes ago, DCS.Tyrant said:

Now lets say, People on the server kill 10 groups, all with a respawn timer, the screen will get cluttered with those messages that wont go away until the respawn actually happens.

IMHO, that is exactly what the symptoms would be if the respawn happens regularly: the message is re-issued with every respawn, and the re-spawn happen every second. So until the respawn occurs (plus a couple of seconds for the time-out), the message simply overwrites itself and will appear to remain on-screen, while in reality it is simply redrawn. To verify if this is the case, try this: Change 

trigger.action.outText("Russian T90 Destroyed. Reinforcements incoming in 120 seconds...", 6, true)

to 

trigger.action.outText("Russian T90 Destroyed. Reinforcements incoming in 120 seconds...", 6, false)

(change last param to false).

Now the screen isn't erased, and the messages start stacking up. Kill a single unit. If you see lots and lots of messages appear, you are constantly rescheduling respawns until the first respawn happens, 120 seconds down the road.

Posted
1 hour ago, cfrag said:

 

trigger.action.outText("Russian T90 Destroyed. Reinforcements incoming in 120 seconds...", 6, false)

(change last param to false).

Now the screen isn't erased, and the messages start stacking up. Kill a single unit. If you see lots and lots of messages appear, you are constantly rescheduling respawns until the first respawn happens, 120 seconds down the road.

Changing it to false made it spam the message over and over again. until the actual respawn happens. So if I set the timer of the respawn to 15 minutes, the message will keep spamming for 15 minutes.

My original problem was that the message doesn't disappear, not that it spams, it just stays on the screen.

I tried adding:

msg.displayTime = 25

but it didnt work for some reason.
Posted
1 hour ago, cfrag said:

you are constantly rescheduling respawns until the first respawn happens, 120 seconds down the road.

I also don't really understand why it would constantly reschedule, how would I fit this, to just have it schedule a single respawn after every group kill ?

Posted
Just now, DCS.Tyrant said:

My original problem was that the message doesn't disappear, not that it spams, it just stays on the screen.

My apologies for being unclear. The fact that the message seems to stay on the screen is not the problem. It's the symptom of a much graver problem: you are queuing up a lot of scheduled respawns, one for each message that appears on the screen. The message keeps re-apprearing (or keeps stacking up) because in the time between the point where your unit is killed, and the time that it is re-spawned, your test is regularly invoked. Since the unit is still dead, and the respawn scheduled at a future time, another respawn is scheduled, and message is written. And again, and again, etc - until, finally, the first scheduled respawn happen. After that, for as long as the original delay was scheduled, your unit is re-spawned. Since it's a respawn with the same name for unit and group, the old one is replaced. Should you try to kill or move the unit, it will be replaced over and over again until the last scheduled respawn happened. If that was 15 minutes, your unit respawns regularly for the next 15 minutes. If your test happens once every second, that would be 15*60 = 900 respawns of that unit.

How can you avoid this? By using additional means like for example a flag that remembers that a respawn was scheduled, and clearing that flag when the respawn has happened.

Here's how this could look in general (WARNING: not tested)

if not Group.getByName('RUS-RESPW-TEST-1') and trigger.misc.getUserFlag("respawnScheduled") < 1 then
    trigger.action.setUserFlag("respawnScheduled", 1) -- remember and prevent additional respawns                                                                
    trigger.action.outText("Russian T90 Destroyed. Reinforcements incoming in 120 seconds...", 6, true)
    timer.scheduleFunction(myRespawnGroup, 'RUS-RESPW-TEST-1', timer.getTime() + 120)
end

I'm using the 'Flag' (something in DCS that has a name and can remember numbers for us) named "respawnScheduled" to remember for us that we have scheduled a respawn. When we schedule the respawn, we set the "Flag" to a value greater than 0. This prevents respawns until the flag is cleared. That happen on respawn, for example like this:

function myRespawnGroup(groupName)
  mist.respawnGroup(groupName, true)
  trigger.action.setUserFlag("respawnScheduled", 0) -- reset so we can respan if killed again 
en

With the flag named "respawnScherduled" flip/flopping between scheduled and executed respawns, this will prevent the reschedules. Note that if you use a similar process for other units, you need differently named flags so they don't "talk over each other".

Posted
21 minutes ago, cfrag said:
if not Group.getByName('RUS-RESPW-TEST-1') and trigger.misc.getUserFlag("respawnScheduled") < 1 then
    trigger.action.setUserFlag("respawnScheduled", 1) -- remember and prevent additional respawns                                                                
    trigger.action.outText("Russian T90 Destroyed. Reinforcements incoming in 120 seconds...", 6, true)
    timer.scheduleFunction(myRespawnGroup, 'RUS-RESPW-TEST-1', timer.getTime() + 120)
end

I'm using the 'Flag' (something in DCS that has a name and can remember numbers for us) named "respawnScheduled" to remember for us that we have scheduled a respawn. When we schedule the respawn, we set the "Flag" to a value greater than 0. This prevents respawns until the flag is cleared. That happen on respawn, for example like this:

function myRespawnGroup(groupName)
  mist.respawnGroup(groupName, true)
  trigger.action.setUserFlag("respawnScheduled", 0) -- reset so we can respan if killed again 
en

 

This seems to be working, so if I understand correctly, I give every group a unique name, and give each group their own trigger, with the code.

The Function I only have to add once, in a seperate trigger, correct?

Posted
Just now, DCS.Tyrant said:

The Function I only have to add once, in a seperate trigger, correct?

Well, you'd have to 'pimp' the code a bit so it sets a flag for each and every group correctly, and it can be automated, yes. You'd need something along the lines of this:

function checkRespawn(groupName)
	if not Group.getByName(groupName) and trigger.misc.getUserFlag(groupName) < 1 then
		trigger.action.setUserFlag(groupName, 1) -- remember and prevent additional respawns                                                                
		trigger.action.outText("Group " .. groupName .. " destroyed. Reinforcements incoming in 120 seconds...", 6, true)
		timer.scheduleFunction(myRespawnGroup, groupName, timer.getTime() + 120)
	end
end

function myRespawnGroup(groupName)
  mist.respawnGroup(groupName, true)
  trigger.action.setUserFlag(groupName, 0) -- reset so we can respan if killed again 
end 

and instead of checking the unit by name directly, you invoke the kill test like this:

checkRespawn('RUS-RESPW-TEST-1')

That should then work for all groups

Posted

One final question regarding the message it gives once a group is destroyed.

The 6 at the end, thats display time correct? so if I change that to 15, it should be on screen for 15 seconds ?

trigger.action.outText("Group " .. groupName .. " destroyed. Reinforcements incoming in 120 seconds...", 6, true)
Posted
12 hours ago, DCS.Tyrant said:

Thank you for your example, I am not a 100% clear on the last line:

         rusB6Respawn = nil      -- delete value so it can be created again with the initial check

The rest I understand and it should work for what I am trying to do but I have to be honest, I understand the code and what it does, but to write my own is still something I am unable to do. My coding skills are, let's say, lacking. It's like reading German, I know what it says and I can generally follow, but to speak the language is something else, it that makes sense.

Setting a flag of the group name is the same thing as what that was doing. It was a value, that when it exists means that the group was going to respawn and acted as a lock of sorts to prevent the multiple messages or multiple respawns. Literally just a different way to do the same thing. 

 

And yes, the number value in outText is the display time. 

https://wiki.hoggitworld.com/view/DCS_func_outText

With the 3rd value set to true it will display the message in a different format and will overwrite any existing message being displayed. 

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...