Ok I inserted this small piece of code to make the enemy hunt the player when he is far, melee him when he's close (after setting him as target of course):
...
:state=4,aihastarget=1,aitargetdistfurther=70:aimovetotarget
:state=4,aihastarget=1,aitargetdistwithin=70:airotatetotarget,setframe=95,state=5
:state=5:airotatetotarget,incframe=95
:state=5,framebeyond=95 60,aitargetdistwithin=70:aisetmeleedamage=5,aiusemelee=1,state=6
:state=5,framebeyond=95 60:state=6
:state=6:incframe=95
:state=6,frameatend=95:setvar=aistate 1,setvar=aianim 1,state=4
...
The problem is that the enemy detects the player and moves towards him but stops when it reaches a certain distance and just remains idle ,until the player moves: when the player moves closer ,the enemy character starts to melee-attack him and when it moves further, it keeps moving towards him again and stops again ... this works whether the target is the player or another character entity ....
Also, I realised that waypoints can't work with Dark AI ,it makes the character movement un-synchronised with animation or footstep sounds
I attached a low-quality 13 Mb video to the thread to show how it works ...
That's the whole script for the entity if you wanna check it out:
Note1: the script is not finished yet ,so you will find some commented out lines and it should be enough to make the enemy moves through waypoints and attacks an enemy when he sees one
Note2: Ignore that "aiss" variable
Here's the full code for the MAIN AI parameter:
;AI script for Melee weapons characters -----------------------------------------------------------------------------------------------------
;Behaviour:-
;
; A character that would keep moving through waypoints, with periods of stopping and looking around. On seeing an enemy (usually
; the player), he will move towards that enemy ,and when close enough (< 70 units) ,he beats him.
;--------------------------------------------------------------------------------------------------------------------------------------------
;Variable meanings:
;"aistate": 0=idle ,1=chasing ,2=attacking -> melee ,3=attacking -> shooting (not used here) ,4=reloading (not used here) ,5=going to cover
;6=resting in cover, 7=going to point (place)
;"aianim": 0=disables Dark AI animation control ,1=enables it
;"aiss": to help scanning with Dark AI while using waypoints for navigation
;--------------------------------------------------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------------------------------------------------
;defining some variables and setting some basic stuff
:state=0:dimlocalvar=aistate,setvar=aistate 0
:state=0:dimlocalvar=aianim,setvar=aianim 0
:state=0:dimlocalvar=aiss,setvar=aiss 0
;--------------------------------------------------------------STATS ------------------------------------------------------------------------
:state=0:dimlocalvar=meleedamage,setvar=meleedamage 5
:state=0:dimlocalvar=meleeblood,setvar=meleeblood 1
;--------------------------------------------------------------------------------------------------------------------------------------------
:state=0:alwaysactive=1,aiusefullaim=1,aiattackawareness=1,aiautofactionoff=1,setaiactive=1,state=1
;CONTROLLING THE ANIMATION
;Standing animations
:varequal=aianim 1,ducking=0,idle=1:animationnormal,animate=1
:varequal=aianim 1,ducking=0,movingforwards=1:animationnormal,animate=2
:varequal=aianim 1,ducking=0,runningforwards=1:animationnormal,animate=5
:varequal=aianim 1,ducking=0,movingbackwards=1:animationreverse,animate=2
:varequal=aianim 1,ducking=0,strafingleft=1:animationnormal,animate=3
:varequal=aianim 1,ducking=0,strafingright=1:animationnormal,animate=4
;Crouching Animations
:varequal=aianim 1,ducking=1,idle=1:animationnormal,animate=31
:varequal=aianim 1,ducking=1,movingforwards=1:animationnormal,animate=32
:varequal=aianim 1,ducking=1,runningforwards=1:animationnormal,animate=35
:varequal=aianim 1,ducking=1,movingbackwards=1:animationreverse,animate=32
:varequal=aianim 1,ducking=1,strafingleft=1:animationnormal,animate=33
:varequal=aianim 1,ducking=1,strafingright=1:animationnormal,animate=34
;STATE: CALM/IDLE
;When the character is calm/idle ,follow waypoints
:state=1,waypointstate=0:animationnormal,animate=2,waypointstart
:state=1,waypointstate=3:animationnormal,animate=1,state=2
:state=1,waypointstate=4:animationnormal,animate=2,waypointrandom
:state=1,waypointstate=5:animationnormal,animate=1,state=3
:state=2:etimerstart,state=20
:state=20,etimergreater=2000:rotateheadrandom=30,state=21
:state=21,etimergreater=4000,random=1:rotateheadrandom=40,state=22
:state=21,etimergreater=4000:state=22
:state=22,etimergreater=7000:resethead=0,animationnormal,animate=2,waypointnext,state=1
:state=3:etimerstart,state=30
:state=30,etimergreater=2000,random=1:rotateheadrandom=50,state=31
:state=30,etimergreater=2000:state=31
:state=31,etimergreater=4000:rotateheadrandom=30,state=32
:state=32,etimergreater=7000:resethead=0,animationnormal,animate=2,waypointreverse,state=1
;:varequal=aistate 0,varequal=aiss 0:setaiactive=1,setvar=aiss 1
;:varequal=aiss 1,aicanshoot=1:waypointstop,aisettarget,resethead=0,airotatetotarget,setvar=aistate 1,setvar=aianim 1,setvar=aiss 0,state=4
;:varequal=aiss 1,aicanshoot=0:setaiactive=0,setvar=aiss 0
:varequal=aistate 0,aicanshoot=1:waypointstop,aisettarget,resethead=0,airotatetotarget,setvar=aistate 1,setvar=aianim 1,state=4
;STATE: CHASING
;When the character sees a fuckin' enemy, make it a target and move towards it till it gets close
:state=4,aihastarget=1:aimovetotarget
:state=4,aihastarget=1,aitargetdistwithin=70:airotatetotarget,setvar=aistate 2,setvar=aianim 0,setframe=95,state=5
;If the target is too far away, go to cover ... waiting!
;:state=4,aitargetdistfurther=2500:setvar=aistate 5,setvar=aianim 1
:state=5:airotatetotarget,incframe=95
:state=5,framebeyond=95 60,aitargetdistwithin=70:aisetmeleedamage=%meleedamage,aiusemelee=%meleeblood,state=6
:state=5,framebeyond=95 60:state=6
:state=6:incframe=95
:state=6,frameatend=95:setvar=aistate 1,setvar=aianim 1,state=4
Any help would be appreciated ... seriously