[REQ] converting a code to lite-c

Posted By: Cowabanga

[REQ] converting a code to lite-c - 12/01/08 17:36

Hi,

Can anyone please convert Kingdom Hearts MovementCode from C-script to Lite-c?

Because i need it.
Thanks smile.
Posted By: NeoNeper

Re: [REQ] converting a code to lite-c - 12/03/08 16:48

ooooooo yeaaa..
Tanks brother..
Very good.. (^.~)
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/03/08 18:48

mad i guess im gonna explode!!
did you get it?

anyone please convert the code to lite-c pleaaaase!
i really need it, seriously if i know c-script and lite-c ill convert it, but i dont know c-script! just lite-c, so please anyone!!!, i said ANYONE!!
Posted By: heinekenbottle

Re: [REQ] converting a code to lite-c - 12/03/08 20:41

I have two papers and a prob-stats exam due Friday but I think I'll crack down on this and try to get it by Monday.

But all in all, C-Script wasn't terribly different from Lite-C, a functioning code wouldn't be too difficult.

Just somethings to consider after looking at a few pages of the tutorial:

1. time is replaced by time_step

2. temp is no longer defined in the engine and must be declared like any other vector, var, pointer, whatever.

3. lite-c is case sensitive whereas C-Script was not. FUNCTION, ACTION, IF, WHILE, were valid in C-Script but not in Lite-c. Same goes for c_move, c_trace, and c_scan modes.

4. Flags are no longer set by the object-dot-property method but by either the set/reset macro or the flags |= / flags &= method. (there is also flags2 and emask)

