I need an AI script for an enemy. Here's the description:
Standard Sniper type AI bot.
Never moves from position.
Always stays in a crouching animation until the player comes into the line of sight.
Line of sight is about 30º left and right.
Attack range is 60000.
If player gets into attack range and line of sight, the enemy waits 1-6 seconds before he stands up and pauses for about 1 second, then shoots his weapon 10-30 times before moving back into the crouching animation.
Model has transitional animations, so there is an animation for going from crouch to standing, and standing to crouch.
Enemy flinches with each hit using randomly flinch animations 1-3
———————
If someone could code this for me, I would GREATLY appreciate it, this is for my contest game, and I'm running out of time, so if anyone would do this for me, it would help a lot. Thanks.
Btw, animation names are:
crouching
standing
crouchtostand
standtocrouch
fire
flinch1
flinch2
flinch3
dying
dead
Give me 4 days. I'm having examinations now, and won't be able to do it now.
Okay, I need it at least 4 days before the end of the month. Thanks for helping.

Mac HD, is tomorrow the last day of your exams?
Today was the last day. I'll start scripting, just as soon as I am done with cleaning my room.
Great!
EDIT: Anyone know if line of sight can be obstructed by objects and geometry? I don't want these terrorist bots seeing me through the wall, but if I'm crouched behind cover I want them to still fire at me.
Well, here it comes. I hope it works. I haven't been able to test it.
Code:
var lastHitTick=0;
var maxShots;
var currentShots;
function construct(obj) {
obj.model.on=true;
obj.model.name="Sniper";
obj.size.x=1000; // alter collision box size here.
obj.size.z=1000;
obj.size.y=2000;
obj.sight.sideFieldAngle=30;
obj.sight.distance=60000;
obj.weapon.add('Sniper Rifle');
obj.health.maximum=100;
obj.health.start=100;
obj.turnSpeed.motionWalk=1;
obj.turnSpeed.facingWalk=1;
}
function watch(obj,subEvent) {
if((!obj.sight.testPlayer)||(!obj.watch.objectIsPlayer)||(subEvent!=DIM3_EVENT_WATCH_OBJECT_NEAR))return;
else {
var rand=utility.random.getInteger(10,60);
obj.event.chain(rand,'standup');
}
if((obj.watch.objectIsPlayer)&&(subEvent!=DIM3_EVENT_WATCH_OBJECT_NEAR)) {
obj.event.clearTimer();
obj.event.clearChain();
}
}
function standup(obj) {
obj.model.animation.startThenChange('crouchtostand','standing');
obj.event.chain(10,'openfire'):
}
function openfire(obj) {
maxShots=utility.random.getInteger(10,30);
currentShots=0;
obj.motionVector.turnToPlayer();
obj.event.startTimer(5,0); // alter refire rate here;
}
function timer(obj) {
obj.animation.start('fire');
obj.weapon.fire('Sniper rifle',0);
if (currentShots<maxShots) {
currentShots=currentShots+1;
}
else {
obj.event.clearTimer();
obj.animation.startThenChange('standtocrouch','crouching');
obj.motionAngle.turnStop();
var rand=utility.random.getInteger(30,100);
obj.event.chain(rand, 'standup');
}
}
function damage(obj,tick) {
if(tick<(lastHitTick+1000)) return;
var anim=utility.random.getInteger(1,3);
obj.model.animation.interrupt("flinch"+anim);
lastHitTick=tick;
}
function die(obj) {
obj.animation.startThenChange('dying','dead');
obj.setting.contact=false;
obj.setting.suspend=true;
obj.event.clearTimer();
obj.event.clearChain();
obj.watch.stop();
}
function event(obj,event,subEvent,id,tick) {
switch(event) {
case DIM3_EVENT_CONSTRUCT:
construct(obj);
break;
case DIM3_EVENT_SPAWN:
obj.watch.start(60000);
obj.model.animation.start('crouching');
break;
case DIM3_EVENT_WATCH:
watch(obj,subEvent);
break;
case DIM3_EVENT_TIMER:
timer(obj);
break;
case DIM3_EVENT_DAMAGE:
damage(obj,tick);
break;
case DIM3_EVENT_DIE:
die(obj);
break;
}
}
Whoooo yeah! Thanks a bunch, I'm going to try this out as soon as I can.
EDIT: Ok I just tested it, and it works great! Only problem is that he doesn't fire his weapon on automatic, it's still bang *pause bang *pause bang. He needs to fire about 3 times a second, can I set that myself? Or do you have to do that?
EDIT2: Oh, and I can't kill them either! And I don't know why. Also, they are supposed to start in a crouching position, not a standing position.
EDIT3:
To make it a little easier, here's the bugs in order:
*Terrorist is invincible, no idea why. They don't even play the flinch animations or spawn the blood particles like their supposed to.
*Terrorist fires about one shot per .75 seconds. They should fire a lot faster then that.
*After firing at me the terrorist becomes inactive. But then when I walk out of the 60000 watch distance the re-enter it, the terrorist starts shooting again. He should remain active and shoot at me as long as I am within the distance.
Some help please! I have only 5 days left!!!
I could help you, but that would be stupid, wouldn't it? :P
Don't want to waste my time working for someone I'm competing against.

I didn't see your edits. Make sure to bump up the thread or make a new post instead of editing, so everyone sees it.