Hi DVader,
I am using the AI FANTASY CHARACTER one and have changed it to my character. I have now got the player being Hurt when he is attacked by the enemy - It was down to HurtPlayer was not in AI script when attacking -
Now I have another issue..... I want some animation frames to play when the player is <400 distance, I got this working in a test script -
Here is the test script -
LUA Script - melee attacker script for skeleton soldier
-- Skeleton Animframes:
-- #idle1 look around 2,271
-- #attack1 overhead slice 272,305
-- #attack2 head hit 306,395
-- #attack3 body hit 396,435
-- #walk1 slow 436,535
-- #walk2 normal 536,567
-- #walk3 cautious 568,596
-- #run 597,613
-- #hit by player 614,662
-- #idle2 wait 663,721
-- #die 722,770
-- #sidestep 771,834
-- #idle3 stand and sway 835,942
-- #getup1 floor face down 943,1003
-- #getup2 grave face up 1004,1063
-- #getup3 throne 1064,1092
-- #riseup magic 1093,1266
-- #Hit dazed walk back 1267,1393
-- #jump 1394,1406
-- state controls
g_ai_skeletonsoldier_state = 0
function ai_skeletonsoldier_init(e)
CharacterControlManual(e)
g_ai_skeletonsoldier_state = 0
end
-- state control
function ai_skeletonsoldier_main(e)
-- start frame laying in dirt
if g_ai_skeletonsoldier_state == 0 then
g_ai_skeletonsoldier_state = 1
SetAnimationFrames(1004,1004)
LoopAnimation(e)
end
if g_ai_skeletonsoldier_state == 1 then
-- idle
end
if g_ai_skeletonsoldier_state == 2 then
-- Rise up
g_ai_skeletonsoldier_state = 3
SetAnimationFrames(1005,1063)
PlayAnimation(e)
end
if g_ai_skeletonsoldier_state == 3 then
-- process of rising up
if GetAnimationFrame(e) > 1055 then
g_ai_skeletonsoldier_state = 4
end
end
if g_ai_skeletonsoldier_state == 4 then
--idle
g_ai_skeletonsoldier_state = 5
SetAnimationFrames(835,942)
LoopAnimation(e)
end
-- triggers
PlayerDist = GetPlayerDistance(e)
if PlayerDist < 400 then
LookAtPlayer(e)
if g_ai_skeletonsoldier_state == 1 then
g_ai_skeletonsoldier_state = 2
end
end
Prompt ( "dist=" .. PlayerDist .. " frame =" .. GetAnimationFrame(e) .. " state=" .. g_ai_skeletonsoldier_state )
end
But I want to merge the above test script which works well with the AI script I am using (basically one script), but I keep getting loads of errors!! Pulling hair out now!!
Here is AI script -
-- LUA Script - precede every function and global member with lowercase name of script
attackdistance = {}
attackstart = {}
attackend = {}
attacktype = {}
viewrange = {}
damageframestart = {}
damageframeend = {}
lastroar = {}
lastswipe = {}
function ai_fantasycharacter_skeletonsoldier_init(e)
ai_soldier_state[e] = "patrol"
ai_soldier_pathindex[e] = -1
SetAnimationFrames(2,272)
LoopAnimation(e)
ModulateSpeed(e,1.0)
SetAnimationSpeed(e,0.7)
attackdistance[e] = 65
attackstart[e] = 272
attackend[e] = 305
attacktype[e] = 0
damageframestart[e] = 614
damageframeend[e] = 662
lastroar[e] = 0
lastswipe[e] = 0
ai_old_health[e] = -1
SetCharacterSoundSet(e)
end
function ai_fantasycharacter_skeletonsoldier_main(e)
PlayerDist = GetPlayerDistance(e)
EntObjNo = g_Entity[e]['obj']
if viewrange[e]==nil then
viewrange[e] = AIGetEntityViewRange(EntObjNo)
end
if ai_soldier_state[e] == "patrol" then
if ai_soldier_pathindex[e] == -1 then
ai_soldier_pathindex[e] = -2
CharacterControlArmed(e)
PathIndex = -1
PathPointIndex = -1
pClosest = 99999
for pa = 1, AIGetTotalPaths(), 1 do
for po = 1 , AIGetPathCountPoints(pa), 1 do
pDX = g_Entity[e]['x'] - AIPathGetPointX(pa,po)
pDZ = g_Entity[e]['z'] - AIPathGetPointZ(pa,po)
pDist = math.sqrt(math.abs(pDX*pDX)+math.abs(pDZ*pDZ))
if pDist < pClosest and pDist < 200 then
pClosest = pDist
PathIndex = pa
PathPointIndex = po
end
end -- po
end -- pa
if PathIndex > -1 then
ai_soldier_pathindex[e] = PathIndex
ai_path_point_index[e] = PathPointIndex
ModulateSpeed(e,1.0)
SetCharacterToWalk(e)
ai_path_point_direction[e] = 1
ai_path_point_max[e] = AIGetPathCountPoints(ai_soldier_pathindex[e])
end
end
if ai_soldier_pathindex[e] > -1 then
ai_patrol_x[e] = AIPathGetPointX(ai_soldier_pathindex[e],ai_path_point_index[e])
ai_patrol_z[e] = AIPathGetPointZ(ai_soldier_pathindex[e],ai_path_point_index[e])
AIEntityGoToPosition(EntObjNo,ai_patrol_x[e],ai_patrol_z[e])
tDistX = g_Entity[e]['x'] - ai_patrol_x[e]
tDistZ = g_Entity[e]['z'] - ai_patrol_z[e]
DistFromPath = math.sqrt(math.abs(tDistX*tDistX)+math.abs(tDistZ*tDistZ))
if DistFromPath < 50 then
if ai_path_point_direction[e] == 1 then
ai_path_point_index[e] = ai_path_point_index[e] + 1
if ( ai_path_point_index[e] > ai_path_point_max[e] ) then
ai_path_point_index[e] = ai_path_point_max[e] - 1
ai_path_point_direction[e] = 0
end
else
ai_path_point_index[e] = ai_path_point_index[e] - 1
if ( ai_path_point_index[e] < 1 ) then
ai_path_point_index[e] = 2
ai_path_point_direction[e] = 1
end
end
end
end
end
if PlayerDist < viewrange[e] then
if GetPlayerDistance(e)<attackdistance[e] and g_PlayerHealth>0 then
if ai_soldier_state[e] ~= "attack" then
AIEntityStop(EntObjNo)
ai_soldier_state[e] = "attack"
CharacterControlLimbo(e)
attacktype[e] = 1
SetAnimationFrames(attackstart[e],attackend[e])
PlayAnimation(e)
HurtPlayer(e,10)
lastswipe[e] = 0
else
if lastswipe[e]==0 and GetAnimationFrame(e)<attackend[e]-1 then
lastswipe[e]=1
end
if lastswipe[e]==1 and GetAnimationFrame(e)>=attackend[e]-1 then
ai_soldier_state[e] = "patrol"
StopAnimation(e)
lastswipe[e]=2
end
end
else
if ai_soldier_state[e] == "attack" then
if GetAnimationFrame(e)<attackstart[e] or GetAnimationFrame(e)>=attackend[e]-1 then
ai_soldier_state[e] = "patrol"
StopAnimation(e)
end
else
if ai_soldier_state[e] ~= "charge" then
ai_soldier_state[e] = "charge"
CharacterControlArmed(e)
SetCharacterToWalk(e)
ModulateSpeed(e,1.5)
if lastroar[e]==0 then
PlayCharacterSound(e,"onAlert")
lastroar[e]=1
end
end
end
end
if ai_soldier_state[e] == "charge" then
RotateToPlayer(e)
AIEntityGoToPosition(EntObjNo,g_PlayerPosX,g_PlayerPosZ)
end
if ai_soldier_state[e] == "attack" then
RotateToPlayer(e)
if GetAnimationFrame(e)>damageframestart[e] and GetAnimationFrame(e)<damageframeend[e] then
if GetPlayerDistance(e)<attackdistance[e]+30 then
PlaySoundIfSilent(e,1)
HurtPlayer(e,1)
end
end
end
end
if ai_old_health[e]==-1 then
ai_old_health[e] = g_Entity[e]['health']
end
if g_Entity[e]['health'] < ai_old_health[e] then
ai_old_health[e] = g_Entity[e]['health']
PlayCharacterSound(e,"onHurt")
end
if PlayerDist >= viewrange[e] and ai_soldier_state[e]~="patrol" then
ai_soldier_state[e] = "patrol"
SetCharacterToWalk(e)
ModulateSpeed(e,1.0)
end
if string.find(string.lower(g_Entity[e]['limbhit']), "head") ~= nil then
SetEntityHealth(e,0)
ResetLimbHit(e)
end
Prompt ( "dist=" .. PlayerDist .. " frame =" .. GetAnimationFrame(e) .. " state=" .. ai_soldier_state[e] )
end
function ai_fantasycharacter_skeletonsoldier_exit(e)
PlayCharacterSound(e,"onDeath")
CollisionOff(e)
end
Any help would be great!!