-- -- Mod: Animals Hud -- -- Author: xDeekay -- email: domkopp29@gmail.com -- @Date: 17.12.2018 -- @Update 3.4.0.0 Date: 20.06.2019 -- @Version: 3.4.0.0 -- Copyright (C) xDeekay, All Rights Reserved. animalsHUD = {}; local modDesc = loadXMLFile("modDesc", g_currentModDirectory .. "modDesc.xml"); animalsChickenHudActive = false; animalsCowHudActive = false; animalsHorseHudActive = false; animalsPigHudActive = false; animalsSheepHudActive = false; combiFillLevelActive = false; hideAllOnHudActive = false; numberOfHudsActiveOnScreen = {animalsChickenHudActive = false, animalsCowHudActive = false, animalsPigHudActive = false, animalsHorseHudActive = false, animalsSheepHudActive = false, hideAllOnHudActive = false} fontSize = 0.011; fontSizeChange = 0.001; animalsHUD.version = getXMLString(modDesc, "modDesc.version"); animalsHUD.modDirectory = g_currentModDirectory; language = {} animalsHUD.overlay = {} addModEventListener(animalsHUD); function animalsHUD:loadMap() print("############################################################"); print("--- Animals HUD v.:" .. self.version .. ", by xDeekay."); print("############################################################"); inputsActive = false animalsHUD.settingsDir = getUserProfileAppPath().. "modsSettings/animalsHUD/"; animalsHUD:LoadSettings(); animalsHUD:SaveSettings(); -- get language from giants engine for fruits and animals name -- ID 28 = GRAS -- ID 24 = SILAGE -- ID 30 = HEU -- ID 19 = MISCHRATION -- ID 18 = WASSER -- ID 31 = STROH -- ID 2 = WEIZEN -- ID 8 = MAIS -- ID 6 = SONNENBLUMEN -- ID 9 = KARTOFFEL -- ID 4 = HAFER -- ID 10 = ZUCKERRÜBEN -- ID 3 = GERSTE -- ID 7 = SOYABOHNEN -- ID 5 = RAPS -- ID 14 Pallets Chicken Eggs goes in game to 1?! -- ID 15 Pallets Sheep wool goes in game to 1 !?! -- ID 16 milk Cows -- ID 45 manure (mist) Cows, pigs -- ID 46 liquid manure (gülle) Cows, pigs language.fruits = { gras = g_i18n:getText("fillType_grass"), hafer = g_i18n:getText("fillType_oat"), weizen = g_i18n:getText("fillType_wheat"), zuckerrueben = g_i18n:getText("fillType_sugarBeet"), kartoffeln = g_i18n:getText("fillType_potato"), gerste = g_i18n:getText("fillType_barley"), sojabohnen = g_i18n:getText("fillType_soybean"), mischration = g_i18n:getText("fillType_forage"), stroh = g_i18n:getText("fillType_straw"), silage = g_i18n:getText("fillType_silage"), heu = g_i18n:getText("fillType_dryGrass"), mais = g_i18n:getText("fillType_maize"), raps = g_i18n:getText("fillType_canola"), wasser = g_i18n:getText("fillType_water"), sonnenblumen = g_i18n:getText("fillType_sunflower"), } language.animals = { huehnerbestand = g_i18n:getText("helpTitle_25"), kuhbestand = g_i18n:getText("helpTitle_21"), schweinebestand = g_i18n:getText("helpTitle_20"), pferdebestand = g_i18n:getText("helpTitle_19_01"), schafebestand = g_i18n:getText("helpTitle_24"), sauberkeit = g_i18n:getText("statistic_cleanliness"), produktivitaet = g_i18n:getText("statistic_productivity"), milch = g_i18n:getText("fillType_milk"), mist = g_i18n:getText("fillType_manure"), guelle = g_i18n:getText("fillType_liquidManure"), wolle = g_i18n:getText("fillType_wool"), eier = g_i18n:getText("fillType_egg"), } end; function animalsHUD:SaveSettings() -- set the xml settings if not given createFolder(getUserProfileAppPath() .. "modsSettings/"); createFolder(animalsHUD.settingsDir); local file = animalsHUD.settingsDir.. "animalsHUD.xml"; local pos = 0; local rootPath = "animalsHUD.settings"; local groupNameTag = string.format("%s.setting(%d)", rootPath, pos); if not fileExists(file) then -- new values save to a xml file local xmlContent = createXMLFile("animalsHUD_XML", file, "animalsHUD"); setXMLFloat(xmlContent, groupNameTag .. "#fontsize", fontSize); -- set here the currentFontSize setXMLBool(xmlContent, groupNameTag .. "#animalsChickenHudActive", animalsChickenHudActive); setXMLBool(xmlContent, groupNameTag .. "#animalsCowHudActive", animalsCowHudActive); setXMLBool(xmlContent, groupNameTag .. "#animalsHorseHudActive", animalsHorseHudActive); setXMLBool(xmlContent, groupNameTag .. "#animalsPigHudActive", animalsPigHudActive); setXMLBool(xmlContent, groupNameTag .. "#animalsSheepHudActive", animalsSheepHudActive); saveXMLFile(xmlContent); else -- if the file exists and data must or should be updated. if fileExists(file) then local xmlContent = loadXMLFile("animalsHUD_XML", file, "animalsHUD") setXMLFloat(xmlContent, groupNameTag .. "#fontsize", fontSize); -- set here the currentFontSize setXMLBool(xmlContent, groupNameTag .. "#animalsChickenHudActive", animalsChickenHudActive); setXMLBool(xmlContent, groupNameTag .. "#animalsCowHudActive", animalsCowHudActive); setXMLBool(xmlContent, groupNameTag .. "#animalsHorseHudActive", animalsHorseHudActive); setXMLBool(xmlContent, groupNameTag .. "#animalsPigHudActive", animalsPigHudActive); setXMLBool(xmlContent, groupNameTag .. "#animalsSheepHudActive", animalsSheepHudActive); saveXMLFile(xmlContent); else print("Animals Hud xml removed or others.") end end end function animalsHUD:LoadSettings() local file = animalsHUD.settingsDir.. "animalsHUD.xml"; if fileExists(file) then local xmlContent = loadXMLFile("animalsHUD_XML", file, "animalsHUD") local pos = 0; local rootPath = "animalsHUD.settings"; local groupNameTag = string.format("%s.setting(%d)", rootPath, pos); fontSize = Utils.getNoNil(getXMLFloat(xmlContent, groupNameTag .. "#fontsize"), ""); animalsChickenHudActive = Utils.getNoNil(getXMLBool(xmlContent, groupNameTag .. "#animalsChickenHudActive"), false); animalsCowHudActive = Utils.getNoNil(getXMLBool(xmlContent, groupNameTag .. "#animalsCowHudActive"), false); animalsHorseHudActive = Utils.getNoNil(getXMLBool(xmlContent, groupNameTag .. "#animalsHorseHudActive"), false); animalsPigHudActive = Utils.getNoNil(getXMLBool(xmlContent, groupNameTag .. "#animalsPigHudActive"), false); animalsSheepHudActive = Utils.getNoNil(getXMLBool(xmlContent, groupNameTag .. "#animalsSheepHudActive"), false); else print("Animals Hud xml removed or others.") end end function animalsHUD:keyEvent(unicode, sym, modifier, isDown) end; function animalsHUD:mouseEvent(posX, posY, isDown, isUp, button) end; function animalsHUD:deleteMap() end; function animalsHUD:ShowChicken() animalsChickenHudActive =not animalsChickenHudActive; animalsHUD:SaveSettings() animalsHUD:LoadSettings() -- set the count for huds on screen numberOfHudsActiveOnScreen.animalsChickenHudActive = animalsChickenHudActive hudsActiveCount(); -- set the number of active huds end function animalsHUD:ShowCows() animalsCowHudActive =not animalsCowHudActive; animalsHUD:SaveSettings() animalsHUD:LoadSettings() -- set the count for huds on screen numberOfHudsActiveOnScreen.animalsCowHudActive = animalsCowHudActive hudsActiveCount(); -- set the number of active huds end function animalsHUD:ShowPigs() animalsPigHudActive =not animalsPigHudActive; animalsHUD:SaveSettings() animalsHUD:LoadSettings() -- set the count for huds on screen numberOfHudsActiveOnScreen.animalsPigHudActive = animalsPigHudActive hudsActiveCount(); -- set the number of active huds end function animalsHUD:ShowHorses() animalsHorseHudActive =not animalsHorseHudActive; animalsHUD:SaveSettings() animalsHUD:LoadSettings() -- set the count for huds on screen numberOfHudsActiveOnScreen.animalsHorseHudActive = animalsHorseHudActive hudsActiveCount(); -- set the number of active huds end function animalsHUD:ShowSheeps() animalsSheepHudActive =not animalsSheepHudActive; animalsHUD:SaveSettings() animalsHUD:LoadSettings() -- set the count for huds on screen numberOfHudsActiveOnScreen.animalsSheepHudActive = animalsSheepHudActive hudsActiveCount(); -- set the number of active huds end function animalsHUD:FontSizeIncrease() fontSize = fontSize + fontSizeChange animalsHUD:SaveSettings() animalsHUD:LoadSettings() end function animalsHUD:FontSizeDecrease() fontSize = fontSize - fontSizeChange animalsHUD:SaveSettings() animalsHUD:LoadSettings() end function animalsHUD:CombiFillLevel() combiFillLevelActive =not combiFillLevelActive; end function animalsHUD:ShowHideAllOnHud() hideAllOnHudActive =not hideAllOnHudActive; end function animalsHUD:update(dt) if g_currentMission:getIsClient() then if g_gui.currentGui == nil and g_currentMission.controlledVehicle == nil then if not inputsActive then local _1, eventShowChicken = g_currentMission.inputManager:registerActionEvent(InputAction.A_HUD_CHICKEN, animalsHUD, animalsHUD.ShowChicken, false, true, false, true); --, false, true, false, true); if g_inputBinding ~= nil and g_inputBinding.events ~= nil and g_inputBinding.events[eventShowChicken] ~= nil then g_inputBinding.events[eventShowChicken].displayIsVisible = false end local _2, eventShowCows = g_currentMission.inputManager:registerActionEvent(InputAction.A_HUD_COWS, animalsHUD, animalsHUD.ShowCows, false, true, false, true); if g_inputBinding ~= nil and g_inputBinding.events ~= nil and g_inputBinding.events[eventShowCows] ~= nil then g_inputBinding.events[eventShowCows].displayIsVisible = false end local _3, eventShowPigs = g_currentMission.inputManager:registerActionEvent(InputAction.A_HUD_PIGS, animalsHUD, animalsHUD.ShowPigs, false, true, false, true); if g_inputBinding ~= nil and g_inputBinding.events ~= nil and g_inputBinding.events[eventShowPigs] ~= nil then g_inputBinding.events[eventShowPigs].displayIsVisible = false end local _4, eventShowHorses = g_currentMission.inputManager:registerActionEvent(InputAction.A_HUD_HORSES, animalsHUD, animalsHUD.ShowHorses, false, true, false, true); if g_inputBinding ~= nil and g_inputBinding.events ~= nil and g_inputBinding.events[eventShowHorses] ~= nil then g_inputBinding.events[eventShowHorses].displayIsVisible = false end local _5, eventShowSheeps = g_currentMission.inputManager:registerActionEvent(InputAction.A_HUD_SHEEPS, animalsHUD, animalsHUD.ShowSheeps, false, true, false, true); if g_inputBinding ~= nil and g_inputBinding.events ~= nil and g_inputBinding.events[eventShowSheeps] ~= nil then g_inputBinding.events[eventShowSheeps].displayIsVisible = false end local _6, eventFontSizeIncrease = g_currentMission.inputManager:registerActionEvent(InputAction.A_HUD_FONT_INCREASE, animalsHUD, animalsHUD.FontSizeIncrease, false, true, false, true); if g_inputBinding ~= nil and g_inputBinding.events ~= nil and g_inputBinding.events[eventFontSizeIncrease] ~= nil then g_inputBinding.events[eventFontSizeIncrease].displayIsVisible = false end local _7, eventFontSizeDecrease = g_currentMission.inputManager:registerActionEvent(InputAction.A_HUD_FONT_DECREASE, animalsHUD, animalsHUD.FontSizeDecrease, false, true, false, true); if g_inputBinding ~= nil and g_inputBinding.events ~= nil and g_inputBinding.events[eventFontSizeDecrease] ~= nil then g_inputBinding.events[eventFontSizeDecrease].displayIsVisible = false end local _8, eventShowCombiFillLevel = g_currentMission.inputManager:registerActionEvent(InputAction.A_HUD_COMBI_FILL_LEVEL, animalsHUD, animalsHUD.CombiFillLevel, false, true, false, true); if g_inputBinding ~= nil and g_inputBinding.events ~= nil and g_inputBinding.events[eventShowCombiFillLevel] ~= nil then g_inputBinding.events[eventShowCombiFillLevel].displayIsVisible = false end local _9, eventShowHideAllOnHud = g_currentMission.inputManager:registerActionEvent(InputAction.A_HUD_SHOW_HIDE_ALL, animalsHUD, animalsHUD.ShowHideAllOnHud, false, true, false, true); if g_inputBinding ~= nil and g_inputBinding.events ~= nil and g_inputBinding.events[eventShowHideAllOnHud] ~= nil then g_inputBinding.events[eventShowHideAllOnHud].displayIsVisible = false end else inputsActive = false end; end; end; end; function setColorWhite() setTextColor(1,1,1,1); end; function animalsHUD:draw() ------------------------------------------------- -- setting for screen render ------------------------------------------------- linePadding = 0.003; paddingBetweenLines = fontSize + 0.004; setTextColor(1,1,1,1); local position_X_Standard = 0.85 local position_X_StandardOffsetRight = 0.12 local position_X_StandardCombi = 0.81 local position_X_StandardCombiOffsetRight = 0.16 local position_Y_Standard = 0.85 local position_X_extendedWindow = 0.70; local position_X_extendedWindowOffsetRight = 0.14; local position_X_extendedWindowCombi = 0.67; local position_X_extendedWindowCombiOffsetRight = 0.16; posY = position_Y_Standard -- all huds have the same start hight ------------------------------------------------------------------------ -- geo location added here--- ------------------------------------------------------------------------ if g_currentMission.player ~= nil then local x_pos_player,y_pos_player,z_pos_player = g_currentMission.player:getPositionData() local radius = 24.0 -- ca. distance in meters local x_positionHotspot = 0 local z_positionHotspot = 0 locationAnimalsBuildingID = 0; for k,husbandry in pairs(g_currentMission.husbandries) do local hotspot = husbandry.mapHotspots[1] if hotspot ~= nil then -- for k,hotspot in pairs(hotspots) do x_positionHotspot = hotspot.xMapPos z_positionHotspot = hotspot.zMapPos local distanceBetweenPlayerAndBuilding = math.sqrt(math.pow((x_pos_player - x_positionHotspot),2) + math.pow((z_pos_player - z_positionHotspot),2)) if distanceBetweenPlayerAndBuilding < radius then locationAnimalsBuildingID = husbandry.id; -- id of the building on the map close to the player. end end end end --check percent and set colors function setColorIndicatorForMaxAndMinPercentValues(percent) setColorWhite(); -- set all text to white if percent ~= nil then if percent >= 75 then setTextColor(0,1,0,1); -- green return percent elseif percent >= 45 then setTextColor(0,1,1,1); -- blue return percent elseif percent >= 15 then setTextColor(1,1,0,1); -- orange return percent elseif percent < 15 then setTextColor(1,0,0,1); -- red return percent end end end function setCleanLinessColorIndicatorForMaxAndMinPercentValues(percent) setColorWhite(); -- set all text to white if percent ~= nil then if percent >= 95 then setTextColor(0,1,0,1); -- green return percent, tostring(":)") elseif percent >= 60 then setTextColor(0,1,1,1); -- blue return percent, tostring(";)") elseif percent >= 30 then setTextColor(1,1,0,1); -- orange return percent, tostring(":/") elseif percent < 30 then setTextColor(1,0,0,1); -- red return percent, tostring(":(") end end end function setProductionColorIndicatorForMaxAndMinPercentValues(percent) setColorWhite(); -- set all text to white if percent >= 95 then setTextColor(0,1,0,1); -- green return percent elseif percent >= 60 then setTextColor(0,1,1,1); -- blue return percent elseif percent >= 30 then setTextColor(1,1,0,1); -- orange return percent elseif percent < 30 then setTextColor(1,0,0,1); -- red return percent end end function hudsActiveCount() local active = 0; if numberOfHudsActiveOnScreen.animalsChickenHudActive == true then active = active + 1 end if numberOfHudsActiveOnScreen.animalsCowHudActive == true then active = active + 1 end if numberOfHudsActiveOnScreen.animalsPigHudActive == true then active = active + 1 end if numberOfHudsActiveOnScreen.animalsHorseHudActive == true then active = active + 1 end if numberOfHudsActiveOnScreen.animalsSheepHudActive == true then active = active + 1 end -- if numberOfHudsActiveOnScreen.hideAllOnHudActive == true then active = active + 1 end return active end ------------------------------------------------- -- draw the animals infos on the screen. ------------------------------------------------- local playerNamePosX = 0.0 local playerNamePosY = 0.0 function drawPlayerOnHud(nameOfPlayer) setTextBold(true); setTextColor(0,1,1,1); setTextAlignment(RenderText.ALIGN_LEFT); renderText(playerNamePosX, playerNamePosY, fontSize, tostring(nameOfPlayer)) end function drawInfo(title, firstValueToDraw, secondValueToDraw, valueForPadding) if combiFillLevelActive == true then posX = position_X_StandardCombi; posX2 = posX + position_X_StandardCombiOffsetRight; else posX = position_X_Standard posX2 = posX + position_X_StandardOffsetRight end -- check if the title a animal name -- if not do no bold text and white text color if title ~=nil then if title == language.animals.huehnerbestand or title == language.animals.kuhbestand or title == language.animals.schweinebestand or title == language.animals.pferdebestand or title == language.animals.schafebestand then setTextBold(true); setTextColor(0,1,1,1); -- blue else setTextBold(false); setColorWhite(); end end setTextAlignment(RenderText.ALIGN_LEFT); posY = posY - paddingBetweenLines; if title~=nil and firstValueToDraw ~=nil then if valueForPadding > 0 then setTextAlignment(RenderText.ALIGN_LEFT); --set playernameLocation on the correct position where is player close to animals. draw the name left from it on hud playerNamePosX = posX - 0.04 playerNamePosY = posY renderText(posX, posY, fontSize, title) -- first item -- RENDER THE TITLE WITH ALIGNMENT LEFT. EXAMPLE "WHEAT: or Count of Animals" setTextAlignment(RenderText.ALIGN_RIGHT); -- CHECK IF A ANIMAL OR FRUIT -- NUMBER = FRUIT if secondValueToDraw ~= "" then -------------------------------------------- -- check if cleanliness or production -------------------------------------------- -- render the cleanliness text with color on the hud if title == language.animals.sauberkeit then local _,warningMessageWithColor = setCleanLinessColorIndicatorForMaxAndMinPercentValues(firstValueToDraw) renderText(posX2, posY, fontSize, "" .. tostring(firstValueToDraw).."%" .. " " .. tostring(warningMessageWithColor)) --RENDER THE VALUES EXAMPLE "5000L: 50%" -- render the production text with color on the hud elseif title == language.animals.produktivitaet then local warningMessageWithColorOfProduction = setProductionColorIndicatorForMaxAndMinPercentValues(firstValueToDraw) renderText(posX2, posY, fontSize, "" .. tostring(warningMessageWithColorOfProduction).."%") --RENDER THE VALUES EXAMPLE "5000L: 50%" else -- if the title not cleanliness or production then -- special for only liters or kgs if secondValueToDraw == "showValueWithLiters" or secondValueToDraw == "showValueWithKg" then -- for all productions from animals in Liters if secondValueToDraw == "showValueWithKg" then renderText(posX2, posY, fontSize, "[" .. tostring(firstValueToDraw).."Kg]") --RENDER THE VALUES EXAMPLE "5000kg" elseif secondValueToDraw == "showValueWithLiters" then renderText(posX2, posY, fontSize, "[" .. tostring(firstValueToDraw).."L]") --RENDER THE VALUES EXAMPLE "5000kg" else -- for all productions from animals in WITHOUT Liters or KGs renderText(posX2, posY, fontSize, "[" .. tostring(firstValueToDraw).."]") --RENDER THE VALUES EXAMPLE "5000" (eggs and wools) end else -- if combiFillLevelActive NOT!! active -- for all other fruits that can gives liters and percent local secondValueWithColorWarning = setColorIndicatorForMaxAndMinPercentValues(secondValueToDraw) renderText(posX2, posY, fontSize, "" .. tostring(firstValueToDraw).."L" .. " " .. tostring(secondValueWithColorWarning).."%") --RENDER THE VALUES EXAMPLE "5000L: 50%" end end else -- if the secondValueToDraw empty continue here. --set all other fonts to color white setColorWhite() renderText(posX2, posY, fontSize, "" .. tostring(firstValueToDraw)) -- only for animals count render end end end end ------------------------------------------------- -- creates a padding freespace ------------------------------------------------- function paddingTop() posY = posY - linePadding; end; --[[ get global food from animals ]]-- function getFillLevelFoodFromId(id, husbandry) if id ~=nil and husbandry ~=nil then --loop for fillCapacity Food local capacities = husbandry.modulesByName.food.foodGroupCapacities local capacity = 0; for k,v in pairs(capacities) do capacity = capacities[k].capacity; end local fillLevelFood = tonumber(math.ceil(husbandry.modulesByName.food.fillLevels[id])); local fillLevelFoodPercent = tonumber(math.ceil((100 * fillLevelFood / capacity))); return fillLevelFood , fillLevelFoodPercent; else print("Fehler mit getFillLevelFoodFromId ID (".. id ..") und husbandry (".. husbandry .. ")") end end --[[ get water from animals ]]-- function getFillLevelWaterFromId(id, husbandry) if id ~=nil and husbandry ~=nil then --loop for fillCapacity Water if husbandry.modulesByName.water ~= nil then local capacity = husbandry.modulesByName.water.fillCapacity local fillLevelWater = tonumber(math.ceil(husbandry.modulesByName.water.fillLevels[id])); local fillLevelWaterPercent = tonumber(math.ceil((100 * fillLevelWater / capacity))); return fillLevelWater , fillLevelWaterPercent; else -- if no moddules with water available return nil, nil; end else print("Fehler mit getFillLevelWaterFromId ID (".. id ..") und husbandry (".. husbandry .. ")") end end --[[ get straw from animals ]]-- function getFillLevelStrawFromId(id, husbandry) if id ~=nil and husbandry ~=nil then --loop for fillCapacity Straw local capacity = husbandry.modulesByName.straw.fillCapacity local fillLevelStraw = tonumber(math.ceil(husbandry.modulesByName.straw.fillLevels[id])); local fillLevelStrawPercent = tonumber(math.ceil((100 * fillLevelStraw / capacity))); return fillLevelStraw, fillLevelStrawPercent; else print("Fehler mit getFillLevelStrawFromId ID (".. id ..") und husbandry (".. husbandry .. ")") end end --[[ get milk from cows ]]-- function getFillLevelMilkFromId(id, husbandry) if id ~=nil and husbandry ~=nil then --loop for fillCapacity Straw -- local capacity = husbandry.modulesByName.milk.fillCapacity local fillLevelMilk = tonumber(math.ceil(husbandry.modulesByName.milk.fillLevels[id])); --- local fillLevelMilkPercent = tonumber(math.ceil((100 * fillLevelMilk / capacity))); return fillLevelMilk --, fillLevelMilkPercent; else print("Fehler mit getFillLevelMilkFromId ID (".. id ..") und husbandry (".. husbandry .. ")") end end --[[ get manure from cows, pigs ]]-- function getFillLevelManureFromId(id, husbandry) if id ~=nil and husbandry ~=nil then --loop for fillCapacity Straw --local capacity = husbandry.modulesByName.manure.fillCapacity local fillLevelManure = tonumber(math.ceil(husbandry.modulesByName.manure.fillLevels[id])); -- local fillLevelManurePercent = tonumber(math.ceil((100 * fillLevelManure / capacity))); return fillLevelManure ---, fillLevelManurePercent; else print("Fehler mit getFillLevelManureFromId ID (".. id ..") und husbandry (".. husbandry .. ")") end end --[[ get liquid manure from cows, pigs ]]-- function getFillLevelLiquidManureFromId(id, husbandry) if id ~=nil and husbandry ~=nil then --loop for fillCapacity Straw --local capacity = husbandry.modulesByName.liquidManure.fillCapacity local fillLevelLiquidManure = tonumber(math.ceil(husbandry.modulesByName.liquidManure.fillLevels[id])); --local fillLevelLiquidManurePercent = tonumber(math.ceil((100 * fillLevelLiquidManure / capacity))); return fillLevelLiquidManure --, fillLevelLiquidManurePercent; else print("Fehler mit ID (".. id ..") und husbandry (".. husbandry .. ")") end end --[[ get pallets from chicken eggs, sheep wool ]]-- function getFillLevelPallets(husbandry) if husbandry ~=nil then --loop for fillLevel Pallets --count the fillLevels. (bug on giants)!?! gives sometimes nil back. try to fix here and get correct vales to user UD. -- getFillLevelPallets(husbandry) == -- no 2nd parameter due the bug from giants.. !! local fillLevels = husbandry.modulesByName.pallets.fillLevels; local level_1 = fillLevels[1] if level_1 then return tonumber(math.ceil(level_1)) else return 0 end end end function getCleanlinessFactorInPercent(husbandry) if husbandry.modulesByName.foodSpillage ~= nil then local cleanPercent = tonumber(math.ceil(husbandry.modulesByName.foodSpillage.cleanlinessFactor * 100)) --% return cleanPercent else print("Fehler mit getCleanlinessFactorInPercent husbandry (".. husbandry .. ")") return 0 end end function getProductionFactorInPercent(husbandry) if husbandry.globalProductionFactor ~= nil then local productionPercent = tonumber(math.ceil(husbandry.globalProductionFactor * 100)) --% return productionPercent else print("Fehler mit getProductionFactorInPercent husbandry (".. husbandry .. ")") return 0 end end function countAnimals(husbandry) if husbandry ~= nil then local numberOfAnimalsChicken = 0; for k,v in pairs(husbandry.modulesByName.animals.animals) do numberOfAnimalsChicken = tonumber(k) end return numberOfAnimalsChicken else print("Fehler mit countAnimals husbandry (".. husbandry .. ")") return 0 end end -- check where is the owner of every single husbandries. farmData = { ownerFarmId = 0, farmId = 0, } local playerIsOwnerOfFarm = false function checkisOwnerOfFarm(husbandry) if g_currentMission:getIsClient() then farmData.ownerFarmID = g_currentMission.player.ownerFarmId farmData.farmId = g_currentMission.player.farmId if husbandry.modulesByName.animals.owner.ownerFarmId == farmData.farmId then playerIsOwnerOfFarm = true return true else playerIsOwnerOfFarm = false return false end end end -- function createOverlayForAnimalsChicken() -- local littleBorder = 0.05 -- if animalsHUD.overlay["chicken"] == nil then -- animalsHUD.overlay["chicken"] = createImageOverlay(animalsHUD.modDirectory .. "overlay_bg.png") -- setOverlayColor(animalsHUD.overlay["chicken"], 0, 0, 0, 0.75) -- end -- renderOverlay(animalsHUD.overlay["chicken"], posX-littleBorder, posY-littleBorder, 1,5) -- end -- buildingIDFromAnimals // -- draws player name near the hud on the screen if the player entered the zone function drawPlayerNameWithLocaltionOfCurrentBuildingID(husbandry) local idCurrentBuilding = 0 local playerName = "" local playerLocationBuildingId = locationAnimalsBuildingID if husbandry ~= nil then idCurrentBuilding = husbandry.id if playerLocationBuildingId == idCurrentBuilding then playerName = g_currentMission.player.visualInformation.playerName return tostring("[" .. playerName .. "]") else return tostring("") end else return tostring("") end end if hideAllOnHudActive == false then if animalsChickenHudActive == true then --CHICKEN for _,husbandry in pairs(g_currentMission.husbandries) do if checkisOwnerOfFarm(husbandry) == true then if husbandry.modulesByName.animals.animalType == "CHICKEN" then local numberOfAnimals = countAnimals(husbandry); if numberOfAnimals > 0 then local cleanliness = getCleanlinessFactorInPercent(husbandry); local cleanlinessPercent,cleanlinessText = setCleanLinessColorIndicatorForMaxAndMinPercentValues(cleanliness) local production = getProductionFactorInPercent(husbandry); local productionPercent = setProductionColorIndicatorForMaxAndMinPercentValues(production) -- animal pen mod START local drawWaterForChicken = false local waterFillLevel,waterFillLevelPercent = getFillLevelWaterFromId(18,husbandry) if waterFillLevel ~= nil and waterFillLevelPercent ~= nil then drawWaterForChicken = true end -- animal pen mod END local weizenFillLevel,weizenFillLevelPercent = getFillLevelFoodFromId(2,husbandry) local gersteFillLevel,gersteFillLevelPercent = getFillLevelFoodFromId(3, husbandry) local eggsFillLevel = getFillLevelPallets(husbandry) -- no 2nd parameter!! local playerName = drawPlayerNameWithLocaltionOfCurrentBuildingID(husbandry); drawInfo(language.animals.huehnerbestand, numberOfAnimals,"", tonumber(linePadding) + 0.010); drawPlayerOnHud(playerName); drawInfo(language.animals.eier, eggsFillLevel,"showValueWithKg", tonumber(linePadding)); drawInfo(language.animals.produktivitaet, productionPercent,nil, tonumber(linePadding)); drawInfo(language.animals.sauberkeit , cleanlinessPercent ,cleanlinessText, tonumber(linePadding)); if drawWaterForChicken == true then drawInfo(language.fruits.wasser , waterFillLevel, waterFillLevelPercent, tonumber(linePadding)); end if combiFillLevelActive == false then drawInfo(language.fruits.weizen , weizenFillLevel,weizenFillLevelPercent ,tonumber(linePadding)); drawInfo(language.fruits.gerste , gersteFillLevel,gersteFillLevelPercent ,tonumber(linePadding)); else local fillLevelCombi = weizenFillLevel + gersteFillLevel local fillLevelPercentCombi = weizenFillLevelPercent + gersteFillLevelPercent drawInfo(language.fruits.weizen .. "/" .. language.fruits.gerste , fillLevelCombi,fillLevelPercentCombi ,tonumber(linePadding)); end else drawInfo(language.animals.huehnerbestand.. " 0","","", tonumber(linePadding)) end; end; -- paddingTop(); end end end if animalsCowHudActive == true then -- COW for _,husbandry in pairs(g_currentMission.husbandries) do if checkisOwnerOfFarm(husbandry) == true then if husbandry.modulesByName.animals.animalType == "COW" then local numberOfAnimals = countAnimals(husbandry); if numberOfAnimals > 0 then local cleanliness = getCleanlinessFactorInPercent(husbandry); local cleanlinessPercent,cleanlinessText = setCleanLinessColorIndicatorForMaxAndMinPercentValues(cleanliness) local production = getProductionFactorInPercent(husbandry); local productionPercent = setProductionColorIndicatorForMaxAndMinPercentValues(production) local waterFillLevel,waterFillLevelPercent = getFillLevelWaterFromId(18,husbandry) local strawFillLevel,strawFillLevelPercent = getFillLevelStrawFromId(31,husbandry) local grassFillLevel,grassFillLevelPercent = getFillLevelFoodFromId(28,husbandry) local mischrationFillLevel,mischrationFillLevelPercent = getFillLevelFoodFromId(19,husbandry) local heuFillLevel,heuFillLevelPercent = getFillLevelFoodFromId(30,husbandry) local silageFillLevel,silageFillLevelPercent = getFillLevelFoodFromId(24, husbandry) local milchFillLevel = getFillLevelMilkFromId(16, husbandry) local mistFillLevel = getFillLevelManureFromId(45, husbandry) local guelleFillLevel = getFillLevelLiquidManureFromId(46, husbandry) local playerName = drawPlayerNameWithLocaltionOfCurrentBuildingID(husbandry); drawInfo(language.animals.kuhbestand, numberOfAnimals,"", tonumber(linePadding) + 0.010); drawPlayerOnHud(playerName); drawInfo(language.animals.milch,milchFillLevel,"showValueWithLiters", tonumber(linePadding)); drawInfo(language.animals.mist,mistFillLevel,"showValueWithLiters", tonumber(linePadding)); drawInfo(language.animals.guelle,guelleFillLevel,"showValueWithLiters", tonumber(linePadding)); drawInfo(language.animals.produktivitaet, productionPercent,nil, tonumber(linePadding)); drawInfo(language.animals.sauberkeit , cleanlinessPercent ,cleanlinessText, tonumber(linePadding)); drawInfo(language.fruits.wasser , waterFillLevel, waterFillLevelPercent, tonumber(linePadding)); drawInfo(language.fruits.stroh , strawFillLevel, strawFillLevelPercent, tonumber(linePadding)); drawInfo(language.fruits.gras , grassFillLevel, grassFillLevelPercent , tonumber(linePadding)); drawInfo(language.fruits.mischration , mischrationFillLevel, mischrationFillLevelPercent, tonumber(linePadding)); if combiFillLevelActive == false then drawInfo(language.fruits.heu , heuFillLevel, heuFillLevelPercent, tonumber(linePadding)); drawInfo(language.fruits.silage , silageFillLevel, silageFillLevelPercent, tonumber(linePadding)); else local fillLevelCombi = heuFillLevel + silageFillLevel local fillLevelPercentCombi = heuFillLevelPercent + silageFillLevelPercent drawInfo(language.fruits.heu .. "/" .. language.fruits.silage , fillLevelCombi,fillLevelPercentCombi ,tonumber(linePadding)); end else drawInfo(language.animals.kuhbestand.. " 0","","", tonumber(linePadding)) end; end; -- paddingTop(); end; end; end; if animalsPigHudActive == true then -- PIG for _,husbandry in pairs(g_currentMission.husbandries) do if checkisOwnerOfFarm(husbandry) == true then if husbandry.modulesByName.animals.animalType == "PIG" then local numberOfAnimals = countAnimals(husbandry); if numberOfAnimals > 0 then local cleanliness = getCleanlinessFactorInPercent(husbandry); local cleanlinessPercent,cleanlinessText = setCleanLinessColorIndicatorForMaxAndMinPercentValues(cleanliness) local production = getProductionFactorInPercent(husbandry); local productionPercent = setProductionColorIndicatorForMaxAndMinPercentValues(production) local waterFillLevel,waterFillLevelPercent = getFillLevelWaterFromId(18,husbandry) local strawFillLevel,strawFillLevelPercent = getFillLevelStrawFromId(31,husbandry) local maisFillLevel,maisFillLevelPercent = getFillLevelFoodFromId(8,husbandry) local weizenFillLevel,weizenFillLevelPercent = getFillLevelFoodFromId(2,husbandry) local gersteFillLevel,gersteFillLevelPercent = getFillLevelFoodFromId(3, husbandry) local sojaFillLevel,sojaFillLevelPercent = getFillLevelFoodFromId(7,husbandry) local rapsFillLevel,rapsFillLevelPercent = getFillLevelFoodFromId(5,husbandry) local sonnenblumenFillLevel,sonnenblumenFillLevelPercent = getFillLevelFoodFromId(6,husbandry) local kartoFillLevel,kartoFillLevelPercent = getFillLevelFoodFromId(9,husbandry) local ruebenFillLevel,ruebenFillLevelPercent = getFillLevelFoodFromId(10,husbandry) local mistFillLevel = getFillLevelManureFromId(45, husbandry) local guelleFillLevel = getFillLevelLiquidManureFromId(46, husbandry) local playerName = drawPlayerNameWithLocaltionOfCurrentBuildingID(husbandry); drawInfo(language.animals.schweinebestand, numberOfAnimals,"", tonumber(linePadding) + 0.010); drawPlayerOnHud(playerName); drawInfo(language.animals.mist,mistFillLevel,"showValueWithLiters", tonumber(linePadding)); drawInfo(language.animals.guelle,guelleFillLevel,"showValueWithLiters", tonumber(linePadding)); drawInfo(language.animals.produktivitaet, productionPercent,nil, tonumber(linePadding)); drawInfo(language.animals.sauberkeit , cleanlinessPercent ,cleanlinessText, tonumber(linePadding)); drawInfo(language.fruits.wasser , waterFillLevel, waterFillLevelPercent, tonumber(linePadding)); drawInfo(language.fruits.stroh , strawFillLevel, strawFillLevelPercent, tonumber(linePadding)); drawInfo(language.fruits.mais , maisFillLevel ,maisFillLevelPercent ,tonumber(linePadding)); if combiFillLevelActive == false then drawInfo(language.fruits.weizen , weizenFillLevel,weizenFillLevelPercent ,tonumber(linePadding)); drawInfo(language.fruits.gerste , gersteFillLevel,gersteFillLevelPercent ,tonumber(linePadding)); drawInfo(language.fruits.sojabohnen , sojaFillLevel ,sojaFillLevelPercent ,tonumber(linePadding)); drawInfo(language.fruits.raps , rapsFillLevel ,rapsFillLevelPercent ,tonumber(linePadding)); drawInfo(language.fruits.sonnenblumen , sonnenblumenFillLevel ,sonnenblumenFillLevelPercent ,tonumber(linePadding)); drawInfo(language.fruits.kartoffeln , kartoFillLevel ,kartoFillLevelPercent ,tonumber(linePadding)); drawInfo(language.fruits.zuckerrueben , ruebenFillLevel ,ruebenFillLevelPercent ,tonumber(linePadding)); else local fillLevelCombi = weizenFillLevel + gersteFillLevel local fillLevelPercentCombi = weizenFillLevelPercent + gersteFillLevelPercent drawInfo(language.fruits.weizen .. "/" .. language.fruits.gerste , fillLevelCombi,fillLevelPercentCombi ,tonumber(linePadding)); local fillLevelCombi_2 = sojaFillLevel + rapsFillLevel + sonnenblumenFillLevel local fillLevelPercentCombi_2 = sojaFillLevelPercent + rapsFillLevelPercent + sonnenblumenFillLevelPercent drawInfo(language.fruits.sojabohnen .. "/" .. language.fruits.raps .. "/" .. language.fruits.sonnenblumen , fillLevelCombi_2,fillLevelPercentCombi_2 ,tonumber(linePadding)); local fillLevelCombi_3 = kartoFillLevel + ruebenFillLevel local fillLevelPercentCombi_3 = kartoFillLevelPercent + ruebenFillLevelPercent drawInfo(language.fruits.kartoffeln .. "/" .. language.fruits.zuckerrueben, fillLevelCombi_3,fillLevelPercentCombi_3 ,tonumber(linePadding)); end else drawInfo(language.animals.schweinebestand.. " 0","","", tonumber(linePadding)) end; end; -- paddingTop(); end; end; end; if animalsHorseHudActive == true then -- HORSE for _,husbandry in pairs(g_currentMission.husbandries) do if checkisOwnerOfFarm(husbandry) == true then if husbandry.modulesByName.animals.animalType == "HORSE" then local numberOfAnimals = countAnimals(husbandry); if numberOfAnimals > 0 then local waterFillLevel,waterFillLevelPercent = getFillLevelWaterFromId(18,husbandry) local strawFillLevel,strawFillLevelPercent = getFillLevelStrawFromId(31,husbandry) local haferFillLevel,haferFillLevelPercent = getFillLevelFoodFromId(4,husbandry) local heuFillLevel,heuFillLevelPercent = getFillLevelFoodFromId(30,husbandry) local playerName = drawPlayerNameWithLocaltionOfCurrentBuildingID(husbandry); drawInfo(language.animals.pferdebestand, numberOfAnimals ,"", tonumber(linePadding) + 0.010); drawPlayerOnHud(playerName); drawInfo(language.fruits.wasser , waterFillLevel, waterFillLevelPercent, tonumber(linePadding)); drawInfo(language.fruits.stroh , strawFillLevel, strawFillLevelPercent, tonumber(linePadding)); drawInfo(language.fruits.hafer , haferFillLevel ,haferFillLevelPercent, tonumber(linePadding)); drawInfo(language.fruits.heu , heuFillLevel ,heuFillLevelPercent, tonumber(linePadding)); else drawInfo(language.animals.pferdebestand.. " 0","","", tonumber(linePadding)) end; end; -- paddingTop(); end; end; end; if animalsSheepHudActive == true then -- SHEEP for _,husbandry in pairs(g_currentMission.husbandries) do if checkisOwnerOfFarm(husbandry) == true then if husbandry.modulesByName.animals.animalType == "SHEEP" then local numberOfAnimals = countAnimals(husbandry); if numberOfAnimals > 0 then local cleanliness = getCleanlinessFactorInPercent(husbandry); local cleanlinessPercent,cleanlinessText = setCleanLinessColorIndicatorForMaxAndMinPercentValues(cleanliness) local production = getProductionFactorInPercent(husbandry); local productionPercent = setProductionColorIndicatorForMaxAndMinPercentValues(production) local waterFillLevel,waterFillLevelPercent = getFillLevelWaterFromId(18,husbandry) local grassFillLevel,grassFillLevelPercent = getFillLevelFoodFromId(28,husbandry) local heuFillLevel,heuFillLevelPercent = getFillLevelFoodFromId(30,husbandry) local woolFillLevel = getFillLevelPallets(husbandry) -- no 2nd parameter!! local playerName = drawPlayerNameWithLocaltionOfCurrentBuildingID(husbandry); drawInfo(language.animals.schafebestand, numberOfAnimals,"", tonumber(linePadding) + 0.010); drawPlayerOnHud(playerName); drawInfo(language.animals.wolle, woolFillLevel,"showValueWithKg", tonumber(linePadding)); drawInfo(language.animals.produktivitaet, productionPercent,nil, tonumber(linePadding)); drawInfo(language.animals.sauberkeit , cleanlinessPercent ,cleanlinessText, tonumber(linePadding)); drawInfo(language.fruits.wasser , waterFillLevel, waterFillLevelPercent, tonumber(linePadding)); if combiFillLevelActive == false then drawInfo(language.fruits.gras , grassFillLevel , grassFillLevelPercent, tonumber(linePadding)); drawInfo(language.fruits.heu , heuFillLevel , heuFillLevelPercent, tonumber(linePadding)); else local fillLevelCombi = grassFillLevel + heuFillLevel local fillLevelPercentCombi = grassFillLevelPercent + heuFillLevelPercent drawInfo(language.fruits.gras .. "/" .. language.fruits.heu, fillLevelCombi,fillLevelPercentCombi ,tonumber(linePadding)); end else drawInfo(language.animals.schafebestand.. " 0","","", tonumber(linePadding)) end; end; -- paddingTop(); end; end; end; -- end animals sheep here end; -- show hide all on hud end; -- draw function end here