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 → Troop Transport cog
Troop Transport cog
2008-08-12, 9:15 AM #1
I need a cog that will make the 3do "trooptran" or any other future transport move 5 frames. It will need 4 call buttons similar to the elev_switch2.cog.

Upon pushing the call button, the trooptran will move from frame 1, 2, 3, 4 and then to 5 in order. Pushing the call button at frame 5 will cause it to move to frame 4, 3, 2, and back to 1 in order. And if possible for it to move to each frame without pausing or the shortest possible pause. Basically its just a horizontal elevator, but I couldn't find any cogs out there that could do such a thing. They would just stop at frame 2 and just hover there.

Please be sure to leave your author name and email, etc in the cog description somewhere so the credit of the cog goes to you :)

I'm at a stalemate with my level until I get this cog.
2008-08-12, 4:40 PM #2
I feel dirty writing this. I mean, Christ, how many times has this bloody thing been implemented? :colbert:

Code:
# 2008-08-12 gbk
symbols
	message activated
	thing trooptran
	surface switch0
	surface switch1
	surface switch2
	surface switch3
	float speed=1
	int numframes=5
end
code
	activated:
		if((getsenderref()==trooptran) || (isthingmoving(trooptran)))
			stop();
		if(getcurframe(trooptran)==numframes)
		{
			movetoframe(trooptran,numframes,speed);
		}
		else
		{
			movetoframe(trooptran,0,speed);
		}
		stop();
end


Values;
trooptran -- your object
switch0 - switch3 -- your switch surfaces. If you need a thing as a switch just change one of the 'surface switchX' bits to 'thing switchX'.
speed -- How fast you want the trooptran to move. You may need to experiment to find the right value for you.
numframes -- The total number of frames in the object, minus one. If the NUMFRAMES param of your object in JED is 6, set this value to 5.

Notes;
  • There is no delay between frames. The trooptran object will move seamlessly though all its defined frames.
  • The cog will not respond to the player activating the trooptran itself.
  • I did not test this cog, and it has been many years since I've actually done serious level development. Also, I've been doing perl development day in and day out for as long, so don't be surprised if this cog makes JK go off and puke.
  • Give me credit, don't give me credit, I don't care. This cog is so ridiculously simple it doesn't matter, and I'm 100% certain I've written this exact piece of code at least a dozen times, most other serious coggers at least 2 dozen, and Hideki, well, at least 2,763,529 times. I mean, seriously, of all the cog code in existence, the *vast majority* of it has got to be trooptran cogs.</rant>


Reply to this thread with any problems/questions.
And when the moment is right, I'm gonna fly a kite.
2008-08-12, 6:21 PM #3
Thanks and i'll try that out. You say that this is simple but I haven't learned cog yet. Maybe when I get a bit more time I'll try to do just that.

I did use search to look for this before hand but didn't find anything.
2008-08-12, 6:58 PM #4
The trooptran didnt move at all this time nor do any of the switches activate. Cogwriter reported missing variables when I used it to write your cog.

;expected, (found
Variable, Function or Keyword expected, but ) found
Variable, Function or Keyword expected, but ; found
;expected, (found
Variable, Function or Keyword expected, but ) found
Variable, Function or Keyword expected, but ; found
2008-08-12, 8:07 PM #5
Stop() isn't a real verb. I'm guessing both the Stop()s are supposed to be StopThing(trooptran).
So change the activated part to this:


Code:
activated:
        if((getsenderref()==trooptran) || (isthingmoving(trooptran)))
StopThing(trooptran);
if(getcurframe(trooptran)==numframes)
        {
            movetoframe(trooptran,numframes,speed);
        }
        else
        {
            movetoframe(trooptran,0,speed);
        }
StopThing(trooptran);
 
end



At least I think...I'm not that experienced with cog.:P
er...
2008-08-12, 9:00 PM #6
Your suggestion fixed the missing variables problem but the cog still apparently does nothing. The switches don't activate, a sound doesn't play and the trooptran doesn't move at all.

If all else fails can somepoing point me to working trooptran cog in a currently uploaded level here on massassi? I could probably just use whatever cog they used.
2008-08-12, 10:51 PM #7
That cog will only send the trooptran from the first frame to the last frame, skipping all the ones inbetween (unless I'm reading it wrong, it has been a few years since I've written in cog)

I'd suggest looking at the jkspecs and the Datamaster, but are good resources and the datamaster has tutorials on cog. Open up some of the original cogs from the game, especially switch activated door cogs and elevator cogs and learn from those.

If nobody helps you in the next 24 hours, I'll try writing you one, but I don't have the time right now. Work calls.
2008-08-13, 4:34 AM #8
Originally posted by Noyjitat:
The trooptran didnt move at all this time nor do any of the switches activate.


My apologies. As I said, its been awhile. Try this one:
Code:
# 2008-08-12 gbk
symbols
	message activated
	thing trooptran
	surface switch0
	surface switch1
	surface switch2
	surface switch3
	float speed=1
	int numframes=5
end
code
	activated:
		if(getsenderref()==trooptran)
			stop;
		if(isthingmoving(trooptran))
			stop;
		if(getcurframe(trooptran)==numframes)
		{
			movetoframe(trooptran,numframes,speed);
		}
		else
		{
			movetoframe(trooptran,0,speed);
		}
		stop;
end


Do note; this cog does not change the mat cel of the switches, nor does it play a sound. Let me know if you want it to do those things.

Originally posted by lexen:
Stop() isn't a real verb. I'm guessing both the Stop()s are supposed to be StopThing(trooptran).

