// don't forget to include this in the main script
// call texture_scan(); in your player script just before the while loop
SOUND* grass_snd = "grass.wav";
SOUND* stone_snd = "stone.wav";
#define grass 1 // to have some decent names as function arguments
#define stone 2
var step_length = 0;
VECTOR player_pos1;
VECTOR player_pos2;
function texture_sound(sound_type)
{
// you can have step_length % 3 to double the steps and so on
// I choose 6 to make sure that it will divide 1 and 3 (step_length += ...)
// 6 / 4 = 1.5 seconds between steps
if ((sound_type == grass) && (step_length % 6 == 0)) // 0, 6
{
snd_play (grass_snd, 60, 0);
}
if ((sound_type == stone) && (step_length % 6 == 0)) // 0, 6
{
snd_play (stone_snd, 50, 0);
}
if (step_length >= 6) {step_length = 0;}
}
function texture_scan()
{
while (player == NULL) {wait (1);}
while (1)
{
vec_set (player_pos1.x, player.x);
wait(1);
vec_set (player_pos2.x, player.x);
c_trace(my.x, vector(my.x, my.y, my.z - 100), IGNORE_ME + IGNORE_MODELS + IGNORE_PASSABLE + SCAN_TEXTURE);
if(vec_dist (player_pos1.x, player_pos2.x) != 0)
{
if (str_cmpi (tex_name,"grass1"))
{
texture_sound(grass);
}
else
{
texture_sound(stone);
}
}
step_length += 1 + 2 * key_shift; // add 4 (12 if shift is pressed) to step_length every second
wait (-1.5); // play with this
}
}