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 → Sound Switch Cog Prob
Sound Switch Cog Prob
2003-08-17, 9:08 AM #1
Hello again. This time i need help with this cog... It works when you press the switch but it wont turn off when you press the switch again... The only way to really get it to turn of right now is to have it play silence.
If someone could help me, I would be very nice [http://forums.massassi.net/html/biggrin.gif] - Unlike some people, whose middle name is cogger, my middle name is retard.


# Jedi Knight Cog Script
#
# prl_sectorsound.cog by Sylvicolus - 23 April 2001
#
# Sound triggered by activating switch. Use 1 or 2 switches.
# Activate switch again to turn sound off.
# Sound is heard inside of 1 to 4 sectors.
# Choose volume and wav sound.
#
# This cog is not supported by LucasArts Entertainment Co.

symbols
message activate

surface switch0 linkid=1
surface switch1 linkid=1
sector sector0 nolink
sector sector1 nolink
sector sector2 nolink
sector sector3 nolink

flex volume=1.0
sound wav0=00AlarmLoop03.WAV

int channel0 local
int channel1 local
int channel2 local
int channel3 local
int soundstatus=0 local
flex FadeOut=0.2 local

end

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

code

startup:
setwallcel(switch0, 1);
if (switch1) setwallcel(switch1, 1);
return;
## Sets the switch mat to the 2nd cell, which is green or off position.

activate:
if (soundstatus==0)
{
soundstatus=1;
setwallcel(switch0, 0);
if (switch1) setwallcel(switch1, 0);
channel0 = SectorSound(sector0, wav0, volume);
if (sector1) channel1 = SectorSound(sector1, wav0, volume);
if (sector2) channel2 = SectorSound(sector2, wav0, volume);
if (sector3) channel3 = SectorSound(sector3, wav0, volume);
return;
} //else turn off sound
soundstatus=0;
setwallcel(switch0, 1);
if (switch1) setwallcel(switch1, 1);
StopSound(channel0,FadeOut);
if (sector1) StopSound(channel1,FadeOut);
if (sector2) StopSound(channel2,FadeOut);
if (sector3) StopSound(channel3,FadeOut);
return;

end

------------------
Bob Dole likes peanut butter. Bob Dole's never been afraid to admit that
2003-08-17, 1:22 PM #2
Hi there [http://forums.massassi.net/html/smile.gif]

Hope this code does what you want it to, but if you have any problems or queries with it, don't hesitate to call back here [http://forums.massassi.net/html/biggrin.gif]

Code:
##
#
# 00_sectorSoundStatus.COG
#
# Caters for up to eight sectors.
# When switch is ON (activated) sound will play (alarm).
# When switch is OFF (deactivated) sound will NOT play.
#   (actually it will, but it will be mute - work-around solution  [http://forums.massassi.net/html/wink.gif]
#
# The sound wave that is played will loop forever in that sector,
# until switched OFF.
#
# status=0 for OFF ; status=1 for ON
#
# Haven't found a way of allocating a channel to sector sounds
# to get a handle for it  :s
# Parsec + JK don't like using SectorSound() verb as an expression...
#
#
# 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.
#
#
# E-mail: lucky_jackpot@hotmail.com
# [RJS]
#
##


symbols

    message startup
    message activated

    surface switch0     linkid=1
    surface switch1     linkid=1

    sector  triggerSector0      nolink
    sector  triggerSector1      nolink
    sector  triggerSector2      nolink
    sector  triggerSector3      nolink
    sector  triggerSector4      nolink
    sector  triggerSector5      nolink
    sector  triggerSector6      nolink
    sector  triggerSector7      nolink

    sound   alarm=00AlarmLoop03.WAV

    int status=0
    int numSectors=8       local
    int counter=0            local

    flex    volume=1.0
    flex    silentVolume=0.0    local

    thing   player             local

    int     verbose=0

end

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

code

startup:

    if (verbose)
    Sleep (1.0);
    Print ("Startup COG !!!");

    if (status == 1) {   // Boolean check - equivalent to (status == 1)
        SetWallCel (switch0, 1);
        SetWallCel (switch1, 1);
    }
    else
    if (status == 0) {
        SetWallCel (switch0, 0);
        SetWallCel (switch1, 0);
    }

    return;

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

activated:

    player = GetLocalPlayerThing();

    if (GetSourceRef() != player)
        return;

    if (GetSenderID() != 1) // Make sure nothing other than the
        return;                  // switches should send a message...

    if (verbose)
    Print ("Activated MSG !!!");

    if (GetSenderID() == 1) {
        if (status == 0) {
            if (verbose)
            Print ("Status is OFF - switch to ON and START SOUNDS...");

            SetWallCel (switch0, 1);    // Reset to first cell after starting cell
            SetWallCel (switch1, 1);

            for (counter=0 ; counter < numSectors ; counter=counter+1) {
                if (verbose)
                    Print ("ALARM !!!");
                SectorSound (triggerSector0[counter], alarm, volume);
            }
            status = 1;     // Reset value...
        }
        else
        if (status == 1) {
            if (verbose)
            Print ("Status is ON --- switch to OFF and STOP SOUNDS !!!");

            SetWallCel (switch0, 0);    // Reset to starting cell...
            SetWallCel (switch1, 0);

            for (counter=0 ; counter < numSectors ; counter=counter+1) {
                if (verbose)
                    Print ("FADE OUT !!!");
                SectorSound (triggerSector0[counter], alarm, silentVolume);
            }
            status = 0; // Reset status...
        }
    }

    return;

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


end


Hope this is the answer you were looking for [http://forums.massassi.net/html/redface.gif] [http://forums.massassi.net/html/biggrin.gif]

------------------
Are you feeling lucky, cuz if you are, get your hands off me... ;)

"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 ||
2003-08-17, 6:20 PM #3
THANKyou a whole lot. Ill test it to see if it works... if it does youll see it in my new lvl - with all due credit, of course [http://forums.massassi.net/html/biggrin.gif]

------------------
Bob Dole likes peanut butter. Bob Dole's never been afraid to admit that
2003-08-18, 8:53 AM #4
YYYYEEEEEEEAAAAAAAAAAAYYYYYYY... It works... Finally a good cog [http://forums.massassi.net/html/biggrin.gif] [http://forums.massassi.net/html/biggrin.gif] [http://forums.massassi.net/html/biggrin.gif] what a relief! Hey, will it work in mp? ill test it tonight but do you know? [http://forums.massassi.net/html/smile.gif] Ohyeah, and thanks alot. [http://forums.massassi.net/html/biggrin.gif]

------------------
Bob Dole likes peanut butter. Bob Dole's never been afraid to admit that
2003-08-18, 9:30 AM #5
Hey - no probs - that's what the Massassi JK community is here for [http://forums.massassi.net/html/smile.gif]

As for whether or not it will play in multi-player - I must confess I don't know (I cog primarily for single-player levels). It may need a correct flag setting at the top (as to whether to play it locally or globally).

Personally, I don't see why it shouldn't work in mp, because the coding logic is all there, but feel free to post back if you have any queries [http://forums.massassi.net/html/smile.gif]

-Jackpot

Oh - and you're very welcome too (after not using my Zero-Gravity cog *mutter, mutter*) lol I'm glad to have helped [http://forums.massassi.net/html/biggrin.gif]

------------------
Are you feeling lucky, cuz if you are, get your hands off me... ;)

"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 ||
2003-08-18, 2:17 PM #6
by the way.. *cough*, *cough* if you, *cough* dont mind, *cough* i modified your *cough* cog to ahhh.. *cough* support *cough*, *cough* 45 sectors *cough*. That is *cough* if you don't *cough* mind.. [http://forums.massassi.net/html/biggrin.gif]

------------------
Bob Dole likes peanut butter. Bob Dole's never been afraid to admit that
2003-08-18, 8:36 PM #7
um... querie! Ive gotta leetle problem... the cog works fine for the host... but the joiner cannot hear the sound or activate the switches... The cog that I posted could let the joiner activate the switches.... just not hear the sound... plz... help... im desprate.. need to release level very soon... anymore of your omnipotent cogging would be greatly appreciated [http://forums.massassi.net/html/biggrin.gif]

------------------
Bob Dole likes peanut butter. Bob Dole's never been afraid to admit that
2003-08-19, 3:06 AM #8
Hi there again [http://forums.massassi.net/html/smile.gif]

1 Question: you modified my code?? How dare you [http://forums.massassi.net/html/wink.gif] lol I don't mind as long as the original comment blurb remains [http://forums.massassi.net/html/smile.gif]

However, I believe that if you add
Code:
flags=0x40


above the symbols declaration, the problem should be fixed [http://forums.massassi.net/html/biggrin.gif]

There is one part of the code that I'm in two minds about as to whether it will effect multi-player, but fix and test what I say in this message and then post back here about whether or not it works, so as I know...

-Jackpot

PS: Oh btw - if you're editing the cog manually, make sure you increase the local "numSectors" variable, otherwise sound won't play in all the sectors - Make sure it has (surprise surprise) the total number of sectors that you wish to use (in your case 45). This is because it creates an array of all your sectors used, and then loops through them all, changing the volume as appropriate [http://forums.massassi.net/html/wink.gif]

Hope this helps [http://forums.massassi.net/html/biggrin.gif]

------------------
Are you feeling lucky, cuz if you are, get your hands off me... ;)

"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 ||
2003-08-19, 7:06 AM #9
I may be a retarded cogger but i AM thourogh [http://forums.massassi.net/html/biggrin.gif] yeah, i did that. It works fine for the host... but ill try that thankyou again... and don't worry, youll get yo' stinkin' credit! [http://forums.massassi.net/html/biggrin.gif]

------------------
Bob Dole likes peanut butter. Bob Dole's never been afraid to admit that

[This message has been edited by Darth_Bano (edited August 19, 2003).]
2003-08-19, 8:05 AM #10
if your in a hurry here's one you can use if you want.
Code:
##########################################################
# Jedi Knight Cog Script  (JK/MotS)
#---------------------------------------------------------
# SECTOR_SOUND.COG
# when either a switch (surface) or a console (thing) is
# activated it starts playing a sound in all the sectors listed.
#---------------------------------------------------------
# Written By DSLS_DeathSythe
# This COG is NOT supported by LucasArts Entertainment Co.
##########################################################
flags=0x240
symbols
#---------------------------------------------------------
message     startup
message     activated
message     trigger

thing       console=-1
thing       console2=-1
surface     switch=-1
surface     switch2=-1

sound       sector_snd=-1
flex        volume=1.0

# Trig Ints
int         act_trig=1

sector      sound_sec=-1
sector      sound_sec2=-1
sector      sound_sec3=-1
sector      sound_sec4=-1
sector      sound_sec5=-1
sector      sound_sec6=-1
sector      sound_sec7=-1
sector      sound_sec8=-1
sector      sound_sec9=-1
sector      sound_sec10=-1
sector      sound_sec11=-1
sector      sound_sec12=-1
sector      sound_sec13=-1
sector      sound_sec14=-1
sector      sound_sec15=-1
sector      sound_sec16=-1
sector      sound_sec17=-1
sector      sound_sec18=-1
sector      sound_sec19=-1
sector      sound_sec20=-1
sector      sound_sec21=-1
sector      sound_sec22=-1
sector      sound_sec23=-1
sector      sound_sec24=-1
sector      sound_sec25=-1
sector      sound_sec26=-1
sector      sound_sec27=-1
sector      sound_sec28=-1
sector      sound_sec29=-1
sector      sound_sec30=-1
sector      sound_sec31=-1
sector      sound_sec32=-1
sector      sound_sec33=-1
sector      sound_sec34=-1
sector      sound_sec35=-1
sector      sound_sec36=-1
sector      sound_sec37=-1
sector      sound_sec38=-1
sector      sound_sec39=-1
sector      sound_sec40=-1
sector      sound_sec41=-1
sector      sound_sec42=-1
sector      sound_sec43=-1
sector      sound_sec44=-1
sector      sound_sec45=-1

int         is_on=0                                  local
int         i=0                                      local
#---------------------------------------------------------
end
#=========================================================
code
#---------------------------------------------------------
startup:
	is_on = 0;
return;
#---------------------------------------------------------
activated:
	SendTrigger(-1, act_trig, is_on, 0, 0, 0);
return;
#---------------------------------------------------------
trigger:
	if(GetSourceRef() != act_trig)
		return;
	is_on = GetParam(0);
	if(is_on == 0)
		{
		for(i=0; i<2; i=i+1)
			if(switch > -1)
				SetWallCel(switch, 1);
		for(i=0; i<46; i=i+1)
			if(sound_sec > -1)
				SectorSound(sound_sec, sector_snd, volume);
		is_on = 1;
		return;
		}
	for(i=0; i<2; i=i+1)
		if(switch > -1)
			SetWallCel(switch, 0);
	for(i=0; i<46; i=i+1)
		if(sound_sec > -1)
			SectorSound(sound_sec, -1, 0.0);
	is_on = 0;
return;
##########################################################
end

its already set up for 45 sectors and it uses a trigger to make sure that everyone can hear the sound.
if you try it just make sure that if you are useing any other cogs with triggers that the act_trig is not the same as any of them.
use it if you want.

------------------
Famous last words - "It seemed like a good idea at the time."
Famous last words - "It seemed like a good idea at the time."
2003-08-19, 11:30 AM #11
thank you... ill see [http://forums.massassi.net/html/biggrin.gif] if anything ill give credit for so much help [http://forums.massassi.net/html/biggrin.gif] *sniff* *sniff*, first time *sniff* in my life anyone ever went out of *sniff* their way to help me -runs off to weep uncontrollably. [http://forums.massassi.net/html/biggrin.gif]

------------------
Bob Dole likes peanut butter. Bob Dole's never been afraid to admit that

↑ Up to the top!