Zackreaver Posted May 23, 2015 Share Posted May 23, 2015 (edited) Hello there, I decided I wanted to help the author for display food values in getting their mod to properly work with the clients. I immediately noticed when looking at the script that the mod is dependant on information that's normally only provided for the host, and while the script runs on both the client and the host without error, because the client is without the necessary components the information can't be displayed. Here's the modmaintable.insert(GLOBAL.STRINGS, "DFV_LANG")table.insert(GLOBAL.STRINGS, "DFV_HUNGER")table.insert(GLOBAL.STRINGS, "DFV_HEALTH")table.insert(GLOBAL.STRINGS, "DFV_SANITY")table.insert(GLOBAL.STRINGS, "DFV_SPOILSOON")table.insert(GLOBAL.STRINGS, "DFV_SPOILIN")table.insert(GLOBAL.STRINGS, "DFV_SPOILDAY")table.insert(GLOBAL.STRINGS, "DFV_MIN")local DFV_LANG = GetModConfigData("DFV_Language")local DFV_MIN = not (GetModConfigData("DFV_MinimalMode")=="default")GLOBAL.STRINGS.DFV_MIN = DFV_MINGLOBAL.STRINGS.DFV_LANG = DFV_LANGif DFV_LANG == "FR" then GLOBAL.STRINGS.DFV_HUNGER = "Points de faim" GLOBAL.STRINGS.DFV_HEALTH = "Points de vie" GLOBAL.STRINGS.DFV_SANITY = "Sante mentale" GLOBAL.STRINGS.DFV_SPOILSOON = "Pourrira bientot" GLOBAL.STRINGS.DFV_SPOILIN = "Pourrira dans" GLOBAL.STRINGS.DFV_SPOILDAY = "jour"elseif DFV_LANG == "GR" then GLOBAL.STRINGS.DFV_HUNGER = "Hunger" GLOBAL.STRINGS.DFV_HEALTH = "Gesundheit" GLOBAL.STRINGS.DFV_SANITY = "Verstand" GLOBAL.STRINGS.DFV_SPOILSOON = "Verdirbt sehr bald" GLOBAL.STRINGS.DFV_SPOILIN = "Verdirbt in" GLOBAL.STRINGS.DFV_SPOILDAY = "Tag"elseif DFV_LANG == "RU" then--Had to remove this for the postelseif DFV_LANG == "SP" then GLOBAL.STRINGS.DFV_HUNGER = "Hambre" GLOBAL.STRINGS.DFV_HEALTH = "Salud" GLOBAL.STRINGS.DFV_SANITY = "Cordura" GLOBAL.STRINGS.DFV_SPOILSOON = "Echara a perder muy pronto" GLOBAL.STRINGS.DFV_SPOILIN = "Echara a perder en" GLOBAL.STRINGS.DFV_SPOILDAY = "dia"elseif DFV_LANG == "IT" then GLOBAL.STRINGS.DFV_HUNGER = "Fame" GLOBAL.STRINGS.DFV_HEALTH = "Vita" GLOBAL.STRINGS.DFV_SANITY = "Sanita'" GLOBAL.STRINGS.DFV_SPOILSOON = "Marcira' molto presto" GLOBAL.STRINGS.DFV_SPOILIN = "Marcira' tra" GLOBAL.STRINGS.DFV_SPOILDAY = "giorn"else GLOBAL.STRINGS.DFV_HUNGER = "Hunger" GLOBAL.STRINGS.DFV_HEALTH = "Health" GLOBAL.STRINGS.DFV_SANITY = "Sanity" GLOBAL.STRINGS.DFV_SPOILSOON = "Will spoil very soon" GLOBAL.STRINGS.DFV_SPOILIN = "Will spoil in" GLOBAL.STRINGS.DFV_SPOILDAY = "day"endlocal require = GLOBAL.require local ItemTile = require "widgets/itemtile" local ItemTile_GetDescriptionString_base = ItemTile.GetDescriptionString or function() return "" endfunction ItemTile:GetDescriptionString() local str = ItemTile_GetDescriptionString_base(self) if self.item ~= nil and self.item:IsValid() and self.item.replica.inventoryitem ~= nil then local realfood = nil local show_spoil = GLOBAL.TheInput:IsControlPressed(GLOBAL.CONTROL_FORCE_INSPECT) local player = GLOBAL.ThePlayer local actionpicker = player.components.playeractionpicker local active_item = player.replica.inventory:GetActiveItem() local actions = actionpicker:GetInventoryActions(self.item) if #actions > 0 then for k,v in pairs(actions) do if v.action == GLOBAL.ACTIONS.EAT or v.action == GLOBAL.ACTIONS.HEAL then realfood = true break end end end local strings = GLOBAL.STRINGS if self.item.components.edible and realfood then --Clients don't get these components local hungervalue = 0 local healthvalue = 0 local sanityhvalue = 0 if player.components.eater and player.components.eater.monsterimmune then--ThePlayer.prefab == "webber" then if self.item.components.edible.hungervalue < 0 and player.components.eater:DoFoodEffects(self.item) or self.item.components.edible.hungervalue > 0 then hungervalue = math.floor(self.item.components.edible:GetHunger(player) * 10 + 0.5) / 10 end if self.item.components.edible.healthvalue < 0 and player.components.eater:DoFoodEffects(self.item) or self.item.components.edible.healthvalue > 0 then healthvalue = math.floor(self.item.components.edible:GetHealth(player) * 10 + 0.5) / 10 end if self.item.components.edible.sanityvalue < 0 and player.components.eater:DoFoodEffects(self.item) or self.item.components.edible.sanityvalue > 0 then sanityhvalue = math.floor(self.item.components.edible:GetSanity(player) * 10 + 0.5) / 10 end else hungervalue = math.floor(self.item.components.edible:GetHunger(player) * 10 + 0.5) / 10 healthvalue = math.floor(self.item.components.edible:GetHealth(player) * 10 + 0.5) / 10 sanityhvalue = math.floor(self.item.components.edible:GetSanity(player) * 10 + 0.5) / 10 end if strings.DFV_MIN then if hungervalue ~= 0 or healthvalue ~= 0 or sanityhvalue ~= 0 then str = str .. "\n" end if hungervalue ~= 0 then str = str .. "\153" .. " " .. hungervalue .. " " end if healthvalue ~= 0 then str = str .. "\151" .. " " .. healthvalue .. " " end if sanityhvalue ~= 0 then str = str .. "\152" .. " " .. sanityhvalue .. " " end else if hungervalue ~= 0 then str = str.."\n" .. strings.DFV_HUNGER .. " " .. hungervalue end if healthvalue ~= 0 then str = str.."\n" .. strings.DFV_HEALTH .. " " .. healthvalue end if sanityhvalue ~= 0 then str = str.."\n" .. strings.DFV_SANITY .. " " .. sanityhvalue end end elseif self.item.components.healer and realfood then --Clients don't get these components str = str.."\n" .. strings.DFV_HEALTH .. " " .. self.item.components.healer.health end if self.item.components.perishable and realfood and show_spoil then --Clients don't get these components local owner = self.item.components.inventoryitem and self.item.components.inventoryitem.owner local modifier = 1 if owner then if owner:HasTag("fridge") then if self.item:HasTag("frozen") then modifier = TUNING.PERISH_COLD_FROZEN_MULT else modifier = TUNING.PERISH_FRIDGE_MULT end elseif owner:HasTag("spoiler") then modifier = TUNING.PERISH_GROUND_MULT end else modifier = TUNING.PERISH_GROUND_MULT end -- if GetSeasonManager() and GetSeasonManager():GetCurrentTemperature() < 0 then-- if self.item:HasTag("frozen") and not self.item.components.perishable.frozenfiremult then-- modifier = TUNING.PERISH_COLD_FROZEN_MULT-- else-- modifier = modifier * TUNING.PERISH_WINTER_MULT-- end-- end if self.item.components.perishable.frozenfiremult then modifier = modifier * TUNING.PERISH_FROZEN_FIRE_MULT end -- if TUNING.OVERHEAT_TEMP ~= nil and GetSeasonManager() and GetSeasonManager():GetCurrentTemperature() > TUNING.OVERHEAT_TEMP then-- modifier = modifier * TUNING.PERISH_SUMMER_MULT-- end modifier = modifier * TUNING.PERISH_GLOBAL_MULT if modifier ~= 0 then local perishremainingtime = math.floor((self.item.components.perishable.perishremainingtime / TUNING.TOTAL_DAY_TIME / modifier) * 10 + 0.5) / 10 if perishremainingtime < 1 then str = str.."\n" .. strings.DFV_SPOILSOON elseif strings.DFV_LANG ~= "RU" then str = str.."\n" .. strings.DFV_SPOILIN .. " " .. perishremainingtime .. " " .. strings.DFV_SPOILDAY else str = str.."\n" .. strings.DFV_SPOILIN .. " " .. perishremainingtime .. " " end if strings.DFV_LANG == "RU" then--Had to remove the russian, it was breaking the forum post else if perishremainingtime >=2 then if strings.DFV_LANG == "GR" then str = str .. "en" elseif strings.DFV_LANG == "IT" then str = str .. "i" else str = str .. "s" end elseif perishremainingtime >= 1 and strings.DFV_LANG == "IT" then str = str .. "o" end end local prep_foods = require("preparedfoods") if prep_foods[self.item.prefab] ~= nil and prep_foods[self.item.prefab].temperatureduration ~= nil then str = str .. " / t " if prep_foods[self.item.prefab].temperature < 0 then str = str .. "-" else str = str .. "+" end str = str .. prep_foods[self.item.prefab].temperatureduration elseif self.item.prefab == "ice" and self.item.components.edible.temperatureduration ~= nil then str = str .. " / t " if self.item.components.edible.temperaturedelta < 0 then str = str .. "-" else str = str .. "+" end str = str .. self.item.components.edible.temperatureduration end else str = str .. "\n" local prep_foods = require("preparedfoods") if prep_foods[self.item.prefab] ~= nil and prep_foods[self.item.prefab].temperatureduration ~= nil then str = str .. "t " if prep_foods[self.item.prefab].temperature < 0 then str = str .. "-" else str = str .. "+" end str = str .. prep_foods[self.item.prefab].temperatureduration elseif self.item.prefab == "ice" and self.item.components.edible.temperatureduration ~= nil then str = str .. "t " if self.item.components.edible.temperaturedelta < 0 then str = str .. "-" else str = str .. "+" end str = str .. self.item.components.edible.temperatureduration end end end end return str end Now from what I figured out, edible and perishable dont have replicas, since client's normally wouldn't need them. So one of my idea's would be to create a replica for them and change this script to gather from the replica instead. Although I could just remotely ask the server for the information when the player puts their mouse over the items and get the information that way. But I'm not exactly quite sure how to do that, I haven't made a replica component before and I'm not exactly sure how they function. Though I do know that the current replicas (health,sanity,hunger) communicate their values with the clients pretty fluidly. But more importantly, I don't know whether I'm missing an even easier way of getting this to work. Anyone have a suggestion on what I should attempt doing? Edited May 23, 2015 by Zackreaver Link to comment https://forums.kleientertainment.com/forums/topic/54319-helping-display-food-values-communicate-with-client/ Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now