local myLines = {}
local lineCount = 0
local source = 0
local target = 0
local frame = 0
local joints ={{},{}}
local lgrip = {{},{}}
local rgrip = {{},{}}
local function invUke( tp )
swapList = { ["19"]="18", ["17"]="16", ["15"]= "14", ["13"]="12", ["7"]="4", ["11"]="10", ["9"]="6", ["8"]="5", ["18"]="19", ["16"]="17", ["14"]= "15", ["12"]="13", ["4"]="7", ["10"]="11", ["6"]="9", ["5"]="8", ["0"]=nil, ["3"]=nil, ["1"]=-1, ["2"]=-1 }
for i,jo in pairs(joints[1+tp])do
echJoint = ""
newJoint = {}
for j,v in pairs(jo)do
echJoint = echJoint.."; "..j.." : "..v
if( swapList[j] ~= nil) then
if( swapList[j] == -1 ) then
if (v == "2") then newJoint[j] = "1" end
if (v == "1") then newJoint[j] = "2" end
if (v == "3") then newJoint[j] = "3" end
if (v == "4") then newJoint[j] = "4" end
else
newJoint[swapList[j]] = v
end
else
newJoint[j] = v
end
end
joints[1+tp][i] = newJoint
end
newRgrip = lgrip[1+tp]
lgrip[1+tp] = rgrip[1+tp]
rgrip[1+tp] = newRgrip
end
local function console(s, i)
lineCount = 0
if(s:find("-s%d")) then
so, eo, source = s:find("-s(%d)")
end
if(s:find("-t%d")) then
so, eo, target = s:find("-t(%d)")
end
echo("source: "..source..", target: ".. target)
if s:find("^re %d") then
so, eo, tp = s:find("^re (%d)")
echo( "reseting "..tp )
joints[1+tp] ={}
joints[1+tp]['0'] = {}
for i,v in pairs(JOINTS) do
if joints[1+tp]['0'][""..v] == nil then
joints[1+tp]['0'][""..v] = 3
lgrip[1+tp] = {}
rgrip[1+tp] = {}
end
end
start_new_game()
end
if s:find("^inv %d") then
so, eo, tp = s:find("^inv (%d)")
echo( "inverting "..tp )
invUke( tp )
start_new_game()
end
if s:find("^me %d") then
so, eo, tp = s:find("^me (%d)")
echo( "playing with "..tp )
joints[1+tp] ={}
joints[1+tp]['0'] = {}
for i,v in pairs(JOINTS) do
if joints[1+tp]['0'][""..v] == nil then
joints[1+tp]['0'][""..v] = 4
lgrip[1+tp] = {}
rgrip[1+tp] = {}
end
end
start_new_game()
end
if s:find("^co %d") then
so, eo, tp = s:find("^co (%d)")
echo( "player controls "..tp )
joints[1+tp] ={}
end
if s:find("^lr [^-]+ ") then
s, e, ws = s:find("^lr ([^-]+) ")
filename = ws .. ".rpl"
echo("loading: ".. filename)
allLines = nil
allLines = io.open(filename, "r")
if allLines == nil then echo("NILL!!") else
joints[1+target] ={}
lgrip[1+target] ={}
rgrip[1+target] ={}
lineCount = 0
for line in allLines:lines()
do
myLines[lineCount] = line
lineCount = lineCount +1
end
for i,line in pairs(myLines)
do
if string.find(line, "NEWGAME") then
s, e, modfile = string.find(line, "([%d%w]+)[.]tbm")
echo("MOD: "..modfile)
run_cmd("loadmod "..modfile..".tbm")
end
if string.find(line, "FRAME")then
s, e, frame = string.find(line, "FRAME (%d+)")
end
if string.find(line, "JOINT "..source) then
frameJoints = {}
jline = string.gmatch(line, "(%d+ %d+)")
mic = 0
echj = ""
for j in jline do
echj = echj.."; "..j
sj, ej, strj = string.find(j, "(%d+) %d+")
sj, ej, strj2 = string.find(j, "%d+ (%d+)")
frameJoints[strj] = strj2
mic = strj
end
joints[1+target][frame] = frameJoints
end
if string.find(line, "GRIP "..source) then
sg, eg, lgs = string.find(line, "(%d+) %d+")
sg, eg, rgs = string.find(line, "%d+ (%d+)")
echo("GRIP!! frame: "..frame.." lgs: "..lgs.." rgs: ".. rgs)
if lgs == "1" then lgrip[1+target][frame] = 1 end
if lgs == "2" then lgrip[1+target][frame] = 0 end
if rgs == "1" then rgrip[1+target][frame] = 1 end
if rgs == "2" then rgrip[1+target][frame] = 0 end
end
end
if(joints[1+target]['0']==nil) then
joints[1+target]['0'] = {}
else
stro = "the ones: "
for i,jo in pairs(joints[1+target]['0'])do
stro = stro.."; "..i..":"..jo
end
end
stro = "nil: "
for i,v in pairs(JOINTS) do
if joints[1+target]['0'][""..v] == nil then
joints[1+target]['0'][""..v] = 4
stro = stro.."; "..i..":"..v
end
end
echo(stro)
start_new_game()
end
end
return 1
end
function update()
worldstate = get_world_state()
currentFrame = worldstate["match_frame"]
for tp = 0,1 do
for i,jo in pairs(joints[1+tp])do
kino = i-currentFrame
if kino == 0 then
echJoint = ""
for j,v in pairs(jo)do
echJoint = echJoint.."; "..j.." : "..v
set_joint_state( tp, j, v )
end
end
end
for fr, g in pairs(lgrip[1+tp]) do
kino = fr - currentFrame
if kino == 0 then
set_grip_info( tp, 12, g )
echo("LGRIP: "..g)
end
end
for fr, g in pairs(rgrip[1+tp]) do
kino = fr - currentFrame
if kino == 0 then
set_grip_info( tp, 11, g )
echo("RGRIP: "..g)
end
end
end
end
function startUke()
for tp = 0,1 do
swt = "lgrip"..tp..": "
for fr, g in pairs(lgrip[1+tp]) do
swt = swt..fr..": "..g.." "
end
swt = swt.." <<<"
swt = "rgrip"..tp..": "
for fr, g in pairs(rgrip[1+tp]) do
swt = swt..fr..": "..g.." "
end
swt = swt.." <<<"
end
update()
end
function whichJoint( which, whichJoint )
if whichJoint ~= -1 then
jinfo = get_joint_info(which, whichJoint)
echo("joint--> playa: "..which.." joint: "..whichJoint.." name: "..jinfo['name'] .. " state: "..jinfo['state'].. " screen name: "..jinfo['screen_state'])
end
end
add_hook("console", "console", console)
add_hook("enter_freeze","enter_freeze",update)
add_hook("new_game", "new_game", startUke)
add_hook("joint_select", "joint_select", whichJoint)