PDA

View Full Version : A cog request



Reid
08-24-2005, 06:29 PM
I would appreciate it if someone would write a cog that simply does:
1) The player activates a thing or mat.
2) A sound is played once.
3) A different sound is looped continuously until
4) The player activates this thing or mat again.
5) And it can be done as many times as wanted

ReT
08-24-2005, 09:19 PM
Basically it does the following:

When Activated(ON) it makes a noise and loops another noise UNTIL it's Activated again(OFF) ?

What do you mean by The player activates a thing or mat? Would a cog with an activated message and pulse be enough? I've never placed cogs in JED before...

ReT

Emon
08-24-2005, 09:54 PM
This should do it.


# reid_sound.cog
#
# By Emon, August 2005
#
# Some sound making thing for Reid.
#
#================================================= =============================
symbols

surface switch
thing switchThing

sound onSound
sound loopSound

flex volume=1
flex minSoundDist=-1
flex maxSoundDist=-1
flex offDelay=1

int channel local
int on=0 local

message activated
message deactivated

end
#================================================= =============================
code

#------------------------------------------------------------------------------
activated:
if(!on)
{
setSurfaceCel(switch, 1);
channel = playSoundPos(onSound, getSurfaceCenter(switch), volume,
minSoundDist, maxSoundDist, 0x0);
channel = playSoundPos(loopSound, getSurfaceCenter(switch), volume,
minSoundDist, maxSoundDist, 0x1);
}
else
{
setSurfaceCel(switch, 0);
stopSound(channel, offDelay);
}
return;

end


Description of symbols.

switch and switchThing = The switch, either a surface or a thing. You can use either.
onSound = The first sound to play when the switch is hit.
loopSound = The sound to loop.
volume = The volume of the sound, 0.0 to 1.0.
minSoundDist/maxSoundDist = The minimum and maximum sound distances for the sound to be heard. The sound will be played at full volume within the min dist and fade to 0 towards the max dist. They default to -1, which will tell JK to use the default distances.
offDelay = A fade delay, in seconds for when the sound turns off. If you set this to 2.0, the sound will fade to a volume of 0 over 2.0 seconds.

This COG will also animate the surface switch. When it's activated it will switch to the second cel (cel #1) and switch back to the first cel when it's activated again (cel #0).

Reid
08-25-2005, 08:46 PM
The cog has 1 problem: When you activate the thing/surface again, it doesn't shut it off, its only will start a new sound loop that mixes with the first one.

Compos Mentis
08-25-2005, 08:54 PM
# reid_sound.cog
#
# By Emon, August 2005
#
# Some sound making thing for Reid.
#
#=================================================
symbols

surface switch
thing switchThing

sound onSound
sound loopSound

flex volume=1
flex minSoundDist=-1
flex maxSoundDist=-1
flex offDelay=1

int channel local
int on=0 local

message activated
message deactivated

end
#=================================================
code

#------------------------------------------------------------------------------
activated:
if(!on)
{
setSurfaceCel(switch, 1);
channel = playSoundPos(onSound, getSurfaceCenter(switch), volume,
minSoundDist, maxSoundDist, 0x0);
channel = playSoundPos(loopSound, getSurfaceCenter(switch), volume,
minSoundDist, maxSoundDist, 0x1);
on = 1;
}
else
{
setSurfaceCel(switch, 0);
stopSound(channel, offDelay);
on = 0;
}
return;

end

That should fix his code, he forget to change the var hehe

Reid
08-25-2005, 10:03 PM
Ok thanks.

Where did you learn how to write in the cog language?

Compos Mentis
08-25-2005, 10:22 PM
Some tutorials here on massassi, some old hack tutorials and mostly just messing around and learning by mistakes.

ProdigyOddigy
08-25-2005, 11:04 PM
Knowing the syntax and then just memorizing every command and what it does over time.

zagibu
08-26-2005, 02:46 AM
The DataMaster (THE cog reference) also contains some useful tutorials: www.geocities.com/sabersdomain

Reid
08-27-2005, 04:09 PM
WOW ty I already made a cog(a doorbell :) )