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 → lucky_jackpot, where art thou?
lucky_jackpot, where art thou?
2004-04-14, 6:06 PM #1
Hey, I was just wondering if you could rewrite that cog you sent me, you know the elevator one (I'll post it below). You see I realeased my level ( see this thread) but people said it would be much improved if I could just make it so that the elevators wouldn't trap people inside of thmem when the doors close. You might know what to do off the bat, but if not you can download and test the level via a link to website's downloads section from my thread. You can always accesss it from my sig. Thankyou very much lucky_jackpot (or anyone else who feels they know what to do), I'm planning on releasing a version 1.1! [http://forums.massassi.net/html/biggrin.gif]

Code:
## Jedi Knight COG Script
#
# 00_doubleDoorElevator.COG
#
# Base script for a double-door elevator.
# (Cog script is fine for SP - will work in MP but should really be optimised for C/S conditions).
#
# Set verbose=1, if you want to see print out messages.
# (More for test purposes than anything else...)
#
#
# This COG script is NOT supported by LucasArts or LEC.
#
# Permission is granted to use this script by the author, as long as credit
# is provided in the readme file for any add-on levels that use this script.
#
# Email: lucky_jackpot@hotmail.com
# -Jackpot
# [RJS]
#
##
#==============================================================

symbols

message startup
message entered
message timer

thing   door0   nolink    # 1st floor
thing   door1   nolink    # 1st floor
thing   door2   nolink    # 2nd floor
thing   door3   nolink    # 2nd floor
thing   elev     nolink

surface trigSurf0   linkid=1    # Used as the trigger surface at the ground/bottom floor (take lift UP)
surface trigSurf1   linkid=2    # Used as the trigger surface at the top (take lift DOWN)

flex    waitTime=2.0
flex    elevMoveSpeed=4.0
flex    doorMoveSpeed=4.0
# int triggerID=666   local  # Intended for client-side script --> needs to be tweaked....
int     timerID=333 local
int     cnt=0     local
int     numDoors=4  local
int     inCycle=0       local   # Specifies whether or not the cog is still in one of its cycles, as the
                                     # cog gets a bit funny, what with having the other trigger surface
                                     # at the opposing floor sending a new trigger, so we don't want to
                                     # process any more information than necessary...

int     verbose=0   # The debugging variable (as always   [http://forums.massassi.net/html/wink.gif] )

end

code

startup:

    if (IsServer() ) {  // Make sure only the host places all the doors in the right frame placeholders
        for (cnt=0 ; cnt<numDoors ; cnt=cnt+1) {
            MoveToFrame (door0[cnt], 0, 10.0);
        }
        MoveToFrame (elev, 0, 10.0);
    }

    Return;

#####################

entered:

    if (IsMoving(elev) )    // Don't waste any more resources if elev is already going...
    Return;

    if (GetSenderID() == 1) {
        if (inCycle)    // Cog is already performing a cycle...
            Return;
        inCycle = 1;
        call openBottomDoors;
        SetTimerEx (waitTime, timerID+1, -1, -1);
    }
    else
    if (GetSenderID() == 2) {
        if (inCycle)
            Return;
        inCycle = 1;
        call openTopDoors;
        call moveElevUp;
        SetTimerEx (waitTime, timerID+2, -1, -1);
    }
Return;


#####################

timer:
    if (GetSenderID() == timerID+1) {   // If approaching from the ground/bottom floor...
        if (verbose)
            PrintInt (timerID);
        call shutBottomDoors;
        call moveElevUp;
        call openTopDoors;
        SetTimerEx (waitTime, timerID+2, -1, -1);
    }
    else
    if (GetSenderID() == timerID+2) {   // If approaching from the top floor...
        if (verbose)
            PrintInt (timerID);
        call shutTopDoors;
        call moveElevDown;
        call openBottomDoors;
        SetTimerEx (waitTime, timerID+3, -1, -1);
    }
    else
    if (GetSenderID() == timerID+3) {
        if (verbose)
            PrintInt (timerID);
        call shutBottomDoors;   // Reset to original "natural" state.
        inCycle = 0;
    }

    Return;

#####################

openBottomDoors:
    if (verbose)
        Print ("Open Bottom Doors...");
    for (cnt=0 ; cnt<numDoors/2 ; cnt=cnt+1) {  // OPEN BOTTOM doors
        MoveToFrame (door0[cnt], 1, doorMoveSpeed);
    }
    Return;

shutBottomDoors:
    if (verbose)
        Print ("Shut Bottom Doors...");
    for (cnt=0 ; cnt<numDoors/2 ; cnt=cnt+1) {  // SHUT BOTTOM doors
        MoveToFrame (door0[cnt], 0, doorMoveSpeed);
    }
    Return;


#####################

openTopDoors:
    if (verbose)
        Print ("Open Top Doors...");
    for (cnt=numDoors/2 ; cnt<4 ; cnt=cnt+1) {  // OPEN TOP doors
        MoveToFrame (door0[cnt], 1, doorMoveSpeed);
    }
    Return;

shutTopDoors:
    if (verbose)
        Print ("Shut Top Doors...");
    for (cnt=numDoors/2 ; cnt<4 ; cnt=cnt+1) {  // SHUT TOP doors
        MoveToFrame (door0[cnt], 0, doorMoveSpeed);
    }
    Return;

######################

moveElevUp:
    MoveToFrame (elev, 1, elevMoveSpeed);   // Elevator goes UP
    waitForStop (elev);
    Return;

moveElevDown:
    MoveToFrame (elev, 0, elevMoveSpeed);   // Elevator goes DOWN
    waitForStop (elev);
    Return;

######################


end



------------------
~ Vader's Corner ~
My JK Level Design | 2005 JK Hub Level Pack (Plexus) | Massassi Levels
2004-04-14, 8:17 PM #2
Here's a fixed copy. Tested and works. [http://forums.massassi.net/html/biggrin.gif]. You just need to define an additional variable in each cog which specifies the "No Player Zone" -- the bottom sector of the elevator shaft that the player can exist in (in your level's case, they would be 83, 178, 146, and 169). You can read my added documentation in the cog's header to see exactly what I changed.
Code:
## Jedi Knight COG Script
#
# 00_doubleDoorElevator.COG
#
# Base script for a double-door elevator.
# (Cog script is fine for SP - will work in MP but should really be optimised for C/S conditions).
#
# Set verbose=1, if you want to see print out messages.
# (More for test purposes than anything else...)
#
#
# This COG script is NOT supported by LucasArts or LEC.
#
# Permission is granted to use this script by the author, as long as credit
# is provided in the readme file for any add-on levels that use this script.
#
# Email: lucky_jackpot@hotmail.com
# -Jackpot
# [RJS]
#
# Small "bug" that caused players to become trapped in the elevtor 
#  shaft fixed by Darth Slaw.
# The pulse checks the "no player zone" sector once every second while
#  the elevator is not in a cycle and if a player is in the "NPZ" sector,
#  it will open the bottom doors. This should be very rare since the
#  inital closing of the doors after a cycle is delayed until no players
#  exist in the NPZ sector.
#
##
#==============================================================#
symbols

message   startup
message   entered
message   timer
message   pulse

thing     door0               nolink
thing     door1               nolink
thing     door2               nolink
thing     door3               nolink
thing     elev                nolink

surface   trigSurf0           linkid=1
surface   trigSurf1           linkid=2

flex      waitTime=2.0
flex      elevMoveSpeed=4.0
flex      doorMoveSpeed=4.0

int       timerID=333         local
int       cnt=0               local
int       numDoors=4          local
int       inCycle=0           local
int       verbose=0

sector    noplayerzone        nolink

# int triggerID=666   local   # Intended for client-side script --> needs to be tweaked....
# cog gets a bit funny, what with having the other trigger surface
# at the opposing floor sending a new trigger, so we don't want to
# process any more information than necessary...

end
#==============================================================#
code
#------------------------------------------------------
startup:
	if(IsServer())
	{
		// Make sure only the host places all the doors in the right frame placeholders
		for(cnt = 0; cnt < numDoors; cnt = cnt + 1)
		{
			MoveToFrame(door0[cnt], 0, 10.0);
		}
		MoveToFrame(elev, 0, 10.0);
	}

Return;
#------------------------------------------------------
entered:
	if(IsMoving(elev))	// Don't waste any more resources if elev is already going...
	Return;
	if(GetSenderID() == 1)
	{
		if(inCycle)	// Cog is already performing a cycle...
		Return;
		inCycle = 1;
		SetPulse(0);
		call openbottomdoors;
		SetTimerEx(waitTime, timerID + 1, -1, -1);
	}
	else if(GetSenderID() == 2)
	{
		if(inCycle) Return;
		inCycle = 1;
		SetPulse(0);
		call opentopdoors;
		call moveelevup;
		SetTimerEx(waitTime, timerID + 2, -1, -1);
	}

Return;
#------------------------------------------------------
timer:
	if(GetSenderID() == timerID + 1)
	{
		// If approaching from the ground/bottom floor...
		if(verbose) PrintInt(timerID);
		call shutbottomdoors;
		call moveelevup;
		call opentopdoors;
		SetTimerEx(waitTime, timerID + 2, -1, -1);
	}
	else if(GetSenderID() == timerID + 2)
	{
		// If approaching from the top floor...
		if(verbose) PrintInt(timerID);
		call shuttopdoors;
		call moveelevdown;
		call openbottomdoors;
		SetTimerEx(waitTime, timerID + 3, -1, -1);
	}
	else if(GetSenderID() == timerID + 3)
	{
		if(verbose) PrintInt(timerID);
		if(GetSectorPlayerCount(noplayerzone) == 0)
		{
			// all players are out of the shaft
			call shutbottomdoors;	// Reset to original "natural" state.
			inCycle = 0;
			// failsafe in case a player gets stuck in the shaft but outside the elev sector
			SetPulse(1);
		}
		else
		{
			// delay closing the doors until all players are out of the elevator shaft
			SetTimerEx(waitTime, timerID + 3, -1, -1);
		}
	}

Return;
#------------------------------------------------------
###############################
# BOTTOM DOORS                #
###############################
openbottomdoors:
	if(verbose) Print("Open Bottom Doors...");
	for(cnt = 0; cnt < numDoors / 2; cnt = cnt + 1)
	{
		// OPEN BOTTOM doors
		MoveToFrame(door0[cnt], 1, doorMoveSpeed);
	}

Return;
#------------------------------------------------------
shutbottomdoors:
	if(verbose) Print("Shut Bottom Doors...");
	for(cnt = 0; cnt < numDoors / 2; cnt = cnt + 1)
	{
		// SHUT BOTTOM doors
		MoveToFrame(door0[cnt], 0, doorMoveSpeed);
	}

Return;
#------------------------------------------------------
###############################
# TOP DOORS                   #
###############################
opentopdoors:
	if(verbose) Print("Open Top Doors...");
	for(cnt = numDoors / 2; cnt < 4; cnt = cnt + 1)
	{
		// OPEN TOP doors
		MoveToFrame(door0[cnt], 1, doorMoveSpeed);
	}

Return;
#------------------------------------------------------
shuttopdoors:
	if(verbose) Print("Shut Top Doors...");
	for(cnt = numDoors / 2; cnt < 4; cnt = cnt + 1)
	{
		// SHUT TOP doors
		MoveToFrame(door0[cnt], 0, doorMoveSpeed);
	}

Return;
#------------------------------------------------------
###############################
# ELEVATOR                    #
###############################
moveelevup:
	MoveToFrame(elev, 1, elevMoveSpeed);	// Elevator goes UP
	WaitForStop(elev);

Return;
#------------------------------------------------------
moveelevdown:
	MoveToFrame(elev, 0, elevMoveSpeed);	// Elevator goes DOWN
	WaitForStop(elev);

Return;
#------------------------------------------------------
pulse:
	if(GetSectorPlayerCount(noplayerzone) > 0)	// trapped player
	{
		if(verbose) Print("Trapped player; Opening doors");
		call openbottomdoors;
		inCycle = 1;
		SetPulse(0);
		SetTimerEx(waitTime, timerID + 3, -1, -1);
	}

Return;
#------------------------------------------------------
end

Good night. (2:14 where I am).

------------------
Bond, Power, CA, The Force, Saber, IC, Epic, Oily Mexican Food, BG, /\ |> /\ /\/\, Sentences.
Now you know where I've been.
May the mass times acceleration be with you.
2004-04-14, 10:55 PM #3
Aww geez [http://forums.massassi.net/html/frown.gif] - didn't even get chance to amend one of my own cog scripts, dam* it !! [http://forums.massassi.net/html/wink.gif]. You see this is what happens when you have a huge pool of water and a timezone, separating the US from the UK... [http://forums.massassi.net/html/wink.gif]

Try as I might, Slaw keeps on getting in there first [http://forums.massassi.net/html/wink.gif]. Good thing I'm not intending on retiring editing/cogging for JK for quite a while yet isn't it, really... [http://forums.massassi.net/html/wink.gif]. Keep up the good work Slaw [http://forums.massassi.net/html/smile.gif] - t'is good to know there's always other helpful people at Massassi [http://forums.massassi.net/html/biggrin.gif]

-Jackpot

------------------
"lucky_jackpot is the smily god..." - gothicX

"Life is mostly froth and bubble,
But two things stand in stone,
Kindness in another's trouble,
Courage in your own"
("Ye Wearie Wayfarer" - by Adam Lindsay Gordon)
"lucky_jackpot is the smily god..." -gothicX
"Life is mostly froth and bubble, but two things stand in stone,
Kindness in another's trouble, courage in your own"
- "Ye Wearie Wayfarer"
|| AI Builder: compatible with both JK & MotS || My website ||

↑ Up to the top!