function luaLFS:small(reqi, subt, uval)
local omsg = bpack("bbbbL", 8, IS[B]P[/B]_SMALL, reqi, subt, uval)
luaLFS.sendmsg(omsg, string.len(omsg))
end
--------------
function luaLFS:mod(sixteenbit, refresh, width, height)
local omsg = bpack("bbbbllll", 20, IS[B]P[/B]_MOD, 0, 0, sixteenbit, refresh, width, height)
luaLFS.sendmsg(omsg, string.len(omsg))
end
function vectors(x1,y1,x2,y2,x3,y3,x4,y4, xa,ya)
local s = math.abs(1/2*((x1-x3)*(y2-y3)-(x2-x3)*(y1-y3))) + math.abs(1/2*((x3-x1)*(y4-y1)-(x4-x1)*(y3-y1)))
local sa = math.abs(1/2*((x1-xa)*(y2-ya)-(x2-xa)*(y1-ya))) + math.abs(1/2*((x2-xa)*(y3-ya)-(x3-xa)*(y2-ya))) + math.abs(1/2*((x3-xa)*(y4-ya)-(x4-xa)*(y3-ya))) + math.abs(1/2*((x4-xa)*(y1-ya)-(x1-xa)*(y4-ya)))
if (s ~= sa) then
return false
elseif (s == sa) then
return true
end
end
-- CAMERA CONTROL
-- XXX: Needs to be finished
function luaLFS:cpp(...)
if (table.maxn(arg) == 1) then
local n, psize, pty, reqi, zero, x, y, z, h, p, r, viewplid, ingamecam, fov, time, flags = bunpack(arg[1], "bbbblllHHHbbfHH")
return { x = x, y = y, z = z, h = h, p = p, r = r, viewplid = viewplid, ingamecam = ingamecam, fov = fov, time = time, flags = flags }
end
end
function l_init(imsg)
luaLFS:small(0, SMALL_NLI, 1000)
luaLFS:tiny(1, TINY_NPL)
end
evt_bind(EVT_CONNECTED, l_init)
function ttest(imsg)
print("ok")
local cpp = luaLFS:cpp(imsg)
luaLFS:btn(1, 255, 1, 0, 0, 0, 172, 15, 28, 10, "PLID="..cpp.viewplid)
luaLFS:btn(2, 255, 1, 0, 0, 0, 172, 25, 28, 10, "X="..cpp.x)
luaLFS:btn(3, 255, 1, 0, 0, 0, 172, 35, 28, 10, "Y="..cpp.y)
luaLFS:btn(4, 255, 1, 0, 0, 0, 172, 45, 28, 10, "Z="..cpp.z)
luaLFS:btn(5, 255, 1, 0, 0, 0, 172, 55, 28, 10, "H="..cpp.h)
luaLFS:btn(6, 255, 1, 0, 0, 0, 172, 65, 28, 10, "P="..cpp.p)
luaLFS:btn(7, 255, 1, 0, 0, 0, 172, 75, 28, 10, "R="..cpp.r)
luaLFS:btn(8, 255, 1, 0, 0, 0, 172, 85, 28, 10, "FOV="..cpp.fov)
luaLFS:btn(9, 255, 1, 0, 0, 0, 172, 95, 28, 10, "Time="..cpp.time)
end
evt_bind(ISP_CPP, ttest)
function tre(imsg)
luaLFS:tiny(1, TINY_SCP)
end
evt_bind(ISP_MCI, tre)
function scroll_line(imsg)
luaLFS.sleep(3)
local i
local str = "^2TEST ^8Scroll Line For Info"
for i = 1, 200, 1 do
luaLFS:btn(1, 255, 1, 0, 32, 0, 0, 100, i, 10, str)
luaLFS.sleep(0.0001)
end
luaLFS.sleep(5)
for i = 200, 1, -1 do
luaLFS:btn(1, 255, 1, 0, 32, 0, 200-i, 100, i, 10, str)
luaLFS.sleep(0.0001)
end
luaLFS:bfn(0, 255, 1, 0)
end
evt_bind(EVT_CONNECTED, scroll_line)
function luaLFS:mci(imsg)
local n, psize, pty, reqi, numc = bunpack(imsg, "bbbb")
local q, compcararr = bunpack(imsg, "A"..28*numc, n)
local compcar = { }
local i, s
s = 1
for i = 1, numc do
local node, lap, plid, position, info, sp3, x, y, z, speed, direction, heading, angvel
s, node, lap, plid, position, info, sp3, x, y, z, speed, direction, heading, angvel = bunpack(compcararr, "HHbbbblllHHHh", s)
compcar[plid] = { node = node, lap = lap, position = position, info = info, x = x, y = y, z = z, speed = speed, direction = direction, heading = heading, angvel = angvel }
end
return { numc = numc, compcar = compcar }
end
function luaLFS:mci(imsg)
-- print("Parsing MCI")
-- local n, psize, pty, reqi, numc, compcar = bunpack(imsg, "bbbb A?")
local n, psize, pty, reqi, numc = bunpack(imsg, "bbbb")
imsg = string.sub(imsg, 5)
-- ALWAYS string.len(imsg)/28 == numC ??????
---------------------------------------------
local i
local compcar = {}
for i = 1, string.len(imsg)/28 do
local n, node, lap, plid, position, info, sp3, x, y, z, speed, direction, heading, angvel = bunpack(imsg, "HHbbbblllHHHh")
compcar[plid] = { node = node, lap = lap, position = position, info = info, x = x, y = y, z = z, speed = speed, direction = direction, heading = heading, angvel = angvel }
imsg = string.sub(imsg, 29)
end
-- print("MCI parsed")
return { compcar = compcar }
end
local mci = luaLFS:mci(imsg)
...
[I]plid[/I] = ...
print(mci.compcar[[i]plid[/i]].node)