Add snoring, including toggle and state sync
This commit is contained in:
parent
f065564cea
commit
5c0768fdcd
42
script.lua
42
script.lua
@ -17,6 +17,12 @@ if vanilla_enabled==nil then
|
|||||||
else
|
else
|
||||||
vanilla_enabled=vanilla_enabled=="true"
|
vanilla_enabled=vanilla_enabled=="true"
|
||||||
end
|
end
|
||||||
|
snore_enabled=data.load("snore_enabled")
|
||||||
|
if snore_enabled==nil then
|
||||||
|
snore_enabled=false
|
||||||
|
else
|
||||||
|
snore_enabled=snore_enabled=="true"
|
||||||
|
end
|
||||||
|
|
||||||
-- utility functions -- {{{
|
-- utility functions -- {{{
|
||||||
--- dump table --
|
--- dump table --
|
||||||
@ -69,6 +75,9 @@ VANILLA_ALL={}
|
|||||||
for _, v in pairs(VANILLA_INNER) do table.insert(VANILLA_ALL,v) end
|
for _, v in pairs(VANILLA_INNER) do table.insert(VANILLA_ALL,v) end
|
||||||
for _, v in pairs(VANILLA_OUTER) do table.insert(VANILLA_ALL,v) end
|
for _, v in pairs(VANILLA_OUTER) do table.insert(VANILLA_ALL,v) end
|
||||||
|
|
||||||
|
SNORES={"snore-1", "snore-2", "snore-3"}
|
||||||
|
snore_index=1
|
||||||
|
|
||||||
-- Expression change -- {{{
|
-- Expression change -- {{{
|
||||||
do
|
do
|
||||||
-- Values for UV mappings --
|
-- Values for UV mappings --
|
||||||
@ -146,11 +155,32 @@ function ping.setArmor(state)
|
|||||||
value.setEnabled(state)
|
value.setEnabled(state)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function snore()
|
||||||
|
if snore_enabled then
|
||||||
|
sound.playCustomSound(SNORES[snore_index], player.getPos(), vectors.of{20,1})
|
||||||
|
snore_index=snore_index%#SNORES+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function setSnoring(state)
|
||||||
|
if state == nil then
|
||||||
|
snore_enabled=not snore_enabled
|
||||||
|
else
|
||||||
|
snore_enabled=state
|
||||||
|
end
|
||||||
|
data.save("snore_enabled", snore_enabled)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ping.setSnoring(state)
|
||||||
|
snore_enabled=state
|
||||||
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
function syncState()
|
function syncState()
|
||||||
ping.setArmor(armor_enabled)
|
ping.setArmor(armor_enabled)
|
||||||
ping.setVanilla(vanilla_enabled)
|
ping.setVanilla(vanilla_enabled)
|
||||||
|
ping.setSnoring(snore_enabled)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Toggle Vanilla ---
|
--- Toggle Vanilla ---
|
||||||
@ -259,6 +289,12 @@ function tick()
|
|||||||
ping.healed()
|
ping.healed()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if player.getAnimation() == "SLEEPING" then
|
||||||
|
if cooldown(20*4, "snore") then
|
||||||
|
snore()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Sync state every 10 seconds
|
-- Sync state every 10 seconds
|
||||||
if world.getTimeOfDay() % (20*10) == 0 then
|
if world.getTimeOfDay() % (20*10) == 0 then
|
||||||
syncState()
|
syncState()
|
||||||
@ -304,5 +340,11 @@ function onCommand(input)
|
|||||||
setExpression(input[2], input[3])
|
setExpression(input[2], input[3])
|
||||||
print(input[2] .. " " .. input[3])
|
print(input[2] .. " " .. input[3])
|
||||||
end
|
end
|
||||||
|
if input[1] == chat_prefix .. "snore" then
|
||||||
|
if input[2] == "toggle" then
|
||||||
|
setSnoring()
|
||||||
|
log("Snoring is now " .. (snore_enabled and "enabled" or "disabled"))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user