No. Stop is an alias of Return.


Originally posted by Stormtrooper:
That cog will only send the trooptran from the first frame to the last frame, skipping all the ones inbetween (unless I'm reading it wrong, it has been a few years since I've written in cog)

No. Movetoframe() sends an object to the specified frame via all intermediate frames.
And when the moment is right, I'm gonna fly a kite.
2008-08-13, 7:58 AM #9
The sound I was referring to was the soundclass that I set on the trooptran in the template manager.

Now this time the soundclass played but the trooptran didn't move and the switchs didnt animate upon activating one. The sound only played for a sec, like it started to move and then stopped immediately.

I found a trooptran cog by savagex but its only a one way transport and cannot be used to return to the first frame plus it activates by using the trooptran as a switch itself. Could you possibly modify this cog so that it is not a one way only transport? It needs to be able to travel back and not just one way if possible.

Code:
# Jedi Knight Cog Script
#
# Trooptran Cog
#
# Modified by SavageX
#
# This file was not made or supported by LucasArts Entertainment Company

symbols
    message    activated
    message    arrived

    thing        trooptran    linkid=1

    float        start_wait=0.25
    float        sleeptime=2.0
    float        speed=4.0

    int        dummy        local
    int        done=0        local

    sound        start_snd=df_elev3-1.wav
    sound        fly_snd=df_elev3-2.wav
    sound        end_snd=df_elev3-3.wav
end                                                                           

## Code Section
code

activated:
    if (IsThingMoving(trooptran)) return;
    if (GetSenderId() != 1) return;
    if(done == 0)
    {
        done = 1;

        playsoundthing(start_snd,trooptran,1.0,-1,3.0,0x0);

        Sleep(start_wait);            // pause before moving up

           dummy = playsoundthing(fly_snd,trooptran,1.0,-1,3.0,0x0);

        MoveToFrame(trooptran, 1, speed);
           MoveToFrame(trooptran, 2, speed);
           MoveToFrame(trooptran, 3, speed);    
        MoveToFrame(trooptran, 4, speed);
        MoveToFrame(trooptran, 5, speed);
        MoveToFrame(trooptran, 6, speed);
        MoveToFrame(trooptran, 7, speed);
           MoveToFrame(trooptran, 8, speed);
           MoveToFrame(trooptran, 9, speed);
        MoveToFrame(trooptran, 10, speed);
        MoveToFrame(trooptran, 11, speed);
        MoveToFrame(trooptran, 12, speed);

        WaitForStop(trooptran);

        Stopsound(dummy);

        playsoundthing(end_snd,trooptran,1.0,-1,3.0,0x0);

        return;
    }
    else if (done == 0)
    {
        playsoundthing(start_snd,trooptran,1.0,-1,3.0,0x0);

        Sleep(start_wait);            // pause before moving up

           dummy = playsoundthing(fly_snd,trooptran,1.0,-1,3.0,0x0);

        MoveToFrame(trooptran, 0, speed);

        WaitForStop(trooptran);

        Stopsound(dummy);

        playsoundthing(end_snd,trooptran,1.0,-1,3.0,0x0);

    }

arrived:
    if (GetCurFrame(trooptran) == 0)
    {
        done = 1;
    }
    if (GetCurFrame(trooptran) == 12)
    {
        done = 0;
    }
    return;

end
2008-08-13, 5:30 PM #10
New version. Added animations to the switches and a switch sound.

Code:
# 2008-08-13 gbk
symbols
	message activated
	message arrived
	thing trooptran
	surface switch0
	surface switch1
	surface switch2
	surface switch3
	sound switchsound=Activate02.wav
	float speed=1
	int numframes=5
	int i local
end
code
	activated:
		if(getsenderref()==trooptran)
			stop;
		if(isthingmoving(trooptran))
			stop;
		if(getcurframe(trooptran)==numframes)
		{
			movetoframe(trooptran,numframes,speed);
		}
		else
		{
			movetoframe(trooptran,0,speed);
		}
		for(i=0;i<4;i=i+1)
			setwallcel(switch0,1);
		stop;
	arrived:
		if(getcurframe(trooptran)!=numframes)
			stop;
		for(i=0;i<4;i=i+1)
		{
			setwallcel(switch0,0);
			playsoundpos(switchsound,surfacecenter(switch0),1,-1,-1,0);
		}
		stop;
end


Originally posted by Noyjitat:
Now this time the soundclass played but the trooptran didn't move and the switchs didnt animate upon activating one. The sound only played for a sec, like it started to move and then stopped immediately.

Check your frame values, and check the numframes variable in the cog.

Quote:
I found a trooptran cog by savagex but its only a one way transport and cannot be used to return to the first frame plus it activates by using the trooptran as a switch itself. Could you possibly modify this cog so that it is not a one way only transport? It needs to be able to travel back and not just one way if possible.


Wow, thats some...interesting code. My opinion of SavageX just took a nosedive.

Actually, his code *does* allow the tranny to return, its just "hard coded" to 12 frames. Also, he is under the mistaken impression that MoveToFrame() is blocking.
And when the moment is right, I'm gonna fly a kite.
2008-08-15, 7:52 PM #11
i use Return; because i cant fight the urge to write Stop;//Hammertime
at the end of every section :(
Code:
if(getThingFlags(source) & 0x8){
  do her}
elseif(getThingFlags(source) & 0x4){
  do other babe}
else{
  do a dude}

↑ Up to the top!