Skip to content

Instantly share code, notes, and snippets.

@brycepg
Created November 7, 2023 19:09
Show Gist options
  • Save brycepg/06f9f5308eaacea852c401bc042812ee to your computer and use it in GitHub Desktop.
Save brycepg/06f9f5308eaacea852c401bc042812ee to your computer and use it in GitHub Desktop.
doSleepOption dedicated server
ISWorldObjectContextMenu.doSleepOption = function(context, bed, player, playerObj)
-- Avoid player sleeping inside a car from the context menu, new radial menu does that now
if(playerObj:getVehicle() ~= nil) then return end
if(bed and bed:getSquare():getRoom() ~= playerObj:getSquare():getRoom()) then return end
local text = getText(bed and "ContextMenu_Sleep" or "ContextMenu_SleepOnGround")
local sleepOption = context:addOption(text, bed, ISWorldObjectContextMenu.onSleep, player);
local tooltipText = nil
-- Not tired enough
local sleepNeeded = not isClient() or getServerOptions():getBoolean("SleepNeeded")
if sleepNeeded and playerObj:getStats():getFatigue() <= 0.3 then
sleepOption.notAvailable = true;
tooltipText = getText("IGUI_Sleep_NotTiredEnough");
end
local isZombies = playerObj:getStats():getNumVisibleZombies() > 0 or playerObj:getStats():getNumChasingZombies() > 0 or playerObj:getStats():getNumVeryCloseZombies() > 0
if sleepNeeded and isZombies then
sleepOption.notAvailable = true;
tooltipText = getText("IGUI_Sleep_NotSafe");
end
-- Sleeping pills counter those sleeping problems
if playerObj:getSleepingTabletEffect() < 2000 then
-- In pain, can still sleep if really tired
if playerObj:getMoodles():getMoodleLevel(MoodleType.Pain) >= 2 and playerObj:getStats():getFatigue() <= 0.85 then
sleepOption.notAvailable = true;
tooltipText = getText("ContextMenu_PainNoSleep");
-- In panic
elseif playerObj:getMoodles():getMoodleLevel(MoodleType.Panic) >= 1 then
sleepOption.notAvailable = true;
tooltipText = getText("ContextMenu_PanicNoSleep");
-- tried to sleep not so long ago
elseif sleepNeeded and (playerObj:getHoursSurvived() - playerObj:getLastHourSleeped()) <= 1 then
sleepOption.notAvailable = true;
tooltipText = getText("ContextMenu_NoSleepTooEarly");
end
end
if bed then
local bedType = bed:getProperties():Val("BedType") or "averageBed";
local bedTypeXln = getTextOrNull("Tooltip_BedType_" .. bedType)
if bedTypeXln then
if tooltipText then
tooltipText = tooltipText .. " <BR> " .. getText("Tooltip_BedType", bedTypeXln)
else
tooltipText = getText("Tooltip_BedType", bedTypeXln)
end
end
end
if tooltipText then
local sleepTooltip = ISWorldObjectContextMenu.addToolTip();
sleepTooltip:setName(getText("ContextMenu_Sleeping"));
sleepTooltip.description = tooltipText;
sleepOption.toolTip = sleepTooltip;
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment