Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Bacta Tank Help - Part 1
Bacta Tank Help - Part 1
2005-07-19, 12:17 PM #1
Greetings. I'm currently developing an advanced Bacta Tank COG for my new level. First, I will explain what the COG's supposed to do.

  • Two switches (one inside the bacta tank and one outside) enable to fill up/empty the water from the bacta tank
  • When in the water, player receives healing


Basically, the water filling up/emptying works by moving a flat water textured 3DO, and then changing the empty sector into water. (As seen in Nebula's level "Deep" (the air lock doors))

Here is an ugly image of the Bacta Tank:

[http://img298.imageshack.us/img298/4620/bacta4cs.jpg]

Now, here is the COG I wrote. It justs moves the Water 3DO and gives Healing+Mana. I still have to figure out how to change the Bacta Tank sector into water.

Code:
# Jedi Knight Cog Script
#
# bacta_tank.cog
#
# This script controls a bacta tank. Two switches (one inside the bacta tank and one outside) enable
# to fill up/empty the water from the bacta tank. When in the water, player receives healing.
# 
# [Dominik]
#
# ========================================================================================

flags=0x40

symbols

message	activate
message	arrived
message       pulse

surface	call0				linkid=1
surface	call1				linkid=1
surface 	call2				linkid=1
surface	call3				linkid=1

thing		water			       desc=water_object

sector		tank	

int		curframe=0		       Local
flex		start_wait=0.25		desc=pause_before_moving_up
flex		speed=4.0
sound		wav0=lvrclik1.wav                    # Switch sound

thing         powerup                    local
thing         player                     local
int           bin=14                     local

flex		healInterval=1.0		         # Time interval (in seconds) between healing pulses
flex		heal=5.0			         # Health gained per pulse

sound		wav1=forcehealing01.wav             # Heal sound

thing		victim		             local	  # Player or actor that's healing
int		type		             local
int		mana=25.0			         # Mana added per pulse
	
end

# ========================================================================================

code
activate:						// If player presses button
	if (GetWallCel(call0) == 1) return;
	if (GetSenderId() != 1) return;
	setwallcel(call0,1);
	setwallcel(call1,1);
	setwallcel(call2,1);
	setwallcel(call3,1);
	PlaySoundPos(wav0, SurfaceCenter(GetSenderRef()), 1, -1, -1, 0);
	curframe=getcurframe(water);
	movetoframe(water, 1-curframe, speed);
       if (curframe == 1);
        {
             if(tank > -1) SetPulse(healInterval);
	      return;
        }
       stop;

# ........................................................................................

arrived:
	setwallcel(call0,0);
	setwallcel(call1,0);
	setwallcel(call2,0);
	setwallcel(call3,0);
	PlaySoundPos(wav0, SurfaceCenter(GetSenderRef()), 1, -1, -1, 0);
	stop;		

# ........................................................................................

pulse:
	victim = FirstThingInSector(tank);
	while (victim != -1)
	{
		type = GetThingType(victim);
		// If we have an actor (2) or a player (10)
		if ((type==2) || (type==10))
		// Heal and add Mana
		{
			HealThing(victim, heal);
			ChangeInv(player, 14, mana);
                     PlaySoundPos(wav1, tank, 1, -1, -1, 0);
		}
		victim = NextThingInSector(victim);
	}
	return;

# ........................................................................................

end


Here are the two issues I get:

  • When I press a switch, the Bacta Tank fills up (Water 3DO goes up) and when I go into the Bacta Tank, I get Healing. The problem's that when the Water 3DO is down (Bacta Tank's empty) and I go into the Bacta Tank, I still get Healing)
  • The Healing sound doesn't work.


That's all for now. I'll have to figure out also how to change the empty Bacta Tank into a Water Sector.

Thanks.
Skateboarding is not a crime.
2005-07-20, 12:18 AM #2
To turn the sector into a water sector, use "SetSectorFlags(sector, 0x2);". To make the sector only heal when flooded, put a if(GetSectorFlags(sector) & 0x2) infront of the healing code. This if condition is only true when the sector is a water sector.
The sound doesn't play, because you are passing a wrong parameter to the PlaySoundPos() verb. The second one should be a position vector, not a sector. You can add a ghost to your symbols, use it as second parameter, but change the verb to PlaySoundThing().
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2005-07-20, 8:07 AM #3
Thanks for the reply.

Sound works now, and the sector becomes water when I press the switch.
Here's the problem: When the level starts, the bacta tank is not a water sector and when I enter it, I don't receive Healing. I press the switch, the Water 3DO goes up, and the sector becomes water and when I go in it, I receive Healing. Then, when I press the switch again, the Water 3DO goes down, but the sector is still water and I still receive Healing.

