Random2.lua for multiplayer
Hello.
Do you like starting every multiplayer match with a random opener? Maybe you wanna do a couple of first random moves? Or maybe you wish to randomize your game as much as possible? Well i've just made a little script which will help you do that.
Usage:
download the script
put it into data/script folder
type /ls random2.lua
whenever it's your turn and you wanna do something random:
- just press the randomize button!
- or press 'q'
// edit - doesn't work in singleplayer //edit2 - now works for tori in singleplayer
Also:
Special thanks to AssassinPro for providing me with info on how to make a button and how to get player username.
This is my first script so feel free to post your opinion about it and suggest changes. I may make it more customizable if anyone will want to use it (apart from me).
randomize button randomizes,
X button deletes buttons
lua code:
-- random2.lua
-- Joint state randomizer 2
-- get logged player username
local loggedUsername = PlayerInfo:getUser()
-- returns true if given username matches with the logged player
local function identifyPlayer(username)
local name1 = string.lower(loggedUsername)
local name2 = string.lower(PlayerInfo:getUser(username))
return (name1 == name2)
end
-- for multiplayer returns 1 if player is tori or 2 if uke
-- else returns 1 (tori; to work in singleplayer)
local function getPlayerIndex()
-- get player names from the list
bouts = get_bouts()
-- check if the logged player is in top 2 spots
for i=1, 2 do
if (identifyPlayer(bouts[i])) then
return i
end
end
return 1
end
-- set random state for each joint
local function randomJoints()
local i = getPlayerIndex() - 1
for k,v in pairs(JOINTS) do
set_joint_state(i, v, math.random(1,4))
end
end
local function keyUp(key)
if key == string.byte('q') then
randomJoints()
set_ghost(2)
end
end
add_hook("key_up", "", keyUp)
echo("random2.lua loaded")
lua code:
-- random2.lua
-- Joint state randomizer 2
-- get logged player username
local loggedUsername = PlayerInfo:getUser()
-- returns true if given username matches with the logged player
local function identifyPlayer(username)
return (loggedUsername == PlayerInfo:getUser(username))
end
-- for multiplayer returns 1 if player is tori or 2 if uke
-- else returns 1 (tori; to work in singleplayer)
local function getPlayerIndex()
-- get player names from the list
bouts = get_bouts()
-- check if the logged player is in top 2 spots
for i=1, 2 do
if (identifyPlayer(bouts[i])) then
return i
end
end
return 1
end
-- set random state for each joint
local function randomJoints()
for k,v in pairs(JOINTS) do
set_joint_state(getPlayerIndex() - 1, v, math.random(1,4))
end
end
-- code for buttons:
local w, h = get_window_size()
local button_w, button_h = 120, 30
local button2_w, button2_h = 20, 30
-- randomizer button
local button = UIElement:new({
pos = {24, 150},
size = {button_w, button_h},
bgColor = TB_MENU_DEFAULT_BG_COLOR,
rounded = 4,
interactive = true,
hoverColor = TB_MENU_DEFAULT_DARKEST_COLOR,
pressedColor = TB_MENU_DEFAULT_LIGHTEST_COLOR
})
button:addAdaptedText(nil, "Randomize")
button:addMouseHandlers(nil, function()
randomJoints()
-- reset ghosts
set_ghost(2)
end)
-- X button
local button2 = UIElement:new({
pos = {2, 150},
size = {button2_w, button2_h},
bgColor = TB_MENU_DEFAULT_BG_COLOR,
rounded = 4,
interactive = true,
hoverColor = TB_MENU_DEFAULT_DARKEST_COLOR,
pressedColor = TB_MENU_DEFAULT_LIGHTEST_COLOR
})
button2:addAdaptedText(nil, "X")
button2:addMouseHandlers(nil, function()
button:kill()
button2:kill()
end)
add_hook("draw2d", "drawButton", function()
for _, v in pairs(UIElementManager) do
v:updatePos()
end
for _, v in pairs(UIVisualManager) do
v:display()
end
end)
-- do the same for keybind so button is not neccessary
local function keyUp(key)
if key == string.byte('q') then
randomJoints()
set_ghost(2)
end
end
add_hook("key_up", "", keyUp)
local function start()
echo("random2.lua loaded")
end
start()
Last edited by 0xdead; Sep 25, 2024 at 09:58 PM.
Reason: bugfix, ignoring case sensitivity