-- random move loader
local function loadrandom ()
local id = get_world_state().selected_player
if 0 > id then return end
for joint = 0, 19 do set_joint_state(id, joint, math.random(4)) end
for hand = 11, 12 do set_grip_info(id, hand, math.random(2) - 1) end
end
local function command (line)
local cmd = line:gmatch("%S+")()
if ("random" == cmd) then loadrandom() end
return 1
end
add_hook("command", "random", command)
local function key_down (key)
if (110 == key or 78 == key) then loadrandom() end
end
add_hook("key_down", "random", key_down)
-- limpness blocker
local moving, joints, hands = false, {}, {}
local function save_move ()
-- only save the move on the first frame of movement
if moving then return end
moving = true
-- make sure we're playing
local id = get_world_state().selected_player
if 0 > id then return end
-- save my move
for joint = 0, 19 do joints[joint] = get_joint_info(id, joint).state end
for hand = 11, 12 do hands[hand] = get_grip_info(id, hand) end
end
add_hook("enter_frame", "random", save_move)
local function not_limp (player)
for joint = 0, 19 do
if 3 ~= get_joint_info(player, joint).state then
return true
end
end
end
local function enter_freeze ()
-- toggle moving flag
moving = false
-- temp save hands/joints and clear them
local h, j = hands, joints
hands, joints = {}, {}
-- make sure we're playing
local id = get_world_state().selected_player
if 0 > id then return end
-- make sure we're limp
if not_limp(id) then return end
-- restore previous move
for joint = 0, 19 do set_joint_state(id, joint, joints[joint]) end
for hand = 11, 12 do set_grip_info(id, hand, hands[hand]) end
end
add_hook("enter_freeze", "random", enter_freeze)
-- get out new dice
math.randomseed(os.time())
echo "botmann.lua by Pegasus Epsilon <pegasus@pimpninjas.org>"
-- (C) 2014 Distribute Unmodified -- http://pegasus.pimpninjas.org/license