Simple enemy...

Posted By: Morph

Simple enemy... - 01/31/08 14:38

A simple enemy code?? put the code only. Thanks
Posted By: tompo

Re: Simple enemy... - 01/31/08 15:05

Enemy = AI
Doesn't exist something like simple code.
Check templates about enemy and AI, search forum.
Posted By: Morph

Re: Simple enemy... - 01/31/08 19:56

Hi, good hehe. I found a code of AUM, is a enemy code but of a sword combat game...look, i copy and paste the part of the enemy action in a new script and save the script call "Enemy.wdl", and i put "include <enemy.wdl>;" in my main script, compile and run and error: "Empty pointer in enemy_fight: if (vec_dist (my.x, player.x) < 200 && player.healthpoints > 0)", look, this is the code:

***************************************************************************

var player_distance; // moves the player
var enemy_distance; // moves the enemy

define sword_base = skill12; // using skill12, 13, 14 to store the sword_base coords
define sword_tip = skill15; // using skill15, 16, 17 to store the sword_tip coords
define healthpoints = skill18; // just another name for skill18

entity* enemy;

action enemy_fight // attached to the enemy
{
enemy = me; // I'm the enemy
enemy.healthpoints = 100; // and I have 100 healthpoints
while (my.healthpoints > 0) // as long as I'm alive
{
if (vec_dist (my.x, player.x) < 200 && player.healthpoints > 0) // the player approaches the enemy
{
vec_set(temp, player.x);
vec_sub(temp, my.x);
vec_to_angle(my.pan, temp);
my.tilt = 0; // I'm a maniac
enemy_distance.x = 5 * time;
enemy_distance.y = 0;
enemy_distance.z = 0;
ent_move(enemy_distance, nullvector);
ent_cycle("walk", my.skill19); // play walk frames animation
my.skill19 += 5 * time; // "walk" animation speed
if (my.skill19 > 100) {my.skill19 = 0;} // loop animation
if (vec_dist (my.x, player.x) < 50) // if the player comes closer than 50 quants attack him
{
my.skill20 = 0; // reset "attack" frames
while (my.skill20 < 100)
{
ent_vertex(my.sword_tip, 291); // sword tip vertex coords - get the value in Med
ent_vertex(my.sword_base, 306); // sword base vertex coords - get the value in Med
trace_mode = ignore_me + ignore_passable;
trace (my.sword_base, my.sword_tip); // trace between these sword positions
if (result != 0) // hit something, could be the player or another enemy
{

if (you != null) {you.healthpoints -= 4 * time;}

}
ent_cycle("attack", my.skill20); // play attack frames animation
my.skill20 += 5 * time; // "attack" animation speed
wait (1);
}
waitt (6); // slows down the enemy and reduces the number of traces per second
}
}
else // the player is farther than 200 quants away
{
ent_cycle("stand", my.skill21); // play stand frames animation
my.skill21 += 2 * time; // "stand" animation speed
if (my.skill21 > 100) {my.skill21 = 0;} // loop animation
}
wait (1);
}
while (my.skill22 < 80) // the enemy is dead
{
ent_cycle("death", my.skill22); // play death frames animation
my.skill22 += 1 * time; // "death" animation speed
wait (1);
}
my.passable = on; // the corpse can't be hit by the sword from now on
}

**********************************************************************

help me in this.
Posted By: Xarthor

Re: Simple enemy... - 01/31/08 20:20

