local health = {} local pressed = 0 --enemies will move into this range to fire local fire_range = 1500 --how close the player needs to get to perform the stealth kill local stealth_kill_range = 120 --how much HP is gained for the kill local kill_health_gain = 50 --the key press required to perform the kill local input = "e" function stealth_kill_init(e) ai_soldier_state[e] = "patrol" ai_soldier_pathindex[e] = -1 end function stealth_kill_main(e) EntObjNo = g_Entity[e]['obj'] if health[e] == nil then health[e] = g_Entity[e]['health'] end if ai_soldier_state[e] == "patrol" then CharacterControlUnarmed(e) if g_Entity[e]['health'] < health[e] or g_Entity[e]['plrvisible'] == 1 or AIGetEntityHeardSound(EntObjNo) == 1 then ai_soldier_state[e] = "alert" else 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 < 300 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 elseif ai_soldier_state[e] == "alert" then CharacterControlArmed(e) RotateToPlayer(e) if GetPlayerDistance(e) > fire_range * 1.3 then ai_soldier_state[e] = "patrol" health[e] = g_Entity[e]['health'] elseif GetPlayerDistance(e) > fire_range then AIEntityGoToPosition(EntObjNo,g_PlayerPosX,g_PlayerPosZ) else AIEntityGoToPosition(EntObjNo,g_Entity[e]['x'],g_Entity[e]['z']) FireWeapon(e) end end --state if GetPlayerDistance(e) < stealth_kill_range and g_Entity[e]['plrvisible'] == 0 then PromptLocal(e,"Stealth Kill? Press " .. input) if g_InKey == input and pressed == 0 then SetEntityHealth(e,0) SetPlayerHealth(g_PlayerHealth + kill_health_gain) pressed = 1 end end end --main function stealth_kill_exit(e) pressed = 0 end