Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,014 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Simple AI Scripts #189454
03/18/08 22:42
03/18/08 22:42
Joined: Mar 2008
Posts: 23
J
jmasterx Offline OP
Newbie
jmasterx  Offline OP
Newbie
J

Joined: Mar 2008
Posts: 23
Hello,

I've seached many sites but can't seem to find any offering scripts, more specifically AI scripts.

right now my problem with the A6 template scripts is thst all the ai does is walk twards you and shoot. My problem is my charactor has an animation for shooting, an animation for walking but not both at the same time like the a6 ai does... I just kind of want an ai wdl that will be basic ai that will run twards you and stay a few feet away... once you stop moving he shoots from where he is... ide be very happy with just this... also any site with wdl acrion scripts for anything would be great too,

thanks...

Re: Simple AI Scripts [Re: jmasterx] #199555
03/31/08 09:41
03/31/08 09:41
Joined: Jul 2005
Posts: 23
Deutschland / Germany
B
Bastian Offline
Newbie
Bastian  Offline
Newbie
B

Joined: Jul 2005
Posts: 23
Deutschland / Germany
well, you may use my own script. it was my first try to write an AI-script. i copied it from my old project and set comments. I dont know how experienced you are in programming c-script in general, so just ask if you have a question about this^^

the action guard will let the npc turn towards the player if he steps into his field of sight, and stop before him, attack until the player runs out of sigth or one of them dies. i also included some effects, like a random choice out of 6 different deathscreams, so the guards arent all the same. you must include 6 sounds for this or erase the part of the script about the deathscreams.
in addition to this, a music will start playing at low volume when the npc starts following you and become louder; if the guard dies the music decreases its volume and stops.

but before you can use this script, you will have to define everything, like variables, the skills for speed, health and damage and the sounds. i defined all this in another script and didnt want to do the work to write this again just for posting it here. the script should work fine like it is posted (hopefully), after you defined everything.
if a project using this AI goes public, i want to know and be credited^^

function faceme()
{
my.savepan=int(my.pan);
//save the direction i am looking for later purposes
while(my.health>0)//as long as i live
{
if(vec_dist(player.x,my.x) < my.sight)
//if the player enters the region i can sense
{
vec_set(temp,player.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp);
//these 3 lines rotate me until i look at the player
my.tilt = 0;//i dont look up and down
followme();//NOW i start walking
if(msc==null)
//musicpointer; if no music plays, do:
{
battlevol=10;
//volume of music=10%
media_play("battle.mid",null,battlevol);//play a battlemusic
msc=media_handle;//set the handle to "battle.mid"
}
if(battlevol<100)
{
battlevol+=1;
//become louder as the enemy comes closer!
}
}else
{//if the player has run out of my sight (coward...)
if(my.pan>my.savepan+1)
{
my.pan-=2;
}else
{
if(my.pan<my.savepan-1)
{
my.pan+=2;
}
//return me to the direction i had faced before following the player
}
}
wait(1);
}
}

function followme()
{
if(vec_dist(player.x,my.x) > 70)
{
//70 is the distance where the npc stops walking!
if(my.skill51<100)
{//walkanimation!
c_move(me,vector(my.speed,0,0),nullvector,ignore_passable | ignore_sprites);
//now i walk forward
my.skill51 += 3*time_step;
if (my.skill51 > 100)
{
my.skill51 -= 100;
}
ent_animate(me,"walk",my.skill51,anm_cycle);
}
}else
{
if(c_scan(my.x,my.pan,vector(100,0,100),use_polygon|ignore_me)>0)
{//if the npc looks at the player
if(you.health>0)//if the player lives
{
if(my.skill52<100)
{//attackanimation!
my.skill52 += 10*time_step;
ent_animate(me,"attack",my.skill52,null);
sleep(0.1);
}else
{
ent_playsound(me,swordsound,1000);
you.health=max((you.health-my.totaldmg),0);//you loose health or die
my.skill52=0;//reset the animation to the start
sleep(2);
}
}
}
}
}

action guard
{
if(my.sight==0)
{
my.sight=400;
}
if(my.health==0)
{
my.health=50;
}
if(my.health_max==0)
{
my.health_max=50;
}
if(my.speed==0)
{
my.speed=10;
}
if(my.damage==0)
{
my.damage=5;
}

my.enable_block=on;
my.enable_entity=on;
my.deathscream=int(random(6));//randomly choose out of 6 screams!
faceme();

while(me!=null)//as long as i exist
{
if(my.health>0)//as long as i live
{
wait(1);
}else
{
if(my.deathscream==0)
{
ent_playsound(me,scream1,500);
}else
{
if(my.deathscream==1)
{
ent_playsound(me,scream2,500);
}else
{
if(my.deathscream==2)
{
ent_playsound(me,scream3,500);
}else
{
if(my.deathscream==3)
{
ent_playsound(me,scream4,500);
}else
{
if(my.deathscream==4)
{
ent_playsound(me,scream5,500);
}else
{
if(my.deathscream==5)
{
ent_playsound(me,scream6,500);
}
}
}
}
}
}
my.passable=on;
my.skill50=0;
while(my.skill50<100)
{//deathanimation!
my.skill50 += 10*time_step;
ent_animate(me,"death",my.skill50,null);
sleep(0.05);
}
while(battlevol>0)
{
battlevol-=5;
sleep(0.1);
//if the enemy is dead, slowly stop the battlemusic
}
media_stop(msc);//stop the music with the pointer msc ("battle.mid")
msc=null;//so we dont have a music playing
sleep(5);
my.transparent=on;
my.alpha=100;
while(my.alpha>0)
{//let me disappear into the shadows
my.alpha-=1;
sleep(0.1);
}
ent_remove(me);

}
wait(1);
}
}

i used the animated version of the guard.mdl the gamestudio offers, so the animations are specially prepared for this modell.
i hope it works as claimed^^

Re: Simple AI Scripts [Re: Bastian] #199728
04/01/08 08:30
04/01/08 08:30
Joined: Jul 2005
Posts: 23
Deutschland / Germany
B
Bastian Offline
Newbie
Bastian  Offline
Newbie
B

Joined: Jul 2005
Posts: 23
Deutschland / Germany
oh, i found an error in this script:
you.health=max((you.health-my.totaldmg),0);//you loose health or die
my.totaldmg doesn't exist here; replace it with my.damage.

Re: Simple AI Scripts [Re: Bastian] #202955
04/18/08 12:31
04/18/08 12:31
Joined: Oct 2007
Posts: 116
S
sydan Offline
Member
sydan  Offline
Member
S

Joined: Oct 2007
Posts: 116
Interesting. This is very much like my code except in mine I have had to cope with NPC's attacking each other as it is a team based tornament game. However I still have errors. I have also added a c_trace command to check to see if the NPCs have a line of sight. This makes the AI more realistic.


For some reason, my ambition always seems to beat my ability.
Re: Simple AI Scripts [Re: sydan] #203489
04/22/08 13:33
04/22/08 13:33
Joined: Oct 2007
Posts: 42
Minnesota, USA
Techd Offline
Newbie
Techd  Offline
Newbie

Joined: Oct 2007
Posts: 42
Minnesota, USA
 Originally Posted By: sydan
Interesting. This is very much like my code except in mine I have had to cope with NPC's attacking each other as it is a team based tornament game. However I still have errors. I have also added a c_trace command to check to see if the NPCs have a line of sight. This makes the AI more realistic.


Would you mind sharing that code? I could really use some NPC on NPC action.

Thankx


Life is what you make it just like Games!

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