action enemy_fight // attached to the enemy
{
enemy = me; // I'm the enemy
enemy.healthpoints = 100; // and I have 100 healthpoints
while(!player) { wait(1); } // wait until the player exists
// rest of the code ...
Posted By: Morph

Re: Simple enemy... - 01/31/08 21:28

Hello Xarthor, thanks for you answer...the problem is solved but i have other problem, ultimate problem, compile and run the project and put me an error:

*******************************************************************

< while(my.skill22<80) {>
enemy.wdl 63:0 (): Parameter unknown while bad keyword in {}

< ent_cycle("death",my.skill22);>
enemy.wdl 64:0 (): Parameter unknown ent_cycle bad keyword in {}

< my.skill22 +=1*time;>
enemy.wdl 65:0 (): Parameter unknown my.skill22 bad keyword in {}

< wait(1);>
enemy.wdl 66:0 (): Parameter unknown wait bad keyword in {}

< my.passable = on;>
enemy.wdl 68:0 (): Parameter unknown my.passable

Script error
Engine shutdown
Startup failure - any key to abort

*************************************************************************

Good, what is the problem????????
Posted By: Damocles

Re: Simple enemy... - 01/31/08 22:04

you forgot to place an " } " or an " ; " above the mentioned "while" statement
Posted By: Morph

Re: Simple enemy... - 01/31/08 22:19

Where?????
Posted By: Morph

Re: Simple enemy... - 02/01/08 15:17

Pleaseeeeeeeeeeeeee, where??
Posted By: Damocles

Re: Simple enemy... - 02/01/08 16:28

You need to post the full code for that to help you.
Posted By: kasimir

Re: Simple enemy... - 02/01/08 16:56

I think you forgot this "}"

Code:

ent_cycle("stand", my.skill21); // play stand frames animation
my.skill21 += 2 * time; // "stand" animation speed
if (my.skill21 > 100) {my.skill21 = 0;} // loop animation
}
wait (1);
} <------------------------------------------------------------------------------------------
while (my.skill22 < 80) // the enemy is dead
{
ent_cycle("death", my.skill22); // play death frames animation
my.skill22 += 1 * time; // "death" animation speed
wait (1);
}


Posted By: Xarthor

Re: Simple enemy... - 02/01/08 17:24

I cannot spot a mistake right now, but here is the whole code looking a bit more nicely:
Code:


action enemy_fight // attached to the enemy
{
enemy = me; // I'm the enemy
enemy.healthpoints = 100; // and I have 100 healthpoints

while (my.healthpoints > 0) // as long as I'm alive
{
if (vec_dist (my.x, player.x) < 200 && player.healthpoints > 0) // the player approaches the enemy
{
vec_set(temp, player.x);
vec_sub(temp, my.x);
vec_to_angle(my.pan, temp);
my.tilt = 0; // I'm a maniac
enemy_distance.x = 5 * time;
enemy_distance.y = 0;
enemy_distance.z = 0;
ent_move(enemy_distance, nullvector);
ent_cycle("walk", my.skill19); // play walk frames animation
my.skill19 += 5 * time; // "walk" animation speed

if (my.skill19 > 100) {my.skill19 = 0;} // loop animation
if (vec_dist (my.x, player.x) < 50) // if the player comes closer than 50 quants attack him
{
my.skill20 = 0; // reset "attack" frames

while (my.skill20 < 100)
{
ent_vertex(my.sword_tip, 291); // sword tip vertex coords - get the value in Med
ent_vertex(my.sword_base, 306); // sword base vertex coords - get the value in Med
trace_mode = ignore_me + ignore_passable;
trace (my.sword_base, my.sword_tip); // trace between these sword positions

if (result != 0) // hit something, could be the player or another enemy
{
if (you != null) {you.healthpoints -= 4 * time;}
}

ent_cycle("attack", my.skill20); // play attack frames animation
my.skill20 += 5 * time; // "attack" animation speed

wait (1);
}

waitt (6); // slows down the enemy and reduces the number of traces per second
}
}
else // the player is farther than 200 quants away
{
ent_cycle("stand", my.skill21); // play stand frames animation
my.skill21 += 2 * time; // "stand" animation speed
if (my.skill21 > 100) {my.skill21 = 0;} // loop animation
}

wait (1);
}

while (my.skill22 < 80) // the enemy is dead
{
ent_cycle("death", my.skill22); // play death frames animation
my.skill22 += 1 * time; // "death" animation speed
wait (1);
}

my.passable = on; // the corpse can't be hit by the sword from now on
}


