Drowning
by Stefan Rampp · in General Discussion · 04/09/2003 (10:40 am) · 26 replies
Just a short code snipit/addition for Realmwars: the following functions add a 'drowning behavior' to the orc/elf. Just add these functions/modify the exisiting ones:
Whenever the head of the orc/elf is underwater and $UnderwaterInitTime ms have passed, the player suffers $UnderwaterDamage points of damage every $UnderwaterCheckTime ms until the player gets his head out of the water again.
I hope this is somewhat useful.
Stefan.
$UnderwaterDamage = 5; //damage done every $UnderwaterCheckTime ms if the player is underwater
$UnderwaterInitTime = 10000; //initial time before the player gets damage
$UnderwaterCheckTime = 1000; //time to check underwater status (ms)
function Orc::onEnterLiquid(%this, %obj, %coverage, %type)
{
Parent::onEnterLiquid(%this, %obj, %coverage, %type);
$Drowning::Schedule = schedule($UnderwaterInitTime, 0, "checkUnderwater", %obj );
}
function Orc::onLeaveLiquid(%this, %obj, %type)
{
cancel($Drowning::Schedule);
}
function Elf::onEnterLiquid(%this, %obj, %coverage, %type)
{
Parent::onEnterLiquid(%this, %obj, %coverage, %type);
$Drowning::Schedule = schedule($UnderwaterInitTime, 0, "checkUnderwater", %obj );
}
function Elf::onLeaveLiquid(%this, %obj, %type)
{
cancel($Drowning::Schedule);
}
function checkUnderwater(%player)
{
//Send a ray from the eye point to the sky to see if it crosses a waterblock.
//If it does, this means that the player is underwater. The raycast only returns true
//it it intersects the water surface!!
%eye = %player.getEyePoint();
%end = VectorAdd(%eye, "0 0 100");
%searchMasks = $TypeMasks::WaterObjectType;
if(ContainerRayCast(%eye, %end, %searchMasks)) %player.applyDamage($UnderwaterDamage);
$Drowning::Schedule = schedule(1000, 0, "checkUnderwater", %player );
}Whenever the head of the orc/elf is underwater and $UnderwaterInitTime ms have passed, the player suffers $UnderwaterDamage points of damage every $UnderwaterCheckTime ms until the player gets his head out of the water again.
I hope this is somewhat useful.
Stefan.
About the author
#22
02/22/2005 (9:07 pm)
Thats the same problem i had when I put it into my rw game. When a player died it just left them there and never respawned them back into the game, no matter what they clicked. They would have to leave the game and re-enter. If u know a fix for this, PLZ PLZ PLZ let me know.
#23
The only problem is when he dies he does exactly what you say above. Still can't get drowning working though ...
02/23/2005 (1:28 am)
I have a similar problem with an "Out of Mission" script I wrote which applies damage if the player goes outside the mission area.The only problem is when he dies he does exactly what you say above. Still can't get drowning working though ...
#24
Put the following code in player.cs in server/scripts/characters/ in Realmwars. Remove the code from my earlier posting.
Tell me if you have any problems.
Stefan.
03/13/2005 (2:12 pm)
A small update that fixes the respawn problem:Put the following code in player.cs in server/scripts/characters/ in Realmwars. Remove the code from my earlier posting.
$UnderwaterDamage = 5; //damage done every $UnderwaterCheckTime ms if the player is underwater
$UnderwaterInitTime = 10000; //initial time before the player gets damage
$UnderwaterCheckTime = 1000; //time to check underwater status (ms)function
function Armor::onEnterLiquid(%this, %obj, %coverage, %type){
$Drowning::Schedule = schedule($UnderwaterInitTime, 0, "checkUnderwater", %obj );
}
function Armor::onLeaveLiquid(%this, %obj, %type){
cancel($Drowning::Schedule);
}
function checkUnderwater(%player){
//Send a ray from the eye point to the sky to see if it crosses a waterblock.
//If it does, this means that the player is underwater. The raycast only returns true
//it it intersects the water surface!!
if (%player.getState() $= "Dead") {
cancel($Drowning::Schedule);
} else {
%eye = %player.getEyePoint();
%end = VectorAdd(%eye, "0 0 100");
%searchMasks = $TypeMasks::WaterObjectType;
if(ContainerRayCast(%eye, %end, %searchMasks)) {
%player.damage(0, %player.getPosition(), $UnderwaterDamage, 0);
echo(%player);
}
$Drowning::Schedule = schedule(1000, 0, "checkUnderwater", %player );
}
}Tell me if you have any problems.
Stefan.
#25
Thanx so much for the update Stefen, it is very awesome.
03/13/2005 (5:02 pm)
Hey YES!!! it finally works. I had to modify the code just slightly, but heres the modified code. Simply put this into your player.cs or all your characters if player.cs isnt your function player datablock.$UnderwaterDamage = 5; //damage done every $UnderwaterCheckTime ms if the player is underwater
$UnderwaterInitTime = 10000; //initial time before the player gets damage
$UnderwaterCheckTime = 3000; //time to check underwater status (ms)
function Armor::onEnterLiquid(%this, %obj, %coverage, %type)
{
switch(%type)
{
case 0: //Water
case 1: //Ocean Water
case 2: //River Water
case 3: //Stagnant Water
case 4: //Lava
%obj.setDamageDt(%this, $DamageLava, "Lava");
case 5: //Hot Lava
%obj.setDamageDt(%this, $DamageHotLava, "Lava");
case 6: //Crusty Lava
%obj.setDamageDt(%this, $DamageCrustyLava, "Lava");
case 7: //Quick Sand
}
$Drowning::Schedule = schedule($UnderwaterInitTime, 0,
"checkUnderwater", %obj );
}
function Armor::onLeaveLiquid(%this, %obj, %type)
{
cancel($Drowning::Schedule);
%obj.clearDamageDt();
}
function checkUnderwater(%player)
{
//Send a ray from the eye point to the sky to see if it crosses a waterblock.
//If it does, this means that the player is underwater. The raycast only returns true
//if it intersects the water surface!!
if (%player.getState() $= "Dead") {
cancel($Drowning::Schedule);
} else {
%eye = %player.getEyePoint();
%end = VectorAdd(%eye, "0 0 100");
%searchMasks = $TypeMasks::WaterObjectType;
if(ContainerRayCast(%eye, %end, %searchMasks)) {
%player.damage(0, %player.getPosition(), $UnderwaterDamage, 0);
echo(%player);
}
$Drowning::Schedule = schedule(1000, 0, "checkUnderwater", %player );
}
}Thanx so much for the update Stefen, it is very awesome.
#26
03/14/2005 (12:31 am)
No problem.
Torque Owner Norris Bonner
the only problem im runnning into now, is that after the player drowns... it doesnt respawn the player to a new state.. Screen just stays where his body was