Here's the modified COG:

Code:
# Jedi Knight Cog Script
#
# bacta_tank.cog
#
# This script controls a bacta tank. Two switches (one inside the bacta tank and one outside) enable
# to fill up/empty the water from the bacta tank. When in the water, player receives healing.
# 
# [Dominik]
#
# ========================================================================================

flags=0x40

symbols

message	activate
message	arrived
message       pulse

surface	call0				linkid=1
surface	call1				linkid=1
surface 	call2				linkid=1
surface	call3				linkid=1

thing		water			       desc=water_object

sector		tank	

int		curframe=0		       Local
flex		start_wait=0.25		desc=pause_before_moving_up
flex		speed=4.0
sound		wav0=lvrclik1.wav                    # Switch sound

thing         powerup                    local
thing         player                     local
int           bin=14                     local

flex		healInterval=1.0		         # Time interval (in seconds) between healing pulses
flex		heal=5.0			         # Health gained per pulse

sound		wav1=forcehealing01.wav             # Heal sound
thing         soundpos                            # Thing position (ghost) where sound is played

thing		victim		             local	  # Player or actor that's healing
int		type		             local
int		mana=25.0			         # Mana added per pulse
	
end

# ========================================================================================

code
activate:						// If player presses button
	if (GetWallCel(call0) == 1) return;
	if (GetSenderId() != 1) return;
	setwallcel(call0,1);
	setwallcel(call1,1);
	setwallcel(call2,1);
	setwallcel(call3,1);
	PlaySoundPos(wav0, SurfaceCenter(GetSenderRef()), 1, -1, -1, 0);
	curframe=getcurframe(water);
	movetoframe(water, 1-curframe, speed);
       SetSectorFlags(tank, 0x2);
       if (GetSectorFlags(tank) & 0x2);
        {
             if(tank > -1) SetPulse(healInterval);
	      return;
        }
       stop;

# ........................................................................................

arrived:
	setwallcel(call0,0);
	setwallcel(call1,0);
	setwallcel(call2,0);
	setwallcel(call3,0);
	PlaySoundPos(wav0, SurfaceCenter(GetSenderRef()), 1, -1, -1, 0);
	stop;		

# ........................................................................................

pulse:
	victim = FirstThingInSector(tank);
	while (victim != -1)
	{
		type = GetThingType(victim);
		// If we have an actor (2) or a player (10)
		if ((type==2) || (type==10))
		// Heal and add Mana
		{
			HealThing(victim, heal);
			ChangeInv(player, 14, mana);
                     PlaySoundThing(wav1, tank, 1, -1, -1, 0);
		}
		victim = NextThingInSector(victim);
	}
	return;

# ........................................................................................

end
Skateboarding is not a crime.
2005-07-20, 8:32 AM #4
Flag the sector as water in JED so it's already water when the level starts. You should be enabling/disabling the water flag in the arrived message. There's a GetCurFrame(thing) verb or something, I don't remember since it's been a while.
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2005-07-20, 9:32 AM #5
Or just replace this code part:
Code:
SetSectorFlags(tank, 0x2);
       if (GetSectorFlags(tank) & 0x2);
        {
             if(tank > -1) SetPulse(healInterval);
	      return;
        }

...with this snippet:
Code:
if(curframe)
{
	SetSectorFlags(tank, 0x2);
	if(tank != -1)
		SetPulse(healInterval);
}
else
{
	ClearSectorFlags(tank, 0x2);
	SetPulse(0);
}

This code is based on the assumption that you are using two frames (0 and 1) for low and hight water. You might have to add a sleep() before this code, not sure if it waits for the water to rise or not.
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2005-07-20, 9:35 AM #6
Code:
# Jedi Knight Cog Script
#
# bacta_tank.cog
#
# This script controls a bacta tank. Two switches (one inside the bacta tank and one outside) enable
# to fill up/empty the water from the bacta tank. When in the water, player receives healing.
# 
# [Dominik]
#
# ==================================================  ======================================

flags=0x40

symbols

message	activate
message	arrived
message       pulse

surface	call0				linkid=1
surface	call1				linkid=1
surface 	call2				linkid=1
surface	call3				linkid=1

thing		water			       desc=water_object

sector		tank	

int		curframe=0		       Local
flex		start_wait=0.25		desc=pause_before_moving_up
flex		speed=4.0
sound		wav0=lvrclik1.wav                    # Switch sound

thing         powerup                    local
thing         player                     local
int           bin=14                     local

