Page 1 of 2

swimming question

Posted: December 9th, 2010, 9:05 pm
by stumpymcnub
HI guys, I have an area in a map that consists of a lot of swimming. I was hopping that there was a way in 2.6 to put a time limit on how long you can be underwater until your character dies. If so can you let me know? thanks all.

Re: swimming question

Posted: December 10th, 2010, 10:45 am
by arcones
Well, there are a couple of ways that is possible.

1) Code a timer for the water that eventually kills you if you don't get out quickly enough (kinda like the lava only it takes longer to die)
2) Make a level_trigger that automatically starts hurting you once you enter the water (although how and why this would work I'm not quite sure)
3) Make a level_trigger that starts taking away your "oxygen" as you enter the water and once you reach 0 oxygen you die (this one would be easiest)

There are probably more ideas, but those were the ones I came up with. I'll explain 3 in more detail.
3)

Code: Select all

Have an GUI that shows how much Health and Oxygen you have. Set health at 100 and set oxygen at 100.
Have a level_trigger that takes away oxygen once you enter the water (just a little bit) Then have level_triggers in the water which are spaced out from each other. These will also deduct oxygen. Once your oxygen is all gone, the level_triggers will start taking away chunks of your health until you die.
It sounds difficult, but it'd be rather simple. I can provide an example if you like.

Re: swimming question

Posted: December 11th, 2010, 7:31 pm
by chocolatepie33
if you're really good at coding, you could make a level trigger (like arc said) that creates a loop starting with 5 million and counts down, and when you get to 0, you "nap" (which is Cubescript for die or whatever).

Re: swimming question

Posted: December 11th, 2010, 8:12 pm
by arcones
Actually CP, mine would insure that you survive if you get out of the water in time as well as replenish your oxygen (that's something that could be added).

Otherwise once the 5 million counts down, you die whether you're in the water or not.

Re: swimming question

Posted: December 14th, 2010, 6:28 pm
by chocolatepie33
oops, yeah that's true...

Re: swimming question

Posted: December 14th, 2010, 8:36 pm
by arcones
Always look for alternate ways to do something ;)

Re: swimming question

Posted: December 15th, 2010, 10:12 pm
by stumpymcnub
Thank you guys, that really helps. And no, i am no good at coding, I have never done it before, so using sandbox is kind of a test/learning process for me. An example then would be more then welcome.

Re: swimming question

Posted: December 16th, 2010, 3:41 pm
by arcones
Okay:

Code: Select all

on_start = [
health = 100
oxygen = 200
]

"level_trigger_1" = [
health = (- $health 10 );
   echo ( format "You now have %1 Health." $health );
   if ( < $health 1 ) [
      nap;
      health = 100;
  ]
]

"level_trigger_2" = [
oxygen = (- $oxygen 10 );
   echo ( format "You now have %1 Oxygen." $oxygen );
   if ( < $oxygen 1 ) [ echo "You have run out of oxygen! You'll start losing health if you don't get out!" ];
   if ( < $oxygen 1 ) [
   health = (- $health 10 );
   if ( < $health 1 ) [
      nap;
      health = 100;
  ]
 ]
]

newgui Inventory [
guibutton "Back" "cleargui 1"
guibar
guitext ( format "You have %1 health." $health )
guitext ( format "You have %1 oxygen." $oxygen )
]

newgui main [
   guilist [
      guilist [
         guibutton "Inventory" "showgui Inventory"
      ]
   ]
   guibar
   @main
]
I'm 98.9% sure this'll work (I just haven't had time to test it out ;D) Place this in your map config to have it work.

Arcones

Re: swimming question

Posted: December 18th, 2010, 1:30 pm
by stumpymcnub
Fantastic! I'll give this a try and let you know how it works.

Re: swimming question

Posted: July 25th, 2011, 7:43 am
by t5yvxc
Im a noob at all of this, can someone tell me where do I find the script to add this? Is it in a folder?
Thanks in advance