5. Precompiler instructions (#include and #define) must be lower case and begin with a "#". .wdl files cannot be used in a .c project and .c projects do not use angular brackets but quotations (ex: #include "movement.c"). Header files (acknex.h) do use angular brackets. Precompiler instructions do not require semicolons, as c-script instructions did (c_script had no true precompiler instructions, everything was compiled at once)

6. actions are now a type of function and must have parenthesis even though actions do not return any value, nor do they pass parameters.

7. var cannot access .x, .y, .z, .pan, .tilt, or .roll like they use to be able to in C-Script. You must either use VECTOR or ANGLE. Alternatively, a 3 variable array can be used, with myVar[0] being x. Any 3 consecutive skills (my.skill1, my.skill2, my.skill3) can also be vectors but note that if you use my.skill1 as a vector, you can't use my.skill2 or my.skill3 for some other variable.

8. Not exactly a syntactical error, but something that makes code clearer, after a conditional branch (if, while, for, etc), if the instruction does not exceed 1 line, curly braces are not needed.

while(!player) { wait(1); } //c-script
while(!player) wait(1); //lite-c

9. trace_mode and move_mode have been built into c_move and c_trace (c_move(entity,relative_distance,absolute_distance,move_mode); and c_trace(to,from,trace_mode);) and the flags in the modes are capitalized.

10. on_key = function; assignments in c_script could be placed outside of functions, anywhere in the script. This is not true in lite-c. In lite-c, on_key assignments are called in a function. Alternatively, we can use "function on_key_event() { doStuff(); } for key strokes. Or we can wait for key strokes in a while loop:
Code:
while(1)
{
  if(key_space)
      jump();
  wait(1);
}


These 10, I'm sure aren't the only differences.

I'll see if I can convert the script this weekend.
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/04/08 09:39

Thanks laugh.
Posted By: heinekenbottle

Re: [REQ] converting a code to lite-c - 12/10/08 03:14

I should NOT have said Monday, I'm sorry about that, but I will get it done soon.
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/10/08 11:10

lol, no problem. laugh
Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 12/10/08 16:19

Ive done the best I could but there are a couple of fudges in player.c with comments.
Hope this is good enough to get you through.
Sorry the source is all here, but I dont have a free web storage facility.

MAIN.C
Click to reveal..
Code:
#include <acknex.h>
#include <default.c>
#include "player.c"
#include "enemy.c"
#include "animation.c"

function main()	{
	camera.clip_near = 0;
	video_switch(7,0,1);
	level_load("level.wmb");
}
PLAYER.C
Click to reveal..
Code:
#ifndef player_c
#define player_c
/////
//
//
#define nullframe	-2
#define blend		-1
#define stand		0
#define run			1
#define walk		2
#define jump		3
#define fall		4
#define attack_a	5
#define attack_b	6
#define attack_c	7
#define attack_d	8
#define attack_e	9
#define attack_f	10
//
#define move_x				skill22
#define move_y				skill23
#define move_z				skill24
#define force_x			skill25
#define force_y			skill26
#define force_z			skill27
#define velocity_x		skill28
#define velocity_y		skill29
#define velocity_z		skill30
#define animate			skill31
#define animate2			skill32
#define animblend			skill33
#define currentframe		skill34
#define blendframe		skill35
#define z_offset			skill50
#define jumping_mode		skill51
#define gravity			skill52
#define movement_mode	skill53
#define moving				skill54
#define hit_by_player	skill55
#define entity_type		skill56
//
//
function handle_animation(var animation_speed); 
function rotate_entity(var rotate_angle, var rotate_speed);
//
//
ENTITY* player_weapon;
ENTITY* target_enemy;
//
VECTOR* camera_move_to = { x=0;	y=0;	z=0; }
var camera_distance = 200;
var camera_pan;
var camera_tilt;
//
var space_press = 0;
var mouse_left_press = 0;
var mouse_right_press = 0;
var combo_continue = 0;
var player_lock_on = 0;
var airborne_attack = 0;
//
VECTOR* tempV = { x=0; 	 y=0; 	z=0; }
VECTOR* tempV2= { x=0; 	 y=0; 	z=0; }
ANGLE*  tempA = { pan=0; tilt=0; roll=0; }
ANGLE*  tempA2= { pan=0; tilt=0; roll=0; }
//
//
//
action attach_weapon()
{
	player_weapon = my;
	set(my,PASSABLE);
	proc_mode = PROC_LATE;
	while(you!=NULL) 
	{
		vec_for_vertex(tempV.x,  you, 1175);		//hand palm base
		vec_for_vertex(tempV2.x, you, 1240);		//hand palm tip
		vec_set(my.x, tempV.x);
		vec_diff(tempV.x, tempV2.x, tempV.x);
		vec_to_angle(tempA.pan, tempV.x);
		vec_set(my.pan, tempA.pan);
		wait(1);
	}
}
//
//

function handle_movement() 
{
	tempV.x = -1000;
	tempV.y = 0;
	my.moving = 0;
	if (key_w == 1 && key_s == 0 && key_a == 0 && key_d == 0) 	{ tempV.x = camera.pan; }
	if (key_s == 1 && key_w == 0 && key_a == 0 && key_d == 0) 	{ tempV.x = camera.pan + 180; }
	if (key_a == 1 && key_s == 0 && key_w == 0 && key_d == 0) 	{ tempV.x = camera.pan + 90; }
	if (key_d == 1 && key_s == 0 && key_a == 0 && key_w == 0) 	{ tempV.x = camera.pan - 90; }
	if (key_w == 1 && key_a == 1 && key_d == 0 && key_s == 0) 	{ tempV.x = camera.pan + 45; }
	if (key_w == 1 && key_d == 1 && key_a == 0 && key_s == 0) 	{ tempV.x = camera.pan - 45; }
	if (key_s == 1 && key_a == 1 && key_d == 0 && key_w == 0) 	{ tempV.x = camera.pan + 135; }
	if (key_s == 1 && key_d == 1 && key_a == 0 && key_w == 0) 	{ tempV.x = camera.pan - 135; }
	if (tempV.x != -1000) 
	{
		my.moving = 1;
		if (key_shift == 1)	{ tempV.y = 10 * time_step; } 
		else 						{ tempV.y = 15 * time_step; }
	}

	if (my.movement_mode == 0) 
	{
		my.move_x = fcos(tempV.x,tempV.y);
		my.move_y = fsin(tempV.x,tempV.y);
	}
	if (my.movement_mode == 1 || my.movement_mode == 2) 
	{
		tempV.y = fsin((my.animate * 1.2) + 45,15 * time_step);
		my.move_x = fcos(my.pan,tempV.y);
		my.move_y = fsin(my.pan,tempV.y);
		tempV.y = 0;
		if (tempV.x != -1000) 	tempV.y = 1;	//if we need to rotate whilst attacking (the player is pressing keys to rotate)
	}
	//
	c_move(my,nullvector,my.move_x, USE_AABB|IGNORE_PASSABLE|GLIDE);
	//
	result = trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - 4000));
	if (result < 0)	{	my.z -= result;	my.velocity_z = 0;	}
	if (target_enemy == NULL) 
	{	
		if (tempV.y > 0) { rotate_entity(tempV.x,30); }		
	} 
	else 
	{
		vec_diff(tempV2.x,target_enemy.x,my.x);
		vec_to_angle(tempA2.pan,tempV2.x);
		rotate_entity(tempA2.pan,30);
	}
	//
	switch(my.movement_mode)
	{
 		case 0:		
			my.gravity = 6;
			if (my.move_x != 0 || my.move_y != 0) 		 //if we are moving
			{
				if (my.animblend == stand) //if our current animation is stand
				{ 
					if (key_shift == 1)	my.blendframe = walk; 
					else 						my.blendframe = run; 
				}
				if (my.animblend == run  && key_shift == 1)	my.blendframe = walk;
				if (my.animblend == walk && key_shift == 0)	my.blendframe = run; 
			} 
			else 
			{
				//if we arn't moving and our current animation is walk or run, blend and cycle the stand animation
				if (my.animblend > stand && my.animblend != jump && my.animblend != fall) 		my.blendframe = stand;
			}
			if (mouse_left == 0 && mouse_left_press == 1)	mouse_left_press = 0; 
			if (mouse_left == 1 && mouse_left_press == 0 && my.animblend >= stand) 
			{
				mouse_left_press = 1;
				my.blendframe = attack_a;
				if (my.jumping_mode == 1) 		airborne_attack = 1;
				else									airborne_attack = 0;
				my.movement_mode = 1;
				combo_continue = 0;
			}
			if (mouse_right == 0 && mouse_right_press == 1) 	mouse_right_press = 0;		///////////////
			if (mouse_right == 1 && mouse_right_press == 0) 
			{
				if (player_lock_on == 0) 
				{
					c_scan(player.x,player.pan,vector(360,180,250),SCAN_ENTS|SCAN_LIMIT|IGNORE_ME);
					if (you != NULL) 
					{
						if (you.entity_type == 2)  //make sure you've scanned an enemy
						{	player_lock_on = 1;		target_enemy = you;		}
					}
				} 
				else 
				{	player_lock_on = 0;		target_enemy = NULL;		}
				mouse_right_press = 1;
			}
			break;
 		case 1:		
			if (my.jumping_mode != 10) 									my.jumping_mode = 0;
			else if((my.animate >= 60)&&(my.animblend >= stand)) 	my.jumping_mode = 0; 
			if(mouse_left == 0 && mouse_left_press == 1) 			mouse_left_press = 0; 
			if(mouse_left == 1 && mouse_left_press == 0 && my.animate >= 30 && combo_continue == 0) 
			{	mouse_left_press = 1; 	combo_continue = 1; 	}
			break;
 		case 2:		
		my.jumping_mode = 0;
		if(mouse_left == 0 && mouse_left_press == 1)		mouse_left_press = 0;
		if(mouse_left == 1 && mouse_left_press == 0 && my.animate >= 30 && combo_continue == 0) 
		{		mouse_left_press = 1;		combo_continue = 1; 		}
		break;
	}
}
//
//
function handle_gravity() 
{
	result = c_trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - 4000),IGNORE_ME|IGNORE_PASSABLE|USE_POLYGON);
	if(result<3) 
	{	
		if(result<0)	result = c_trace(my.x,vector(my.x,my.y,my.z + 4000),IGNORE_ME|IGNORE_PASSABLE|USE_POLYGON);	//!!FUDGE!! stop skyjumping
		//
		if(my.jumping_mode==0) 
		{
			my.force_z = -1 * result;
			if((key_space==0) && (space_press==1))	space_press = 0; 
			if((key_space==1) && (space_press==0) && (my.movement_mode==0) && (my.animblend>=stand) && (my.animblend!=jump) 	&& (my.animblend!=fall)) 
			{
				space_press = 1;
				my.jumping_mode = 1;
				my.force_z = 25;
				my.blendframe = jump;
				my.animate2 = 0;
				my.animblend = blend;
			}
		}
		if((my.jumping_mode==2) || (my.jumping_mode==3))	my.jumping_mode = 0;
	} 
	else 
	{
		if(my.jumping_mode==2) 
		{
			if(result>120) 
			{
				my.animate = 60;
				my.jumping_mode = 3;
			} 
			else	my.jumping_mode = 0;
		}
		if((my.jumping_mode==3) && (result<=120))		my.jumping_mode = 0;	
		if((my.jumping_mode==0) && (my.movement_mode==0))
		{
			if((result>120) && (my.animblend>=stand) && (my.animblend!=jump) && (my.animblend!=fall)) 
			{
				my.jumping_mode = 3;
				my.blendframe = fall;
				my.animate2 = 0;
				my.animblend = blend;
			}
		}
		my.force_z -= my.gravity * time_step;
		my.force_z = maxv(-30,my.force_z);
		if(my.movement_mode==2)		my.force_z = 0;
	}
 	my.velocity_z += (time_step * my.force_z) - (minv(time_step*0.7,1) * my.velocity_z);
	my.move_z = my.velocity_z * time_step;
}
//
//
//////////////////////////////
//Stable/rigid camera collision
//////////////////////////////
function handle_camera() 
{
	camera.pan -= mouse_force.x * 12 * time_step;
	camera.tilt += mouse_force.y * 8 * time_step;
	camera.tilt = clamp(camera.tilt,-30,10);
	tempA.pan = fcos(camera.tilt,-camera_distance);
	vec_set(camera.x,vector(my.x + fcos(camera.pan,tempA.pan),my.y + fsin(camera.pan,tempA.pan),my.z + 20 + fsin(camera.tilt,-camera_distance)));
	vec_diff(tempV.x,camera.x,my.x); 	//find the vector from the player to the camera
	vec_normalize(tempV.x,16); 			//get the magnitude of it's vector to 16 quants and store it in temp
	vec_add(tempV.x,camera.x); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.
	result = c_trace(my.x,tempV.x,IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS);
	if(result > 0) 
	{
		vec_diff(tempV.x,my.x,target.x); //find the vector from the point the trace hit to the player
		vec_normalize(tempV.x,16); 		//get the magnitude of this vector to 16 quants and store in temp
		vec_set(camera.x,target.x);		//place the camera at the trace hit point
		vec_add(camera.x,tempV.x);			//move the camera away from the wall by the vector temp, 16 quants towards the player
	}
}
//
//
//////////////////////////////
//Smoother camera collision
//////////////////////////////
/*
function handle_camera() {
	camera_pan -= mouse_force.x * 12 * time_step;
	camera_tilt += mouse_force.y * 8 * time_step;
	camera_tilt = clamp(camera_tilt,-30,10);
	camera.pan = camera_pan;
	tempA.pan = fcos(camera_tilt,-camera_distance);
	vec_set(camera_move_to.x,vector(my.x + fcos(camera.pan,tempA.pan),my.y + fsin(camera.pan,tempA.pan),my.z + 20 + fsin(camera_tilt,-camera_distance)));
	var temp = minv(1,0.5 * time_step); //changing 0.5 will change how fast the camera moves, at 1 places us at target, this value is what allows the smooth movement
	camera.x += temp*(camera_move_to.x - camera.x);
	camera.y += temp*(camera_move_to.y - camera.y);
	camera.z += temp*(camera_move_to.z - camera.z);
	vec_diff(tempV.x,camera.x,my.x);
	vec_normalize(tempV.x,16);
	vec_add(tempV.x,camera.x);
	if (c_trace(my.x,tempV.x,IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS) > 0) {
		vec_diff(tempV.x,my.x,target.x);
		vec_normalize(tempV.x,16);
		vec_set(camera.x,target.x);
		vec_add(camera.x,tempV.x);
	}
	vec_diff(tempV.x,my.x,camera.x);
	vec_to_angle(camera.pan,tempV.x);
}
*/
//
//
function rotate_entity(var rotate_angle, var rotate_speed)
{
	if(my.pan == rotate_angle)			return;
	result = ang(rotate_angle - my.pan);
	if (result > 0)		my.pan += rotate_speed * time_step;
	if (result < 0)		my.pan -= rotate_speed * time_step; 
	if ((ang(rotate_angle - my.pan) < 0) && (result > 0))	my.pan = rotate_angle; 
	if ((ang(rotate_angle - my.pan) > 0) && (result < 0))	my.pan = rotate_angle; 
}
//
//
function handle_sword_collision()
{
	you = NULL;
	vec_for_vertex(tempV.x, player_weapon,274); //sword base
	vec_for_vertex(tempV2.x,player_weapon, 54); //sword tip
	result = c_trace(tempV.x,tempV2.x,IGNORE_ME|IGNORE_PASSABLE|USE_BOX);
	if (you != NULL) {
		if ((you.entity_type == 2) && (you.hit_by_player == 0))
		{
			if (airborne_attack == 1 && my.animblend == attack_a) 	my.movement_mode = 2;
			you.hit_by_player = 1;
			if (target_enemy == NULL)		{	target_enemy = you; 		player_lock_on = 1; 	}
		}
	}
}
//
//
action player_action()
{
	c_setminmax(me);					//added to correct ground collisions
	wait(1);								//added to correct ground collisions
	player = me;
	my.gravity = 6;
	my.z_offset = -my.min_z;		//was 6	//added to correct ground collisions
	set(my,SHADOW);
	ent_create("sword.mdl", my.x, attach_weapon);
	wait(1);
	while(1) 
	{ //the main loop
		handle_gravity();
		handle_movement();
		handle_animation(1);
		handle_camera();
		wait(1);
	}
}
//
//
/////
#endif	//  player_c
ENEMY.C
Click to reveal..
Code:
#ifndef enemy_c
#define enemy_c
/////
//
//
action enemy_dummy()
{
	set(my,SHADOW);
	my.entity_type = 2;
	my.emask |= ENABLE_SCAN;
	while(1) 
	{
		if(player!=NULL)
		{
			if(my.hit_by_player==1) 
			{
				my.move_x = player.move_x;
				my.move_y = player.move_y;
				my.move_z = player.move_z;
				c_move(my, nullvector, my.move_x, USE_AABB|IGNORE_PASSABLE|GLIDE);
				if((player.animblend==blend) || (player.animblend<attack_a) || (my.animblend>attack_f))		my.hit_by_player=0;
			}
			if((player.animblend>=stand) && (target_enemy==my) && (player_lock_on==0) && ((player.animblend<attack_a) || (player.animblend>attack_f)))
			{	target_enemy = NULL;	 }
			if((target_enemy==my)&&(vec_dist(my.x,player.x)>200))		target_enemy = NULL;
		}
		wait(1);
	}
}
//
//
/////
#endif	//enemy_c
ANIMATION.C
Click to reveal..
Code:
#ifndef animation_c
#define animation_c
/////
//
//
function handle_animation(var animation_speed) 
{
	if(animation_speed <= 0) { animation_speed = 1; }
	if(my.animblend != blend && my.blendframe != nullframe) { my.animate2 = 0; my.animblend = blend; }
	if(my.animblend == blend) {
		if(my.currentframe == stand) { ent_animate(my,"stand",my.animate,ANM_CYCLE); }
		if(my.currentframe == run) { ent_animate(my,"run",my.animate,ANM_CYCLE); }
		if(my.currentframe == walk) { ent_animate(my,"walk",my.animate,ANM_CYCLE); }
		if(my.currentframe == jump) { ent_animate(my,"jump",my.animate,0); }
		if(my.currentframe == attack_a) { ent_animate(my,"attack_a",my.animate,0); }
		if(my.currentframe == attack_b) { ent_animate(my,"attack_b",my.animate,0); }
		if(my.currentframe == attack_c) { ent_animate(my,"attack_c",my.animate,0); }
		if(my.currentframe == attack_d) { ent_animate(my,"attack_d",my.animate,0); }
		if(my.currentframe == attack_e) { ent_animate(my,"attack_e",my.animate,0); }
		if(my.currentframe == attack_f) { ent_animate(my,"attack_f",my.animate,0); }
		if(my.blendframe == stand) { ent_blend("stand",0,my.animate2); }
		if(my.blendframe == run) { ent_blend("run",0,my.animate2); }
		if(my.blendframe == walk) { ent_blend("walk",0,my.animate2); }
		if(my.blendframe == jump) { ent_blend("jump",0,my.animate2); }
		if(my.blendframe == fall) { ent_blend("jump",60,my.animate2); }
		if(my.blendframe == attack_a) { ent_blend("attack_a",0,my.animate2); }
		if(my.blendframe == attack_b) { ent_blend("attack_b",0,my.animate2); }
		if(my.blendframe == attack_c) { ent_blend("attack_c",0,my.animate2); }
		if(my.blendframe == attack_d) { ent_blend("attack_d",0,my.animate2); }
		if(my.blendframe == attack_e) { ent_blend("attack_e",0,my.animate2); }
		if(my.blendframe == attack_f) { ent_blend("attack_f",0,my.animate2); }
		my.animate2 += 45 * time_step;
		if(my.animate2 >= 100) {
			my.animate = 0;
			my.animblend = my.blendframe;
			my.blendframe = nullframe;
		}
	}
	if(my.animblend == stand) {
		ent_animate(my,"stand",my.animate,ANM_CYCLE);
		my.animate += 5 * animation_speed * time_step;
		my.animate %= 100;
		my.currentframe = stand;
	}
	if(my.animblend == run) {
		ent_animate(my,"run",my.animate,ANM_CYCLE);
		my.animate += 8 * animation_speed * time_step;
		my.animate %= 100;
		my.currentframe = run;
	}
	if(my.animblend == walk) {
		ent_animate(my,"walk",my.animate,ANM_CYCLE);
		my.animate += 8 * animation_speed * time_step;
		my.animate %= 100;
		my.currentframe = walk;
	}
	if(my.animblend == jump || my.animblend == fall) {
		if(my.jumping_mode == 3) { my.animate = 60; }
		ent_animate(my,"jump",my.animate,0);
		my.animate += 10 * animation_speed * time_step;
		my.currentframe = jump;
		if(my.animate >= 60 && my.jumping_mode == 1) { my.jumping_mode = 2; }
		if(my.animate >= 100) {
			ent_animate(my,"jump",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if(my.moving == 1) {
				if(key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
		}
	}
	if(my.animblend == attack_a) {
		ent_animate(my,"attack_a",my.animate,0);
		my.animate += 20 * animation_speed * time_step;
		my.currentframe = attack_a;
		if(my.animate >= 100) {
			ent_animate(my,"attack_a",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if(my.moving == 1) {
				if(key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
			if(combo_continue == 1) {
				combo_continue = 0;
				my.blendframe = attack_b;
			} else {
				my.movement_mode = 0;
			}
		}
	}
	if(my.animblend == attack_b) {
		ent_animate(my,"attack_b",my.animate,0);
		my.animate += 15 * animation_speed * time_step;
		my.currentframe = attack_b;
		if(my.animate >= 100) {
			ent_animate(my,"attack_b",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if(my.moving == 1) {
				if(key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
			if(combo_continue == 1) {
				combo_continue = 0;
				my.blendframe = attack_c;
			} else {
				my.movement_mode = 0;
			}
		}
	}
	if(my.animblend == attack_c) {
		ent_animate(my,"attack_c",my.animate,0);
		my.animate += 10 * animation_speed * time_step;
		my.currentframe = attack_c;
		if(my.animate >= 100) {
			ent_animate(my,"attack_c",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if(my.moving == 1) {
				if(key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
			if(combo_continue == 1) {
				my.jumping_mode = 10;
				my.force_z = 12;
				my.gravity = 4;
				combo_continue = 0;
				my.blendframe = attack_d;
			} else {
				my.movement_mode = 0;
			}
		}
	}
	if(my.animblend == attack_d) {
		handle_sword_collision();
		ent_animate(my,"attack_d",my.animate,0);
		my.animate += 15 * animation_speed * time_step;
		my.currentframe = attack_d;
		if(my.animate >= 100) {
			ent_animate(my,"attack_d",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if(my.moving == 1) {
				if(key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
			if(combo_continue == 1) {
				combo_continue = 0;
				my.blendframe = attack_e;
			} else {
				my.movement_mode = 0;
			}
		}
	}
	if(my.animblend == attack_e) {
		ent_animate(my,"attack_e",my.animate,0);
		my.animate += 15 * animation_speed * time_step;
		my.currentframe = attack_e;
		if(my.jumping_mode == 0 && my.animate >= 20 && my.animate < 60) {
			my.gravity = 3;
			my.jumping_mode = 10;
			my.force_z = 15;
		}
		if(my.animate >= 100) {
			ent_animate(my,"attack_e",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if(my.moving == 1) {
				if(key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
			if(combo_continue == 1) {
				combo_continue = 0;
				my.blendframe = attack_f;
			} else {
				my.movement_mode = 0;
			}
		}
	}
	if(my.animblend == attack_f) {
		ent_animate(my,"attack_f",my.animate,0);
		my.animate += 6 * animation_speed * time_step;
		my.currentframe = attack_f;
		if(my.jumping_mode == 0 && my.animate >= 40 && my.animate < 60) {
			my.gravity = 6;
			my.jumping_mode = 10;
			my.force_z = 12;
		}
		if(my.animate >= 100) {
			my.movement_mode = 0;
			ent_animate(my,"attack_f",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if(my.moving == 1) {
				if(key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
		}
	}
	if(my.animblend >= attack_a && my.animblend <= attack_f) { handle_sword_collision(); }
	if(my.animblend != blend && my.blendframe != nullframe) { my.animate2 = 0; my.animblend = blend; }
}
//
//
/////
#endif	//animation_c

Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/11/08 12:09

Thanks!
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/11/08 12:27

Problems.... player can't jump and the glide mode isn't activated.
Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 12/11/08 15:58

Im sorry to say, Ive reached the limits of my available help.
Im just not competant enough with c_move and c_scan to know whats wrong...

I was able to dodge the issue by altering the model's origin point, but that
is cheating... I had a couple of other fudges in there that both link to this problem.

If maybe hienekenbottle can help Im sure both you AND me will be grateful..

Again, my apologies for my limitations.
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/11/08 16:04

Please hienekenbottle hurry.
Posted By: croman

Re: [REQ] converting a code to lite-c - 12/11/08 16:08

http://www.coniserver.net/wiki/index.php/Scripts

Take a look under "Player Movement" section. It's already converted to lite-c but it looks a bit different and smaller..but it works.
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/11/08 16:12

i know but where is the combo attack?

Originally Posted By: Wiki
I took David Lancaster's Kingdom Heart's movement code and converted it to c-lite and made some changes.


see, he made some changes.
Posted By: croman

Re: [REQ] converting a code to lite-c - 12/11/08 16:26

yeah i know he made some changes. i thought you might wanna know about that but it seems you already do know about it.

btw. i tried converting that code in lite-c myself and i got those problems with jumping also. then i tried to implement only KH jumping into my project and i once again i got the problem.

so i think that it's not a coincidence that jumping isn't working to me and to you, it has to do with newer Acknex version or c-script & lite-c language difference
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/11/08 16:29

i got an idea! put the combo attack code in the Modified KH movementcode wink
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/11/08 16:35

doesn't work -.- waiting you hienekenbottle wink .
Posted By: heinekenbottle

Re: [REQ] converting a code to lite-c - 12/11/08 19:58

Originally Posted By: Cowabanga
doesn't work -.- waiting you hienekenbottle wink .


Alright, he's got a script on the wiki, so you just need the combo attack code?
Posted By: heinekenbottle

Re: [REQ] converting a code to lite-c - 12/11/08 21:08

Actually, I just finished and I encountered a problem.

But once that problem is fixed, I think it will be complete.

I took the script, reworked it as lite-c. It is still David Lancaster's script in look and function, I simply translated.

Now from what works, it seems to be fine except for one thing:

the player keeps falling. When he hits the ground he "teleports" to the top of the screen and continues falling.

I think the other scripts work, because he moves and he's animated and he swings his sword, but he keeps falling.

Big script inc:

main.c

Code:
///////////////////////////////
#define PRAGMA_PATH "%EXE_DIR%\templates\images";
#define PRAGMA_PATH "%EXE_DIR%\templates\models";
#define PRAGMA_PATH "%EXE_DIR%\templates\sounds";

#include <acknex.h>
//#include "default.c"
#include "player.c"
#include "enemy.c"
#include "animation.c"

function main()
{
	camera.clip_near = 0;
	video_switch(7,0,1);
	level_load("khmove.wmb");
}



player.c

Code:
function rotate_entity(rotate_angle,rotate_speed);
function handle_animation(animation_speed);

#define nullframe -2
#define blend -1
#define stand 0
#define run 1
#define walk 2
#define jump 3
#define fall 4
#define attack_a 5
#define attack_b 6
#define attack_c 7
#define attack_d 8
#define attack_e 9
#define attack_f 10

#define move_x skill22
#define move_y skill23
#define move_z skill24
#define force_x skill25
#define force_y skill26
#define force_z skill27
#define velocity_x skill28
#define velocity_y skill29
#define velocity_z skill30
#define animate skill31
#define animate2 skill32
#define animblend skill33
#define currentframe skill34
#define blendframe skill35
#define z_offset skill50
#define jumping_mode skill51
#define grav skill52
#define movement_mode skill53
#define moving skill54
#define hit_by_player skill55
#define entity_type skill56

ENTITY* player_weapon;
ENTITY* target_enemy;


var camera_move_to[3];
var camera_distance = 200;
var camera_pan;
var camera_tilt;

var space_press = 0;
var mouse_left_press = 0;
var mouse_right_press = 0;
var combo_continue = 0;
var player_lock_on = 0;
var airborne_attack = 0;

action attach_weapon()
{
	VECTOR temp;
	VECTOR temp2;
	ANGLE tempAng;
	player_weapon = my;
	set(my,PASSABLE,SHADOW);
	proc_mode = PROC_LATE;
	while(!player) wait(1);
	while (player) {
		vec_for_vertex(temp.x,player,1175); //hand palm base
		vec_for_vertex(temp2.x,player,1240); //hand palm tip
		vec_set(my.x,temp.x);
		vec_diff(temp.x,temp2.x,temp.x);
		vec_to_angle(tempAng.pan,temp.x);
		vec_set(my.pan,tempAng.pan);
		wait(1);
	}
}

function handle_movement() 
{
	VECTOR temp;
	VECTOR temp2;
	ANGLE plAng;
	temp.x = -1000;
	temp.y = 0;
	my.moving = 0;
	if (key_w == 1 && key_s == 0 && key_a == 0 && key_d == 0) { temp.x = camera.pan; }
	if (key_s == 1 && key_w == 0 && key_a == 0 && key_d == 0) { temp.x = camera.pan + 180; }
	if (key_a == 1 && key_s == 0 && key_w == 0 && key_d == 0) { temp.x = camera.pan + 90; }
	if (key_d == 1 && key_s == 0 && key_a == 0 && key_w == 0) { temp.x = camera.pan - 90; }
	if (key_w == 1 && key_a == 1 && key_d == 0 && key_s == 0) { temp.x = camera.pan + 45; }
	if (key_w == 1 && key_d == 1 && key_a == 0 && key_s == 0) { temp.x = camera.pan - 45; }
	if (key_s == 1 && key_a == 1 && key_d == 0 && key_w == 0) { temp.x = camera.pan + 135; }
	if (key_s == 1 && key_d == 1 && key_a == 0 && key_w == 0) { temp.x = camera.pan - 135; }
	if (temp.x != -1000) {
		my.moving = 1;
		if (key_shift == 1) { temp.y = 10 * time_step; } else { temp.y = 15 * time_step; }
	}

	if (my.movement_mode == 0) {
		my.move_x = fcos(temp.x,temp.y);
		my.move_y = fsin(temp.x,temp.y);
	}
	if (my.movement_mode == 1 || my.movement_mode == 2) {
		temp.y = fsin((my.animate * 1.2) + 45,15 * time_step);
		my.move_x = fcos(my.pan,temp.y);
		my.move_y = fsin(my.pan,temp.y);
		temp.y = 0;
		if (temp.x != -1000) { //if we need to rotate whilst attacking (the player is pressing keys to rotate)
			temp.y = 1;
		}
	}

//	move_mode = IGNORE_PASSABLE | GLIDE; //replace c_move with these 2 lines in versions of gamestudio below 6.4
//	ent_move(nullvector,my.move_x);
	c_move(my,nullvector,my.move_x,USE_AABB | IGNORE_PASSABLE | GLIDE);

	result = c_trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - 4000),IGNORE_ME | IGNORE_PASSABLE | USE_BOX);
	if (result < 0) { my.z -= result; my.velocity_z = 0; }

	if (target_enemy == NULL) {
		if (temp.y > 0) { rotate_entity(temp.x,30); }
	} else {
		vec_diff(temp2.x,target_enemy.x,my.x);
		vec_to_angle(plAng.pan,temp2.x);
		rotate_entity(plAng.pan,30);
	}

	if (my.movement_mode == 0) {
		my.grav = 6;
		if (my.move_x != 0 || my.move_y != 0) { //if we are moving
			if (my.animblend == stand) { //if our current animation is stand
				if (key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
			if (my.animblend == run && key_shift == 1) { my.blendframe = walk; }
			if (my.animblend == walk && key_shift == 0) { my.blendframe = run; }
		} else {
			if (my.animblend > stand && my.animblend != jump && my.animblend != fall) { //if we arn't moving and our current animation is walk or run, blend and cycle the stand animation
				my.blendframe = stand;
			}
		}
		if (mouse_left == 0 && mouse_left_press == 1) { mouse_left_press = 0; }
		if (mouse_left == 1 && mouse_left_press == 0 && my.animblend >= stand) {
			mouse_left_press = 1;
			my.blendframe = attack_a;
			if (my.jumping_mode == 1) {
				airborne_attack = 1;
			} else {
				airborne_attack = 0;
			}
			my.movement_mode = 1;
			combo_continue = 0;
		}
		if (mouse_right == 0 && mouse_right_press == 1) { mouse_right_press = 0; } ///////////////
		if (mouse_right == 1 && mouse_right_press == 0) {
			if (player_lock_on == 0) {
//				vec_set(temp.x,vector(360,180,250)); //replace c_scan with these 2 lines in versions of gamestudio below 6.4
//			 	result = scan_entity(player.x,temp);
				c_scan(player.x,player.pan,vector(360,180,250),SCAN_ENTS | SCAN_LIMIT | IGNORE_ME);
				if (you != NULL) {
					if (you.entity_type == 2) { //make sure you've scanned an enemy
						player_lock_on = 1;
						target_enemy = you;
					}
				}
			} else {
				player_lock_on = 0;
				target_enemy = NULL;
			}
			mouse_right_press = 1;
		}
	}
	if (my.movement_mode == 1) {
		if (my.jumping_mode != 10) {
			my.jumping_mode = 0;
		} else {
			if (my.animate >= 60 && my.animblend >= stand) { my.jumping_mode = 0; }
		}
		if (mouse_left == 0 && mouse_left_press == 1) { mouse_left_press = 0; }
		if (mouse_left == 1 && mouse_left_press == 0 && my.animate >= 30 && combo_continue == 0) { mouse_left_press = 1; combo_continue = 1; }
	}
	if (my.movement_mode == 2) {
		my.jumping_mode = 0;
		if (mouse_left == 0 && mouse_left_press == 1) { mouse_left_press = 0; }
		if (mouse_left == 1 && mouse_left_press == 0 && my.animate >= 30 && combo_continue == 0) { mouse_left_press = 1; combo_continue = 1; }
	}
}

function handle_grav() 
{
	//trace_mode = IGNORE_ME+IGNORE_PASSABLE+USE_BOX;
	result = c_trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - 4000),IGNORE_ME | IGNORE_PASSABLE | USE_BOX);
	if (result < 3) {
		if (my.jumping_mode == 0) {
			my.force_z = -1 * result;
			if (key_space == 0 && space_press == 1) { space_press = 0; }
			if (key_space == 1 && space_press == 0 && my.movement_mode == 0 && my.animblend >= stand && my.animblend != jump && my.animblend != fall) {
				space_press = 1;
				my.jumping_mode = 1;
				my.force_z = 25;
				my.blendframe = jump;
				my.animate2 = 0;
				my.animblend = blend;
			}
		}
		if (my.jumping_mode == 2 || my.jumping_mode == 3) { my.jumping_mode = 0; }
	} else {
		if (my.jumping_mode == 2) {
			if (result > 120) {
				my.animate = 60;
				my.jumping_mode = 3;
			} else {
				my.jumping_mode = 0;
			}
		}
		if (my.jumping_mode == 3 && result <= 120) { my.jumping_mode = 0;	}
		if (my.jumping_mode == 0 && my.movement_mode == 0) {
			if (result > 120 && my.animblend >= stand && my.animblend != jump && my.animblend != fall) {
				my.jumping_mode = 3;
				my.blendframe = fall;
				my.animate2 = 0;
				my.animblend = blend;
			}
		}
		my.force_z -= my.grav * time_step;
		my.force_z = maxv(-30,my.force_z);
		if (my.movement_mode == 2) { my.force_z = 0; }
	}
 	my.velocity_z += (time_step * my.force_z) - (minv(time_step*0.7,1) * my.velocity_z);
	my.move_z = my.velocity_z * time_step;
}

//////////////////////////////
//Stable/rigid camera collision
//////////////////////////////
function handle_camera()
{
	var temp;
	VECTOR tempVec;
	camera.pan -= mouse_force.x * 12 * time_step;
	camera.tilt += mouse_force.y * 8 * time_step;
	camera.tilt = clamp(camera.tilt,-30,10);
	temp = fcos(camera.tilt,-camera_distance);
	vec_set(camera.x,vector(my.x + fcos(camera.pan,temp),my.y + fsin(camera.pan,temp),my.z + 20 + fsin(camera.tilt,-camera_distance)));

	vec_diff(tempVec.x,camera.x,my.x); //find the vector from the player to the camera
	vec_normalize(tempVec.x,16); //get the magnitude of it's vector to 16 quants and store it in temp
	vec_add(tempVec.x,camera.x); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.

	//trace_mode = IGNORE_ME+IGNORE_PASSABLE+ignore_models;
	result = c_trace(my.x,tempVec.x,IGNORE_ME | IGNORE_PASSABLE | IGNORE_MODELS); //trace from the player to 16 quants behind the camera.
	if (result > 0) {
		vec_diff(tempVec.x,my.x,target.x); //find the vector from the point the trace hit to the player
		vec_normalize(tempVec.x,16); //get the magnitude of this vector to 16 quants and store in temp
		vec_set(camera.x,target.x); //place the camera at the trace hit point
		vec_add(camera.x,tempVec.x); //move the camera away from the wall by the vector temp, 16 quants towards the player
	}
}


//////////////////////////////
//Smooth camera collision
//////////////////////////////
/*function handle_camera() {
	camera_pan -= mouse_force.x * 12 * time_step_step_step;
	camera_tilt += mouse_force.y * 8 * time_step_step_step;
	camera_tilt = clamp(camera_tilt,-30,10);

	camera.pan = camera_pan;
	temp = fcos(camera_tilt,-camera_distance);
	vec_set(camera_move_to.x,vector(my.x + fcos(camera.pan,temp),my.y + fsin(camera.pan,temp),my.z + 20 + fsin(camera_tilt,-camera_distance)));

	temp = minv(1,0.5 * time_step_step); //changing 0.5 will change how fast the camera moves, at 1 places us at target, this value is what allows the smooth movement
	camera.x += temp*(camera_move_to.x - camera.x);
	camera.y += temp*(camera_move_to.y - camera.y);
	camera.z += temp*(camera_move_to.z - camera.z);

	vec_diff(temp.x,camera.x,my.x);
	vec_normalize(temp.x,16);
	vec_add(temp.x,camera.x);

	trace_mode = IGNORE_ME + IGNORE_PASSABLE + ignore_models;
	if (trace(my.x,temp.x) > 0) {
		vec_diff(temp.x,my.x,target.x);
		vec_normalize(temp.x,16);
		vec_set(camera.x,target.x);
		vec_add(camera.x,temp.x);
	}

	vec_diff(temp.x,my.x,camera.x);
	vec_to_angle(camera.pan,temp.x);
}*/

function rotate_entity(rotate_angle,rotate_speed)
{
	if (my.pan == rotate_angle) return;
	result = ang(rotate_angle - my.pan);
	if (result > 0) { my.pan += rotate_speed * time_step; }
	if (result < 0) { my.pan -= rotate_speed * time_step; }
	if (ang(rotate_angle - my.pan) < 0 && result > 0) { my.pan = rotate_angle; }
	if (ang(rotate_angle - my.pan) > 0 && result < 0) { my.pan = rotate_angle; }
}

function handle_sword_collision()
{
	VECTOR temp;
	VECTOR temp2;
	you = NULL;
	vec_for_vertex(temp.x,player_weapon,274); //sword base
	vec_for_vertex(temp2.x,player_weapon,54); //sword tip
	//trace_mode = IGNORE_ME+IGNORE_PASSABLE+USE_BOX;
	result = c_trace(temp.x,temp2.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX);
	if (you != NULL) {
		if (you.entity_type == 2 && you.hit_by_player == 0) {
			if (airborne_attack == 1 && my.animblend == attack_a) {
				my.movement_mode = 2;
			}
			you.hit_by_player = 1;
			if (target_enemy == NULL) { target_enemy = you; player_lock_on = 1; }
		}
	}
}


action player_action()
{
	player = my;
	my.grav = 6;
	my.z_offset = 6;
	set(my,SHADOW);
	ent_create("sword.mdl",my.x,attach_weapon);
	wait(1);
	while (1) { //the main loop
		handle_grav();
		handle_movement();
		handle_camera();
		handle_animation(1);
		wait(1);
	}
}


enemy.c

Code:
action enemy_dummy()
{
	set(my,SHADOW);
	my.entity_type = 2;
	//my.enable_scan = on;
	my.emask |= ENABLE_SCAN;
	while (1) {
		if (my.hit_by_player == 1) {
			my.move_x = player.move_x;
			my.move_y = player.move_y;
			my.move_z = player.move_z;
			//	move_mode = ignore_passable | glide; //replace c_move with these 2 lines in versions of gamestudio below 6.4
			//	ent_move(nullvector,my.move_x);
			c_move(my,nullvector,my.move_x,USE_AABB | IGNORE_PASSABLE | GLIDE);
			if (player.animblend == blend || player.animblend < attack_a || my.animblend > attack_f) { my.hit_by_player = 0; }
		}
		if ((player.animblend >= stand && target_enemy == my && player_lock_on == 0) && (player.animblend < attack_a || player.animblend > attack_f)) target_enemy = NULL;
		if (target_enemy == my && vec_dist(my.x,player.x) > 200) target_enemy = NULL;
		wait(1);
	}
}


animation.c

Code:
function handle_animation(animation_speed) {
	if (animation_speed <= 0) { animation_speed = 1; }
	if (my.animblend != blend && my.blendframe != nullframe) { my.animate2 = 0; my.animblend = blend; }
	if (my.animblend == blend) {
		if (my.currentframe == stand) { ent_animate(my,"stand",my.animate,ANM_CYCLE); }
		if (my.currentframe == run) { ent_animate(my,"run",my.animate,ANM_CYCLE); }
		if (my.currentframe == walk) { ent_animate(my,"walk",my.animate,ANM_CYCLE); }
		if (my.currentframe == jump) { ent_animate(my,"jump",my.animate,0); }
		if (my.currentframe == attack_a) { ent_animate(my,"attack_a",my.animate,0); }
		if (my.currentframe == attack_b) { ent_animate(my,"attack_b",my.animate,0); }
		if (my.currentframe == attack_c) { ent_animate(my,"attack_c",my.animate,0); }
		if (my.currentframe == attack_d) { ent_animate(my,"attack_d",my.animate,0); }
		if (my.currentframe == attack_e) { ent_animate(my,"attack_e",my.animate,0); }
		if (my.currentframe == attack_f) { ent_animate(my,"attack_f",my.animate,0); }
		if (my.blendframe == stand) { ent_blend("stand",0,my.animate2); }
		if (my.blendframe == run) { ent_blend("run",0,my.animate2); }
		if (my.blendframe == walk) { ent_blend("walk",0,my.animate2); }
		if (my.blendframe == jump) { ent_blend("jump",0,my.animate2); }
		if (my.blendframe == fall) { ent_blend("jump",60,my.animate2); }
		if (my.blendframe == attack_a) { ent_blend("attack_a",0,my.animate2); }
		if (my.blendframe == attack_b) { ent_blend("attack_b",0,my.animate2); }
		if (my.blendframe == attack_c) { ent_blend("attack_c",0,my.animate2); }
		if (my.blendframe == attack_d) { ent_blend("attack_d",0,my.animate2); }
		if (my.blendframe == attack_e) { ent_blend("attack_e",0,my.animate2); }
		if (my.blendframe == attack_f) { ent_blend("attack_f",0,my.animate2); }
		my.animate2 += 45 * time_step;
		if (my.animate2 >= 100) {
			my.animate = 0;
			my.animblend = my.blendframe;
			my.blendframe = nullframe;
		}
	}
	if (my.animblend == stand) {
		ent_animate(my,"stand",my.animate,ANM_CYCLE);
		my.animate += 5 * animation_speed * time_step;
		my.animate %= 100;
		my.currentframe = stand;
	}
	if (my.animblend == run) {
		ent_animate(my,"run",my.animate,ANM_CYCLE);
		my.animate += 8 * animation_speed * time_step;
		my.animate %= 100;
		my.currentframe = run;
	}
	if (my.animblend == walk) {
		ent_animate(my,"walk",my.animate,ANM_CYCLE);
		my.animate += 8 * animation_speed * time_step;
		my.animate %= 100;
		my.currentframe = walk;
	}
	if (my.animblend == jump || my.animblend == fall) {
		if (my.jumping_mode == 3) { my.animate = 60; }
		ent_animate(my,"jump",my.animate,0);
		my.animate += 10 * animation_speed * time_step;
		my.currentframe = jump;
		if (my.animate >= 60 && my.jumping_mode == 1) { my.jumping_mode = 2; }
		if (my.animate >= 100) {
			ent_animate(my,"jump",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if (my.moving == 1) {
				if (key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
		}
	}
	if (my.animblend == attack_a) {
		ent_animate(my,"attack_a",my.animate,0);
		my.animate += 20 * animation_speed * time_step;
		my.currentframe = attack_a;
		if (my.animate >= 100) {
			ent_animate(my,"attack_a",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if (my.moving == 1) {
				if (key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
			if (combo_continue == 1) {
				combo_continue = 0;
				my.blendframe = attack_b;
			} else {
				my.movement_mode = 0;
			}
		}
	}
	if (my.animblend == attack_b) {
		ent_animate(my,"attack_b",my.animate,0);
		my.animate += 15 * animation_speed * time_step;
		my.currentframe = attack_b;
		if (my.animate >= 100) {
			ent_animate(my,"attack_b",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if (my.moving == 1) {
				if (key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
			if (combo_continue == 1) {
				combo_continue = 0;
				my.blendframe = attack_c;
			} else {
				my.movement_mode = 0;
			}
		}
	}
	if (my.animblend == attack_c) {
		ent_animate(my,"attack_c",my.animate,0);
		my.animate += 10 * animation_speed * time_step;
		my.currentframe = attack_c;
		if (my.animate >= 100) {
			ent_animate(my,"attack_c",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if (my.moving == 1) {
				if (key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
			if (combo_continue == 1) {
				my.jumping_mode = 10;
				my.force_z = 12;
				my.grav = 4;
				combo_continue = 0;
				my.blendframe = attack_d;
			} else {
				my.movement_mode = 0;
			}
		}
	}
	if (my.animblend == attack_d) {
		handle_sword_collision();
		ent_animate(my,"attack_d",my.animate,0);
		my.animate += 15 * animation_speed * time_step;
		my.currentframe = attack_d;
		if (my.animate >= 100) {
			ent_animate(my,"attack_d",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if (my.moving == 1) {
				if (key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
			if (combo_continue == 1) {
				combo_continue = 0;
				my.blendframe = attack_e;
			} else {
				my.movement_mode = 0;
			}
		}
	}
	if (my.animblend == attack_e) {
		ent_animate(my,"attack_e",my.animate,0);
		my.animate += 15 * animation_speed * time_step;
		my.currentframe = attack_e;
		if (my.jumping_mode == 0 && my.animate >= 20 && my.animate < 60) {
			my.grav = 3;
			my.jumping_mode = 10;
			my.force_z = 15;
		}
		if (my.animate >= 100) {
			ent_animate(my,"attack_e",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if (my.moving == 1) {
				if (key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
			if (combo_continue == 1) {
				combo_continue = 0;
				my.blendframe = attack_f;
			} else {
				my.movement_mode = 0;
			}
		}
	}
	if (my.animblend == attack_f) {
		ent_animate(my,"attack_f",my.animate,0);
		my.animate += 6 * animation_speed * time_step;
		my.currentframe = attack_f;
		if (my.jumping_mode == 0 && my.animate >= 40 && my.animate < 60) {
			my.grav = 6;
			my.jumping_mode = 10;
			my.force_z = 12;
		}
		if (my.animate >= 100) {
			my.movement_mode = 0;
			ent_animate(my,"attack_f",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if (my.moving == 1) {
				if (key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
		}
	}
	if (my.animblend >= attack_a && my.animblend <= attack_f) { handle_sword_collision(); }
	if (my.animblend != blend && my.blendframe != nullframe) { my.animate2 = 0; my.animblend = blend; }
}


Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/12/08 09:28

Great. now player keeps falling.

what to do now.... so okay! ill get the modified kh movement code. but it have an errors, and i need the combo attack.

and kh movement code animation is cool, so can you put the kh animation code to the modified?

sorry -_-
Posted By: croman

Re: [REQ] converting a code to lite-c - 12/13/08 09:59

heinekenbottle that's exactly what happened to me when i tried to translate it. i believe that you'll need to implement different gravity(falling) code.
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/13/08 10:57

but from where? dunno.
Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 12/13/08 11:41

All the issues with the KH conversion all boil down to its gravity simulation.
Everything else seems to convert OK, for the others who have converted it too.

I dont think its an engine version issue, because the WDL version runes fine
under the current release. Only the lite-c version's gravity is warped.

If you take my one of our conversions (mine at least I know this works for),
and cripple the handle_gravity() function, then everything else works OK.

That should give you something to work from.

Hell, if you re-wrote the handle_gravity function we would all be grateful Im sure.
Posted By: croman

Re: [REQ] converting a code to lite-c - 12/13/08 12:04

it has to do with c_move or c_scan function in lite-c. i dont know how and why is that so unfortunately.
Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 12/13/08 12:14

I dont know the why, but the problem lies in the start on the handle_gravity
function in the results to the c_scan.

From memory of my conversion then testing this code, this c_scan generates
different returns in WDL and c-lite, which doesnt make sense to me.
In WDL, it returns a -quants_depth if the object passes through the floor.
In lite-c, it returns a -1400 and something if the object passes through the floor.
I dont know why. But this same seemingly-wrong return value does cause problems
elsewhere in KHmovement, but minor compared to the gravity issue.
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/13/08 12:24

so ill replace handle_gravity function to you function and ill see wink.
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/13/08 12:36

AWESOME!! it doesn't work, error in player.c line 231.
Posted By: croman

Re: [REQ] converting a code to lite-c - 12/13/08 12:51

what kind of error?
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/13/08 13:03

'gravity' is not a member of 'ENTITY'
Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 12/13/08 13:10

Sorry no.
In player.C, in the player_action() function, in the while loop,
comment out the line handle_gravity(); that is all.
That will by-pass all the gravity problems.
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/13/08 13:49

sorry but your function is bad, player can't jump with your function.
Posted By: croman

Re: [REQ] converting a code to lite-c - 12/13/08 14:04

that gravity is not a member of ENTITY problem try to solve with putting this define:
#define gravity skill70
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/13/08 14:10

ill try
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/13/08 14:17

now player is flying, not falling, and can't jump.
Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 12/13/08 14:43

Unfortunately, thats what happens when you turn gravity off.
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/13/08 15:05

The gravity is ON, ON and ON
Posted By: testDummy

Re: [REQ] converting a code to lite-c - 12/13/08 16:21

pseudo-fixed, here (jump + fall)
with->
collision: model (not BSP)
version: Lite-C 7.50 (not full A7)

Code is and was a mess anyway.
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/13/08 16:55

what do you mean?
Posted By: croman

Re: [REQ] converting a code to lite-c - 12/13/08 17:39

try with this gravity code:

Code:
//Gravity:
vec_set(temp, my.x); 
temp.z -= 1000; 
player_dist.z = -abs(c_trace (my.x, temp, IGNORE_ME | IGNORE_PASSABLE | USE_BOX));


it's from Peter Soxberg's (Dark_Samurai) code...and it works
Posted By: testDummy

Re: [REQ] converting a code to lite-c - 12/13/08 21:43

player.c
Click to reveal..

Code:
#ifndef player_c
#define player_c
/////
//
//
#define nullframe	-2
#define blend		-1
#define stand		0
#define run			1
#define walk		2
#define jump		3
#define fall		4
#define attack_a	5
#define attack_b	6
#define attack_c	7
#define attack_d	8
#define attack_e	9
#define attack_f	10
//
#define move_x				skill22
#define move_y				skill23
#define move_z				skill24
#define force_x			skill25
#define force_y			skill26
#define force_z			skill27
#define velocity_x		skill28
#define velocity_y		skill29
#define velocity_z		skill30
#define animate			skill31
#define animate2			skill32
#define animblend			skill33
#define currentframe		skill34
#define blendframe		skill35
#define z_offset			skill50
#define jumping_mode		skill51
#define gravity			skill52
#define movement_mode	skill53
#define moving				skill54
#define hit_by_player	skill55
#define entity_type		skill56
//
//
function handle_animation(var animation_speed); 
function rotate_entity(var rotate_angle, var rotate_speed);
//
//
ENTITY* player_weapon;
ENTITY* target_enemy;
//
VECTOR* camera_move_to = { x=0;	y=0;	z=0; }
var camera_distance = 200;
var camera_pan;
var camera_tilt;
//
var space_press = 0;
var mouse_left_press = 0;
var mouse_right_press = 0;
var combo_continue = 0;
var player_lock_on = 0;
var airborne_attack = 0;
//
VECTOR* tempV = { x=0; 	 y=0; 	z=0; }
VECTOR* tempV2= { x=0; 	 y=0; 	z=0; }
ANGLE*  tempA = { pan=0; tilt=0; roll=0; }
ANGLE*  tempA2= { pan=0; tilt=0; roll=0; }
//
//
//
action attach_weapon()
{
	player_weapon = my;
	set(my,PASSABLE);
	proc_mode = PROC_LATE;
	while(you!=NULL) 
	{
		vec_for_vertex(tempV.x,  you, 1175);		//hand palm base
		vec_for_vertex(tempV2.x, you, 1240);		//hand palm tip
		vec_set(my.x, tempV.x);
		vec_diff(tempV.x, tempV2.x, tempV.x);
		vec_to_angle(tempA.pan, tempV.x);
		vec_set(my.pan, tempA.pan);
		wait(1);
	}
}
//
//

function handle_movement() 
{
	tempV.x = -1000;
	tempV.y = 0;
	my.moving = 0;
	if (key_w == 1 && key_s == 0 && key_a == 0 && key_d == 0) 	{ tempV.x = camera.pan; }
	if (key_s == 1 && key_w == 0 && key_a == 0 && key_d == 0) 	{ tempV.x = camera.pan + 180; }
	if (key_a == 1 && key_s == 0 && key_w == 0 && key_d == 0) 	{ tempV.x = camera.pan + 90; }
	if (key_d == 1 && key_s == 0 && key_a == 0 && key_w == 0) 	{ tempV.x = camera.pan - 90; }
	if (key_w == 1 && key_a == 1 && key_d == 0 && key_s == 0) 	{ tempV.x = camera.pan + 45; }
	if (key_w == 1 && key_d == 1 && key_a == 0 && key_s == 0) 	{ tempV.x = camera.pan - 45; }
	if (key_s == 1 && key_a == 1 && key_d == 0 && key_w == 0) 	{ tempV.x = camera.pan + 135; }
	if (key_s == 1 && key_d == 1 && key_a == 0 && key_w == 0) 	{ tempV.x = camera.pan - 135; }
	if (tempV.x != -1000) 
	{
		my.moving = 1;
		if (key_shift == 1)	{ tempV.y = 10 * time_step; } 
		else 						{ tempV.y = 15 * time_step; }
	}

	if (my.movement_mode == 0) 
	{
		my.move_x = fcos(tempV.x,tempV.y);
		my.move_y = fsin(tempV.x,tempV.y);
	}
	if (my.movement_mode == 1 || my.movement_mode == 2) 
	{
		tempV.y = fsin((my.animate * 1.2) + 45,15 * time_step);
		my.move_x = fcos(my.pan,tempV.y);
		my.move_y = fsin(my.pan,tempV.y);
		tempV.y = 0;
		if (tempV.x != -1000) 	tempV.y = 1;	//if we need to rotate whilst attacking (the player is pressing keys to rotate)
	}
	//
	c_move(my,nullvector,my.move_x, USE_AABB|IGNORE_PASSABLE|GLIDE);
	//
	//result = trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - 4000));
	//if (result < 0)	{	my.z -= result;	my.velocity_z = 0;	}
	if (target_enemy == NULL) 
	{	
		if (tempV.y > 0) { rotate_entity(tempV.x,30); }		
	} 
	else 
	{
		vec_diff(tempV2.x,target_enemy.x,my.x);
		vec_to_angle(tempA2.pan,tempV2.x);
		rotate_entity(tempA2.pan,30);
	}
	//
	switch(my.movement_mode)
	{
 		case 0:		
			my.gravity = 6;
			if (my.move_x != 0 || my.move_y != 0) 		 //if we are moving
			{
				if (my.animblend == stand) //if our current animation is stand
				{ 
					if (key_shift == 1)	my.blendframe = walk; 
					else 						my.blendframe = run; 
				}
				if (my.animblend == run  && key_shift == 1)	my.blendframe = walk;
				if (my.animblend == walk && key_shift == 0)	my.blendframe = run; 
			} 
			else 
			{
				//if we arn't moving and our current animation is walk or run, blend and cycle the stand animation
				if (my.animblend > stand && my.animblend != jump && my.animblend != fall) 		my.blendframe = stand;
			}
			if (mouse_left == 0 && mouse_left_press == 1)	mouse_left_press = 0; 
			if (mouse_left == 1 && mouse_left_press == 0 && my.animblend >= stand) 
			{
				mouse_left_press = 1;
				my.blendframe = attack_a;
				if (my.jumping_mode == 1) 		airborne_attack = 1;
				else									airborne_attack = 0;
				my.movement_mode = 1;
				combo_continue = 0;
			}
			if (mouse_right == 0 && mouse_right_press == 1) 	mouse_right_press = 0;		///////////////
			if (mouse_right == 1 && mouse_right_press == 0) 
			{
				if (player_lock_on == 0) 
				{
					c_scan(player.x,player.pan,vector(360,180,250),SCAN_ENTS|SCAN_LIMIT|IGNORE_ME);
					if (you != NULL) 
					{
						if (you.entity_type == 2)  //make sure you've scanned an enemy
						{	player_lock_on = 1;		target_enemy = you;		}
					}
				} 
				else 
				{	player_lock_on = 0;		target_enemy = NULL;		}
				mouse_right_press = 1;
			}
			break;
 		case 1:		
			if (my.jumping_mode != 10) 									my.jumping_mode = 0;
			else if((my.animate >= 60)&&(my.animblend >= stand)) 	my.jumping_mode = 0; 
			if(mouse_left == 0 && mouse_left_press == 1) 			mouse_left_press = 0; 
			if(mouse_left == 1 && mouse_left_press == 0 && my.animate >= 30 && combo_continue == 0) 
			{	mouse_left_press = 1; 	combo_continue = 1; 	}
			break;
 		case 2:		
		my.jumping_mode = 0;
		if(mouse_left == 0 && mouse_left_press == 1)		mouse_left_press = 0;
		if(mouse_left == 1 && mouse_left_press == 0 && my.animate >= 30 && combo_continue == 0) 
		{		mouse_left_press = 1;		combo_continue = 1; 		}
		break;
	}
}
//
//
function handle_gravity() 
{
	result = c_trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - 120),IGNORE_ME|IGNORE_PASSABLE|USE_POLYGON);
	if(trace_hit == 0 && result == 0) { result = 120; }
	if(result<3) 
	{	
		//if(result<0)	result = c_trace(my.x,vector(my.x,my.y,my.z + 4000),IGNORE_ME|IGNORE_PASSABLE|USE_POLYGON);	//!!FUDGE!! stop skyjumping
		//
		if(my.jumping_mode==0) 
		{
			my.force_z = -1 * result;
			if((key_space==0) && (space_press==1))	space_press = 0; 
			if((key_space==1) && (space_press==0) && (my.movement_mode==0) && (my.animblend>=stand) && (my.animblend!=jump) 	&& (my.animblend!=fall)) 
			{
				space_press = 1;
				my.jumping_mode = 1;
				my.force_z = 25;
				my.blendframe = jump;
				my.animate2 = 0;
				my.animblend = blend;
			}
		}
		if((my.jumping_mode==2) || (my.jumping_mode==3))	my.jumping_mode = 0;
	} 
	else 
	{
		if(my.jumping_mode==2) 
		{
			if(result>120) 
			{
				my.animate = 60;
				my.jumping_mode = 3;
			} 
			else	my.jumping_mode = 0;
		}
		if((my.jumping_mode==3) && (result<=120))		my.jumping_mode = 0;	
		if((my.jumping_mode==0) && (my.movement_mode==0))
		{
			if((result>120) && (my.animblend>=stand) && (my.animblend!=jump) && (my.animblend!=fall)) 
			{
				my.jumping_mode = 3;
				my.blendframe = fall;
				my.animate2 = 0;
				my.animblend = blend;
			}
		}
		my.force_z -= my.gravity * time_step;
		my.force_z = maxv(-30,my.force_z);
		if(my.movement_mode==2)		my.force_z = 0;
	}
 	my.velocity_z += (time_step * my.force_z) - (minv(time_step*0.7,1) * my.velocity_z);
	my.move_z = my.velocity_z * time_step;
}
//
//
//////////////////////////////
//Stable/rigid camera collision
//////////////////////////////
function handle_camera() 
{
	camera.pan -= mouse_force.x * 12 * time_step;
	camera.tilt += mouse_force.y * 8 * time_step;
	camera.tilt = clamp(camera.tilt,-30,10);
	tempA.pan = fcos(camera.tilt,-camera_distance);
	vec_set(camera.x,vector(my.x + fcos(camera.pan,tempA.pan),my.y + fsin(camera.pan,tempA.pan),my.z + 20 + fsin(camera.tilt,-camera_distance)));
	vec_diff(tempV.x,camera.x,my.x); 	//find the vector from the player to the camera
	vec_normalize(tempV.x,16); 			//get the magnitude of it's vector to 16 quants and store it in temp
	vec_add(tempV.x,camera.x); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.
	result = c_trace(my.x,tempV.x,IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS);
	if(result > 0) 
	{
		vec_diff(tempV.x,my.x,target.x); //find the vector from the point the trace hit to the player
		vec_normalize(tempV.x,16); 		//get the magnitude of this vector to 16 quants and store in temp
		vec_set(camera.x,target.x);		//place the camera at the trace hit point
		vec_add(camera.x,tempV.x);			//move the camera away from the wall by the vector temp, 16 quants towards the player
	}
}
//
//
//////////////////////////////
//Smoother camera collision
//////////////////////////////
/*
function handle_camera() {
	camera_pan -= mouse_force.x * 12 * time_step;
	camera_tilt += mouse_force.y * 8 * time_step;
	camera_tilt = clamp(camera_tilt,-30,10);
	camera.pan = camera_pan;
	tempA.pan = fcos(camera_tilt,-camera_distance);
	vec_set(camera_move_to.x,vector(my.x + fcos(camera.pan,tempA.pan),my.y + fsin(camera.pan,tempA.pan),my.z + 20 + fsin(camera_tilt,-camera_distance)));
	var temp = minv(1,0.5 * time_step); //changing 0.5 will change how fast the camera moves, at 1 places us at target, this value is what allows the smooth movement
	camera.x += temp*(camera_move_to.x - camera.x);
	camera.y += temp*(camera_move_to.y - camera.y);
	camera.z += temp*(camera_move_to.z - camera.z);
	vec_diff(tempV.x,camera.x,my.x);
	vec_normalize(tempV.x,16);
	vec_add(tempV.x,camera.x);
	if (c_trace(my.x,tempV.x,IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS) > 0) {
		vec_diff(tempV.x,my.x,target.x);
		vec_normalize(tempV.x,16);
		vec_set(camera.x,target.x);
		vec_add(camera.x,tempV.x);
	}
	vec_diff(tempV.x,my.x,camera.x);
	vec_to_angle(camera.pan,tempV.x);
}
*/
//
//
function rotate_entity(var rotate_angle, var rotate_speed)
{
	if(my.pan == rotate_angle)			return;
	result = ang(rotate_angle - my.pan);
	if (result > 0)		my.pan += rotate_speed * time_step;
	if (result < 0)		my.pan -= rotate_speed * time_step; 
	if ((ang(rotate_angle - my.pan) < 0) && (result > 0))	my.pan = rotate_angle; 
	if ((ang(rotate_angle - my.pan) > 0) && (result < 0))	my.pan = rotate_angle; 
}
//
//
function handle_sword_collision()
{
	you = NULL;
	vec_for_vertex(tempV.x, player_weapon,274); //sword base
	vec_for_vertex(tempV2.x,player_weapon, 54); //sword tip
	result = c_trace(tempV.x,tempV2.x,IGNORE_ME|IGNORE_PASSABLE|USE_BOX);
	if (you != NULL) {
		if ((you.entity_type == 2) && (you.hit_by_player == 0))
		{
			if (airborne_attack == 1 && my.animblend == attack_a) 	my.movement_mode = 2;
			you.hit_by_player = 1;
			if (target_enemy == NULL)		{	target_enemy = you; 		player_lock_on = 1; 	}
		}
	}
}
//
//
action player_action()
{
	c_setminmax(me);					//added to correct ground collisions
	wait(1);								//added to correct ground collisions
	player = me;
	my.gravity = 6;
	my.z_offset = -my.min_z;		//was 6	//added to correct ground collisions
	set(my,SHADOW);
	ent_create("sword.mdl", my.x, attach_weapon);
	wait(1);
	while(1) 
	{ //the main loop
		handle_gravity();
		handle_movement();
		handle_animation(1);
		handle_camera();
		wait(1);
	}
}
//
//
/////
#endif


Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/14/08 13:14

Thanks, I'll try it.
Posted By: testDummy

Re: [REQ] converting a code to lite-c - 12/17/08 18:13

Quoting Cowabanga.
Quote:
Thanks, I'll try it.

...and?
('We' cannot test it properly here without more data / samples.
At least for 'our' records, did the results seem better, or worse?)
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 12/19/08 06:46

I'll test it in 7.60 soon but because i have 7.07, it crashes every time when i to run the script.
Posted By: testDummy

Re: [REQ] converting a code to lite-c - 12/20/08 01:17

KHMovement D.Lancaster; EvilSOB
Lite-C 7.50
ver: min mod
player.c
Click to reveal..

Code:
#ifndef player_c
#define player_c
/////
//
//
#define nullframe	-2
#define blend		-1
#define stand		0
#define run			1
#define walk		2
#define jump		3
#define fall		4
#define attack_a	5
#define attack_b	6
#define attack_c	7
#define attack_d	8
#define attack_e	9
#define attack_f	10
//
#define move_x				skill22
#define move_y				skill23
#define move_z				skill24
#define force_x			skill25
#define force_y			skill26
#define force_z			skill27
#define velocity_x		skill28
#define velocity_y		skill29
#define velocity_z		skill30
#define animate			skill31
#define animate2			skill32
#define animblend			skill33
#define currentframe		skill34
#define blendframe		skill35
#define z_offset			skill50
#define jumping_mode		skill51
#define gravity			skill52
#define movement_mode	skill53
#define moving				skill54
#define hit_by_player	skill55
#define entity_type		skill56
//
//
function handle_animation(var animation_speed); 
function rotate_entity(var rotate_angle, var rotate_speed);
//
//
ENTITY* player_weapon;
ENTITY* target_enemy;
//
VECTOR* camera_move_to = { x=0;	y=0;	z=0; }
var camera_distance = 200;
var camera_pan;
var camera_tilt;
//
var space_press = 0;
var mouse_left_press = 0;
var mouse_right_press = 0;
var combo_continue = 0;
var player_lock_on = 0;
var airborne_attack = 0;
//
VECTOR* tempV = { x=0; 	 y=0; 	z=0; }
VECTOR* tempV2= { x=0; 	 y=0; 	z=0; }
ANGLE*  tempA = { pan=0; tilt=0; roll=0; }
ANGLE*  tempA2= { pan=0; tilt=0; roll=0; }
//
//
//
action attach_weapon()
{
	player_weapon = my;
	set(my,PASSABLE);
	proc_mode = PROC_LATE;
	while(you!=NULL) 
	{
		vec_for_vertex(tempV.x,  you, 1175);		//hand palm base
		vec_for_vertex(tempV2.x, you, 1240);		//hand palm tip
		vec_set(my.x, tempV.x);
		vec_diff(tempV.x, tempV2.x, tempV.x);
		vec_to_angle(tempA.pan, tempV.x);
		vec_set(my.pan, tempA.pan);
		wait(1);
	}
}
//
//

function handle_movement() 
{
	tempV.x = -1000;
	tempV.y = 0;
	my.moving = 0;
	if (key_w == 1 && key_s == 0 && key_a == 0 && key_d == 0) 	{ tempV.x = camera.pan; }
	if (key_s == 1 && key_w == 0 && key_a == 0 && key_d == 0) 	{ tempV.x = camera.pan + 180; }
	if (key_a == 1 && key_s == 0 && key_w == 0 && key_d == 0) 	{ tempV.x = camera.pan + 90; }
	if (key_d == 1 && key_s == 0 && key_a == 0 && key_w == 0) 	{ tempV.x = camera.pan - 90; }
	if (key_w == 1 && key_a == 1 && key_d == 0 && key_s == 0) 	{ tempV.x = camera.pan + 45; }
	if (key_w == 1 && key_d == 1 && key_a == 0 && key_s == 0) 	{ tempV.x = camera.pan - 45; }
	if (key_s == 1 && key_a == 1 && key_d == 0 && key_w == 0) 	{ tempV.x = camera.pan + 135; }
	if (key_s == 1 && key_d == 1 && key_a == 0 && key_w == 0) 	{ tempV.x = camera.pan - 135; }
	if (tempV.x != -1000) 
	{
		my.moving = 1;
		if (key_shift == 1)	{ tempV.y = 10 * time_step; } 
		else 						{ tempV.y = 15 * time_step; }
	}

	if (my.movement_mode == 0) 
	{
		my.move_x = fcos(tempV.x,tempV.y);
		my.move_y = fsin(tempV.x,tempV.y);
	}
	if (my.movement_mode == 1 || my.movement_mode == 2) 
	{
		tempV.y = fsin((my.animate * 1.2) + 45,15 * time_step);
		my.move_x = fcos(my.pan,tempV.y);
		my.move_y = fsin(my.pan,tempV.y);
		tempV.y = 0;
		if (tempV.x != -1000) 	tempV.y = 1;	//if we need to rotate whilst attacking (the player is pressing keys to rotate)
	}
	//
	c_move(my,nullvector,my.move_x, USE_AABB|IGNORE_PASSABLE|GLIDE);
	//
	//result = trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - 4000));
	//if (result < 0)	{	my.z -= result;	my.velocity_z = 0;	}
	if (target_enemy == NULL) 
	{	
		if (tempV.y > 0) { rotate_entity(tempV.x,30); }		
	} 
	else 
	{
		vec_diff(tempV2.x,target_enemy.x,my.x);
		vec_to_angle(tempA2.pan,tempV2.x);
		rotate_entity(tempA2.pan,30);
	}
	//
	switch(my.movement_mode)
	{
 		case 0:		
			my.gravity = 6;
			if (my.move_x != 0 || my.move_y != 0) 		 //if we are moving
			{
				if (my.animblend == stand) //if our current animation is stand
				{ 
					if (key_shift == 1)	my.blendframe = walk; 
					else 						my.blendframe = run; 
				}
				if (my.animblend == run  && key_shift == 1)	my.blendframe = walk;
				if (my.animblend == walk && key_shift == 0)	my.blendframe = run; 
			} 
			else 
			{
				//if we arn't moving and our current animation is walk or run, blend and cycle the stand animation
				if (my.animblend > stand && my.animblend != jump && my.animblend != fall) 		my.blendframe = stand;
			}
			if (mouse_left == 0 && mouse_left_press == 1)	mouse_left_press = 0; 
			if (mouse_left == 1 && mouse_left_press == 0 && my.animblend >= stand) 
			{
				mouse_left_press = 1;
				my.blendframe = attack_a;
				if (my.jumping_mode == 1) 		airborne_attack = 1;
				else									airborne_attack = 0;
				my.movement_mode = 1;
				combo_continue = 0;
			}
			if (mouse_right == 0 && mouse_right_press == 1) 	mouse_right_press = 0;		///////////////
			if (mouse_right == 1 && mouse_right_press == 0) 
			{
				if (player_lock_on == 0) 
				{
					c_scan(player.x,player.pan,vector(360,180,250),SCAN_ENTS|SCAN_LIMIT|IGNORE_ME);
					if (you != NULL) 
					{
						if (you.entity_type == 2)  //make sure you've scanned an enemy
						{	player_lock_on = 1;		target_enemy = you;		}
					}
				} 
				else 
				{	player_lock_on = 0;		target_enemy = NULL;		}
				mouse_right_press = 1;
			}
			break;
 		case 1:		
			if (my.jumping_mode != 10) 									my.jumping_mode = 0;
			else if((my.animate >= 60)&&(my.animblend >= stand)) 	my.jumping_mode = 0; 
			if(mouse_left == 0 && mouse_left_press == 1) 			mouse_left_press = 0; 
			if(mouse_left == 1 && mouse_left_press == 0 && my.animate >= 30 && combo_continue == 0) 
			{	mouse_left_press = 1; 	combo_continue = 1; 	}
			break;
 		case 2:		
		my.jumping_mode = 0;
		if(mouse_left == 0 && mouse_left_press == 1)		mouse_left_press = 0;
		if(mouse_left == 1 && mouse_left_press == 0 && my.animate >= 30 && combo_continue == 0) 
		{		mouse_left_press = 1;		combo_continue = 1; 		}
		break;
	}
}
//
//
function handle_gravity() 
{
	result = c_trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - 120),IGNORE_ME|IGNORE_PASSABLE|USE_POLYGON);
	if(trace_hit == 0 && result == 0) { result = 120; }
	if(result<3) 
	{	
		//if(result<0)	result = c_trace(my.x,vector(my.x,my.y,my.z + 4000),IGNORE_ME|IGNORE_PASSABLE|USE_POLYGON);	//!!FUDGE!! stop skyjumping
		//
		if(my.jumping_mode==0) 
		{
			my.force_z = -1 * result;
			if((key_space==0) && (space_press==1))	space_press = 0; 
			if((key_space==1) && (space_press==0) && (my.movement_mode==0) && (my.animblend>=stand) && (my.animblend!=jump) 	&& (my.animblend!=fall)) 
			{
				space_press = 1;
				my.jumping_mode = 1;
				my.force_z = 25;
				my.blendframe = jump;
				my.animate2 = 0;
				my.animblend = blend;
			}
		}
		if((my.jumping_mode==2) || (my.jumping_mode==3))	my.jumping_mode = 0;
	} 
	else 
	{
		if(my.jumping_mode==2) 
		{
			if(result>120) 
			{
				my.animate = 60;
				my.jumping_mode = 3;
			} 
			else	my.jumping_mode = 0;
		}
		if((my.jumping_mode==3) && (result<=120))		my.jumping_mode = 0;	
		if((my.jumping_mode==0) && (my.movement_mode==0))
		{
			if((result>120) && (my.animblend>=stand) && (my.animblend!=jump) && (my.animblend!=fall)) 
			{
				my.jumping_mode = 3;
				my.blendframe = fall;
				my.animate2 = 0;
				my.animblend = blend;
			}
		}
		my.force_z -= my.gravity * time_step;
		my.force_z = maxv(-30,my.force_z);
		if(my.movement_mode==2)		my.force_z = 0;
	}
 	my.velocity_z += (time_step * my.force_z) - (minv(time_step*0.7,1) * my.velocity_z);
	my.move_z = my.velocity_z * time_step;
}
//
//
//////////////////////////////
//Stable/rigid camera collision
//////////////////////////////
function handle_camera() 
{
	camera.pan -= mouse_force.x * 12 * time_step;
	camera.tilt += mouse_force.y * 8 * time_step;
	camera.tilt = clamp(camera.tilt,-30,10);
	tempA.pan = fcos(camera.tilt,-camera_distance);
	vec_set(camera.x,vector(my.x + fcos(camera.pan,tempA.pan),my.y + fsin(camera.pan,tempA.pan),my.z + 20 + fsin(camera.tilt,-camera_distance)));
	vec_diff(tempV.x,camera.x,my.x); 	//find the vector from the player to the camera
	vec_normalize(tempV.x,16); 			//get the magnitude of it's vector to 16 quants and store it in temp
	vec_add(tempV.x,camera.x); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.
	result = c_trace(my.x,tempV.x,IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS);
	if(result > 0) 
	{
		vec_diff(tempV.x,my.x,target.x); //find the vector from the point the trace hit to the player
		vec_normalize(tempV.x,16); 		//get the magnitude of this vector to 16 quants and store in temp
		vec_set(camera.x,target.x);		//place the camera at the trace hit point
		vec_add(camera.x,tempV.x);			//move the camera away from the wall by the vector temp, 16 quants towards the player
	}
}
//
//
//////////////////////////////
//Smoother camera collision
//////////////////////////////
/*
function handle_camera() {
	camera_pan -= mouse_force.x * 12 * time_step;
	camera_tilt += mouse_force.y * 8 * time_step;
	camera_tilt = clamp(camera_tilt,-30,10);
	camera.pan = camera_pan;
	tempA.pan = fcos(camera_tilt,-camera_distance);
	vec_set(camera_move_to.x,vector(my.x + fcos(camera.pan,tempA.pan),my.y + fsin(camera.pan,tempA.pan),my.z + 20 + fsin(camera_tilt,-camera_distance)));
	var temp = minv(1,0.5 * time_step); //changing 0.5 will change how fast the camera moves, at 1 places us at target, this value is what allows the smooth movement
	camera.x += temp*(camera_move_to.x - camera.x);
	camera.y += temp*(camera_move_to.y - camera.y);
	camera.z += temp*(camera_move_to.z - camera.z);
	vec_diff(tempV.x,camera.x,my.x);
	vec_normalize(tempV.x,16);
	vec_add(tempV.x,camera.x);
	if (c_trace(my.x,tempV.x,IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS) > 0) {
		vec_diff(tempV.x,my.x,target.x);
		vec_normalize(tempV.x,16);
		vec_set(camera.x,target.x);
		vec_add(camera.x,tempV.x);
	}
	vec_diff(tempV.x,my.x,camera.x);
	vec_to_angle(camera.pan,tempV.x);
}
*/
//
//
function rotate_entity(var rotate_angle, var rotate_speed)
{
	if(my.pan == rotate_angle)			return;
	result = ang(rotate_angle - my.pan);
	if (result > 0)		my.pan += rotate_speed * time_step;
	if (result < 0)		my.pan -= rotate_speed * time_step; 
	if ((ang(rotate_angle - my.pan) < 0) && (result > 0))	my.pan = rotate_angle; 
	if ((ang(rotate_angle - my.pan) > 0) && (result < 0))	my.pan = rotate_angle; 
}
//
//
function handle_sword_collision()
{
	you = NULL;
	vec_for_vertex(tempV.x, player_weapon,274); //sword base
	vec_for_vertex(tempV2.x,player_weapon, 54); //sword tip
	result = c_trace(tempV.x,tempV2.x,IGNORE_ME|IGNORE_PASSABLE|USE_BOX);
	if (you != NULL) {
		if ((you.entity_type == 2) && (you.hit_by_player == 0))
		{
			if (airborne_attack == 1 && my.animblend == attack_a) 	my.movement_mode = 2;
			you.hit_by_player = 1;
			if (target_enemy == NULL)		{	target_enemy = you; 		player_lock_on = 1; 	}
		}
	}
}
//
//
action player_action()
{
	c_setminmax(me);					//added to correct ground collisions
	wait(1);								//added to correct ground collisions
	player = me;
	my.gravity = 6;
	my.z_offset = -my.min_z;		//was 6	//added to correct ground collisions
	set(my,SHADOW);
	ent_create("sword.mdl", my.x, attach_weapon);
	wait(1);
	while(1) 
	{ //the main loop
		handle_gravity();
		handle_movement();
		handle_animation(1);
		handle_camera();
		wait(1);
	}
}
//
//
/////
#endif


enemy.c
Click to reveal..

Code:
#ifndef enemy_c
#define enemy_c
/////
//
//
action enemy_dummy()
{
	set(my,SHADOW);
	my.entity_type = 2;
	my.emask |= ENABLE_SCAN;
	while(1) 
	{
		if(player!=NULL)
		{
			if(my.hit_by_player==1) 
			{
				my.move_x = player.move_x;
				my.move_y = player.move_y;
				my.move_z = player.move_z;
				c_move(my, nullvector, my.move_x, USE_AABB|IGNORE_PASSABLE|GLIDE);
				if((player.animblend==blend) || (player.animblend<attack_a) || (my.animblend>attack_f))		my.hit_by_player=0;
			}
			if((player.animblend>=stand) && (target_enemy==my) && (player_lock_on==0) && ((player.animblend<attack_a) || (player.animblend>attack_f)))
			{	target_enemy = NULL;	 }
			if((target_enemy==my)&&(vec_dist(my.x,player.x)>200))		target_enemy = NULL;
		}
		wait(1);
	}
}
//
//
/////
#endif


animation.c
Click to reveal..

Code:
#ifndef animation_c
#define animation_c
/////
//
//
function handle_animation(var animation_speed) 
{
	if(animation_speed <= 0) { animation_speed = 1; }
	if(my.animblend != blend && my.blendframe != nullframe) { my.animate2 = 0; my.animblend = blend; }
	if(my.animblend == blend) {
		if(my.currentframe == stand) { ent_animate(my,"stand",my.animate,ANM_CYCLE); }
		if(my.currentframe == run) { ent_animate(my,"run",my.animate,ANM_CYCLE); }
		if(my.currentframe == walk) { ent_animate(my,"walk",my.animate,ANM_CYCLE); }
		if(my.currentframe == jump) { ent_animate(my,"jump",my.animate,0); }
		if(my.currentframe == attack_a) { ent_animate(my,"attack_a",my.animate,0); }
		if(my.currentframe == attack_b) { ent_animate(my,"attack_b",my.animate,0); }
		if(my.currentframe == attack_c) { ent_animate(my,"attack_c",my.animate,0); }
		if(my.currentframe == attack_d) { ent_animate(my,"attack_d",my.animate,0); }
		if(my.currentframe == attack_e) { ent_animate(my,"attack_e",my.animate,0); }
		if(my.currentframe == attack_f) { ent_animate(my,"attack_f",my.animate,0); }
		if(my.blendframe == stand) { ent_blend("stand",0,my.animate2); }
		if(my.blendframe == run) { ent_blend("run",0,my.animate2); }
		if(my.blendframe == walk) { ent_blend("walk",0,my.animate2); }
		if(my.blendframe == jump) { ent_blend("jump",0,my.animate2); }
		if(my.blendframe == fall) { ent_blend("jump",60,my.animate2); }
		if(my.blendframe == attack_a) { ent_blend("attack_a",0,my.animate2); }
		if(my.blendframe == attack_b) { ent_blend("attack_b",0,my.animate2); }
		if(my.blendframe == attack_c) { ent_blend("attack_c",0,my.animate2); }
		if(my.blendframe == attack_d) { ent_blend("attack_d",0,my.animate2); }
		if(my.blendframe == attack_e) { ent_blend("attack_e",0,my.animate2); }
		if(my.blendframe == attack_f) { ent_blend("attack_f",0,my.animate2); }
		my.animate2 += 45 * time_step;
		if(my.animate2 >= 100) {
			my.animate = 0;
			my.animblend = my.blendframe;
			my.blendframe = nullframe;
		}
	}
	if(my.animblend == stand) {
		ent_animate(my,"stand",my.animate,ANM_CYCLE);
		my.animate += 5 * animation_speed * time_step;
		my.animate %= 100;
		my.currentframe = stand;
	}
	if(my.animblend == run) {
		ent_animate(my,"run",my.animate,ANM_CYCLE);
		my.animate += 8 * animation_speed * time_step;
		my.animate %= 100;
		my.currentframe = run;
	}
	if(my.animblend == walk) {
		ent_animate(my,"walk",my.animate,ANM_CYCLE);
		my.animate += 8 * animation_speed * time_step;
		my.animate %= 100;
		my.currentframe = walk;
	}
	if(my.animblend == jump || my.animblend == fall) {
		if(my.jumping_mode == 3) { my.animate = 60; }
		ent_animate(my,"jump",my.animate,0);
		my.animate += 10 * animation_speed * time_step;
		my.currentframe = jump;
		if(my.animate >= 60 && my.jumping_mode == 1) { my.jumping_mode = 2; }
		if(my.animate >= 100) {
			ent_animate(my,"jump",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if(my.moving == 1) {
				if(key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
		}
	}
	if(my.animblend == attack_a) {
		ent_animate(my,"attack_a",my.animate,0);
		my.animate += 20 * animation_speed * time_step;
		my.currentframe = attack_a;
		if(my.animate >= 100) {
			ent_animate(my,"attack_a",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if(my.moving == 1) {
				if(key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
			if(combo_continue == 1) {
				combo_continue = 0;
				my.blendframe = attack_b;
			} else {
				my.movement_mode = 0;
			}
		}
	}
	if(my.animblend == attack_b) {
		ent_animate(my,"attack_b",my.animate,0);
		my.animate += 15 * animation_speed * time_step;
		my.currentframe = attack_b;
		if(my.animate >= 100) {
			ent_animate(my,"attack_b",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if(my.moving == 1) {
				if(key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
			if(combo_continue == 1) {
				combo_continue = 0;
				my.blendframe = attack_c;
			} else {
				my.movement_mode = 0;
			}
		}
	}
	if(my.animblend == attack_c) {
		ent_animate(my,"attack_c",my.animate,0);
		my.animate += 10 * animation_speed * time_step;
		my.currentframe = attack_c;
		if(my.animate >= 100) {
			ent_animate(my,"attack_c",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if(my.moving == 1) {
				if(key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
			if(combo_continue == 1) {
				my.jumping_mode = 10;
				my.force_z = 12;
				my.gravity = 4;
				combo_continue = 0;
				my.blendframe = attack_d;
			} else {
				my.movement_mode = 0;
			}
		}
	}
	if(my.animblend == attack_d) {
		handle_sword_collision();
		ent_animate(my,"attack_d",my.animate,0);
		my.animate += 15 * animation_speed * time_step;
		my.currentframe = attack_d;
		if(my.animate >= 100) {
			ent_animate(my,"attack_d",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if(my.moving == 1) {
				if(key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
			if(combo_continue == 1) {
				combo_continue = 0;
				my.blendframe = attack_e;
			} else {
				my.movement_mode = 0;
			}
		}
	}
	if(my.animblend == attack_e) {
		ent_animate(my,"attack_e",my.animate,0);
		my.animate += 15 * animation_speed * time_step;
		my.currentframe = attack_e;
		if(my.jumping_mode == 0 && my.animate >= 20 && my.animate < 60) {
			my.gravity = 3;
			my.jumping_mode = 10;
			my.force_z = 15;
		}
		if(my.animate >= 100) {
			ent_animate(my,"attack_e",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if(my.moving == 1) {
				if(key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
			if(combo_continue == 1) {
				combo_continue = 0;
				my.blendframe = attack_f;
			} else {
				my.movement_mode = 0;
			}
		}
	}
	if(my.animblend == attack_f) {
		ent_animate(my,"attack_f",my.animate,0);
		my.animate += 6 * animation_speed * time_step;
		my.currentframe = attack_f;
		if(my.jumping_mode == 0 && my.animate >= 40 && my.animate < 60) {
			my.gravity = 6;
			my.jumping_mode = 10;
			my.force_z = 12;
		}
		if(my.animate >= 100) {
			my.movement_mode = 0;
			ent_animate(my,"attack_f",100,0);
			my.animate = 100;
			my.blendframe = stand;
			if(my.moving == 1) {
				if(key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
			}
		}
	}
	if(my.animblend >= attack_a && my.animblend <= attack_f) { handle_sword_collision(); }
	if(my.animblend != blend && my.blendframe != nullframe) { my.animate2 = 0; my.animblend = blend; }
}
//
//
/////
#endif


KHMovement D.Lancaster; EvilSOB
Lite-C 7.50
ver: partial dummification (isanely idiotic) mod high
player.c
Click to reveal..

Code:
#ifndef player_c
#define player_c
/////
//
//
#define nullframe	-2
#define blend		-1
#define stand		0
#define run			1
#define walk		2
#define jump		3
#define fall		4
#define attack_a	5
#define attack_b	6
#define attack_c	7
#define attack_d	8
#define attack_e	9
#define attack_f	10
TEXT* pl1_tAnim = {
	strings = 32;
	string = "stand";
	string = "run";
	string = "walk";
	string = "jump";
	string = "fall";
	string = "attack_a";
	string = "attack_b";
	string = "attack_c";
	string = "attack_d";
	string = "attack_e";
	string = "attack_f";

}
var pl1_aAnimMode[32];
var pl1_aAnimSp[32];


#define jmp0 0
#define jmp1 1
#define jmp2 2
#define jmp3 3
#define jmp10 10

#define mv0 0
#define mv1 1
#define mv2 2

//
#define _moveX				skill22
#define _moveY				skill23
#define _moveZ				skill24
#define force_x				skill25
#define force_y				skill26
#define force_z				skill27
#define velocity_x		skill28
#define velocity_y		skill29
#define velocity_z		skill30
#define _ani1				skill31
#define _ani2			skill32
#define _aniBlend			skill33
#define currentframe		skill34
#define blendframe		skill35
#define z_offset			skill50
#define _jmp					skill51
#define _gravity			skill52
#define _mv						skill53
#define _moving				skill54
#define hit_by_player	skill55
#define entity_type		skill56

#define _ht skill57


ENTITY* pl1_eWp1;
ENTITY* pl1_eTargetEnemy;
var pl1_nAirAttack = 0;
var pl1_nComboNext = 0;
var pl1_nLockOn = 0;


VECTOR* cam_vMoveTo = { x=0;	y=0;	z=0; }
var cam_nDist = 200;
var cam_nPan;
var cam_nTilt;
//
var in_space = 0;
var in_mouseL = 0;
var in_mouseR = 0;

//
VECTOR* v1 = { x=0; 	 y=0; 	z=0; }
VECTOR* v2= { x=0; 	 y=0; 	z=0; }
ANGLE*  angle1 = { pan=0; tilt=0; roll=0; }
ANGLE*  angle2= { pan=0; tilt=0; roll=0; }
//
//
var c_nResult = 0;
var c_nRotate = 2;
STRING* wp1_md1 = "sword.mdl";

function pl1f_anim(var animation_speed); 
function cf_rotate1(var _nAngle, var _nSp);
function cf_rotate2(var _angle, var _speed);


action wpa_1() {
	pl1_eWp1 = me;
	set(my,PASSABLE);
	proc_mode = PROC_LATE;
	while(you!=NULL) {
		vec_for_vertex(v1.x,  you, 1175);		//hand palm base
		vec_for_vertex(v2.x, you, 1240);		//hand palm tip
		vec_set(my.x, v1.x);
		vec_diff(v1.x, v2.x, v1.x);
		vec_to_angle(angle1.pan, v1.x);
		vec_set(my.pan, angle1.pan);
		wait(1);
	}
}

/******************************
	pl1f_animE
*******************************/
function pl1f_animE(var _index, STRING* _name, var _mode, var _speed) {
	str_cpy((pl1_tAnim.pstring)[_index], _name);
	pl1_aAnimMode[_index] = _mode;
	pl1_aAnimSp[_index] = _speed;
}
/******************************
	pl1f_animInit
*******************************/
function pl1f_animInit() {
	pl1f_animE(stand, "stand", ANM_CYCLE, 5);
	pl1f_animE(run, "run", ANM_CYCLE, 8);
	pl1f_animE(walk, "walk", ANM_CYCLE, 8);
	pl1f_animE(jump, "jump", 0, 10);
	//plf_animE(fall, "fall", 0, 
	pl1f_animE(attack_a, "attack_a", 0, 20);
	pl1f_animE(attack_b, "attack_b", 0, 15);
	pl1f_animE(attack_c, "attack_c", 0, 10);
	pl1f_animE(attack_d, "attack_d", 0, 15);
	pl1f_animE(attack_e, "attack_e", 0, 15);
	pl1f_animE(attack_f, "attack_f", 0, 6);
}
/******************************
	pl1f_move
*******************************/
function pl1f_move() {
	v1.x = -1000;
	v1.y = 0;
	my._moving = 0;
	if (key_w == 1 && key_s == 0 && key_a == 0 && key_d == 0) 	{ v1.x = camera.pan; }
	if (key_s == 1 && key_w == 0 && key_a == 0 && key_d == 0) 	{ v1.x = camera.pan + 180; }
	if (key_a == 1 && key_s == 0 && key_w == 0 && key_d == 0) 	{ v1.x = camera.pan + 90; }
	if (key_d == 1 && key_s == 0 && key_a == 0 && key_w == 0) 	{ v1.x = camera.pan - 90; }
	if (key_w == 1 && key_a == 1 && key_d == 0 && key_s == 0) 	{ v1.x = camera.pan + 45; }
	if (key_w == 1 && key_d == 1 && key_a == 0 && key_s == 0) 	{ v1.x = camera.pan - 45; }
	if (key_s == 1 && key_a == 1 && key_d == 0 && key_w == 0) 	{ v1.x = camera.pan + 135; }
	if (key_s == 1 && key_d == 1 && key_a == 0 && key_w == 0) 	{ v1.x = camera.pan - 135; }
	if (v1.x != -1000) {
		my._moving = 1;
		if (key_shift == 1)	{ 
			v1.y = 10 * time_step; 
		} else { 
			v1.y = 15 * time_step; 
		}
	}

	if (my._mv == mv0) {
		my._moveX = fcos(v1.x,v1.y);
		my._moveY = fsin(v1.x,v1.y);
	}
	if (my._mv == mv1 || my._mv == mv2) {
		v1.y = fsin((my._ani1 * 1.2) + 45,15 * time_step);
		my._moveX = fcos(my.pan,v1.y);
		my._moveY = fsin(my.pan,v1.y);
		v1.y = 0;
		if (v1.x != -1000) { v1.y = 1; }	//if we need to rotate whilst attacking (the player is pressing keys to rotate)
	}
	//
	c_move(me,nullvector,my._moveX, USE_AABB|IGNORE_PASSABLE|GLIDE);
	//
	//result = trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - 4000));
	//if (result < 0)	{	my.z -= result;	my.velocity_z = 0;	}
	if (pl1_eTargetEnemy == NULL) {	
		if (v1.y > 0) { cf_rotate1(v1.x,30); }		
	} else {
		vec_diff(v2.x,pl1_eTargetEnemy.x,my.x);
		vec_to_angle(angle2.pan,v2.x);
		cf_rotate1(angle2.pan,30);
	}
	//
	switch(my._mv) {
 		case mv0:		
			my._gravity = 6;
			if (my._moveX != 0 || my._moveY != 0) { //if we are moving
				if (my._aniBlend == stand) {//if our current animation is stand
					if (key_shift == 1)	{ 
						my.blendframe = walk;
					} else { 
						my.blendframe = run;
					} 
				}
				if (my._aniBlend == run  && key_shift == 1)	{ my.blendframe = walk; }
				if (my._aniBlend == walk && key_shift == 0)	{ my.blendframe = run; } 
			} else {
				//if we arn't moving and our current animation is walk or run, blend and cycle the stand animation
				if (my._aniBlend > stand 
				&& my._aniBlend != jump 
				&& my._aniBlend != fall) {
					my.blendframe = stand;
				}
			}
			if (mouse_left == 0 && in_mouseL == 1)	{ in_mouseL = 0; } 
			if (mouse_left == 1 
			&& in_mouseL == 0 
			&& my._aniBlend >= stand) {
				in_mouseL = 1;
				my.blendframe = attack_a;						
				pl1_nAirAttack = (my._jmp == jmp1);
				my._mv = 1;
				pl1_nComboNext = 0;
			}
			if (mouse_right == 0 && in_mouseR == 1) { in_mouseR = 0; }
			if (mouse_right == 1 && in_mouseR == 0) {
				if (pl1_nLockOn == 0) {
					c_scan(player.x,player.pan,vector(360,180,250),SCAN_ENTS|SCAN_LIMIT|IGNORE_ME);
					if (you != NULL) {
						if (you.entity_type == 2)  {//make sure you've scanned an enemy
							pl1_nLockOn = 1;		
							pl1_eTargetEnemy = you;		
						}
					}
				} else {	
					pl1_nLockOn = 0;		pl1_eTargetEnemy = NULL;		
				}
				in_mouseR = 1;
			}
			break;
 		case mv1:		
			if (my._jmp != jmp10) { 
				my._jmp = jmp0; 
			} else if((my._ani1 >= 60)
			&&(my._aniBlend >= stand)) { 
				my._jmp = jmp0; 
			}
			if(mouse_left == 0 && in_mouseL == 1)  { in_mouseL = 0; }
			if(mouse_left == 1 
			&& in_mouseL == 0 
			&& my._ani1 >= 30 
			&& pl1_nComboNext == 0) {	
				in_mouseL = 1;
				pl1_nComboNext = 1; 	
			}
			break;
 		case mv2:		
			my._jmp = jmp0;
			if(mouse_left == 0 && in_mouseL == 1) { in_mouseL = 0; }
			if(mouse_left == 1 
			&& in_mouseL == 0 
			&& my._ani1 >= 30 
			&& pl1_nComboNext == 0) {
				in_mouseL = 1;
				pl1_nComboNext = 1; 		
			}
			break;
	}
}
/******************************
	pl1f_gravity
*******************************/
function pl1f_gravity() {
	//c_nResult = c_trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - 1000),IGNORE_ME|IGNORE_PASSABLE|USE_POLYGON);
	my._ht = c_trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - (my.z_offset * 2)),IGNORE_ME|IGNORE_PASSABLE|USE_POLYGON);
	my._ht += (trace_hit == 0 && my._ht == 0) * my.z_offset * 2;
	//spof_n1("ht: ", my._ht);
	if(my._ht < 3) {	
		//if(c_nResult < 0) {	c_nResult = c_trace(my.x,vector(my.x,my.y,my.z + 4000),IGNORE_ME|IGNORE_PASSABLE|USE_POLYGON);	}//!!FUDGE!! stop skyjumping
		//
		if(my._jmp==jmp0) {
			my.force_z = -1 * my._ht;
			if((key_space==0) && (in_space==1))	{ in_space = 0; } 
			if((key_space==1) 
			&& (in_space==0) 
			&& (my._mv==mv0) 
			&& (my._aniBlend>=stand) 
			&& (my._aniBlend!=jump)
			&& (my._aniBlend!=fall)) {
				in_space = 1;
				my._jmp = jmp1;
				my.force_z = 25;
				my.blendframe = jump;
				my._ani2 = 0;
				my._aniBlend = blend;
			}
		}
		if((my._jmp==jmp2) || (my._jmp==jmp3))	{ my._jmp = jmp0; }
	} else {
		if(my._jmp==jmp2) {
			if(my._ht > 120) {
				my._ani1 = 60;
				my._jmp = jmp3;
			} else	{ 
				my._jmp = jmp0;
			}
		}
		if((my._jmp==jmp3) && (my._ht <=120)) { my._jmp = jmp0; }	
		if((my._jmp==jmp0) && (my._mv==0)) {
			if((my._ht > 120) 
			&& (my._aniBlend>=stand) 
			&& (my._aniBlend!=jump) 
			&& (my._aniBlend!=fall)) {
				my._jmp = jmp3;
				my.blendframe = fall;
				my._ani2 = 0;
				my._aniBlend = blend;
			}
		}
		my.force_z -= my._gravity * time_step;
		my.force_z = maxv(-30,my.force_z);
		if(my._mv==mv2) { my.force_z = 0; }
	}
 	my.velocity_z += (time_step * my.force_z) - (minv(time_step*0.7,1) * my.velocity_z);
	my._moveZ = my.velocity_z * time_step;
}

/******************************
	pl1f_cam1
		Stable/rigid camera collision
*******************************/
function pl1f_cam1() {
	camera.pan -= mouse_force.x * 12 * time_step;
	camera.tilt += mouse_force.y * 8 * time_step;
	camera.tilt = clamp(camera.tilt,-30,10);
	angle1.pan = fcos(camera.tilt,-cam_nDist);
	vec_set(camera.x,vector(my.x + fcos(camera.pan,angle1.pan),my.y + fsin(camera.pan,angle1.pan),my.z + 20 + fsin(camera.tilt,-cam_nDist)));
	vec_diff(v1.x,camera.x,my.x); 	//find the vector from the player to the camera
	vec_normalize(v1.x,16); 			//get the magnitude of it's vector to 16 quants and store it in temp
	vec_add(v1.x,camera.x); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.
	c_nResult = c_trace(my.x,v1.x,IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS);
	if(c_nResult > 0) {
		vec_diff(v1.x,my.x,target.x); //find the vector from the point the trace hit to the player
		vec_normalize(v1.x,16); 		//get the magnitude of this vector to 16 quants and store in temp
		vec_set(camera.x,target.x);		//place the camera at the trace hit point
		vec_add(camera.x,v1.x);			//move the camera away from the wall by the vector temp, 16 quants towards the player
	}
}

/******************************
	pl1f_cam2
		Smoother camera collision
			not used
*******************************/
function pl1f_cam2() {
	cam_nPan -= mouse_force.x * 12 * time_step;
	cam_nTilt += mouse_force.y * 8 * time_step;
	cam_nTilt = clamp(cam_nTilt,-30,10);
	camera.pan = cam_nPan;
	angle1.pan = fcos(cam_nTilt,-cam_nDist);
	vec_set(cam_vMoveTo.x,vector(my.x + fcos(camera.pan,angle1.pan),my.y + fsin(camera.pan,angle1.pan),my.z + 20 + fsin(cam_nTilt,-cam_nDist)));
	var temp = minv(1,0.5 * time_step); //changing 0.5 will change how fast the camera moves, at 1 places us at target, this value is what allows the smooth movement
	camera.x += temp*(cam_vMoveTo.x - camera.x);
	camera.y += temp*(cam_vMoveTo.y - camera.y);
	camera.z += temp*(cam_vMoveTo.z - camera.z);
	vec_diff(v1.x,camera.x,my.x);
	vec_normalize(v1.x,16);
	vec_add(v1.x,camera.x);
	if (c_trace(my.x,v1.x,IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS) > 0) {
		vec_diff(v1.x,my.x,target.x);
		vec_normalize(v1.x,16);
		vec_set(camera.x,target.x);
		vec_add(camera.x,v1.x);
	}
	vec_diff(v1.x,my.x,camera.x);
	vec_to_angle(camera.pan,v1.x);
}

/******************************
	cf_rotate1
*******************************/
function cf_rotate1(var _nAngle, var _nSp) {
	if (c_nRotate == 2) { cf_rotate2(_nAngle, _nSp); }
	if(my.pan == _nAngle) { return; }
	c_nResult = ang(_nAngle - my.pan);
	if (c_nResult > 0)		my.pan += _nSp * time_step;
	if (c_nResult < 0)		my.pan -= _nSp * time_step; 
	if ((ang(_nAngle - my.pan) < 0) && (c_nResult > 0))	{ my.pan = _nAngle; } 
	if ((ang(_nAngle - my.pan) > 0) && (c_nResult < 0))	{ my.pan = _nAngle; } 
}
/******************************
	cf_rotate2
		uses c_rotate
		not currenty used
*******************************/
function cf_rotate2(var _angle, _speed) {
	if (my.pan == _angle) { return; }
	c_nResult = ang(_angle - my.pan);
	angle1.pan = minv(abs(c_nResult), time_step * _speed) * sign(c_nResult);
	angle1.tilt = 0;
	angle1.roll = 0;
	c_rotate(me, angle1, IGNORE_ME | IGNORE_PASSABLE);
}
//
/******************************
	wp1f_collide
*******************************/
function wp1f_collide() {
	you = NULL;
	vec_for_vertex(v1.x, pl1_eWp1,274); //sword base
	vec_for_vertex(v2.x,pl1_eWp1, 54); //sword tip
	c_nResult = c_trace(v1.x,v2.x,IGNORE_ME|IGNORE_PASSABLE|USE_BOX);
	if (you != NULL) {
		if ((you.entity_type == 2) && (you.hit_by_player == 0)) {
			if (pl1_nAirAttack == 1 && my._aniBlend == attack_a) { my._mv = mv2; }
			you.hit_by_player = 1;
			if (pl1_eTargetEnemy == NULL)		{	
				pl1_eTargetEnemy = you;
				pl1_nLockOn = 1; 	
			}
		}
	}
}
/******************************
	pl1a1
*******************************/
action pl1a1() {
	pl1f_animInit();
	c_setminmax(me);					//added to correct ground collisions
	wait(1);								//added to correct ground collisions
	player = me;
	my._gravity = 6;
	my.z_offset = -my.min_z;		//was 6	//added to correct ground collisions
	set(my,SHADOW);
	ent_create(wp1_md1, my.x, wpa_1);
	wait(1);
	while(me != NULL) { //the main loop
		pl1f_gravity();
		pl1f_move();
		pl1f_anim(1);
		pl1f_cam1();
		wait(1);
	}
}

#endif



enemy.c
Click to reveal..

Code:
#ifndef enemy_c
#define enemy_c
/////
//
//
action enemy_dummy()
{
	set(my,SHADOW);
	my.entity_type = 2;
	my.emask |= ENABLE_SCAN;
	while(1) {
		if(player!=NULL) {
			if(my.hit_by_player==1) {
				my._moveX = player._moveX;
				my._moveY = player._moveY;
				my._moveZ = player._moveZ;
				c_move(my, nullvector, my._moveX, USE_AABB|IGNORE_PASSABLE|GLIDE);
				if((player._aniBlend==blend)
				|| (player._aniBlend<attack_a) 
				|| (my._aniBlend>attack_f)) { 
					my.hit_by_player=0;
				}
			}
			if((player._aniBlend>=stand) 
			&& (pl1_eTargetEnemy==me) 
			&& (pl1_nLockOn==0) 
			&& ((player._aniBlend<attack_a) || (player._aniBlend>attack_f))) {	
				pl1_eTargetEnemy = NULL;	 
			}
			if((pl1_eTargetEnemy==me)&&(vec_dist(my.x,player.x)>200)) { pl1_eTargetEnemy = NULL; }
		}
		wait(1);
	}
}
//
//
/////
#endif


animaton.c
Click to reveal..

Code:
#ifndef animation_c
#define animation_c
/////
//
//


function pl1f_anim(var anim_sp) 
{
	if(anim_sp <= 0) { anim_sp = 1; }
	if(my._aniBlend != blend 
	&& my.blendframe != nullframe) { 
		my._ani2 = 0;
		my._aniBlend = blend; 
	}
	if(my._aniBlend == blend) {
		/*
		if(my.currentframe == stand) { ent_animate(my,"stand",my._ani1,ANM_CYCLE); }
		if(my.currentframe == run) { ent_animate(my,"run",my._ani1,ANM_CYCLE); }
		if(my.currentframe == walk) { ent_animate(my,"walk",my._ani1,ANM_CYCLE); }
		if(my.currentframe == jump) { ent_animate(my,"jump",my._ani1,0); }
		if(my.currentframe == attack_a) { ent_animate(my,"attack_a",my._ani1,0); }
		if(my.currentframe == attack_b) { ent_animate(my,"attack_b",my._ani1,0); }
		if(my.currentframe == attack_c) { ent_animate(my,"attack_c",my._ani1,0); }
		if(my.currentframe == attack_d) { ent_animate(my,"attack_d",my._ani1,0); }
		if(my.currentframe == attack_e) { ent_animate(my,"attack_e",my._ani1,0); }
		if(my.currentframe == attack_f) { ent_animate(my,"attack_f",my._ani1,0); }
		*/
		ent_animate(me, (pl1_tAnim.pstring)[my.currentframe], my._ani1, pl1_aAnimMode[my.currentframe]);
		if (my.blendframe != blend) {
			ent_blend((pl1_tAnim.pstring)[my.blendframe], 0, my._ani2);
		}
		
		my._ani2 += 45 * time_step;
		if(my._ani2 >= 100) {
			my._ani1 = 0;
			my._aniBlend = my.blendframe;
			my.blendframe = nullframe;
		}
	}
	switch(my._aniBlend) {
		case stand:	
			ent_animate(me,"stand",my._ani1,ANM_CYCLE);
			my._ani1 += 5 * anim_sp * time_step;
			my._ani1 %= 100;
			my.currentframe = my._aniBlend;
			break;
		case run:
			ent_animate(my,"run",my._ani1,ANM_CYCLE);
			my._ani1 += 8 * anim_sp * time_step;
			my._ani1 %= 100;
			my.currentframe = my._aniBlend;
			break;
		case walk:
			ent_animate(my,"walk",my._ani1,ANM_CYCLE);
			my._ani1 += 8 * anim_sp * time_step;
			my._ani1 %= 100;
			my.currentframe = my._aniBlend;
			break;
		case attack_a:
			ent_animate(my,"attack_a",my._ani1,0);
			my._ani1 += 20 * anim_sp * time_step;
			my.currentframe = attack_a;
			if(my._ani1 >= 100) {
				ent_animate(my,"attack_a",100,0);
				my._ani1 = 100;
				my.blendframe = stand;
				if(my._moving == 1) {
					if(key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
				}
				if(pl1_nComboNext == 1) {
					pl1_nComboNext = 0;
					my.blendframe = attack_b;
				} else {
					my._mv = 0;
				}
			}
			break;
		case attack_b:
			ent_animate(my,"attack_b",my._ani1,0);
			my._ani1 += 15 * anim_sp * time_step;
			my.currentframe = attack_b;
			if(my._ani1 >= 100) {
				ent_animate(my,"attack_b",100,0);
				my._ani1 = 100;
				my.blendframe = stand;
				if(my._moving == 1) {
					if(key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
				}
				if(pl1_nComboNext == 1) {
					pl1_nComboNext = 0;
					my.blendframe = attack_c;
				} else {
					my._mv = 0;
				}
			}
			break;
		case attack_c:
			ent_animate(my,"attack_c",my._ani1,0);
			my._ani1 += 10 * anim_sp * time_step;
			my.currentframe = attack_c;
			if(my._ani1 >= 100) {
				ent_animate(my,"attack_c",100,0);
				my._ani1 = 100;
				my.blendframe = stand;
				if(my._moving == 1) {
					if(key_shift == 1) { 
						my.blendframe = walk; 
					} else { 
						my.blendframe = run; 
					}
				}
				if(pl1_nComboNext == 1) {
					my._jmp = jmp10;
					my.force_z = 12;
					my._gravity = 4;
					pl1_nComboNext = 0;
					my.blendframe = attack_d;
				} else {
					my._mv = 0;
				}
			}
			break;
		case attack_d:
			wp1f_collide();
			ent_animate(my,"attack_d",my._ani1,0);
			my._ani1 += 15 * anim_sp * time_step;
			my.currentframe = attack_d;
			if(my._ani1 >= 100) {
				ent_animate(my,"attack_d",100,0);
				my._ani1 = 100;
				my.blendframe = stand;
				if(my._moving == 1) {
					if(key_shift == 1) { 
						my.blendframe = walk; 
					} else { 
						my.blendframe = run; 
					}
				}
				if(pl1_nComboNext == 1) {
					pl1_nComboNext = 0;
					my.blendframe = attack_e;
				} else {
					my._mv = mv0;
				}
			}
			break;
		case attack_e:
			ent_animate(my,"attack_e",my._ani1,0);
			my._ani1 += 15 * anim_sp * time_step;
			my.currentframe = attack_e;
			if(my._jmp == jmp0
			&& my._ani1 >= 20 
			&& my._ani1 < 60) {
				my._gravity = 3;
				my._jmp = jmp10;
				my.force_z = 15;
			}
			//block122
			if(my._ani1 >= 100) {
				ent_animate(my,"attack_e",100,0);
				my._ani1 = 100;
				my.blendframe = stand;
				if(my._moving == 1) {
					if(key_shift == 1) { 
						my.blendframe = walk; 
					} else { 
						my.blendframe = run; 
					}
				}

				if(pl1_nComboNext == 1) {
					pl1_nComboNext = 0;
					my.blendframe = attack_f;
				} else {
					my._mv = mv0;
				}
			}
			break;
		case attack_f:
			ent_animate(my,"attack_f",my._ani1,0);
			my._ani1 += 6 * anim_sp * time_step;
			my.currentframe = attack_f;
			if(my._jmp == jmp0 
			&& my._ani1 >= 40 
			&& my._ani1 < 60) {
				my._gravity = 6;
				my._jmp = jmp10;
				my.force_z = 12;
			}
			//block121
			if(my._ani1 >= 100) {
				my._mv = mv0;
				ent_animate(my,"attack_f",100,0);
				my._ani1 = 100;
				my.blendframe = stand;
				if(my._moving == 1) {
					if(key_shift == 1) { 
						my.blendframe = walk; 
					} else { 
						my.blendframe = run; 
					}
				}
			}
			break;
	}
	if(my._aniBlend == jump 
	|| my._aniBlend == fall) {
		if(my._jmp == jmp3) { my._ani1 = 60; }
		ent_animate(me,"jump",my._ani1,0);
		my._ani1 += 10 * anim_sp * time_step;
		my.currentframe = jump;
		if(my._ani1 >= 60 && my._jmp == jmp1) { my._jmp = jmp2; }
		if(my._ani1 >= 100) {
			ent_animate(me,"jump",100,0);
			my._ani1 = 100;
			my.blendframe = stand;
			if(my._moving == 1) {
				if(key_shift == 1) { 
					my.blendframe = walk; 
				} else { 
					my.blendframe = run; 
				}
			}
		}
	}

	if(my._aniBlend >= attack_a && my._aniBlend <= attack_f) { wp1f_collide(); }
	if(my._aniBlend != blend && my.blendframe != nullframe) { my._ani2 = 0; my._aniBlend = blend; }
}
//
//
/////
#endif



Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 01/30/09 12:49

Originally Posted By: testDummy
Quoting Cowabanga.
Quote:
Thanks, I'll try it.

...and?
('We' cannot test it properly here without more data / samples.
At least for 'our' records, did the results seem better, or worse?)


seem worse. Crash in all events.

Hey? Try to copy the gravity function from the modified KH Movement to the Original one!

But i can't. It's kinda hard frown.
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 02/03/09 07:39

[Sorry for double posting]


Anyone PLEEEEEAAAASSSSSEEEE!
Posted By: testDummy

Re: [REQ] converting a code to lite-c - 02/11/09 21:35

Not that it matters, but HERE, both of the previously posted tri-set samples appear to function 'adequately' under Lite-C free 1.70.1

main.c (mod high version)
Click to reveal..

Code:
#include <acknex.h>
#include <default.c>
//#include "_0c.h"
//#include "_0c.c"
#include "player.c"
#include "enemy.c"
#include "animation.c"

STRING* floor_md1 = "plate256x256x2.mdl";
STRING* pl_md1 = "player.mdl";

action floor_a1() {
	set(me, POLYGON);
}
//VECTOR* v7 = { x=1; y=2; z=3; }
function main()	{
	camera.clip_near = 0;
	video_switch(7,0,1);
	level_load("");
	//dgf_1();
	// create variable floor plates
	ent_create(floor_md1, vector(0, 0, -64), floor_a1);
	ent_create(floor_md1, vector(256, 0, -64), floor_a1);
	ent_create(floor_md1, vector(-256, 0, -64), floor_a1);
	ent_create(floor_md1, vector(0, 256, -64), floor_a1);
	ent_create(floor_md1, vector(0, -256, -64), floor_a1);
	ent_create(floor_md1, vector(256, 256, -128), floor_a1);
	ent_create(floor_md1, vector(-256, 256, -128), floor_a1);
	ent_create(floor_md1, vector(256, -256, -128), floor_a1);

	// create inactive enemy
	ent_create(pl_md1, vector(0, 128, 0), enemy_dummy);
	
	wait(3);
	// create player
	ent_create(pl_md1, vector(0,0,128), pl1a1);
}


Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 02/12/09 06:32

I can take another look, Ive learnt a bit about collisions
since my last attempt, but which one should I start from?

Will I start from the original, the low mod, or the high mod version?
Your choice, its your request.
Posted By: testDummy

Re: [REQ] converting a code to lite-c - 02/12/09 07:56

runs HERE
Lite-C 1.50 (7.50) ~OK
Lite-C 1.70.1 (7.70.1) ~OK
Quoting Cowabanga.
Abbreviated guess list for "crash in all events" -> "crash in event":
Quote:
I'll test it in 7.60 soon but because i have 7.07, it crashes every time when i to run the script

1. residuals @ 7.07 ?
2. empty pointer (related to ordering?)?
3. other (obvious dummy error)?

Quoting EvilSOB.
Quote:
Will I start from the original, the low mod, or the high mod version? Your choice, its your request.

4|1. start from the original C-Script source -
5. write completely new version from scratch +
Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 02/12/09 08:41

I'd prefer to start from the original, but its up to cowabanga.
I'll most likely to a restart from original anyway.
But a complete re-write is too much for me. I aint that good yet...
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 02/12/09 09:00

Quote:
1. residuals @ 7.07 ?

That's before! Now i have 7.66.

Quote:
3. other (obvious dummy error)?

It says "Crash in event" and closing!

But i'll test the new one now.

EDIT: @testdummy: Can you send to me the plate model?
And please can you extract the gravity code from the modified one? Becuase this one is for Free Lite-C. Because it generates a plates. I need it to move at the level.
Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 02/12/09 15:07

So near and yet so far.

Everything is (to my eyes) working identical ecxept for one odd quirk.

Climbing the slope in the demo "level" doesnt work with my re-code (YET!),
UNLESS I compile level as meshes.

And the original WDL code goes into jumping spasms if you DO compile as mesh.
(I would know if this happens to other people too please)

The work continues........

PS minimal changes to code, running on 7.66 comm but should be lite-c compatible
Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 02/12/09 17:14

Got him at last, USE_AABB flag be-damned!
Code looks horrible in the forum windows, but just copy and paste into SED and it will look fine.

Minimal changes in my opinion. Thoroughly test please, as many versions of 3DGS as possible.

Main.C
Click to reveal..
Code:
#include <acknex.h>
#include <default.c>

#include "player.c"
#include "enemy.c"
#include "animation.c"


function main()
{
	camera.clip_near = 0;
	video_switch(7,0,1);
	level_load("level.wmb");
}


player.C
Click to reveal..
Code:
function rotate_entity(var rotate_angle, var rotate_speed);
function handle_gravity();
function handle_movement();
function handle_camera();
function handle_animation(var animation_speed); 


#define nullframe	-2
#define blend		-1
#define stand		 0
#define run			 1
#define walk		 2
#define jump		 3
#define fall		 4
#define attack_a	 5
#define attack_b	 6
#define attack_c	 7
#define attack_d	 8
#define attack_e	 9
#define attack_f	 10

#define move_x				skill22
#define move_y				skill23
#define move_z				skill24
#define force_x			skill25
#define force_y			skill26
#define force_z			skill27
#define velocity_x		skill28
#define velocity_y		skill29
#define velocity_z		skill30
#define animate			skill31
#define animate2			skill32
#define animblend			skill33
#define currentframe		skill34
#define blendframe		skill35
#define z_offset			skill50
#define jumping_mode		skill51
#define gravity			skill52
#define movement_mode	skill53
#define moving				skill54
#define hit_by_player	skill55
#define entity_type		skill56

ENTITY*	player_weapon;
ENTITY*	target_enemy;

var		temp;
VECTOR*	tempV = { x=0; 	y=0; 		z=0; 		}
VECTOR*	tempV2= { x=0; 	y=0; 		z=0; 		}
ANGLE*	tempA = { pan=0; 	tilt=0; 	roll=0;	}
ANGLE*	tempA2= { pan=0; 	tilt=0; 	roll=0;	}

VECTOR*	camera_move_to = { x=0;	y=0;	z=0;	}
var camera_distance = 200;
var camera_pan;
var camera_tilt;

var space_press = 0;
var mouse_left_press = 0;
var mouse_right_press = 0;
var combo_continue = 0;
var player_lock_on = 0;
var airborne_attack = 0;


action attach_weapon()
{
	player_weapon = my;
	set(my,PASSABLE);
	proc_mode = PROC_LATE;
	while(you != NULL) 
	{
		vec_for_vertex(tempV.x, you, 1175);			//hand palm base
		vec_for_vertex(tempV2.x, you, 1240);		//hand palm tip
		vec_set(my.x, tempV.x);
		vec_diff(tempV.x, tempV2.x, tempV.x);
		vec_to_angle(tempA.pan, tempV.x);
		vec_set(my.pan, tempA.pan);
		wait(1);
	}
}

action player_action() 
{
	player = my;
	my.gravity = 6;
	my.z_offset = 12;
	set(my,SHADOW);
	ent_create("sword.mdl", my.x, attach_weapon);
	wait(1);
	while(1) 
	{	//the main player loop
		handle_gravity();
		handle_movement();
		handle_camera();
		handle_animation(1);
		wait(1);
	}
}

function handle_movement() 
{
	tempV.x = -1000;
	tempV.y = 0;
	my.moving = 0;
	if(key_w == 1 && key_s == 0 && key_a == 0 && key_d == 0)	tempV.x = camera.pan;
	if(key_s == 1 && key_w == 0 && key_a == 0 && key_d == 0)	tempV.x = camera.pan + 180;
	if(key_a == 1 && key_s == 0 && key_w == 0 && key_d == 0)	tempV.x = camera.pan + 90;
	if(key_d == 1 && key_s == 0 && key_a == 0 && key_w == 0)	tempV.x = camera.pan - 90;
	if(key_w == 1 && key_a == 1 && key_d == 0 && key_s == 0)	tempV.x = camera.pan + 45;
	if(key_w == 1 && key_d == 1 && key_a == 0 && key_s == 0)	tempV.x = camera.pan - 45;
	if(key_s == 1 && key_a == 1 && key_d == 0 && key_w == 0)	tempV.x = camera.pan + 135;
	if(key_s == 1 && key_d == 1 && key_a == 0 && key_w == 0)	tempV.x = camera.pan - 135;
	if(tempV.x != -1000) 
	{
		my.moving = 1;
		if(key_shift == 1)	tempV.y = 10 * time_step;  
		else						tempV.y = 15 * time_step; 
	}
	//
	if(my.movement_mode==0)
	{
		my.move_x = fcos(tempV.x, tempV.y);
		my.move_y = fsin(tempV.x, tempV.y);
	}
	else if((my.movement_mode==1)||(my.movement_mode==2))
	{
		tempV.y = fsin((my.animate * 1.2) + 45,15 * time_step);
		my.move_x = fcos(my.pan, tempV.y);
		my.move_y = fsin(my.pan, tempV.y);
		tempV.y = 0;
		//NextLine: if we need to rotate whilst attacking (the player is pressing keys to rotate)
		if(tempV.x != -1000) 	tempV.y = 1;
	}
	//
	c_move(my, nullvector, my.move_x, USE_BOX | IGNORE_PASSABLE | GLIDE);
	result = -my.z_offset + c_trace(vector(my.x,my.y,my.z - my.z_offset), vector(my.x,my.y,my.z - 4000), IGNORE_ME | IGNORE_PASSABLE | USE_BOX);
	result = clamp(result, -50, 50);
	if(result < 0) 	{	my.z -= result;	my.velocity_z = 0;	}
	//
	if(target_enemy == NULL) 
	{	if(tempV.y > 0)	rotate_entity(tempV.x, 30); 	}
	else
	{
		vec_diff(tempV2.x, target_enemy.x, my.x);
		vec_to_angle(tempA2.pan, tempV2.x);
		rotate_entity(tempA2.pan,30);
	}
	//
	if(my.movement_mode == 0) 
	{
		my.gravity = 6;
		if(my.move_x != 0 || my.move_y != 0) 
		{	//ifwe are moving
			if(my.animblend == stand) 
			{	//ifour current animation is stand
				if(key_shift == 1)	my.blendframe = walk;
				else						my.blendframe = run;
			}
			if(my.animblend == run && key_shift == 1)		my.blendframe = walk;
			if(my.animblend == walk && key_shift == 0)	my.blendframe = run;
		} 
		else
		{
			if(my.animblend > stand && my.animblend != jump && my.animblend != fall) 
			{	//if we arn't moving and our current animation is walk or run, blend and cycle the stand animation
				my.blendframe = stand;
			}
		}
		if(mouse_left == 0 && mouse_left_press == 1)		mouse_left_press = 0;
		if(mouse_left == 1 && mouse_left_press == 0 && my.animblend >= stand) 
		{
			mouse_left_press = 1;
			my.blendframe = attack_a;
			if(my.jumping_mode == 1) 	airborne_attack = 1;
			else								airborne_attack = 0;
			my.movement_mode = 1;
			combo_continue = 0;
		}
		if(mouse_right == 0 && mouse_right_press == 1)	mouse_right_press = 0;
		if(mouse_right == 1 && mouse_right_press == 0) 
		{
			if(player_lock_on == 0) 
			{
				c_scan(player.x, player.pan, vector(360,180,250), SCAN_ENTS | SCAN_LIMIT | IGNORE_ME);
				if(you != NULL) 
				{
					if(you.entity_type == 2) 
					{	//make sure you've scanned an enemy
						player_lock_on = 1;
						target_enemy = you;
					}
				}
			} 
			else
			{
				player_lock_on = 0;
				target_enemy = NULL;
			}
			mouse_right_press = 1;
		}
	}
	//
	if(my.movement_mode == 1) 
	{
		if(my.jumping_mode != 10)										my.jumping_mode = 0;
		else if(my.animate >= 60 && my.animblend >= stand)		my.jumping_mode = 0;
		//
		if(mouse_left == 0 && mouse_left_press == 1)
			mouse_left_press = 0;
		if(mouse_left == 1 && mouse_left_press == 0 && my.animate >= 30 && combo_continue == 0) 
		{	mouse_left_press = 1; combo_continue = 1; }
	}
	//
	if(my.movement_mode == 2) 
	{
		my.jumping_mode = 0;
		if(mouse_left == 0 && mouse_left_press == 1)
			mouse_left_press = 0; 
		if(mouse_left == 1 && mouse_left_press == 0 && my.animate >= 30 && combo_continue == 0) 
		{	mouse_left_press = 1; combo_continue = 1; }
	}
}

function handle_gravity() 
{
	result = -my.z_offset + c_trace(vector(my.x,my.y,my.z - my.z_offset), vector(my.x,my.y,my.z - 4000), IGNORE_ME | IGNORE_PASSABLE | USE_BOX );
	result = clamp(result, -50, 50);
	if(result < 3) 
	{
		if(my.jumping_mode == 0) 
		{
			my.force_z = -1 * result;
			if(key_space == 0 && space_press == 1) 			space_press = 0;
			if(key_space == 1 && space_press == 0 && my.movement_mode == 0 && my.animblend >= stand && my.animblend != jump && my.animblend != fall) 
			{
				space_press = 1;
				my.jumping_mode = 1;
				my.force_z = 25;
				my.blendframe = jump;
				my.animate2 = 0;
				my.animblend = blend;
			}
		}
		if(my.jumping_mode == 2 || my.jumping_mode == 3)	my.jumping_mode = 0;
	} 
	else
	{
		if(my.jumping_mode == 2) 
		{
			if(result > 120) 
			{
				my.animate = 60;
				my.jumping_mode = 3;
			} 
			else
				my.jumping_mode = 0;
		}
		if(my.jumping_mode == 3 && result <= 120)		my.jumping_mode = 0;
		if(my.jumping_mode == 0 && my.movement_mode == 0) 
		{
			if(result > 120 && my.animblend >= stand && my.animblend != jump && my.animblend != fall) 
			{
				my.jumping_mode = 3;
				my.blendframe = fall;
				my.animate2 = 0;
				my.animblend = blend;
			}
		}
		my.force_z -= my.gravity * time_step;
		my.force_z =  maxv(-30, my.force_z);
		if(my.movement_mode == 2)		my.force_z = 0;
	}
 	my.velocity_z += (time_step * my.force_z) - (minv(time_step*0.7, 1) * my.velocity_z);
	my.move_z = my.velocity_z * time_step;
}

//////////////////////////////
//Stable/rigid camera collision
//////////////////////////////
function handle_camera() 
{
	camera.pan -=  mouse_force.x * 12 * time_step;
	camera.tilt += mouse_force.y * 8 * time_step;
	camera.tilt = clamp(camera.tilt, -30, 10);
	temp = fcos(camera.tilt, -camera_distance);
	vec_set(camera.x, vector(my.x + fcos(camera.pan, temp),my.y + fsin(camera.pan, temp),my.z + 20 + fsin(camera.tilt, -camera_distance)));

	vec_diff(tempV.x, camera.x, my.x); //find the vector from the player to the camera
	vec_normalize(tempV.x, 16); //get the magnitude of it's vector to 16 quants and store it in temp
	vec_add(tempV.x, camera.x); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.

	result = c_trace(my.x, tempV.x, IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS); //trace from the player to 16 quants behind the camera.
	if(result > 0) 
	{
		vec_diff(tempV.x, my.x, target.x); //find the vector from the point the trace hit to the player
		vec_normalize(tempV.x, 16); //get the magnitude of this vector to 16 quants and store in temp
		vec_set(camera.x, target.x); //place the camera at the trace hit point
		vec_add(camera.x, tempV.x); //move the camera away from the wall by the vector temp, 16 quants towards the player
	}
}


//////////////////////////////
//Smooth camera collision
//////////////////////////////
/*function handle_camera() 
{
	camera_pan -= mouse_force.x * 12 * time_step;
	camera_tilt += mouse_force.y * 8 * time_step;
	camera_tilt = clamp(camera_tilt, -30, 10);

	camera.pan = camera_pan;
	temp = fcos(camera_tilt,-camera_distance);
	vec_set(camera_move_to.x, vector(my.x + fcos(camera.pan, temp), my.y + fsin(camera.pan, temp), my.z + 20 + fsin(camera_tilt, -camera_distance)));

	temp = minv(1,0.5 * time_step); //changing 0.5 will change how fast the camera moves, at 1 places us at target, this value is what allows the smooth movement
	camera.x += temp*(camera_move_to.x - camera.x);
	camera.y += temp*(camera_move_to.y - camera.y);
	camera.z += temp*(camera_move_to.z - camera.z);

	vec_diff(tempV.x, camera.x, my.x);
	vec_normalize(tempV.x, 16);
	vec_add(tempV.x, camera.x);

	if(c_trace(my.x, tempV.x, IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS) > 0) 
	{
		vec_diff(tempV.x, my.x, target.x);
		vec_normalize(tempV.x, 16);
		vec_set(camera.x, target.x);
		vec_add(camera.x, tempV.x);
	}

	vec_diff(tempV.x, my.x, camera.x);
	vec_to_angle(camera.pan, tempV.x);
}*/

function rotate_entity(var rotate_angle, var rotate_speed) 
{
	if(my.pan == rotate_angle)		return;
	result = ang(rotate_angle - my.pan);
	if(result > 0)	my.pan += rotate_speed * time_step;
	if(result < 0)	my.pan -= rotate_speed * time_step; 
	if(ang(rotate_angle - my.pan) < 0 && result > 0)	my.pan = rotate_angle; 
	if(ang(rotate_angle - my.pan) > 0 && result < 0)	my.pan = rotate_angle; 
}

function handle_sword_collision()
{
	you = NULL;
	vec_for_vertex(tempV.x, player_weapon, 274); //sword base
	vec_for_vertex(tempV2.x, player_weapon, 54); //sword tip
	result = c_trace(tempV.x, tempV2.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX);
	if(you != NULL) 
	{
		if(you.entity_type == 2 && you.hit_by_player == 0) 
		{
			if(airborne_attack == 1 && my.animblend == attack_a)		my.movement_mode = 2;
			you.hit_by_player = 1;
			if(target_enemy == NULL)				{ target_enemy = you; player_lock_on = 1; }
		}
	}
}


enemy.C
Click to reveal..
Code:
action enemy_dummy()
{
	set(my,SHADOW);
	my.entity_type = 2;
	my.emask |= ENABLE_SCAN;
	while(1) 
	{
		if(my.hit_by_player == 1) 
		{
			my.move_x = player.move_x;
			my.move_y = player.move_y;
			my.move_z = player.move_z;
			c_move(my, nullvector, my.move_x, USE_BOX | IGNORE_PASSABLE | GLIDE);
			if(player.animblend == blend || player.animblend < attack_a || my.animblend > attack_f)	my.hit_by_player = 0; 
		}
		if((player.animblend >= stand && target_enemy == me && player_lock_on == 0) && (player.animblend < attack_a || player.animblend > attack_f))
			target_enemy = NULL;
		if(target_enemy == my && vec_dist(my.x, player.x) > 200)		
			target_enemy = NULL;
		wait(1);
	}
}


animation.C
Click to reveal..
Code:
function handle_animation(var animation_speed) 
{
	if(animation_speed <= 0)	animation_speed = 1; 
	if(my.animblend != blend && my.blendframe != nullframe) { my.animate2 = 0; my.animblend = blend; }
	if(my.animblend == blend) 
	{
		if		 (my.currentframe == stand)		ent_animate(my, "stand",    my.animate, ANM_CYCLE); 
		else if(my.currentframe == run)			ent_animate(my, "run",      my.animate, ANM_CYCLE);
		else if(my.currentframe == walk)			ent_animate(my, "walk",     my.animate, ANM_CYCLE);
		else if(my.currentframe == jump)			ent_animate(my, "jump",     my.animate,0);
		else if(my.currentframe == attack_a)	ent_animate(my, "attack_a", my.animate,0);
		else if(my.currentframe == attack_b)	ent_animate(my, "attack_b", my.animate,0);
		else if(my.currentframe == attack_c)	ent_animate(my, "attack_c", my.animate,0);
		else if(my.currentframe == attack_d)	ent_animate(my, "attack_d", my.animate,0);
		else if(my.currentframe == attack_e)	ent_animate(my, "attack_e", my.animate,0);
		else if(my.currentframe == attack_f)	ent_animate(my, "attack_f", my.animate,0);
		if		 (my.blendframe == stand)		ent_blend("stand",0,my.animate2);
		else if(my.blendframe == run)			ent_blend("run",0,my.animate2);
		else if(my.blendframe == walk)		ent_blend("walk",0,my.animate2);
		else if(my.blendframe == jump)		ent_blend("jump",0,my.animate2);
		else if(my.blendframe == fall)		ent_blend("jump",60,my.animate2);
		else if(my.blendframe == attack_a)	ent_blend("attack_a",0,my.animate2);
		else if(my.blendframe == attack_b)	ent_blend("attack_b",0,my.animate2);
		else if(my.blendframe == attack_c)	ent_blend("attack_c",0,my.animate2);
		else if(my.blendframe == attack_d)	ent_blend("attack_d",0,my.animate2);
		else if(my.blendframe == attack_e)	ent_blend("attack_e",0,my.animate2);
		else if(my.blendframe == attack_f)	ent_blend("attack_f",0,my.animate2);
		my.animate2 += 45 * time_step;
		if(my.animate2 >= 100) 
		{
			my.animate = 0;
			my.animblend = my.blendframe;
			my.blendframe = nullframe;
		}
	}
	//
	switch(my.animblend)
	{
		case stand:
			ent_animate(my,"stand",my.animate,ANM_CYCLE);
			my.animate += 5 * animation_speed * time_step;
			my.animate %= 100;
			my.currentframe = stand;
			break;
		case run:
			ent_animate(my,"run",my.animate,ANM_CYCLE);
			my.animate += 8 * animation_speed * time_step;
			my.animate %= 100;
			my.currentframe = run;
			break;
		case walk:
			ent_animate(my,"walk",my.animate,ANM_CYCLE);
			my.animate += 8 * animation_speed * time_step;
			my.animate %= 100;
			my.currentframe = walk;
			break;
		case jump:	//flow through to fall
		case fall:
			if(my.jumping_mode == 3) { my.animate = 60; }
			ent_animate(my,"jump",my.animate,0);
			my.animate += 10 * animation_speed * time_step;
			my.currentframe = jump;
			if(my.animate >= 60 && my.jumping_mode == 1)		my.jumping_mode = 2; 
			if(my.animate >= 100) 
			{
				ent_animate(my,"jump",100,0);
				my.animate = 100;
				my.blendframe = stand;
				if(my.moving == 1) 
				{
					if(key_shift == 1)	my.blendframe = walk;
					else						my.blendframe = run; 
				}
			}
			break;
		case attack_a:
			ent_animate(my,"attack_a",my.animate,0);
			my.animate += 20 * animation_speed * time_step;
			my.currentframe = attack_a;
			if(my.animate >= 100) 
			{
				ent_animate(my,"attack_a",100,0);
				my.animate = 100;
				my.blendframe = stand;
				if(my.moving == 1) 
				{
					if(key_shift == 1)		my.blendframe = walk;
					else							my.blendframe = run; 
				}
				if(combo_continue == 1) 
				{
					combo_continue = 0;
					my.blendframe = attack_b;
				} 
				else
					my.movement_mode = 0;
			}
			break;
		case attack_b:
			ent_animate(my,"attack_b",my.animate,0);
			my.animate += 15 * animation_speed * time_step;
			my.currentframe = attack_b;
			if(my.animate >= 100) 
			{
				ent_animate(my,"attack_b",100,0);
				my.animate = 100;
				my.blendframe = stand;
				if(my.moving == 1) 
				{
					if(key_shift == 1)		my.blendframe = walk;
					else							my.blendframe = run; 
				}
				if(combo_continue == 1) 
				{
					combo_continue = 0;
					my.blendframe = attack_c;
				}
				else
					my.movement_mode = 0;
			}
			break;
		case attack_c:
			ent_animate(my,"attack_c",my.animate,0);
			my.animate += 10 * animation_speed * time_step;
			my.currentframe = attack_c;
			if(my.animate >= 100) 
			{
				ent_animate(my,"attack_c",100,0);
				my.animate = 100;
				my.blendframe = stand;
				if(my.moving == 1) 
				{
					if(key_shift == 1)		my.blendframe = walk;
					else							my.blendframe = run; 
				}
				if(combo_continue == 1) 
				{
					my.jumping_mode = 10;
					my.force_z = 12;
					my.gravity = 4;
					combo_continue = 0;
					my.blendframe = attack_d;
				}
				else
					my.movement_mode = 0;
			}
			break;
		case attack_d:
			handle_sword_collision();
			ent_animate(my,"attack_d",my.animate,0);
			my.animate += 15 * animation_speed * time_step;
			my.currentframe = attack_d;
			if(my.animate >= 100) 
			{
				ent_animate(my,"attack_d",100,0);
				my.animate = 100;
				my.blendframe = stand;
				if(my.moving == 1) 
				{
					if(key_shift == 1)		my.blendframe = walk;
					else							my.blendframe = run; 
				}
				if(combo_continue == 1) 
				{
					combo_continue = 0;
					my.blendframe = attack_e;
				}
				else
					my.movement_mode = 0;
			}
			break;
		case attack_e:
			ent_animate(my,"attack_e",my.animate,0);
			my.animate += 15 * animation_speed * time_step;
			my.currentframe = attack_e;
			if(my.jumping_mode == 0 && my.animate >= 20 && my.animate < 60) 
			{
				my.gravity = 3;
				my.jumping_mode = 10;
				my.force_z = 15;
			}
			if(my.animate >= 100) 
			{
				ent_animate(my,"attack_e",100,0);
				my.animate = 100;
				my.blendframe = stand;
				if(my.moving == 1) 
				{
					if(key_shift == 1)		my.blendframe = walk;
					else							my.blendframe = run; 
				}
				if(combo_continue == 1) 
				{
					combo_continue = 0;
					my.blendframe = attack_f;
				}
				else
					my.movement_mode = 0;
			}
			break;
		case attack_f:
			ent_animate(my,"attack_f",my.animate,0);
			my.animate += 6 * animation_speed * time_step;
			my.currentframe = attack_f;
			if(my.jumping_mode == 0 && my.animate >= 40 && my.animate < 60) 
			{
				my.gravity = 6;
				my.jumping_mode = 10;
				my.force_z = 12;
			}
			if(my.animate >= 100) 
			{
				my.movement_mode = 0;
				ent_animate(my,"attack_f",100,0);
				my.animate = 100;
				my.blendframe = stand;
				if(my.moving == 1) 
				{
					if(key_shift == 1)		my.blendframe = walk;
					else							my.blendframe = run; 
				}
			}
			break;
	}
	if(my.animblend >= attack_a && my.animblend <= attack_f)		handle_sword_collision();
	if(my.animblend != blend && my.blendframe != nullframe) 		{ my.animate2 = 0; my.animblend = blend; }
}


Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 02/12/09 18:44

EvilSOB! You're my hero! How can i thank you?

EDIT: Just a tiny problem. When it falls, It doesn't play the falling animation.
ANOTHER EDIT: Just a huge problem. Player can't defeat enemies
Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 02/12/09 19:26

Found the falling problem, my bad sorry.
At lines approx 140 & approx 230 you will find a clamp statement(clamped maximum movement speed) that needs changing to
Code:
result = clamp(result, -150, 150);

As for the enemies never dying, thats just because the supplied enemy code doesnt have
any "life" tracking, so they can never die, unless you add the code yourself.


Also, heres the whole of Player.c if it makes it easier...
Click to reveal..
Code:
function rotate_entity(var rotate_angle, var rotate_speed);
function handle_gravity();
function handle_movement();
function handle_camera();
function handle_animation(var animation_speed); 


#define nullframe	-2
#define blend		-1
#define stand		 0
#define run			 1
#define walk		 2
#define jump		 3
#define fall		 4
#define attack_a	 5
#define attack_b	 6
#define attack_c	 7
#define attack_d	 8
#define attack_e	 9
#define attack_f	 10

#define move_x				skill22
#define move_y				skill23
#define move_z				skill24
#define force_x			skill25
#define force_y			skill26
#define force_z			skill27
#define velocity_x		skill28
#define velocity_y		skill29
#define velocity_z		skill30
#define animate			skill31
#define animate2			skill32
#define animblend			skill33
#define currentframe		skill34
#define blendframe		skill35
#define z_offset			skill50
#define jumping_mode		skill51
#define gravity			skill52
#define movement_mode	skill53
#define moving				skill54
#define hit_by_player	skill55
#define entity_type		skill56

ENTITY*	player_weapon;
ENTITY*	target_enemy;

var		temp;
VECTOR*	tempV = { x=0; 	y=0; 		z=0; 		}
VECTOR*	tempV2= { x=0; 	y=0; 		z=0; 		}
ANGLE*	tempA = { pan=0; 	tilt=0; 	roll=0;	}
ANGLE*	tempA2= { pan=0; 	tilt=0; 	roll=0;	}

VECTOR*	camera_move_to = { x=0;	y=0;	z=0;	}
var camera_distance = 200;
var camera_pan;
var camera_tilt;

var space_press = 0;
var mouse_left_press = 0;
var mouse_right_press = 0;
var combo_continue = 0;
var player_lock_on = 0;
var airborne_attack = 0;


action attach_weapon()
{
	player_weapon = my;
	set(my,PASSABLE);
	proc_mode = PROC_LATE;
	while(you != NULL) 
	{
		vec_for_vertex(tempV.x, you, 1175);			//hand palm base
		vec_for_vertex(tempV2.x, you, 1240);		//hand palm tip
		vec_set(my.x, tempV.x);
		vec_diff(tempV.x, tempV2.x, tempV.x);
		vec_to_angle(tempA.pan, tempV.x);
		vec_set(my.pan, tempA.pan);
		wait(1);
	}
}

action player_action() 
{
	player = my;
	my.gravity = 6;
	my.z_offset = 12;
	set(my,SHADOW);
	ent_create("sword.mdl", my.x, attach_weapon);
	wait(1);
	while(1) 
	{	//the main player loop
		handle_gravity();
		handle_movement();
		handle_camera();
		handle_animation(1);
		wait(1);
	}
}

function handle_movement() 
{
	tempV.x = -1000;
	tempV.y = 0;
	my.moving = 0;
	if(key_w == 1 && key_s == 0 && key_a == 0 && key_d == 0)	tempV.x = camera.pan;
	if(key_s == 1 && key_w == 0 && key_a == 0 && key_d == 0)	tempV.x = camera.pan + 180;
	if(key_a == 1 && key_s == 0 && key_w == 0 && key_d == 0)	tempV.x = camera.pan + 90;
	if(key_d == 1 && key_s == 0 && key_a == 0 && key_w == 0)	tempV.x = camera.pan - 90;
	if(key_w == 1 && key_a == 1 && key_d == 0 && key_s == 0)	tempV.x = camera.pan + 45;
	if(key_w == 1 && key_d == 1 && key_a == 0 && key_s == 0)	tempV.x = camera.pan - 45;
	if(key_s == 1 && key_a == 1 && key_d == 0 && key_w == 0)	tempV.x = camera.pan + 135;
	if(key_s == 1 && key_d == 1 && key_a == 0 && key_w == 0)	tempV.x = camera.pan - 135;
	if(tempV.x != -1000) 
	{
		my.moving = 1;
		if(key_shift == 1)	tempV.y = 10 * time_step;  
		else						tempV.y = 15 * time_step; 
	}
	//
	if(my.movement_mode==0)
	{
		my.move_x = fcos(tempV.x, tempV.y);
		my.move_y = fsin(tempV.x, tempV.y);
	}
	else if((my.movement_mode==1)||(my.movement_mode==2))
	{
		tempV.y = fsin((my.animate * 1.2) + 45,15 * time_step);
		my.move_x = fcos(my.pan, tempV.y);
		my.move_y = fsin(my.pan, tempV.y);
		tempV.y = 0;
		//NextLine: if we need to rotate whilst attacking (the player is pressing keys to rotate)
		if(tempV.x != -1000) 	tempV.y = 1;
	}
	//
	c_move(my, nullvector, my.move_x, USE_BOX | IGNORE_PASSABLE | GLIDE);
	result = -my.z_offset + c_trace(vector(my.x,my.y,my.z - my.z_offset), vector(my.x,my.y,my.z - 4000), IGNORE_ME | IGNORE_PASSABLE | USE_BOX);
	result = clamp(result, -150, 150);
	if(result < 0) 	{	my.z -= result;	my.velocity_z = 0;	}
	//
	if(target_enemy == NULL) 
	{	if(tempV.y > 0)	rotate_entity(tempV.x, 30); 	}
	else
	{
		vec_diff(tempV2.x, target_enemy.x, my.x);
		vec_to_angle(tempA2.pan, tempV2.x);
		rotate_entity(tempA2.pan,30);
	}
	//
	if(my.movement_mode == 0) 
	{
		my.gravity = 6;
		if(my.move_x != 0 || my.move_y != 0) 
		{	//ifwe are moving
			if(my.animblend == stand) 
			{	//ifour current animation is stand
				if(key_shift == 1)	my.blendframe = walk;
				else						my.blendframe = run;
			}
			if(my.animblend == run && key_shift == 1)		my.blendframe = walk;
			if(my.animblend == walk && key_shift == 0)	my.blendframe = run;
		} 
		else
		{
			if(my.animblend > stand && my.animblend != jump && my.animblend != fall) 
			{	//if we arn't moving and our current animation is walk or run, blend and cycle the stand animation
				my.blendframe = stand;
			}
		}
		if(mouse_left == 0 && mouse_left_press == 1)		mouse_left_press = 0;
		if(mouse_left == 1 && mouse_left_press == 0 && my.animblend >= stand) 
		{
			mouse_left_press = 1;
			my.blendframe = attack_a;
			if(my.jumping_mode == 1) 	airborne_attack = 1;
			else								airborne_attack = 0;
			my.movement_mode = 1;
			combo_continue = 0;
		}
		if(mouse_right == 0 && mouse_right_press == 1)	mouse_right_press = 0;
		if(mouse_right == 1 && mouse_right_press == 0) 
		{
			if(player_lock_on == 0) 
			{
				c_scan(player.x, player.pan, vector(360,180,250), SCAN_ENTS | SCAN_LIMIT | IGNORE_ME);
				if(you != NULL) 
				{
					if(you.entity_type == 2) 
					{	//make sure you've scanned an enemy
						player_lock_on = 1;
						target_enemy = you;
					}
				}
			} 
			else
			{
				player_lock_on = 0;
				target_enemy = NULL;
			}
			mouse_right_press = 1;
		}
	}
	//
	if(my.movement_mode == 1) 
	{
		if(my.jumping_mode != 10)										my.jumping_mode = 0;
		else if(my.animate >= 60 && my.animblend >= stand)		my.jumping_mode = 0;
		//
		if(mouse_left == 0 && mouse_left_press == 1)
			mouse_left_press = 0;
		if(mouse_left == 1 && mouse_left_press == 0 && my.animate >= 30 && combo_continue == 0) 
		{	mouse_left_press = 1; combo_continue = 1; }
	}
	//
	if(my.movement_mode == 2) 
	{
		my.jumping_mode = 0;
		if(mouse_left == 0 && mouse_left_press == 1)
			mouse_left_press = 0; 
		if(mouse_left == 1 && mouse_left_press == 0 && my.animate >= 30 && combo_continue == 0) 
		{	mouse_left_press = 1; combo_continue = 1; }
	}
}

function handle_gravity() 
{
	result = -my.z_offset + c_trace(vector(my.x,my.y,my.z - my.z_offset), vector(my.x,my.y,my.z - 4000), IGNORE_ME | IGNORE_PASSABLE | USE_BOX );
	result = clamp(result, -150, 150);
	if(result < 3) 
	{
		if(my.jumping_mode == 0) 
		{
			my.force_z = -1 * result;
			if(key_space == 0 && space_press == 1) 			space_press = 0;
			if(key_space == 1 && space_press == 0 && my.movement_mode == 0 && my.animblend >= stand && my.animblend != jump && my.animblend != fall) 
			{
				space_press = 1;
				my.jumping_mode = 1;
				my.force_z = 25;
				my.blendframe = jump;
				my.animate2 = 0;
				my.animblend = blend;
			}
		}
		if(my.jumping_mode == 2 || my.jumping_mode == 3)	my.jumping_mode = 0;
	} 
	else
	{
		if(my.jumping_mode == 2) 
		{
			if(result > 120) 
			{
				my.animate = 60;
				my.jumping_mode = 3;
			} 
			else
				my.jumping_mode = 0;
		}
		if(my.jumping_mode == 3 && result <= 120)		my.jumping_mode = 0;
		if(my.jumping_mode == 0 && my.movement_mode == 0) 
		{
			if(result > 120 && my.animblend >= stand && my.animblend != jump && my.animblend != fall) 
			{
				my.jumping_mode = 3;
				my.blendframe = fall;
				my.animate2 = 0;
				my.animblend = blend;
			}
		}
		my.force_z -= my.gravity * time_step;
		my.force_z =  maxv(-30, my.force_z);
		if(my.movement_mode == 2)		my.force_z = 0;
	}
 	my.velocity_z += (time_step * my.force_z) - (minv(time_step*0.7, 1) * my.velocity_z);
	my.move_z = my.velocity_z * time_step;
}

//////////////////////////////
//Stable/rigid camera collision
//////////////////////////////
function handle_camera() 
{
	camera.pan -=  mouse_force.x * 12 * time_step;
	camera.tilt += mouse_force.y * 8 * time_step;
	camera.tilt = clamp(camera.tilt, -30, 10);
	temp = fcos(camera.tilt, -camera_distance);
	vec_set(camera.x, vector(my.x + fcos(camera.pan, temp),my.y + fsin(camera.pan, temp),my.z + 20 + fsin(camera.tilt, -camera_distance)));

	vec_diff(tempV.x, camera.x, my.x); //find the vector from the player to the camera
	vec_normalize(tempV.x, 16); //get the magnitude of it's vector to 16 quants and store it in temp
	vec_add(tempV.x, camera.x); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.

	result = c_trace(my.x, tempV.x, IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS); //trace from the player to 16 quants behind the camera.
	if(result > 0) 
	{
		vec_diff(tempV.x, my.x, target.x); //find the vector from the point the trace hit to the player
		vec_normalize(tempV.x, 16); //get the magnitude of this vector to 16 quants and store in temp
		vec_set(camera.x, target.x); //place the camera at the trace hit point
		vec_add(camera.x, tempV.x); //move the camera away from the wall by the vector temp, 16 quants towards the player
	}
}


//////////////////////////////
//Smooth camera collision
//////////////////////////////
/*function handle_camera() 
{
	camera_pan -= mouse_force.x * 12 * time_step;
	camera_tilt += mouse_force.y * 8 * time_step;
	camera_tilt = clamp(camera_tilt, -30, 10);

	camera.pan = camera_pan;
	temp = fcos(camera_tilt,-camera_distance);
	vec_set(camera_move_to.x, vector(my.x + fcos(camera.pan, temp), my.y + fsin(camera.pan, temp), my.z + 20 + fsin(camera_tilt, -camera_distance)));

	temp = minv(1,0.5 * time_step); //changing 0.5 will change how fast the camera moves, at 1 places us at target, this value is what allows the smooth movement
	camera.x += temp*(camera_move_to.x - camera.x);
	camera.y += temp*(camera_move_to.y - camera.y);
	camera.z += temp*(camera_move_to.z - camera.z);

	vec_diff(tempV.x, camera.x, my.x);
	vec_normalize(tempV.x, 16);
	vec_add(tempV.x, camera.x);

	if(c_trace(my.x, tempV.x, IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS) > 0) 
	{
		vec_diff(tempV.x, my.x, target.x);
		vec_normalize(tempV.x, 16);
		vec_set(camera.x, target.x);
		vec_add(camera.x, tempV.x);
	}

	vec_diff(tempV.x, my.x, camera.x);
	vec_to_angle(camera.pan, tempV.x);
}*/

function rotate_entity(var rotate_angle, var rotate_speed) 
{
	if(my.pan == rotate_angle)		return;
	result = ang(rotate_angle - my.pan);
	if(result > 0)	my.pan += rotate_speed * time_step;
	if(result < 0)	my.pan -= rotate_speed * time_step; 
	if(ang(rotate_angle - my.pan) < 0 && result > 0)	my.pan = rotate_angle; 
	if(ang(rotate_angle - my.pan) > 0 && result < 0)	my.pan = rotate_angle; 
}

function handle_sword_collision()
{
	you = NULL;
	vec_for_vertex(tempV.x, player_weapon, 274); //sword base
	vec_for_vertex(tempV2.x, player_weapon, 54); //sword tip
	result = c_trace(tempV.x, tempV2.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX);
	if(you != NULL) 
	{
		if(you.entity_type == 2 && you.hit_by_player == 0) 
		{
			if(airborne_attack == 1 && my.animblend == attack_a)		my.movement_mode = 2;
			you.hit_by_player = 1;
			if(target_enemy == NULL)				{ target_enemy = you; player_lock_on = 1; }
		}
	}
}

Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 02/12/09 20:39

Wow! Thanks EvilSOB

But about enemies, The player can't push them.
Dowanload the video here, Please.
Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 02/13/09 08:48

Its hard to tell from the video, but your player cant just push the enemies
around, he has to whack em with his sword (left mouse click) before they move.

Or, if you sword isnt moving cause your animations arent done yet, try
positioning your player so the sword is touching the enemy, then hit left
click.
Otherwise you'll need to get the animations done and the sword attached first.

The player script only checks for sword impact whilst the left mouse is pressed.
(player.c around line 180)
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 02/13/09 09:03

Great! Now it's working fine!

Maybe i bothering you a lot, But can you tell me how to remove the sword from the player? (I tried to delete the sword commands etc. but then i get errors.)
Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 02/13/09 10:18

Its pretty heavily embedded right through player.c and animation.c, so it would be a good exercise for you to hack it all out.

BUT, all attack reactions by the enemy are based on if the "player_weapon" entity hits them, but nothing else.
So you'll need to code an entirely new hit-detection system if you do hack the "player_weapon" out.


Be that as it may, to DISABLE the weapon, just three changes to make. They are all in the PLAYER.C script.

First, just for pointer safety, change the following global pointer declares found early the script.
ENTITY* player_weapon = NULL;
ENTITY* target_enemy = NULL;


Second, in PLAYER_ACTION function, find the line "ent_create("sword.mdl", my.x, attach_weapon);".
Remove or comment out this line and the weapon wont get created.

And last, add the following line to the start of the function HANDLE_SWORD_COLLISION.
Code:
function handle_sword_collision()
{
   if(player_weapon==NULL)   return;   //<<<< insert this line.
   you = NULL;
   ...

Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 02/13/09 10:31

How can i thank you?

Thank you very much! smile

But player can't push them. How can i make him push the enemies with his hands?
Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 02/13/09 13:03

Hmm, I'll need to think on that one, but it'll be easy enough I think.
BUT, do you want it to "need to press left mouse button" to move them, or just purely on contact?

[EDIT]Heres the code update to make the enemy move when "hit" by attacking hands.
(Making the enemies move when just bumped into too much work. Write a new action to do that.)

WHOLE enemy.c(though only one "paragraph" added)
Click to reveal..
Code:
action enemy_dummy()
{
	set(my,SHADOW);
	my.entity_type = 2;
	my.emask |= ENABLE_SCAN;
	while(1) 
	{
		if(my.hit_by_player == 1)	//sucessful attack by player weapon
		{
			my.move_x = player.move_x;
			my.move_y = player.move_y;
			my.move_z = player.move_z;
			c_move(my, nullvector, my.move_x, USE_BOX | IGNORE_PASSABLE | GLIDE);
			if(player.animblend == blend || player.animblend < attack_a || my.animblend > attack_f)	my.hit_by_player = 0; 
		}
		else if(my.hit_by_player == 2)	//sucessful HAND attack by player
		{
			my.move_x = player.move_x;
			my.move_y = player.move_y;
			my.move_z = player.move_z;
			c_move(my, nullvector, my.move_x, USE_BOX | IGNORE_PASSABLE | GLIDE);
			if(player.animblend == blend || player.animblend < attack_a || my.animblend > attack_f)	my.hit_by_player = 0; 
		}
		if((player.animblend >= stand && target_enemy == me && player_lock_on == 0) && (player.animblend < attack_a || player.animblend > attack_f))
			target_enemy = NULL;
		if(target_enemy == my && vec_dist(my.x, player.x) > 200)		
			target_enemy = NULL;
		wait(1);
	}
}

PARTIAL player.c(two functions to replace handle_sword_collisions(), found at end of script)
Click to reveal..
Code:
function handle_hand_collision()
{
	vec_for_vertex(tempV.x, player, 1146); 	//thumb tip
	vec_for_vertex(tempV2.x, player, 1144); 	//thumb joint
	result = c_trace(tempV.x, tempV2.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX);
	if(you != NULL) 
	{
		if(you.entity_type == 2 && you.hit_by_player == 0) 
		{
			if(airborne_attack == 1 && my.animblend == attack_a)		my.movement_mode = 2;
			you.hit_by_player = 2;
			if(target_enemy == NULL)				{ target_enemy = you; player_lock_on = 1; }
		}
	}
}

function handle_sword_collision()
{
	you = NULL;
	if(player_weapon==NULL)		{	handle_hand_collision();	return;	}
	vec_for_vertex(tempV.x, player_weapon, 274); //sword base
	vec_for_vertex(tempV2.x, player_weapon, 54); //sword tip
	result = c_trace(tempV.x, tempV2.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX);
	if(you != NULL) 
	{
		if(you.entity_type == 2 && you.hit_by_player == 0) 
		{
			if(airborne_attack == 1 && my.animblend == attack_a)		my.movement_mode = 2;
			you.hit_by_player = 1;
			if(target_enemy == NULL)				{ target_enemy = you; player_lock_on = 1; }
		}
	}
}


Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 02/13/09 13:58

A NOTE TO ALL USING MY RE-CODE!

I discovered an instability in my code during my last bit of research,
if youve already copied my code from above you'll need to change the following.
(Ive updated my above code post so this has been fixed there)

In ENEMY.C the following line must be changed
Code:
c_move(my, nullvector, my.move_x, USE_AABB | IGNORE_PASSABLE | GLIDE);
    must be changed to
c_move(my, nullvector, my.move_x, USE_BOX | IGNORE_PASSABLE | GLIDE);

Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 02/13/09 14:23

OK! Thanks. But now i replaced enemy.c by the new one

and i updated function handle_sword_collision and i put handle_hand_collision.

Now how can i activate the hand?
Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 02/13/09 14:47

With the two bits of code I just gave you, it should already be running.
Face the enemy from close, hit left-mouse click and you will run through the normal attack animations,
and it will push the enemy back.

No other mode besides the new enemy.c and the modded handle_???_collision functions.
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 02/13/09 15:04

Thank you very much! This is good to thank you wink :

http://www.flashgamecodes.ca/games/84e5f721da67.swf

And BTW, I'll put the converted code in the wiki and i'll put your name as the converter. Ok?

EDIT: How can i make the player move using WASD or UP DOWN LEFT RIGHT?
Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 02/13/09 16:10

Cool, thanks.

And to add the UP DOWN LEFT RIGHT functionality, go to the start of the handle_movement()
function in PLAYER.C and add the following just before or after the other big block of if's.
[you'll see where I mean, as long as its before the line "if(tempV.x != -1000)"]
Code:
	if(key_cuu == 1 && key_cud == 0 && key_cul == 0 && key_cur == 0)	tempV.x = camera.pan;
	if(key_cud == 1 && key_cuu == 0 && key_cul == 0 && key_cur == 0)	tempV.x = camera.pan + 180;
	if(key_cul == 1 && key_cud == 0 && key_cuu == 0 && key_cur == 0)	tempV.x = camera.pan + 90;
	if(key_cur == 1 && key_cud == 0 && key_cur == 0 && key_cuu == 0)	tempV.x = camera.pan - 90;
	if(key_cuu == 1 && key_cul == 1 && key_cud == 0 && key_cud == 0)	tempV.x = camera.pan + 45;
	if(key_cuu == 1 && key_cur == 1 && key_cul == 0 && key_cud == 0)	tempV.x = camera.pan - 45;
	if(key_cud == 1 && key_cul == 1 && key_cur == 0 && key_cuu == 0)	tempV.x = camera.pan + 135;
	if(key_cud == 1 && key_cur == 1 && key_cul == 0 && key_cuu == 0)	tempV.x = camera.pan - 135;


Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 02/13/09 16:55

Wow! Thanks!
Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 02/13/09 16:59

No problem. Im just amazed at how much I seem to have learned in the last
couple of months, without even noticing it...
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 02/13/09 17:21

See: http://www.opserver.de/wiki/index.php/Original_Kingdom_Hearts_Movement

I putted the code and your name and the add-ons etc. smile
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 02/13/09 18:20

BTW, How can i make a double jump and hang?

And how can i make a rotate camera?
Download here, Please! smile
But with less rotating.
Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 02/13/09 19:55

I'll leave the cameras to someone else, as my vector maths is terrible.

And the hang I havent any idea on, I think its a big bit beyond the scope of this script.

But, here is some code to get the double-jump in, splice it in at around line 250 in PLAYER.c
The the abs(my.velocity_z) <= 10 is the number to play with to set the time the
double jump is available. Its currently set to about the top 20% of the jump.
So double jump wont react unless you hit space when you are 'almost' at the top,
or just starting to come back down. It doesnt react at all to falling from a height.

Code:
      ...
      }
      if(my.jumping_mode == 2 || my.jumping_mode == 3)   my.jumping_mode = 0;
   } 
   else
   {

   ////////////////////////////////// vvvvv insert this code
   if(my.jumping_mode == 1)
   {
      if(key_space == 0 && space_press == 1)         space_press = 0;
      if(key_space == 1 && space_press == 0 && abs(my.velocity_z) <= 10)  //section of jump where double is available
      {
         space_press = 1;
         my.jumping_mode = 2;
         my.force_z = 25;
         my.velocity_z = 0;
         my.blendframe = jump;
         my.animate2 = 0;
         my.animblend = blend;
      }
   }
   ////////////////////////////////// ^^^^^ insert this code

   if(my.jumping_mode == 2) 
   {
      if(result > 120) 
      ...

Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 02/13/09 21:43

Thanks... Added to Wiki... Now please anyone what about hanging and camera?
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 02/24/09 17:04

Well, I've found a bug. When i put the correct falling code. Everything will be fine. Except one thing. The framerate will be low, Around 35 FPS. frown
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 03/02/09 13:48

Originally Posted By: Cowabanga
Well, I've found a bug. When i put the correct falling code. Everything will be fine. Except one thing. The framerate will be low, Around 35 FPS. frown


So?
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 03/15/09 14:47

OK. Sorry for these posts, but how can i control the rotation speed and the animations return speed?

I searched many times in the and i haven't see anything related to that.

EDIT: Okay??
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 03/18/09 15:17

EDIT: No problems now. smile
Posted By: paracharlie

Re: [REQ] converting a code to lite-c - 06/16/09 20:09

I know this post is kind of old but I wanted to share this little extra because I think it's pretty cool.

I added mickey.z zoom in and out and also converted an old if comparison for alpha fade on the character. When you zoom in or if the camera collides with a wall and comes close to the character the character will become translucent. Also added two wait(1)'s to handle_sword_collision and handle_hand_collision. There seemed to be a Crash to desktop if you clicked the mouse to many times and from what I can tell the wait()'s seem to be helping.

I did not put alpha fade on the sword because it just seems really cool to me to be able to still see the sword while zoomed in.
I hope someone finds this useful, cheers...

Alpha fade between lines: 331 and 351
wait(1) at line: 413 and 432

Code:

function rotate_entity(var rotate_angle, var rotate_speed);
function handle_gravity();
function handle_movement();
function handle_camera();
function handle_animation(var animation_speed); 


#define nullframe	-2
#define blend		-1
#define stand		 0
#define run			 1
#define walk		 2
#define jump		 3
#define fall		 4
#define attack_a	 5
#define attack_b	 6
#define attack_c	 7
#define attack_d	 8
#define attack_e	 9
#define attack_f	 10

#define move_x				skill22
#define move_y				skill23
#define move_z				skill24
#define force_x			skill25
#define force_y			skill26
#define force_z			skill27
#define velocity_x		skill28
#define velocity_y		skill29
#define velocity_z		skill30
#define animate			skill31
#define animate2			skill32
#define animblend			skill33
#define currentframe		skill34
#define blendframe		skill35
#define z_offset			skill50
#define jumping_mode		skill51
#define gravity			skill52
#define movement_mode	skill53
#define moving				skill54
#define hit_by_player	skill55
#define entity_type		skill56

ENTITY*	player_weapon;
ENTITY*	target_enemy;

var		temp;
VECTOR*	tempV = { x=0; 	y=0; 		z=0; 		}
VECTOR*	tempV2= { x=0; 	y=0; 		z=0; 		}
ANGLE*	tempA = { pan=0; 	tilt=0; 	roll=0;	}
ANGLE*	tempA2= { pan=0; 	tilt=0; 	roll=0;	}

VECTOR*	camera_move_to = { x=0;	y=0;	z=0;	}
var camera_distance = 200;
var camera_pan;
var camera_tilt;
var fade_toggle = 1; //0 = off; 1 = on
var fade_start = 90;
var fade_end = 60; 
var space_press = 0;
var mouse_left_press = 0;
var mouse_right_press = 0;
var combo_continue = 0;
var player_lock_on = 0;
var airborne_attack = 0;


action attach_weapon()
{
	player_weapon = my;
	set(my,PASSABLE);
	proc_mode = PROC_LATE;
	while(you != NULL) 
	{
		vec_for_vertex(tempV.x, you, 1175);			//hand palm base
		vec_for_vertex(tempV2.x, you, 1240);		//hand palm tip
		vec_set(my.x, tempV.x);
		vec_diff(tempV.x, tempV2.x, tempV.x);
		vec_to_angle(tempA.pan, tempV.x);
		vec_set(my.pan, tempA.pan);
		wait(1);
	}
}

action player_action() 
{
	player = my;
	my.gravity = 6;
	my.z_offset = 12;
	set(my,SHADOW);
	ent_create("sword.mdl", my.x, attach_weapon);
	wait(1);
	while(1) 
	{	//the main player loop
		handle_gravity();
		handle_movement();
		handle_camera();
		handle_animation(1);
		wait(1);
	}
}

function handle_movement() 
{
	tempV.x = -1000;
	tempV.y = 0;
	my.moving = 0;
	if(key_w == 1 && key_s == 0 && key_a == 0 && key_d == 0)	tempV.x = camera.pan;
	if(key_s == 1 && key_w == 0 && key_a == 0 && key_d == 0)	tempV.x = camera.pan + 180;
	if(key_a == 1 && key_s == 0 && key_w == 0 && key_d == 0)	tempV.x = camera.pan + 90;
	if(key_d == 1 && key_s == 0 && key_a == 0 && key_w == 0)	tempV.x = camera.pan - 90;
	if(key_w == 1 && key_a == 1 && key_d == 0 && key_s == 0)	tempV.x = camera.pan + 45;
	if(key_w == 1 && key_d == 1 && key_a == 0 && key_s == 0)	tempV.x = camera.pan - 45;
	if(key_s == 1 && key_a == 1 && key_d == 0 && key_w == 0)	tempV.x = camera.pan + 135;
	if(key_s == 1 && key_d == 1 && key_a == 0 && key_w == 0)	tempV.x = camera.pan - 135;
   if(key_cuu == 1 && key_cud == 0 && key_cul == 0 && key_cur == 0)	tempV.x = camera.pan;
	if(key_cud == 1 && key_cuu == 0 && key_cul == 0 && key_cur == 0)	tempV.x = camera.pan + 180;
	if(key_cul == 1 && key_cud == 0 && key_cuu == 0 && key_cur == 0)	tempV.x = camera.pan + 90;
	if(key_cur == 1 && key_cud == 0 && key_cur == 0 && key_cuu == 0)	tempV.x = camera.pan - 90;
	if(key_cuu == 1 && key_cul == 1 && key_cud == 0 && key_cud == 0)	tempV.x = camera.pan + 45;
	if(key_cuu == 1 && key_cur == 1 && key_cul == 0 && key_cud == 0)	tempV.x = camera.pan - 45;
	if(key_cud == 1 && key_cul == 1 && key_cur == 0 && key_cuu == 0)	tempV.x = camera.pan + 135;
	if(key_cud == 1 && key_cur == 1 && key_cul == 0 && key_cuu == 0)	tempV.x = camera.pan - 135;	
	if(tempV.x != -1000) 
	{
		my.moving = 1;
		if(key_shift == 1)	tempV.y = 10 * time_step;  
		else						tempV.y = 15 * time_step; 
	}
	//
	if(my.movement_mode==0)
	{
		my.move_x = fcos(tempV.x, tempV.y);
		my.move_y = fsin(tempV.x, tempV.y);
	}
	else if((my.movement_mode==1)||(my.movement_mode==2))
	{
		tempV.y = fsin((my.animate * 1.2) + 45,15 * time_step);
		my.move_x = fcos(my.pan, tempV.y);
		my.move_y = fsin(my.pan, tempV.y);
		tempV.y = 0;
		//NextLine: if we need to rotate whilst attacking (the player is pressing keys to rotate)
		if(tempV.x != -1000) 	tempV.y = 1;
	}
	//
	c_move(my, nullvector, my.move_x, USE_BOX | IGNORE_PASSABLE | GLIDE);
	result = -my.z_offset + c_trace(vector(my.x,my.y,my.z - my.z_offset), vector(my.x,my.y,my.z - 4000), IGNORE_ME | IGNORE_PASSABLE | USE_BOX);
	result = clamp(result, -150, 150);
	if(result < 0) 	{	my.z -= result;	my.velocity_z = 0;	}
	//
	if(target_enemy == NULL) 
	{	if(tempV.y > 0)	rotate_entity(tempV.x, 30); 	}
	else
	{
		vec_diff(tempV2.x, target_enemy.x, my.x);
		vec_to_angle(tempA2.pan, tempV2.x);
		rotate_entity(tempA2.pan,30);
	}
	//
	if(my.movement_mode == 0) 
	{
		my.gravity = 6;
		if(my.move_x != 0 || my.move_y != 0) 
		{	//ifwe are moving
			if(my.animblend == stand) 
			{	//ifour current animation is stand
				if(key_shift == 1)	my.blendframe = walk;
				else						my.blendframe = run;
			}
			if(my.animblend == run && key_shift == 1)		my.blendframe = walk;
			if(my.animblend == walk && key_shift == 0)	my.blendframe = run;
		} 
		else
		{
			if(my.animblend > stand && my.animblend != jump && my.animblend != fall) 
			{	//if we arn't moving and our current animation is walk or run, blend and cycle the stand animation
				my.blendframe = stand;
			}
		}
		if(mouse_left == 0 && mouse_left_press == 1)		mouse_left_press = 0;
		if(mouse_left == 1 && mouse_left_press == 0 && my.animblend >= stand) 
		{
			mouse_left_press = 1;
			my.blendframe = attack_a;
			if(my.jumping_mode == 1) 	airborne_attack = 1;
			else								airborne_attack = 0;
			my.movement_mode = 1;
			combo_continue = 0;
		}
		if(mouse_right == 0 && mouse_right_press == 1)	mouse_right_press = 0;
		if(mouse_right == 1 && mouse_right_press == 0) 
		{
			if(player_lock_on == 0) 
			{
				c_scan(player.x, player.pan, vector(360,180,250), SCAN_ENTS | SCAN_LIMIT | IGNORE_ME);
				if(you != NULL) 
				{
					if(you.entity_type == 2) 
					{	//make sure you've scanned an enemy
						player_lock_on = 1;
						target_enemy = you;
					}
				}
			} 
			else
			{
				player_lock_on = 0;
				target_enemy = NULL;
			}
			mouse_right_press = 1;
		}
	}
	//
	if(my.movement_mode == 1) 
	{
		if(my.jumping_mode != 10)										my.jumping_mode = 0;
		else if(my.animate >= 60 && my.animblend >= stand)		my.jumping_mode = 0;
		//
		if(mouse_left == 0 && mouse_left_press == 1)
			mouse_left_press = 0;
		if(mouse_left == 1 && mouse_left_press == 0 && my.animate >= 30 && combo_continue == 0) 
		{	mouse_left_press = 1; combo_continue = 1; }
	}
	//
	if(my.movement_mode == 2) 
	{
		my.jumping_mode = 0;
		if(mouse_left == 0 && mouse_left_press == 1)
			mouse_left_press = 0; 
		if(mouse_left == 1 && mouse_left_press == 0 && my.animate >= 30 && combo_continue == 0) 
		{	mouse_left_press = 1; combo_continue = 1; }
	}
}

function handle_gravity() 
{
	result = -my.z_offset + c_trace(vector(my.x,my.y,my.z - my.z_offset), vector(my.x,my.y,my.z - 4000), IGNORE_ME | IGNORE_PASSABLE | USE_BOX );
	result = clamp(result, -150, 150);
	if(result < 3) 
	{
		if(my.jumping_mode == 0) 
		{
			my.force_z = -1 * result;
			if(key_space == 0 && space_press == 1) 			space_press = 0;
			if(key_space == 1 && space_press == 0 && my.movement_mode == 0 && my.animblend >= stand && my.animblend != jump && my.animblend != fall) 
			{
				space_press = 1;
				my.jumping_mode = 1;
				my.force_z = 25;
				my.blendframe = jump;
				my.animate2 = 0;
				my.animblend = blend;
			}
	   }
      if(my.jumping_mode == 2 || my.jumping_mode == 3)   my.jumping_mode = 0;
   } 
   else
   {

   ////////////////////////////////// vvvvv spliced this code
   if(my.jumping_mode == 1)
   {
      if(key_space == 0 && space_press == 1)         space_press = 0;
      if(key_space == 1 && space_press == 0 && abs(my.velocity_z) <= 10)  //section of jump where double jump is available play with 10
      {
         space_press = 1;
         my.jumping_mode = 2;
         my.force_z = 25;
         my.velocity_z = 0;
         my.blendframe = jump;
         my.animate2 = 0;
         my.animblend = blend;
      }
   }
   ////////////////////////////////// ^^^^^ spliced this code

   if(my.jumping_mode == 2) 
   {
      if(result > 120)
         {
				my.animate = 60;
				my.jumping_mode = 3;
			} 
			else
				my.jumping_mode = 0;
		}
		if(my.jumping_mode == 3 && result <= 120)		my.jumping_mode = 0;
		if(my.jumping_mode == 0 && my.movement_mode == 0) 
		{
			if(result > 120 && my.animblend >= stand && my.animblend != jump && my.animblend != fall) 
			{
				my.jumping_mode = 3;
				my.blendframe = fall;
				my.animate2 = 0;
				my.animblend = blend;
			}
		}
		my.force_z -= my.gravity * time_step;
		my.force_z =  maxv(-30, my.force_z);
		if(my.movement_mode == 2)		my.force_z = 0;
	}
 	my.velocity_z += (time_step * my.force_z) - (minv(time_step*0.7, 1) * my.velocity_z);
	my.move_z = my.velocity_z * time_step;
}

//////////////////////////////
//Stable/rigid camera collision
//////////////////////////////
function handle_camera() 
{
	camera_distance -= mickey.z * time_step;
	camera_distance = clamp(camera_distance, 50, 500);
	camera.pan -=  mouse_force.x * 12 * time_step;
	camera.tilt += mouse_force.y * 8 * time_step;
	camera.tilt = clamp(camera.tilt, -30, 10);
	temp = fcos(camera.tilt, -camera_distance);
	vec_set(camera.x, vector(my.x + fcos(camera.pan, temp),my.y + fsin(camera.pan, temp),my.z + 20 + fsin(camera.tilt, -camera_distance)));

	vec_diff(tempV.x, camera.x, my.x); //find the vector from the player to the camera
	vec_normalize(tempV.x, 16); //get the magnitude of it's vector to 16 quants and store it in temp
	vec_add(tempV.x, camera.x); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.

	result = c_trace(my.x, tempV.x, IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS); //trace from the player to 16 quants behind the camera.
	if(result > 0) 
	{
		vec_diff(tempV.x, my.x, target.x); //find the vector from the point the trace hit to the player
		vec_normalize(tempV.x, 16); //get the magnitude of this vector to 16 quants and store in temp
		vec_set(camera.x, target.x); //place the camera at the trace hit point
		vec_add(camera.x, tempV.x); //move the camera away from the wall by the vector temp, 16 quants towards the player
	}//start the alpha fade on the character for zooming in and out ***********************
	if(fade_toggle == 1)	{
		
				vec_diff(tempV.x, my.x, camera.x);
				if(fade_start > 0) {	
				 
		  			tempV.x = vec_length(tempV.x); // distance from camera to target
		  			if(tempV.x < fade_start) {
		  				
				   	   set(my, TRANSLUCENT); // fade to zero depending distance to fade end
			   		   reset(my, SHADOW);
	   				//NOTE: use 1st max to avoid negative alpha
	   				//			use 2nd max to avoid divide by zero
	   			   	my.alpha = 100 * maxv(0, ((tempV.x - fade_end) / maxv(1,(fade_start - fade_end))));
	  				}
	  				else {
	  					
			    		reset(my, TRANSLUCENT);
			    		set(my, SHADOW);
			  		}
 		  		}//endif fade_start
   		}//endif fade_toggle == 1
}//endfunction


//////////////////////////////
//Smooth camera collision
//////////////////////////////
/*function handle_camera() 
{
	camera_pan -= mouse_force.x * 12 * time_step;
	camera_tilt += mouse_force.y * 8 * time_step;
	camera_tilt = clamp(camera_tilt, -30, 10);

	camera.pan = camera_pan;
	temp = fcos(camera_tilt,-camera_distance);
	vec_set(camera_move_to.x, vector(my.x + fcos(camera.pan, temp), my.y + fsin(camera.pan, temp), my.z + 20 + fsin(camera_tilt, -camera_distance)));

	temp = minv(1,0.5 * time_step); //changing 0.5 will change how fast the camera moves, at 1 places us at target, this value is what allows the smooth movement
	camera.x += temp*(camera_move_to.x - camera.x);
	camera.y += temp*(camera_move_to.y - camera.y);
	camera.z += temp*(camera_move_to.z - camera.z);

	vec_diff(tempV.x, camera.x, my.x);
	vec_normalize(tempV.x, 16);
	vec_add(tempV.x, camera.x);

	if(c_trace(my.x, tempV.x, IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS) > 0) 
	{
		vec_diff(tempV.x, my.x, target.x);
		vec_normalize(tempV.x, 16);
		vec_set(camera.x, target.x);
		vec_add(camera.x, tempV.x);
	}

	vec_diff(tempV.x, my.x, camera.x);
	vec_to_angle(camera.pan, tempV.x);
}*/

function rotate_entity(var rotate_angle, var rotate_speed) 
{
	if(my.pan == rotate_angle)		return;
	result = ang(rotate_angle - my.pan);
	if(result > 0)	my.pan += rotate_speed * time_step;
	if(result < 0)	my.pan -= rotate_speed * time_step; 
	if(ang(rotate_angle - my.pan) < 0 && result > 0)	my.pan = rotate_angle; 
	if(ang(rotate_angle - my.pan) > 0 && result < 0)	my.pan = rotate_angle; 
}

function handle_hand_collision()
{
	vec_for_vertex(tempV.x, player, 1146); 	//thumb tip
	vec_for_vertex(tempV2.x, player, 1144); 	//thumb joint
	result = c_trace(tempV.x, tempV2.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX);
	if(you != NULL) 
	{
		if(you.entity_type == 2 && you.hit_by_player == 0) 
		{
			if(airborne_attack == 1 && my.animblend == attack_a)		my.movement_mode = 2;
			you.hit_by_player = 2;
			if(target_enemy == NULL)				{ target_enemy = you; player_lock_on = 1; }
		}
	}
	wait(1);//added this because I was crashing to desktop with repeated mouseclicks **************************
}

function handle_sword_collision()
{
	you = NULL;
	if(player_weapon==NULL)		{	handle_hand_collision();	return;	}
	vec_for_vertex(tempV.x, player_weapon, 274); //sword base
	vec_for_vertex(tempV2.x, player_weapon, 54); //sword tip
	result = c_trace(tempV.x, tempV2.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX);
	if(you != NULL) 
	{
		if(you.entity_type == 2 && you.hit_by_player == 0) 
		{
			if(airborne_attack == 1 && my.animblend == attack_a)		my.movement_mode = 2;
			you.hit_by_player = 1;
			if(target_enemy == NULL)				{ target_enemy = you; player_lock_on = 1; }
		}
	}
	wait(1);//added this wait because I was crashing to desktop with repeated mouse clicks*********************
}
 





Attached File
player.rar  (87 downloads)
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 06/17/09 09:18

Thanks!! Added to wiki. smile
Posted By: Cowabanga

Re: [REQ] converting a code to lite-c - 06/17/09 09:38

NOTE: To anyone who uses EvilSOB's solution to move with UP-LEFT-RIGHT-DOWN, it was wrong, because the player can't move right.

So here's the correct one:
Code:
	if(key_w == 1 && key_s == 0 && key_a == 0 && key_d == 0)	tempV.x = camera.pan;
	if(key_s == 1 && key_w == 0 && key_a == 0 && key_d == 0)	tempV.x = camera.pan + 180;
	if(key_a == 1 && key_s == 0 && key_w == 0 && key_d == 0)	tempV.x = camera.pan + 90;
	if(key_d == 1 && key_s == 0 && key_a == 0 && key_w == 0)	tempV.x = camera.pan - 90;
	if(key_w == 1 && key_a == 1 && key_d == 0 && key_s == 0)	tempV.x = camera.pan + 45;
	if(key_w == 1 && key_d == 1 && key_a == 0 && key_s == 0)	tempV.x = camera.pan - 45;
	if(key_s == 1 && key_a == 1 && key_d == 0 && key_w == 0)	tempV.x = camera.pan + 135;
	if(key_s == 1 && key_d == 1 && key_a == 0 && key_w == 0)	tempV.x = camera.pan - 135;
	
	if(key_cuu == 1 && key_cud == 0 && key_cul == 0 && key_cur == 0)	tempV.x = camera.pan;
	if(key_cud == 1 && key_cuu == 0 && key_cul == 0 && key_cur == 0)	tempV.x = camera.pan + 180;
	if(key_cul == 1 && key_cud == 0 && key_cuu == 0 && key_cur == 0)	tempV.x = camera.pan + 90;
	if(key_cur == 1 && key_cud == 0 && key_cul == 0 && key_cuu == 0)	tempV.x = camera.pan - 90;
	if(key_cuu == 1 && key_cul == 1 && key_cur == 0 && key_cud == 0)	tempV.x = camera.pan + 45;
	if(key_cuu == 1 && key_cur == 1 && key_cul == 0 && key_cud == 0)	tempV.x = camera.pan - 45;
	if(key_cud == 1 && key_cul == 1 && key_cur == 0 && key_cuu == 0)	tempV.x = camera.pan + 135;
	if(key_cud == 1 && key_cur == 1 && key_cul == 0 && key_cuu == 0)	tempV.x = camera.pan - 135;

Posted By: EvilSOB

Re: [REQ] converting a code to lite-c - 06/17/09 10:03

Sorry all. Typo's will be the death of me.
I need a new keyboard....
© 2024 lite-C Forums