Jump to content
roguetrooper

Prevent death at 0% oxygen?

Recommended Posts

Is there any way to prevent a player's death at 0% oxygen?

(Except a looping check for the oxygen level and let that level never sink below e.g. 10%)

Share this post


Link to post
Share on other sites
23 minutes ago, roguetrooper said:

Is there any way to prevent a player's death at 0% oxygen?

(Except a looping check for the oxygen level and let that level never sink below e.g. 10%)

What other ways were you thinking about?

There's no relevant eventhandler or anything similar other than do a simple check once every frame, that's technically not a loop.

 

//initplayerlocal.sqf or similar
addMissionEventHandler ["EachFrame",{if (getOxygenRemaining player < 0.1) then {player setOxygenRemaining 0.1}}];

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, roguetrooper said:

Is there any way to prevent a player's death at 0% oxygen?

(Except a looping check for the oxygen level and let that level never sink below e.g. 10%)

 

Sometimes loop are better. That's the case here.

[] spawn {while {true} do { waitUntil {sleep 2; getOxygenRemaining player < 0.1}; player setOxyGenRemaining 0.1 }};

will check every 2 seconds.

Share this post


Link to post
Share on other sites
13 minutes ago, pierremgi said:

 

Sometimes loop are better. That's the case here.

[] spawn {while {true} do { waitUntil {sleep 2; getOxygenRemaining player < 0.1}; player setOxyGenRemaining 0.1 }};

will check every 2 seconds.

 

How long does it take to die without O2 in the game? 2 secs may be too long. :icon15:  I really have no idea. I only died in a mini-sub once because I falsely assumed they had internal oxygen supply. Geez was I wrong.

Share this post


Link to post
Share on other sites
6 minutes ago, AZCoder said:

 

How long does it take to die without O2 in the game? 2 secs may be too long. :icon15:  I really have no idea. I only died in a mini-sub once because I falsely assumed they had internal oxygen supply. Geez was I wrong.

Roughly 8 seconds from 0.1 to 0.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

LOL I didn't really expect an answer, but good to know!

Share this post


Link to post
Share on other sites

I have a modify BTC Quick Revive that the players will never die only stay unconscious or incapacitated including on the bottom of the ocean for a search and rescue mission I made a while ago based on a movie called universal Soldier ? if the OP still needs to prevent death from lack of oxygen.

Share this post


Link to post
Share on other sites

@Grumpy Old Man and @pierremgi 

 

What is the difference in call the code into the game from mission init.sqf or a initplayerlocal.sqf

 

What is the difference addMissionEventHandler  vs [] spawn {while {true}

 

I am always done with a modify AIS wound system that I am working on. I have this in a modify BTC  Quick Revive script but the overall script is lacking functionally that AIS has and AIS is still being updated by psychobastard.

 

I am trying to lean more about scripting my ideas and mission design are superior then my working knowledge of scripting :down:

 

 

Share this post


Link to post
Share on other sites

@Grumpy Old Man your way allows for team switch to still be used with no death of the unit If you switch into them  while they are under water.   Pierremgi way the unit will not die if it's an AI  but if a human player switches into that unit it will die.  FYI for anyone else who wants to know :f: 

Share this post


Link to post
Share on other sites

I couldn't imagine you'd intend to switch into a diving unit with no rebreather. Not sure to understand why he's alive anyway. The problem in helping people with some code is to understand all these hidden intentions, weird cases, bad trips.

Next time, perhaps, we'll have a look at team switch. Right now, I surrender.

Share this post


Link to post
Share on other sites

I really appreciate that help you guys give on scripting like I said 

my ideas and mission design are superior then my working knowledge of scripting. 

 

I usually play missions alone with AI or just a few other people not into the whole big clan group thing. In my missions I don't like respawns and single life I would never complete one section of my mission. The whole revive systems that I use never allows the playable units to die the mission ends when all units are incapacitated with limited medical supplies in the mission.  I use team switch a lot and AIS wound system utilize it very well but I still needed to make some modifications for it to work like I needed it to work for my missions. 

 

My question is what is the difference when you call scripts in a game  addMissionEventHandler vs [] spawn {while {true} ? 

 

Share this post


Link to post
Share on other sites
30 minutes ago, avibird 1 said:

I really appreciate that help you guys give on scripting like I said 

my ideas and mission design are superior then my working knowledge of scripting. 

 

I usually play missions alone with AI or just a few other people not into the whole big clan group thing. In my missions I don't like respawns and single life I would never complete one section of my mission. The whole revive systems that I use never allows the playable units to die the mission ends when all units are incapacitated with limited medical supplies in the mission.  I use team switch a lot and AIS wound system utilize it very well but I still needed to make some modifications for it to work like I needed it to work for my missions. 

 

My question is what is the difference when you call scripts in a game  addMissionEventHandler vs [] spawn {while {true} ? 

 

 

A while true loop runs,  all the time, without any chance to stop it besides exiting the mission.

Not a bad thing in some cases but as a rule of thumb if you can avoid a loop, avoid it.

It's always good practice to at least define a variable that can stop the loop from running, if there's no matching eventhandler to do what you want.

 

Eventhandlers execute upon certain events, so instead of having a while loop running all the time or a waitUntil loop being evaluated (mostly) every frame, an EH is a better on demand solution.

Most eventhandlers do very specific stuff, like triggering once a unit opens an ammocrate, which would be needlessly complicated to do using loops.

 

Just note that most scripting commands don't take too long to execute, a simple distance check for example "player distance [0,0,0]" takes 700 nanoseconds, or 0.0007 milliseconds on my PC.

Now imagine you have a non scheduled (call, not spawned) while true loop, which is getting evaluated at most 10.000 times each frame (at 60fps one frame is around 16.67 milliseconds), with just the "player distance [0,0,0]" this will lead to 7 milliseconds runtime for 10.000 iterations.

This is more than 40% of a frames runtime and will most likely bog down your games performance if you don't put any wait condition inside the while true loop.

 

As for your teamswitch example, the thread starter didn't specify it in his question so it wasn't taken into account when creating the answer.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

@Grumpy Old Man  thank you for the explanation. The bottom line is your code block works for my need/desire of using team switch and never allowing my playable units to fully die ? somehow I managed to accomplish this using a modified BTC Quick Revive that I adjusted over the last few years to work for my needs but AIS wound System is far superior in functionality. 

 

@pierremgi I will try to be a little more specific in the future when asking for assistance with script/coding so you guys have more detail. Once again it's greatly appreciated Avibird.

  • Like 1

Share this post


Link to post
Share on other sites

Yes thanks.

Some behaviors for units/player(s) health are depending on the context. Anyway, it's always useful to precise:

- SP or MP context, (I can't count how much time this info is not given, and discovered lately).

- addons used, especially those deeply altering the units vulnerability/performance/equipment.

For example, I never reply if I read ACE3 inside a question. There are far better skilled users and I don't want to test codes with this kind of addon.

 

I forget to reply at your question:

The differences between init.sqf and initPlayerLocal.sqf is: in the second case, player is already defined, I mean you can use this command without waiting for some extra check and you'll never fire this code on a dedicated served.

Your sqf will be clearer.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×