Posted By: Aaron
how to code ..... - 02/17/07 17:48
I need to know how to code sounds in footsteps of different sounds depending on texture, and also how to put music in main menu??
//Volume for media
define MenuVol, 100;
//Sound File
string sndMMBG = "Menu.mp3";
//
var BGSound;
Function StartMenu()
{
BGSound = media_loop(sndMMBG, null, MenuVol);
}
Function EndMenu()
{
media_stop(BGSound);
}
//volume for footsteps
define StepVol, 100;
//
string tstr;
function PlayFootstep(Texname)
{
str_cpy(tstr, Texname);
var i;
i = str_len(tstr);
if (i < 5)
{return(0);}
i -= 4;
str_trunc(tstr, i);
//
if (str_cmpi(tstr, "dirt"))
{ent_playsound(my, sndStepDirt, StepVol); return(1);}
if (str_cmpi(tstr, "gras"))
{ent_playsound(my, sndStepGrass, StepVol); return(1);}
if (str_cmpi(tstr, "metl"))
{ent_playsound(my, sndStepMetal, StepVol); return(1);}
return(2);
}
Function Footstep()
{
vec_set(temp, my.x);
temp.z -= 500;
c_trace(my.x, temp, scan_texture);
PlayFootstep(tex_name);
}


. In truth, I still use the manual, but rarely. After you've been writing it for >3 years, you start to remember basic concepts of how things work. However, sometimes you have to look up the syntax of a function (which parameters to use), like i do.
. First off, the gate code. Now, physics gates (like in Manhunt) are a little harder to make, so I'm just gonna give you one that opens when the player is close to it. You will need to put the origin of the model on one of the sides of the gate (where the hinges would be).
ACTION GATE
{
// Distance from center...
my.skill1 = 500;
//
// Gate Speed...
my.skill2 = 5;
//
// Gate Angle to swing to
my.skill3 = 130;
//
// Set center of gate...
var MCenter[3];
vec_set(MCenter, my.x);
vec_add(MCenter, my.max_x);
MCenter.x -= ((my.max_x - my.min_x) / 2);
MCenter.y -= ((my.max_y - my.min_y) / 2);
MCenter.z -= ((my.max_z - my.min_z) / 2);
//
// Wait until close enough...
while(vec_dist(MCenter, player.x) < my.skill1)
{wait(1);}
//
// Remember original pan angle...
my.skill11 = my.pan;
//
// contains angle to add to original angle
my.skill10 = 0;
//
// Wait until gate reaches angle
while(my.skill10 < my.skill3)
{
// increase gates angle by speed, but don't go too far!
my.skill10 = min(my.skill10 + (my.skill2 * time), my.skill3);
//
// Set pan to original pan + new angle
my.pan = my.skill11 + my.skill10;
wait(1);
}
//
// Done!
}
. As for animating, here's a short example...
// The name of the scene in MED (default: Frame)
string SceneGlassBreak = "Break";
//
// Speed to animate
var AnimSpeed = 10;
//
...
// variable for holding animate position (in percent)
var i = 0;
//
// cycle until animation is done
while(i < 100)
{
// increase i by AnimSpeed, but not past 100%
i = min(i + (AnimSpeed * time), 100);
//
// Animate entity (non cycling animation)...
ent_animate(my, SceneGlassBreak, i, null);
//
wait(1);
}
// Done!
...

Quote:
@Nidhogg: I didn't forget any wait(); statements... & time/time_step are the same. time hasn't been removed yet. But you are correct, I should start using time_step more... time is just a habit...![]()