Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,541 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
AI search food help #278667
07/15/09 02:17
07/15/09 02:17
Joined: May 2006
Posts: 30
awstar Offline OP
Newbie
awstar  Offline OP
Newbie

Joined: May 2006
Posts: 30
I got the Robby the robot ai code and i'm trying to get it to scan for food, get health from it. The code i have works except after it picks up food it doesn't continue searching. Here's the code:

action robby_the_robot
{
creature = me;
creature.healthpoints = 100;
my.enable_entity = on;
my.enable_impact = on;
my.enable_block = on;
ent_create (healthbar_mdl, my.pos, display_health);
my.event = robby_event;
// my.ENABLE_SCAN = on;
//
// my.event = rotate_now;


ent_create(antenna_pcx, nullvector, check_front);

while(1)
{

standing_time = 3 + random(1); // stand for 3..10 seconds
while (standing_time > 0)
{
standing_time -= time / 16;
ent_cycle("stand", my.skill20); // play "stand" animation
my.skill20 += 2 * time;
my.skill20 %= 100; // loop
wait (1);
}
walking_time = 10 + random(10); // walk for 10..20 seconds
walk_speed.x = 3;
walk_speed.y = 0;
walk_speed.z = 0;
walk_speed *= time; // keep the same speed at different frame rates
wait (1);

while (walking_time > 0)
{

///////////////////////////////////////////
while (grub == null) //////<---------this code gets rid of empty pointer error, but freezes the AI after he picks up the food.
{wait (1);}
if (vec_dist (my.x, grub.pos) < 200) // the player approaches the food
{

// name_ent2();
vec_set(temp, grub.pos);
vec_sub(temp, my.pos);
vec_to_angle(my.pan, temp);
my.tilt = 0; // I'm a maniac smile
walk_speed.x = 10 * time;
walk_speed.y = 0;
walk_speed.z = 0;
ent_move(creature_distance, nullvector);
ent_cycle("walk", my.skill19); // play walk frames animation
my.skill19 += 5 * time; // "walk" animation speed
// ent_playsound (my, walk_snd, 50);

wait (1);

}

/////////////////////////////////////////////
if (content(front_coords) == content_solid)
{
my.skill40 = my.pan;
my.skill41 = 30 + random(90);
while (my.pan < my.skill40 + my.skill41) // rotate 30..120 degrees
{
my.pan += 3 * time;
wait (1);
}
}



else
{

walking_time -= time / 16;
ent_cycle("walk", my.skill20); // play "walk" animation
my.skill20 += 4 * time;
my.skill20 %= 100; // loop
move_mode = ignore_passable; // ignore passable entities
result = ent_move (walk_speed, nullvector);
if (result == 0) // got stuck!
{
walk_speed.x *= -1; // reversed movement
my.skill40 = my.pan;
my.skill41 = 30 + random(90);
while (my.pan < my.skill40 + my.skill41) // rotate 30..120 degrees
{
my.pan += 3 * time;
ent_cycle("walk", my.skill20); // play reversed "walk" animation
my.skill20 -= 4 * time;
my.skill20 %= 100; // loop
move_mode = ignore_passable; // ignore passable entities
ent_move (walk_speed, nullvector);
wait (1);
}
walk_speed.x *= -1; // restore walk_speed
}
}
wait (1);
}
wait (1);
}
}

Re: AI search food help [Re: awstar] #278687
07/15/09 07:47
07/15/09 07:47
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline
Expert
Rei_Ayanami  Offline
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Can you tell us "grub" is? Is it the Food Entity? If yes: Have you defined a pointer for it, like ENTITY* grub?

Re: AI search food help [Re: Rei_Ayanami] #278818
07/15/09 17:31
07/15/09 17:31
Joined: May 2006
Posts: 30
awstar Offline OP
Newbie
awstar  Offline OP
Newbie

Joined: May 2006
Posts: 30
food, if I did it correct,

Re: AI search food help [Re: awstar] #278826
07/15/09 19:02
07/15/09 19:02
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline
Expert
Rei_Ayanami  Offline
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Originally Posted By: awstar
food, if I did it correct,

What do you mean with if I did it coorect?

Re: AI search food help [Re: awstar] #278867
07/15/09 21:59
07/15/09 21:59
Joined: May 2006
Posts: 30
awstar Offline OP
Newbie
awstar  Offline OP
Newbie

