-- LUA Script - melee attacker script for classic characters -- DOGMAN Animframes: -- 2,50 - idle -- 51,100 - roar -- 102,164 - attack (142) -- 166,203 - attack (189) -- 211,280 - hurt -- 211,310 - hurt and dead -- 401,426 - walk -- 513,530 - run attackdistance = {} attackstart = {} attackend = {} roarstart = {} roarend = {} hurtstart = {} hurtend = {} viewrange = {} damageframestart = {} damageframeend = {} chargemode = {} attacktype = {} lastroar = {} lastswipe = {} function ai_advsurvanimal_init(e) ai_soldier_state[e] = "patrol" ai_soldier_pathindex[e] = -1 SetAnimationFrames(2,79) LoopAnimation(e) ModulateSpeed(e,1.45) SetAnimationSpeed(e,1.0) roarstart[e]=51 roarend[e]=100 hurtstart[e]=211 hurtend[e]=280 attackdistance[e]=75 attackstart[e]=102 attackend[e]=164 damageframestart[e]=142 damageframeend[e]=147 lastroar[e] = 0 lastswipe[e] = 0 ai_old_health[e] = -1 SetCharacterSoundSet(e) end function ai_advsurvanimal_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 CharacterControlUnarmed(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.45) 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 PlayerDist < 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] = math.random(1,2) if attacktype[e] == 1 then attackstart[e]=102 attackend[e]=164 damageframestart[e]=142 damageframeend[e]=147 end if attacktype[e] == 2 then attackstart[e]=166 attackend[e]=203 damageframestart[e]=189 damageframeend[e]=194 end SetAnimationFrames(attackstart[e],attackend[e]) PlayAnimation(e) lastswipe[e] = 0 else if lastswipe[e]==0 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)=attackend[e]-1 then ai_soldier_state[e] = "patrol" StopAnimation(e) end elseif ai_soldier_state[e] ~= "charge" then if lastroar[e]==0 or lastroar[e] > g_Time then if lastroar[e] == 0 then lastroar[e] = g_Time + 1000 end AIEntityGoToPosition(EntObjNo,g_PlayerPosX,g_PlayerPosZ) else if ai_soldier_state[e] == "hurtanim" then if GetAnimationFrame(e) > hurtend[e]-2 then ai_soldier_state[e] = "dazedreadytochargenext" end end if ai_soldier_state[e] ~= "hurtanim" then if (GetAnimationFrame(e) > roarend[e]-2 and GetAnimationFrame(e) < roarend[e]+20) or lastroar[e] == -2 then ai_soldier_state[e] = "charge" CharacterControlUnarmed(e) chargemode[e] = math.random(1,2) if chargemode[e]==1 then SetCharacterToWalk(e) ModulateSpeed(e,1.45) end if chargemode[e]==2 then SetCharacterToRun(e) ModulateSpeed(e,1.75) end lastroar[e] = -2 end end if lastroar[e] > 0 then AIEntityStop(EntObjNo) ai_soldier_state[e] = "roar" CharacterControlLimbo(e) SetAnimationFrames(roarstart[e],roarend[e]) PlayAnimation(e) RotateToPlayer(e) PlaySound(e,1) 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)= viewrange[e] and ai_soldier_state[e]~="patrol" then ai_soldier_state[e] = "patrol" CharacterControlUnarmed(e) SetCharacterToWalk(e) ModulateSpeed(e,1.45) end if string.find(string.lower(g_Entity[e]['limbhit']), "head") ~= nil then SetEntityHealth(e,0) ResetLimbHit(e) end end g_foraged = g_foraged or {} function ai_advsurvanimal_exit(e) PlayCharacterSound(e,"onDeath") CollisionOff(e) g_exp = g_exp + 50 local foraged = g_foraged if foraged[ 'Hides' ] == nil then foraged[ 'Hides' ] = { amount = 1 } else foraged[ 'Hides' ].amount = foraged[ 'Hides' ].amount + 1 end if foraged[ 'Meat' ] == nil then foraged[ 'Meat' ] = { amount = 1 } else foraged[ 'Meat' ].amount = foraged[ 'Meat' ].amount + math.random(2 , 5) end end