Posted By: Morph

Re: Simple enemy... - 02/01/08 18:43

hi, i clear the bracket and modified the code in some cases, is equal but more nicely...and i have other error lol, (sorry for the much questions but i am begginer), look the update code:

(the fields in red colour are the updates)

Code:
  
var player_distance; // moves the player
var enemy_distance; // moves the enemy
var distance;

define sword_base = skill12; // using skill12, 13, 14 to store the sword_base coords
define sword_tip = skill15; // using skill15, 16, 17 to store the sword_tip coords
define healthpoints = skill18; // just another name for skill18

entity* enemy;

action enemy_fight // attached to the enemy
{
distance = vec_dist (my.x, player.x);
enemy = me; // I'm the enemy

enemy.healthpoints = 100; // and I have 100 healthpoints
while(!player) { wait(1); } // wait until the player exists
{
if (distance < 200) // the player approaches the enemy
{
vec_set(temp, player.x);
vec_sub(temp, my.x);
vec_to_angle(my.pan, temp);
my.tilt = 0; // I'm a maniac :)
enemy_distance.x = 5 * time;
enemy_distance.y = 0;
enemy_distance.z = 0;
ent_move(enemy_distance, nullvector);
ent_cycle("walk", my.skill19); // play walk frames animation
my.skill19 += 5 * time; // "walk" animation speed
if (my.skill19 > 100) {my.skill19 = 0;} // loop animation
if (vec_dist (my.x, player.x) < 50) // if the player comes closer than 50 quants attack him
{
my.skill20 = 0; // reset "attack" frames
while (my.skill20 < 100)
{
ent_vertex(my.sword_tip, 291); // sword tip vertex coords - get the value in Med
ent_vertex(my.sword_base, 306); // sword base vertex coords - get the value in Med
trace_mode = ignore_me + ignore_passable;
trace (my.sword_base, my.sword_tip); // trace between these sword positions
if (result != 0) // hit something, could be the player or another enemy
{

if (you != null) {you.healthpoints -= 4 * time;}

}
ent_cycle("attack", my.skill20); // play attack frames animation
my.skill20 += 5 * time; // "attack" animation speed
wait (1);
}
waitt (6); // slows down the enemy and reduces the number of traces per second
}
}
else // the player is farther than 200 quants away
{
ent_cycle("stand", my.skill21); // play stand frames animation
my.skill21 += 2 * time; // "stand" animation speed
if (my.skill21 > 100) {my.skill21 = 0;} // loop animation
}
wait (1);

while (my.skill22 < 80) // the enemy is dead
{
ent_cycle("death", my.skill22); // play death frames animation
my.skill22 += 1 * time; // "death" animation speed
wait (1);
}

my.passable = on; // the corpse can't be hit by the sword from now on
}





Good, put me error in ejecution: "Empty pointer in enemy_fight: distance=vec_dist(my.x,player.x)"

Help me please. bye
Posted By: Damocles

Re: Simple enemy... - 02/01/08 20:21

the player is not initialised yet

make a wait at the beginning:

action enemy_fight // attached to the enemy
{
wait(1);



or:

action enemy_fight // attached to the enemy
{
while(player==null){wait(1);}
Posted By: Morph

Re: Simple enemy... - 02/01/08 21:19

Hi Democles, look, the error is solved, now compile and run and the error not visible but the enemy... not move . What is the problem now? the enemy would that attack the player at the 50 quants...but the enemy NOT MOVE. Help me again please, is important.
Posted By: kasimir

Re: Simple enemy... - 02/01/08 21:31

did you set the pointer to your player???

action player_move
{
player = me;
...
Posted By: Morph

Re: Simple enemy... - 02/01/08 23:58

Thanks you all!!!!!!!!!! Problem solved! thank you kasimir!!
Posted By: Blink

Re: Simple enemy... - 02/03/08 00:24

@Xarthor:
just a question, i was playing around with your code a bit, and changed a few things to see if it would attack the template plbiped01_entity. the code ran with no errors, but when the level started, i got an error saying "invalid arguements in enemy_fight: ent_animate(@2, my.skill21)", then a crash afterwards saying the same thing. what did i miss?
Posted By: Blink

Re: Simple enemy... - 02/03/08 00:46

here's the modification:
Code:
var enemy_distance; // moves the enemy
var distance;
define sword_base = skill12; // using skill12, 13, 14 to store the sword_base coords
define sword_tip = skill15; // using skill15, 16, 17 to store the sword_tip coords
define healthpoints = skill18; // just another name for skill18
entity* enemy;
action enemy_fight // attached to the enemy
{
while(plBiped01_entity==null){wait(1);}
distance = vec_dist (my.x, plBiped01_entity.x);
enemy = me; // I'm the enemy
enemy.healthpoints = 100; // and I have 100 healthpoints
while(!plBiped01_entity) { wait(1); } // wait until the player exists
{
if (distance < 200) // the player approaches the enemy
{
vec_set(temp, plBiped01_entity.x);
vec_sub(temp, my.x);
vec_to_angle(my.pan, temp);
my.tilt = 0; // I'm a maniac :)
enemy_distance.x = 5 * time_step;
enemy_distance.y = 0;
enemy_distance.z = 0;
ent_move(enemy_distance, nullvector);
ent_animate("walk", my.skill19); // play walk frames animation
my.skill19 += 5 * time_step; // "walk" animation speed
if (my.skill19 > 100) {my.skill19 = 0;} // loop animation
if (vec_dist (my.x, plBiped01_entity.x) < 50) // if the player comes closer than 50 quants attack him
{
my.skill20 = 0; // reset "attack" frames
while (my.skill20 < 100)
{
ent_vertex(my.sword_tip, 291); // sword tip vertex coords - get the value in Med
ent_vertex(my.sword_base, 306); // sword base vertex coords - get the value in Med
trace_mode = ignore_me + ignore_passable;
trace (my.sword_base, my.sword_tip); // trace between these sword positions
if (result != 0) // hit something, could be the player or another enemy
{
if (you != null) {you.healthpoints -= 4 * time_step;
} }
ent_animate("attack", my.skill20); // play attack frames animation
my.skill20 += 5 * time_step; // "attack" animation speed
wait (1);
}
wait (6); // slows down the enemy and reduces the number of traces per second
}
}
else // the player is farther than 200 quants away
{
ent_animate("stand", my.skill21); // play stand frames animation
my.skill21 += 2 * time_step; // "stand" animation speed
if (my.skill21 > 100) {my.skill21 = 0;} // loop animation
}
wait (1);

while (my.skill22 < 80) // the enemy is dead
{
ent_animate("death", my.skill22); // play death frames animation
my.skill22 += 1 * time_step; // "death" animation speed
wait (1);
}
my.passable = on; // the corpse can't be hit by the sword from now on
}


Posted By: Xarthor

Re: Simple enemy... - 02/03/08 09:42

You have to be carefull with "ent_animate". The ent_animate instruction expects an entity pointer as first argument:
Quote:


ent_animate(ENTITY* entity,STRING* scene,var percent,var mode)





Thus you need to change all your ent_animate instructions:
Simply add a "my," in the instruction.
Example:
ent_animate(me,"stand",my.skill21,ANM_CYCLE);
Posted By: Blink

Re: Simple enemy... - 02/03/08 19:54

thanks a lot Xarthor, but now i have another issue. the level runs with no errors, but the enemy is dead when i approach it. what should i do?
Posted By: Xarthor

Re: Simple enemy... - 02/03/08 22:10

There is a mistake in the code.
I'm not sure why the compiler does not report an error:
Code:

action enemy_fight // attached to the enemy
{
while(plBiped01_entity==null){wait(1);}
distance = vec_dist (my.x, plBiped01_entity.x);
enemy = me; // I'm the enemy
enemy.healthpoints = 100; // and I have 100 healthpoints
while(!plBiped01_entity) { wait(1); } // wait until the player exists
{


Can you see it?
Do you see it now:
Code:

while(!plBiped01_entity) { wait(1); } // wait until the player exists
{


It should be:
Code:

while(!plBiped01_entity) { wait(1); } // wait until the player exists
while(my.healthpoints > 0)
{



Furthermore you may replace these lines:
Code:

enemy = me; // I'm the enemy
enemy.healthpoints = 100; // and I have 100 healthpoints


With this:
Code:

my.healthpoints = 100;


The enemy = my; stuff makes only sense if you have on enemy at a time.
But its useless if you use many enemies.
Posted By: Blink

Re: Simple enemy... - 02/03/08 23:32

no errors or arguements anymore, and the enemy is alive, but he doesnt respond at all when i run into him, matter of fact, he is passable. also, he doesnt die, i shot him over a hundred times, but no affect. here is the code with the corrections.

Code:
var enemy_distance; // moves the enemy
var distance;
define sword_base = skill12; // using skill12, 13, 14 to store the sword_base coords
define sword_tip = skill15; // using skill15, 16, 17 to store the sword_tip coords
define healthpoints = skill18; // just another name for skill18
entity* enemy;
action enemy_fight // attached to the enemy
{
while(plBiped01_entity==null){wait(1);}
distance = vec_dist (my.x, plBiped01_entity.x);
my.healthpoints = 100;
while(!plBiped01_entity) { wait(1); } // wait until the player exists
while(my.healthpoints > 0)
{
if (distance < 200) // the player approaches the enemy
{
vec_set(temp, plBiped01_entity.x);
vec_sub(temp, my.x);
vec_to_angle(my.pan, temp);
my.tilt = 0; // I'm a maniac :)
enemy_distance.x = 5 * time_step;
enemy_distance.y = 0;
enemy_distance.z = 0;
ent_move(enemy_distance, nullvector);
ent_animate(me,"walk", my.skill19, ANM_CYCLE); // play walk frames animation
my.skill19 += 5 * time_step; // "walk" animation speed
if (my.skill19 > 100) {my.skill19 = 0;} // loop animation
if (vec_dist (my.x, plBiped01_entity.x) < 50) // if the player comes closer than 50 quants attack him
{
my.skill20 = 0; // reset "attack" frames
while (my.skill20 < 100)
{
ent_vertex(my.sword_tip, 291); // sword tip vertex coords - get the value in Med
ent_vertex(my.sword_base, 306); // sword base vertex coords - get the value in Med
trace_mode = ignore_me + ignore_passable;
trace (my.sword_base, my.sword_tip); // trace between these sword positions
if (result != 0) // hit something, could be the player or another enemy
{
if (you != null) {you.healthpoints -= 4 * time_step;
} }
ent_animate(me,"attack", my.skill20, ANM_CYCLE); // play attack frames animation
my.skill20 += 5 * time_step; // "attack" animation speed
wait (1);
}
wait (6); // slows down the enemy and reduces the number of traces per second
}
}
else // the player is farther than 200 quants away
{
ent_animate(me,"stand", my.skill21, ANM_CYCLE); // play stand frames animation
my.skill21 += 2 * time_step; // "stand" animation speed
if (my.skill21 > 100) {my.skill21 = 0;} // loop animation
}
wait (1);

while (my.skill22 < 80) // the enemy is dead
{
ent_animate(me,"death", my.skill22, ANM_CYCLE); // play death frames animation
my.skill22 += 1 * time_step; // "death" animation speed
wait (1);
}
my.passable = on; // the corpse can't be hit by the sword from now on
}
}


Posted By: Nidhogg

Re: Simple enemy... - 02/04/08 00:15

Hi, Blink
I think maybe where you got my.passable = on;
should be in the while loop.

Code:

while (my.skill22 < 80) // the enemy is dead
{
ent_animate(me,"death", my.skill22, ANM_CYCLE); // play death frames animation
my.skill22 += 1 * time_step; // "death" animation speed
my.passable = on; // the corpse can't be hit by the sword from now on
wait (1);
}


Posted By: Blink

Re: Simple enemy... - 02/04/08 03:08

still no change, thanks anyway.
Posted By: Xarthor

Re: Simple enemy... - 02/04/08 08:05

There was some weird bracket stuff going on.
I rewrote and cleaned up the code a bit, now you should also be able to use it on many enemies:
Code:


define sword_base = skill12; // using skill12, 13, 14 to store the sword_base coords
define sword_tip = skill15; // using skill15, 16, 17 to store the sword_tip coords
define healthpoints = skill18; // just another name for skill18


action enemy_fight
{
var move_dist[3];
var distance;

my.healthpoints = 100;

c_setminmax(my);
wait(1);

while(plBiped01_entity == null) { wait(1); }

while(my.healthpoints > 0)
{
distance = vec_dist(my.x, plBiped01_entity.x);

if(distance < 200) // the player approaches the enemy
{
vec_set(temp, plBiped01_entity.x);
vec_sub(temp, my.x);
vec_to_angle(my.pan, temp);
my.tilt = 0;

move_dist.x = 5 * time_step;
move_dist.y = 0;
move_dist.z = 0;
c_move(my,move_dist,nullvector,IGNORE_PASSABLE);

ent_animate(my, "walk", my.skill19, ANM_CYCLE); // play walk frames animation
my.skill19 = cycle(my.skill19+5*time_step,0,101); // "walk" animation speed + loop animation

if(distance < 50) // if the player comes closer than 50 quants attack him
{
my.skill20 = 0; // reset "attack" frames

while(my.skill20 < 100)
{
vec_for_vertex(my.sword_base,my,306);
vec_for_vertex(my.sword_tip,my,291);

c_trace(my.sword_base,my.sword_tip,IGNORE_ME|IGNORE_PASSABLE);

if(you)
{
you.healthpoints -= 4 * time_step;
}

ent_animate(my,"attack",my.skill20,ANM_CYCLE); // play attack frames animation
my.skill20 += 5 * time_step; // "attack" animation speed

wait(1);
}

wait(6);
}
}
else // the player is farther than 200 quants away
{
ent_animate(my,"stand",my.skill21,ANM_CYCLE); // play stand frames animation
my.skill21 = cycle(my.skill21+2*time_step,0,101); // "stand" animation speed + loop animation
}

wait(1);
}

// enemy was killed:
while(my.skill22 < 80)
{
ent_animate(me,"death", my.skill22, ANM_CYCLE); // play death frames animation
my.skill22 += 1 * time_step; // "death" animation speed

wait(1);
}

my.passable = on; // the corpse can't be hit by the sword from now on
}



But be aware: This code does not include that the enemy takes damage (reacts to a certain event), thus your weapon code needs to handle this.
I'm not sure how the templates work though.
Posted By: Blink

Re: Simple enemy... - 02/04/08 22:17

well, it works sort of...i couldnt kill him, but he attacks, sort of, and he walks and stands fine. am i forgetting to add something to the code? maybe something i have to add to the plbiped code so the plbiped weapons will affect the enemy model and vice versa? what do you think Xarthor?
Posted By: Xarthor

Re: Simple enemy... - 02/05/08 09:11

I think you need to add something to the enemy code.
However this is based up on the weapon code you use.
If your weapons use the "ACTIVATE_SHOOT" flag you simply need an event function for the enemy which reduces his health points when his event is event_shoot:
Code:

function enemy_events()
{
if(event_type == event_shoot)
{
my.healthpoints -= 10;
}
}

action enemy_fight
{
var move_dist[3];
var distance;

my.enable_shoot = on;
my.event = enemy_events;


my.healthpoints = 100;
//rest of the code


Posted By: Blink

Re: Simple enemy... - 02/05/08 12:23

works perfectly! thanks for your help. after i tweak it a little, i will post it for the community. you are a genius!
© 2024 lite-C Forums