Joined: May 2006
Posts: 30
associating *ENTITY correctly. Here's the whole code in wdl. Maybe someone has a better way of writing an AI that forages.

///////////////////////////////////////////////////////////////////////////////////////////////////////
// copy / overwrite the files inside this folder in your game folder (work if you are using the templates)
// don't forget to include robby.wdl in your main game file (office.wdl if you are using the templates)
// place a model in your level and attach it the robby_the_robot action
///////////////////////////////////////////////////////////////////////////////////////////////////////

var standing_time;
var walking_time;
var walk_speed;
var front_coords;
var creature_distance;
///////////////////////////////////////////////////////////////////////////////////////////////////////
entity* grub;
entity* creature;
string antenna_pcx = <antenna.pcx>;
define healthpoints = skill18;
///////////////////////////////////////////////////////////////////////////////////////////////////////
string health_str = "Player Health: Enemy Health:";
string healthbar_mdl = <hbar.mdl>;
//sound sorry_wav = <sorry.wav>;

///////////////////////////////////////////////////////////////////////////////////////////////////////

font comic_font, <comic20.pcx>, 34, 38;

///////////////////////////////////////////////////////////////////////////////////////////////////////

function robby_event();
function check_front();

///////////////////////////////////////////////////////////////////////////////////////////////////////

//panel time_pan // a simple panel, without a bitmap, used for the score
//{
// pos_x = 0;
// pos_y = 0;
// digits 520, 400, 3, comic_font, 1, standing_time; // displays the score with 3 digits
// digits 520, 440, 3, comic_font, 1, walking_time; // displays the score with 3 digits
// flags = refresh, d3d, visible;
//}
//
//text info_txt
//{
// pos_x = 350;
// pos_y = 400;
// font = comic_font;
// string = "Stand:\n Walk:";
// flags = visible;
//}

///////////////////////////////////////////////////////////////////////////////////////////////////////

function display_health( )
{
my.passable = on;
while (you != null)
{
my.x = you.x;
my.y = you.y;
my.z = you.z + 50;
my.scale_y = you.healthpoints / 5;
vec_set(temp, camera.x);
vec_sub(temp, my.x);
vec_to_angle (my.pan, temp);
my.tilt = 0;
wait (1);
}
my.invisible = on;
}
action robby_the_robot
{
creature = me;
creature.healthpoints = 100;
my.enable_entity = on;
my.enable_impact = on;
my.enable_block = on;
ent_create (healthbar_mdl, my.pos, display_health);
my.event = robby_event;
// my.ENABLE_SCAN = on;
//
// my.event = rotate_now;


ent_create(antenna_pcx, nullvector, check_front);

while(1)
{

standing_time = 3 + random(1); // stand for 3..10 seconds
while (standing_time > 0)
{
standing_time -= time / 16;
ent_cycle("stand", my.skill20); // play "stand" animation
my.skill20 += 2 * time;
my.skill20 %= 100; // loop
wait (1);
}
walking_time = 10 + random(10); // walk for 10..20 seconds
walk_speed.x = 3;
walk_speed.y = 0;
walk_speed.z = 0;
walk_speed *= time; // keep the same speed at different frame rates
wait (1);

while (walking_time > 0)
{

///////////////////////////////////////////
while (grub == null) //////<---------this code gets rid of empty pointer error, but freezes the AI after he picks up the food.
{wait (1);}
if (vec_dist (my.x, grub.pos) < 200) // the player approaches the food
{

// name_ent2();
vec_set(temp, grub.pos);
vec_sub(temp, my.pos);
vec_to_angle(my.pan, temp);
my.tilt = 0; // I'm a maniac smile
walk_speed.x = 10 * time;
walk_speed.y = 0;
walk_speed.z = 0;
ent_move(creature_distance, nullvector);
ent_cycle("walk", my.skill19); // play walk frames animation
my.skill19 += 5 * time; // "walk" animation speed
// ent_playsound (my, walk_snd, 50);

wait (1);

}

/////////////////////////////////////////////
if (content(front_coords) == content_solid)
{
my.skill40 = my.pan;
my.skill41 = 30 + random(90);
while (my.pan < my.skill40 + my.skill41) // rotate 30..120 degrees
{
my.pan += 3 * time;
wait (1);
}
}



else
{

walking_time -= time / 16;
ent_cycle("walk", my.skill20); // play "walk" animation
my.skill20 += 4 * time;
my.skill20 %= 100; // loop
move_mode = ignore_passable; // ignore passable entities
result = ent_move (walk_speed, nullvector);
if (result == 0) // got stuck!
{
walk_speed.x *= -1; // reversed movement
my.skill40 = my.pan;
my.skill41 = 30 + random(90);
while (my.pan < my.skill40 + my.skill41) // rotate 30..120 degrees
{
my.pan += 3 * time;
ent_cycle("walk", my.skill20); // play reversed "walk" animation
my.skill20 -= 4 * time;
my.skill20 %= 100; // loop
move_mode = ignore_passable; // ignore passable entities
ent_move (walk_speed, nullvector);
wait (1);
}
walk_speed.x *= -1; // restore walk_speed
}
}
wait (1);
}
wait (1);
}
}

