Ok, thanks for your reply. This is the player_action:

Code:
action player_action()
{
	player = me;
	my.health = 100;
	my.eflags |= FAT | NARROW;
	set(my, INVISIBLE);
	player.z = 150;
	camera.arc = 80;
	//vec_set(my.min_x, vector(-20, -20, -40));
	//vec_set(my.max_x, vector(20, 20, 40));
	my.min_z *= 0.5;
	wait(1);
	ent_create(CUBE_MDL, nullvector, flashlight_action); // flashlight
	c_updatehull(my, 1);
	player_movement();
	player_camera();
}



forget the flashlight part tongue

and the movement code:


Code:
function player_movement()
{
	var resistance = 100;
	var key_space_off = 1;
	var jump_wait = 0;
	var rest = 0;
	var step_wait = 0;
	var step_random = 0;
	var step_last = 0;
	var move_speed = 10;
	var fire = 0;
	var reloading = 0;
	set(pan_health_hud, SHOW);
	random_seed(0);
	while(player.health > 0)
	{
		// Gravity
		if (c_trace(my.x, vector(my.x, my.y, my.z - 1000), IGNORE_ME | IGNORE_PASSABLE | IGNORE_PASSENTS | USE_BOX) > 5) absdist.z -= 2 * time_step;
		else absdist.z = 0;		
		
		if (key_shift && resistance > 0) move_speed = 15;
		else move_speed = 10;
		
		dist.x = move_speed * (key_w - key_s) * time_step;
		dist.y = move_speed * (key_a - key_d) * time_step;
		
		if ((key_w || key_s || key_a || key_d || key_space) && key_shift) resistance -= 0.5 * time_step;
		if (resistance <= 0) key_shift = 0;
		
		if ((key_d || key_a || key_w || key_s) && step_wait <= 0) 
		{
			while (step_random == step_last) step_random = integer(random(4)) + 1;
			step_last = step_random;
			if (step_random == 1) snd_play(snd_footstep1, 75, 0);
			else if (step_random == 2) snd_play(snd_footstep2, 75, 0);
			else if (step_random == 3) snd_play(snd_footstep3, 75, 0);
			else if (step_random == 4) snd_play(snd_footstep4, 75, 0);
			if (key_shift && resistance >= 0) step_wait = 15;
			else step_wait = 25;
		}
		if (resistance <= 0)	
		{
			if (rest == 0) snd_play(snd_breath, 80, 0);
			if (rest <= 35)
			{
				rest += 0.35 * time_step;
				if (rest >= 35) 
				{
					resistance = 40;
					rest = 0;
				}
			}
		}
		
		if (key_space && result <= 5 && key_space_off && jump_wait <= 0 && resistance > 0)
		{
			absdist.z = 7.5;
			key_space_off = 0;
			jump_wait = 30;
		}
		else if (!key_space) key_space_off = 1;
		
		if (key_t) player.health -= 5;
		
		if (ent_pistol != NULL)
		{
			if (mouse_left == 1 && fire == 0 && ent_pistol != NULL)
			{
				if (weapon_bullets > 0)
				{
					fire = 1;
					snd_play(snd_fire, 80, 0);
				}	
			}
			if (fire == 1 && my.skill50 < 100)
			{
				ent_animate(ent_pistol, "shoot_a", my.skill50, ANM_CYCLE);
				my.skill50 += 10 * time_step;
			}
			else if (my.skill50 >= 100)
			{
				weapon_bullets -= 1;
				my.skill50 = 0;
				fire = 0;
			}
			if (key_pressed(key_for_str(str_reload_key)) && weapon_bullets < 12 && weapon_loads > 0 && reloading == 0)
			{
				reloading = 1;
				// sonido de recarga
			}
			if (reloading == 1 && my.skill50 < 100)
			{
				ent_animate(ent_pistol, "reload", my.skill50, ANM_CYCLE);
				my.skill50 += 8 * time_step;
			}
			else if (my.skill50 >= 100)
			{
				weapon_bullets = 12;
				weapon_loads -= 1;
				my.skill50 = 0;
				reloading = 0;
			}			
		}			
		
		move_friction = 0;
		c_move(my, dist, absdist, IGNORE_PASSABLE | GLIDE);
		if (ent_pistol != NULL) c_move(ent_pistol, dist, absdist, IGNORE_PASSABLE | GLIDE);
		
		if ((key_shift == 0 || (key_shift == 1 && key_w == 0 && key_a == 0 && key_s == 0 && key_d == 0)) && resistance < 100 && rest == 0) resistance += 0.3 * time_step;
		if (step_wait > 0) step_wait -= 3.5 * time_step;
		if (jump_wait > 0) jump_wait -= 3.5 * time_step;
		wait(1);
	}
	// Death Animation;
	set(my, PASSABLE);
	var tempPos = c_trace(camera.x, vector(camera.x, camera.y, camera.z - 1000), IGNORE_ME | IGNORE_PASSABLE | IGNORE_PASSENTS | USE_BOX);
	tempPos = target.z + 20;
	while(camera.z > tempPos)
	{
		camera.z -= 1.5 * time_step;
		if (camera.tilt > (-80)) camera.tilt -= 1 * time_step;
		wait(1);
	}
	wait(-0.5);
	snd_stopall(4);
	lose_screen();
}



I made my self "resistance" code, when the player run it slow down and then he cant run for a while tongue

its the code, thanks laugh

Last edited by Gino_Fabrizio; 07/26/13 13:42.