Skip to content

Commit

Permalink
Merge pull request #38 from SMTheGuild/dev
Browse files Browse the repository at this point in the history
Counter Block Fix
  • Loading branch information
QuestionableM authored Jun 13, 2022
2 parents 8f4ae4e + ca87594 commit fb966a8
Showing 1 changed file with 48 additions and 41 deletions.
89 changes: 48 additions & 41 deletions Scripts/libs/game_improvements/interactable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,40 @@ __InteractableImprovements_Loaded = true

local values = {} -- <<not directly accessible for other scripts
function sm.interactable.setValue(interactable, value)
local inter_id = interactable.id
local stored = values[inter_id] or {}
local inter_id = interactable.id
local cur_data = values[inter_id] or {}

local current_tick = sm.game.getCurrentTick()
local changed_tick = cur_data.changedTick
if changed_tick and changed_tick < current_tick then
cur_data.current = cur_data.next
end

cur_data.next = value
cur_data.changedTick = current_tick

stored.next = value
stored.changedTick = sm.game.getCurrentTick()

values[inter_id] = stored
values[inter_id] = cur_data
end

function sm.interactable.getValue(interactable, NOW)
if not (interactable and sm.exists(interactable)) then
return
end

local value_data = values[interactable.id]
if value_data == nil then
return
end

if value_data.changedTick < sm.game.getCurrentTick() then
value_data.current = value_data.next
end
return NOW and value_data.next or value_data.current
if not (interactable and sm.exists(interactable)) then
return
end

local cur_data = values[interactable.id]
if cur_data == nil then
return
end

if cur_data.changedTick < sm.game.getCurrentTick() then
cur_data.current = cur_data.next
end

return NOW and cur_data.next or cur_data.current
end

function sm.interactable.isNumberType(interactable)
return (interactable:getType() == "scripted" and tostring(interactable:getShape().shapeUuid) ~= "6f2dd83e-bc0d-43f3-8ba5-d5209eb03d07" --[[tickbutton]])
return (interactable:getType() == "scripted" and tostring(interactable:getShape().shapeUuid) ~= "6f2dd83e-bc0d-43f3-8ba5-d5209eb03d07" --[[tickbutton]])
end


Expand All @@ -41,18 +48,18 @@ end
local uvs = {} -- <<not directly accessible for other scripts
local __OLD_setUvFrameIndex = sm.interactable.setUvFrameIndex
function sm.interactable.setUvFrameIndex(interactable, value)
local currenttick = sm.game.getCurrentTick()
local currenttick = sm.game.getCurrentTick()
__OLD_setUvFrameIndex(interactable, value)
uvs[interactable.id] = {
{tick = currenttick, value = {value}},
uvs[interactable.id] and (
uvs[interactable.id][1] ~= nil and
(uvs[interactable.id][1].tick < currenttick) and
uvs[interactable.id][1].value or
uvs[interactable.id] = {
{tick = currenttick, value = {value}},
uvs[interactable.id] and (
uvs[interactable.id][1] ~= nil and
(uvs[interactable.id][1].tick < currenttick) and
uvs[interactable.id][1].value or
uvs[interactable.id][2]
)
or nil
}
)
or nil
}
end
local __OLD_getUvFrameIndex = sm.interactable.getUvFrameIndex
Expand All @@ -71,18 +78,18 @@ end
local glows = {} -- <<not directly accessible for other scripts
local __OLD_setGlowMultiplier = sm.interactable.setGlowMultiplier
function sm.interactable.setGlowMultiplier(interactable, value)
local currenttick = sm.game.getCurrentTick()
local currenttick = sm.game.getCurrentTick()
__OLD_setGlowMultiplier(interactable, value)
glows[interactable.id] = {
{tick = currenttick, value = {value}},
glows[interactable.id] and (
glows[interactable.id][1] ~= nil and
(glows[interactable.id][1].tick < currenttick) and
glows[interactable.id][1].value or
glows[interactable.id] = {
{tick = currenttick, value = {value}},
glows[interactable.id] and (
glows[interactable.id][1] ~= nil and
(glows[interactable.id][1].tick < currenttick) and
glows[interactable.id][1].value or
glows[interactable.id][2]
)
or nil
}
)
or nil
}
end
local __OLD_getGlowMultiplier = sm.interactable.getGlowMultiplier
Expand Down

0 comments on commit fb966a8

Please sign in to comment.