Add command support and several debug commands
This commit is contained in:
parent
60b5cb495c
commit
e5eb735858
291
script.lua
291
script.lua
@ -1,127 +1,164 @@
|
|||||||
-- Texture dimensions --
|
--- Initial definitions ---
|
||||||
size = 128
|
-- Texture dimensions --
|
||||||
factor = size / 64
|
size = 128
|
||||||
-- Values for UV mappings --
|
factor = size / 64
|
||||||
face_damage=0
|
-- Values for UV mappings --
|
||||||
face_expr=0
|
face_damage=0
|
||||||
step_u_face=32
|
face_expr=0
|
||||||
step_v_face=16
|
step_u_face=32
|
||||||
offset_u_face=64
|
step_v_face=16
|
||||||
offset_v_face=0
|
offset_u_face=64
|
||||||
armor_enabled=true
|
offset_v_face=0
|
||||||
|
armor_enabled=true
|
||||||
-- initialize values --
|
vanilla_enabled=true
|
||||||
function player_init()
|
|
||||||
old_health=player.getHealth()
|
-- initialize values --
|
||||||
end
|
function player_init()
|
||||||
expr_cooldown=0
|
old_health=player.getHealth()
|
||||||
|
end
|
||||||
-- Parts --
|
expr_cooldown=0
|
||||||
HEAD=model.Head.Head
|
|
||||||
|
-- Parts --
|
||||||
-- Initial configuration --
|
HEAD=model.Head.Head
|
||||||
for key, value in pairs(vanilla_model) do
|
VANILLA_OUTER={ vanilla_model.HAT, vanilla_model.JACKET, vanilla_model.LEFT_SLEEVE, vanilla_model.RIGHT_SLEEVE, vanilla_model.LEFT_PANTS_LEG, vanilla_model.RIGHT_PANTS_LEG }
|
||||||
value.setEnabled(false)
|
|
||||||
end
|
-- Expression change --
|
||||||
vanilla_model.CAPE.setEnabled(true)
|
function getExprUV(damage, expression)
|
||||||
|
local u=offset_u_face+(damage*step_u_face)
|
||||||
-- Expression change --
|
local v=offset_v_face+(expression*step_v_face)
|
||||||
function getExprUV(damage, expression)
|
return {u/size,v/size}
|
||||||
local u=offset_u_face+(damage*step_u_face)
|
end
|
||||||
local v=offset_v_face+(expression*step_v_face)
|
function changeExpression(_damage, _expression, ticks)
|
||||||
return {u/size,v/size}
|
-- u is damage, v is expression
|
||||||
end
|
local damage = _damage
|
||||||
function changeExpression(_damage, _expression, ticks)
|
local expression = _expression
|
||||||
-- u is damage, v is expression
|
if damage == nil then
|
||||||
local damage = _damage
|
damage = face_damage
|
||||||
local expression = _expression
|
end
|
||||||
if damage == nil then
|
if expression == nil then
|
||||||
damage = face_damage
|
expression = face_expr
|
||||||
end
|
end
|
||||||
if expression == nil then
|
|
||||||
expression = face_expr
|
HEAD.setUV(getExprUV(damage,expression))
|
||||||
end
|
expr_cooldown=ticks
|
||||||
|
end
|
||||||
HEAD.setUV(getExprUV(damage,expression))
|
function setExpression(damage, expression)
|
||||||
expr_cooldown=ticks
|
face_damage=damage
|
||||||
end
|
face_expr=expression
|
||||||
function setExpression(damage, expression)
|
HEAD.setUV(getExprUV(damage, expression))
|
||||||
face_damage=damage
|
end
|
||||||
face_expr=expression
|
function resetExpression()
|
||||||
HEAD.setUV(getExprUV(damage, expression))
|
HEAD.setUV(getExprUV(face_damage,face_expr))
|
||||||
end
|
end
|
||||||
function resetExpression()
|
|
||||||
HEAD.setUV(getExprUV(face_damage,face_expr))
|
function setVanilla(state)
|
||||||
end
|
|
||||||
|
end
|
||||||
-- Action Wheel --
|
|
||||||
action_wheel.SLOT_1.setTitle('test expression')
|
-- Initial configuration --
|
||||||
action_wheel.SLOT_1.setFunction(function() ping.expressionTest() end)
|
for key, value in pairs(vanilla_model) do
|
||||||
function ping.expressionTest()
|
value.setEnabled(false)
|
||||||
setExpression(1,0)
|
end
|
||||||
changeExpression(nil, 1, 10)
|
vanilla_model.CAPE.setEnabled(true)
|
||||||
end
|
|
||||||
action_wheel.SLOT_2.setTitle('log health')
|
-- Action Wheel --
|
||||||
action_wheel.SLOT_2.setFunction(function() print(player.getHealth()) end)
|
action_wheel.SLOT_1.setTitle('test expression')
|
||||||
action_wheel.SLOT_3.setTitle('Toggle Armor')
|
action_wheel.SLOT_1.setFunction(function() ping.expressionTest() end)
|
||||||
action_wheel.SLOT_3.setFunction(function() ping.setArmor() end)
|
function ping.expressionTest()
|
||||||
|
setExpression(1,0)
|
||||||
-- Pings --
|
changeExpression(nil, 1, 10)
|
||||||
--- Damage function --
|
end
|
||||||
function ping.oof(health)
|
action_wheel.SLOT_2.setTitle('log health')
|
||||||
if health <= 5 then
|
action_wheel.SLOT_2.setFunction(function() print(player.getHealth()) end)
|
||||||
setExpression(1,0)
|
action_wheel.SLOT_3.setTitle('Toggle Armor')
|
||||||
end
|
action_wheel.SLOT_3.setFunction(function() ping.setArmor() end)
|
||||||
changeExpression(nil,1,10)
|
|
||||||
end
|
-- Pings --
|
||||||
--- Heal function (revert expression) --
|
--- Damage function --
|
||||||
function ping.healed(health)
|
function ping.oof(health)
|
||||||
setExpression(0,0)
|
if health <= 5 then
|
||||||
end
|
setExpression(1,0)
|
||||||
--- Toggle Armor ---
|
end
|
||||||
function ping.setArmor(enabled)
|
changeExpression(nil,1,10)
|
||||||
if enabled == nil then
|
end
|
||||||
armor_enabled=not armor_enabled
|
--- Heal function (revert expression) --
|
||||||
else
|
function ping.healed(health)
|
||||||
armor_enabled=enabled
|
setExpression(0,0)
|
||||||
end
|
end
|
||||||
|
--- Toggle Armor ---
|
||||||
for key, value in pairs(armor_model) do
|
function ping.setArmor(enabled)
|
||||||
value.setEnabled(armor_enabled)
|
if enabled == nil then
|
||||||
end
|
armor_enabled=not armor_enabled
|
||||||
end
|
else
|
||||||
|
armor_enabled=enabled
|
||||||
|
end
|
||||||
-- does not work on multiplayer, use ping.oof()
|
|
||||||
function onDamage(amount, source)
|
for key, value in pairs(armor_model) do
|
||||||
end
|
value.setEnabled(armor_enabled)
|
||||||
|
end
|
||||||
-- Tick function --
|
end
|
||||||
function tick()
|
|
||||||
-- expression reset spaghetti code --
|
--- Toggle Vanilla ---
|
||||||
if expr_cooldown > 0 then
|
function ping.setVanilla(state)
|
||||||
expr_cooldown = expr_cooldown-1
|
if state == nil then
|
||||||
if expr_cooldown <= 0 then
|
vanilla_enabled=not vanilla_enabled
|
||||||
resetExpression()
|
else
|
||||||
end
|
vanilla_enabled=state
|
||||||
end
|
end
|
||||||
|
end
|
||||||
-- optimization, only execute these once a second --
|
|
||||||
if world.getTimeOfDay() % 20 then
|
|
||||||
-- if face is cracked
|
|
||||||
if face_damage==1 and player.getHealth() > 5 then
|
-- does not work on multiplayer, use ping.oof()
|
||||||
ping.healed()
|
function onDamage(amount, source)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
-- Tick function --
|
||||||
-- Damage ping (onDamage doesn't work in multiplayer) --
|
function tick()
|
||||||
if old_health>player.getHealth() then
|
-- expression reset spaghetti code --
|
||||||
-- debug
|
if expr_cooldown > 0 then
|
||||||
-- print(string.format('old_health=%03.2f, player.getHealth=%03.2f', old_health,player.getHealth()))
|
expr_cooldown = expr_cooldown-1
|
||||||
ping.oof(player.getHealth())
|
if expr_cooldown <= 0 then
|
||||||
end
|
resetExpression()
|
||||||
|
end
|
||||||
-- End of tick --
|
end
|
||||||
old_health=player.getHealth()
|
|
||||||
end
|
-- optimization, only execute these once a second --
|
||||||
|
if world.getTimeOfDay() % 20 then
|
||||||
|
-- if face is cracked
|
||||||
|
if face_damage==1 and player.getHealth() > 5 then
|
||||||
|
ping.healed()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Damage ping (onDamage doesn't work in multiplayer) --
|
||||||
|
if old_health>player.getHealth() then
|
||||||
|
-- debug
|
||||||
|
-- print(string.format('old_health=%03.2f, player.getHealth=%03.2f', old_health,player.getHealth()))
|
||||||
|
ping.oof(player.getHealth())
|
||||||
|
end
|
||||||
|
|
||||||
|
-- End of tick --
|
||||||
|
old_health=player.getHealth()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Enable commands --
|
||||||
|
chat_prefix="./"
|
||||||
|
chat.setFiguraCommandPrefix(chat_prefix)
|
||||||
|
function onCommand(input)
|
||||||
|
if input == chat_prefix .. "vanilla" then
|
||||||
|
ping.setVanilla()
|
||||||
|
print("Toggled vanilla skin")
|
||||||
|
end
|
||||||
|
if input == chat_prefix .. "toggle_custom" then
|
||||||
|
for key, value in pairs(model) do
|
||||||
|
value.setEnabled(not value.getEnabled())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if input == chat_prefix .. "toggle_outer" then
|
||||||
|
for k, v in pairs(VANILLA_OUTER) do
|
||||||
|
v.setEnabled(not v.getEnabled())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user