function check_front()
{
// my.invisible = on; // remove the comment to make the antenna invisible
my.passable = on;
my.transparent = on;
while (1)
{
my.x = you.x + 30 * cos(you.pan); // the antenna is placed
my.y = you.y + 30 * sin(you.pan); // 30 quants in front of the player
my.z = you.z;
vec_set (front_coords, my.pos);
wait (1);
}

}

function robby_event()
{
exclusive_global;
if (event_type == event_entity) // collided with an entity (the player)
{
// snd_play (sorry_wav, 50, 0);
}
}
action food
{
grub = me;
// you.size +=1;
wait (1);
var randomhealth;
randomhealth = 25 + random(20);
my.passable = on;
while (creature == null) {wait (1);}
while (vec_dist (my.x, creature.x) > 25) {wait (1);}
creature.healthpoints += 40; // add 25 health points
// effect (particle_sparks, 2, target, normal);
ent_remove (me);
}






action animatetrig
{
my.passable = on;
while (player == null) {wait (1);}

if (vec_dist (my.x, player.x) < 50) // if the player comes closer than 50 quants attack him
{
while (1)
{var anim_speed;
my.skill88 = 0;
while (my.skill88 < 10) // play this animation for 10 seconds
{
my.skill88 += time_step / 16;
anim_speed += 2 * time_step; // 2 = walk animation speed
ent_animate(my, "open", anim_speed, ANM_CYCLE);
wait (1);
}
my.skill88 = 0;
while (my.skill88 < 10) // play this animation for 10 seconds
{
my.skill88 += time_step / 16;
anim_speed += 3 * time_step; // 3 = jump animation speed
ent_animate(my, "roll", anim_speed, ANM_CYCLE);
wait (1);
}
wait (1);
}


}
}

Re: AI search food help [Re: awstar] #278871
07/15/09 22:16
07/15/09 22:16
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline
Expert
Rei_Ayanami  Offline
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
while (grub != NULL)
try writing it big
and put a wait(3) in the first line of the food action

not tested

ohh and use the code box, makes it easyer to read wink

Last edited by Rei_Ayanami; 07/15/09 22:17.
Re: AI search food help [Re: Rei_Ayanami] #278882
07/15/09 22:51
07/15/09 22:51
Joined: May 2006
Posts: 30
awstar Offline OP
Newbie
awstar  Offline OP
Newbie

Joined: May 2006
Posts: 30
i'll try it later, one thing it did do was give empty pointer error without the null, but with it makes it stop after it picks up the food forgetting to walk or forage.

Re: AI search food help [Re: awstar] #278894
07/16/09 00:09
07/16/09 00:09
Joined: May 2006
Posts: 30
awstar Offline OP
Newbie
awstar  Offline OP
Newbie

Joined: May 2006
Posts: 30
didn't work, the AI played stand animation then froze. I'll try to upload the project.

Re: AI search food help [Re: awstar] #278895
07/16/09 00:15
07/16/09 00:15
Joined: May 2006
Posts: 30
awstar Offline OP
Newbie
awstar  Offline OP
Newbie

Joined: May 2006
Posts: 30












Click here to Download Creature Ai forage food project from rapidshare


message me your email if you need it sent to you, since download max is 10

Re: AI search food help [Re: awstar] #278920
07/16/09 07:21
07/16/09 07:21
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline
Expert
Rei_Ayanami  Offline
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
OK, iīll download it and look fr the mistake wink

Itīs *.wdl and not Lite-C but the problem is that I have no Gamestudio only LIte-C free.

Last edited by Rei_Ayanami; 07/16/09 07:23.
Page 1 of 2 1 2

Moderated by  HeelX, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1