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 → Random Key file
Random Key file
2006-04-16, 10:20 PM #1
I need a cog that makes a key file play (once) in random intervals... with a min wait time of about 30 seconds... (with a wide range... it's a LONG keyfile))... also the cog needs to play a sound everytime the key file is played (hopefully from the 3do that the key is on) also the sound distance range needs to be great enough for you to be able to hear it from some distance (maybe 15)...

someone sent me a cog, but when the level starts, the 3do is still for about 2 seconds, then the keyfile plays, but before the key is finished animating, it plays over again.. and again.. and again..

i set the multiplier as "10" and the mintime value to "3"

any ideas?


Code:
# Plays an animation on thing "focus" at random intervals.
#==============================================================#
symbols
message		startup
message		timer
thing		focus
keyframe	anim
flex		multiplier
flex		min_time
flex		time		local
sound		giveway
int   channel  local
end
#==============================================================#
code
#------------------------------------------------------
startup:
	Sleep(0.5);
	while(time<min_time) {
		time=Rand()*multiplier;
	}
	SetTimer(time);
return;
#------------------------------------------------------
timer:
	PlayKey(focus, anim, 1, 0x8);
	channel=PlaySoundThing(giveway, focus, .8, 1, 3, 0x0);
	while(time<min_time) {
		time=Rand()*multiplier;
	}
	SetTimer(time);
return;
#------------------------------------------------------
end

[ Code tags, please... ;) ]
||||||||||||||||||||
2006-04-16, 10:40 PM #2
I've got it for him. :)
-Hell Raiser
2006-04-16, 11:10 PM #3
We talked a bit over PM, he had to leave.

Code for all!

Code:
# JK Cog Script
#
# random_keyplay.cog
#
# Created By: Hell Raiser 4-17-6

symbols

thing		Key_Thing=-1
keyframe	Key_Played=-1

sound		Key_Sound=-1
flex		Volume=1.0
flex		Min_Distance=0.5
flex		Max_Distance=1.0

flex		Max_Wait=60
flex		Min_Wait=30
flex		First_Wait=0.5
flex		RandomTime					local

int			KeyHandle=-1				local

message		startup
message		timer

end

code

startup:

	SetTimer(First_Wait);

return;

timer:

	if(KeyHandle != -1)
	{
		StopKey(Key_Thing, KeyHandle, 0);
		KeyHandle=-1;
	}
	
	KeyHandle=PlayKey(Key_Thing, Key_Played, 5, 0x4);
	PlaySoundThing(Key_Sound, Key_Thing, Volume, Min_Distance, Max_Distance, 0x180);

	RandomTime=((Max_Wait - Min_Wait)*rand() + Min_Wait);
	SetTimer(Random_Time);

return;

end


I think this should do ya. :)
-Hell Raiser
2006-04-17, 9:29 PM #4
hmm.. never heard of code tags before.. is this something new?

HR, when using that code, the level loads about 75%, then I get a "could not load level" prompt.
||||||||||||||||||||
2006-04-17, 10:40 PM #5
We worked this out over PM. Turns out JED will stick your keyframe default value in the keyframe section.

And my silly naming convention stressing caused me to leave Random_Time in the timer instead of using RandomTime.
-Hell Raiser

↑ Up to the top!