flex		healInterval=1.0		         # Time interval (in seconds) between healing pulses
flex		heal=5.0			         # Health gained per pulse

sound		wav1=forcehealing01.wav             # Heal sound
thing         soundpos                            # Thing position (ghost) where sound is played

thing		victim		             local	  # Player or actor that's healing
int		type		             local
int		mana=25.0			         # Mana added per pulse
	
end

# ==================================================  ======================================

code
activate:						// If player presses button
	if (GetWallCel(call0) == 1) return;
	if (GetSenderId() != 1) return;
        if (IsMoving(water)) return;
	setwallcel(call0,1);
	setwallcel(call1,1);
	setwallcel(call2,1);
	setwallcel(call3,1);
	PlaySoundPos(wav0, SurfaceCenter(GetSenderRef()), 1, -1, -1, 0);
	movetoframe(water, 1-curframe, speed);
        return;

# ..................................................  ......................................

arrived:
        curframe = 1-curframe;
	setwallcel(call0,0);
	setwallcel(call1,0);
	setwallcel(call2,0);
	setwallcel(call3,0);
	PlaySoundPos(wav0, SurfaceCenter(GetSenderRef()), 1, -1, -1, 0);
        if(curframe){
            SetSectorFlags(tank, 0x2);
            if(tank > -1) SetPulse(healInterval);
        }else{
            ClearSectorFlags(tank, 0x2);
        }
	stop;		

# ..................................................  ......................................

pulse:
	victim = FirstThingInSector(tank);
	while (victim != -1)
	{
		type = GetThingType(victim);
		// If we have an actor (2) or a player (10)
		if ((type==2) || (type==10))
		// Heal and add Mana
		{
			HealThing(victim, heal);
			ChangeInv(player, 14, mana);
                     PlaySoundThing(wav1, tank, 1, -1, -1, 0);
		}
		victim = NextThingInSector(victim);
	}
	return;
end


That should do it. Edited it a bit. Should work just fine now.
_ _ _____________ _ _
Wolf Moon
Cast Your Spell On Me
Beware
The Woods At Night
The Wolf Has Come
2005-07-20, 10:43 AM #7
Originally posted by zagibu:
Or just replace this code part:
Code:
SetSectorFlags(tank, 0x2);
       if (GetSectorFlags(tank) & 0x2);
        {
             if(tank > -1) SetPulse(healInterval);
	      return;
        }

...with this snippet:
Code:
if(curframe)
{
	SetSectorFlags(tank, 0x2);
	if(tank != -1)
		SetPulse(healInterval);
}
else
{
	ClearSectorFlags(tank, 0x2);
	SetPulse(0);
}

This code is based on the assumption that you are using two frames (0 and 1) for low and hight water. You might have to add a sleep() before this code, not sure if it waits for the water to rise or not.


This did the opposite of what it was supposed to do. So I changed if(curframe) to if(1-curframe) and it worked. :o The timing is not right though. The sector changes to normal (no water), and the Water 3DO is still going down. Shall I change that with Sleep()?
Skateboarding is not a crime.
2005-07-20, 11:10 AM #8
Originally posted by Dominik:
This did the opposite of what it was supposed to do. So I changed if(curframe) to if(1-curframe) and it worked. :o The timing is not right though. The sector changes to normal (no water), and the Water 3DO is still going down. Shall I change that with Sleep()?

This is probably, because the second frame has not been reached when my code is processed. If you sleep long enough before my code block (or try adding a WaitForStop(water); ...), the condition "should" be the way I posted it.
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2005-07-20, 2:52 PM #9
You may also consider using several water sectors and flagging/clearing them as the water moves through them. This fixes the ugliness of when you jump into the tank when it's still rising/falling. A very simple way would be to flag/clear the curent sector which the water 3DO is in. Have its frames slightly below the physical water level (just enough so that JK knows which sector its in). You could then use entered or exited to switch the sectors on and off.
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2005-07-21, 7:00 AM #10
I'm not experienced in COG. How can JK know where the 3DO is? Also, I would have to have more sectors in the symbols then?
Skateboarding is not a crime.
2005-07-21, 8:44 AM #11
Originally posted by Dominik:
How can JK know where the 3DO is?

You are already using this technique: GetCurFrame(thing); It should return the current frame (if the thing is idle) or the last frame (if the thing is moving).

Originally posted by Dominik:
Also, I would have to have more sectors in the symbols then?

Yes, this is the plan: to create a more believable transition of water and nowater areas. It's quite a bit of work, and you have to decide if it's worth it or if one sector already looks good enough.
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)

↑ Up to the top!