Skip to content

Commit

Permalink
Update OutTheWindow_ContextMenu.lua: Fix bug with fence (IsoObject.is…
Browse files Browse the repository at this point in the history
…Hoppable() not working since 41.65)
  • Loading branch information
quarantin committed Dec 26, 2021
1 parent bbbf49d commit 97356e6
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions media/lua/client/OutTheWindow/OutTheWindow_ContextMenu.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
function onFillWorldObjectContextMenu(playerId, context, worldobjects, test)
local OutTheWindow = {}

OutTheWindow.hasFence = function(window)

local sq = window:getSquare()
for i = 0, sq:getObjects():size() - 1 do
local obj = sq:getObjects():get(i)
if obj:isHoppable() then
return obj
end
end
end

OutTheWindow.onFillWorldObjectContextMenu = function(playerId, context, worldobjects, test)

local player = getSpecificPlayer(playerId)
local inventory = player:getInventory()
Expand All @@ -15,35 +28,34 @@ function onFillWorldObjectContextMenu(playerId, context, worldobjects, test)
if instanceof(window, 'IsoWindow') then

if (window:IsOpen() or window:isSmashed()) and not window:isBarricaded() then
context:addOption(getText('ContextMenu_ThrowCorpseOutTheWindow'), worldobjects, onThrowCorpse, player, window, corpses:get(0))
context:addOption(getText('ContextMenu_ThrowCorpseOutTheWindow'), worldobjects, OutTheWindow.onThrowCorpse, player, window, corpses:get(0))
return
end

elseif instanceof(window, 'IsoThumpable') and not window:isDoor() then

--if window:isWindow() and window:canClimbThrough(player) and not window:getSquare():getWindow(window:getNorth()) then
if window:isWindow() and window:canClimbThrough(player) then
context:addOption(getText('ContextMenu_ThrowCorpseOutTheWindow'), worldobjects, onThrowCorpse, player, window, corpses:get(0))
context:addOption(getText('ContextMenu_ThrowCorpseOutTheWindow'), worldobjects, OutTheWindow.onThrowCorpse, player, window, corpses:get(0))
return

elseif window:isHoppable() and window:canClimbOver(player) then
context:addOption(getText('ContextMenu_ThrowCorpseOverFence'), worldobjects, onThrowCorpse, player, window, corpses:get(0))
context:addOption(getText('ContextMenu_ThrowCorpseOverFence'), worldobjects, OutTheWindow.onThrowCorpse, player, window, corpses:get(0))
return
end

elseif instanceof(window, 'IsoObject') and window:isHoppable() then
context:addOption(getText('ContextMenu_ThrowCorpseOverFence'), worldobjects, onThrowCorpse, player, window, corpses:get(0))
elseif instanceof(window, 'IsoObject') and (window:isHoppable() or OutTheWindow.hasFence(window)) then
context:addOption(getText('ContextMenu_ThrowCorpseOverFence'), worldobjects, OutTheWindow.onThrowCorpse, player, (window:isHoppable() and window or OutTheWindow.hasFence(window)), corpses:get(0))
return
end
end
end

function onThrowCorpse(worldobjects, player, window, corpse)
OutTheWindow.onThrowCorpse = function(worldobjects, player, window, corpse)
if luautils.walkAdj(player, window:getSquare(), false) then
local primary, twoHands = true, true
ISWorldObjectContextMenu.equip(player, player:getPrimaryHandItem(), corpse, primary, twoHands)
ISTimedActionQueue.add(ISThrowCorpse:new(player, window, corpse, 100))
end
end

Events.OnFillWorldObjectContextMenu.Add(onFillWorldObjectContextMenu)
Events.OnFillWorldObjectContextMenu.Add(OutTheWindow.onFillWorldObjectContextMenu)

0 comments on commit 97356e6

Please sign in to comment.