--script by smallg local state = {} local health = {} local hide_delay = {} local hidden = {} local patrol = {} local forget_time = {} function stealth_warrior_init(e) ai_soldier_pathindex[e] = -1 state[e] = "patrol" hidden[e] = 0 end function stealth_warrior_main(e) EntObjNo = g_Entity[e]['obj'] if health[e] == nil then health[e] = g_Entity[e]['health'] end if state[e] == "patrol" then CharacterControlUnarmed(e) ModulateSpeed(e,1.0) SetCharacterToWalk(e) Show(e) StopParticleEmitter(e) patrol[e] = 0 forget_time[e] = math.random(1000,2000) hide_delay[e] = GetTimer(e) + math.random(500,1000) if ai_soldier_pathindex[e] == -1 then ai_soldier_pathindex[e] = -2 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 < 500 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 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 if g_Entity[e]['health'] < health[e] or AIGetEntityHeardSound(EntObjNo) == 1 or g_Entity[e]['plrvisible'] == 1 then state[e] = "alert" end elseif state[e] == "alert" then SetCharacterToRun(e) CharacterControlArmed(e) health[e] = g_Entity[e]['health'] if g_Entity[e]['plrvisible'] == 0 then patrol[e] = patrol[e] + 1 else patrol[e] = 0 end if patrol[e] > forget_time[e] then state[e] = "patrol" --ai_soldier_pathindex[e] = -1 end AIEntityGoToPosition(EntObjNo,g_PlayerPosX,g_PlayerPosZ) if GetTimer(e) > hide_delay[e] then if hidden[e] == 0 then if g_Entity[e]['health'] > 50 then hide_delay[e] = GetTimer(e) + math.random(250,750) hidden[e] = 1 Hide(e) StartParticleEmitter(e) end else hide_delay[e] = GetTimer(e) + math.random(500,1000) hidden[e] = 0 Show(e) StopParticleEmitter(e) end end if g_Entity[e]['plrvisible'] == 1 then state[e] = "attack" end elseif state[e] == "attack" then if g_Entity[e]['plrvisible'] == 0 then state[e] = "alert" Show(e) StopParticleEmitter(e) hidden[e] = 0 end AIEntityStop(e) AIEntityGoToPosition(EntObjNo,g_PlayerPosX+math.random(-1000,1000),g_PlayerPosZ+math.random(-1000,1000)) LookAtPlayer(e) if hidden[e] == 0 then FireWeapon(e) end if GetTimer(e) > hide_delay[e] then if hidden[e] == 0 then if g_Entity[e]['health'] > 30 then hide_delay[e] = GetTimer(e) + math.random(250,750) hidden[e] = 1 Hide(e) StartParticleEmitter(e) end else hide_delay[e] = GetTimer(e) + math.random(500,1000) hidden[e] = 0 Show(e) StopParticleEmitter(e) end end end --state if g_Entity[e]['health'] < 30 then Show(e) StopParticleEmitter(e) end end --main function stealth_warrior_exit(e) Show(e) end