Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- chess tournament board 24/7 for up to 10 players. AntiGrief protection
- boards = {'d6d31d','29986b','350b4c','ce9240','46214c'} -- 5 big chess boards !!! keep rotation: 1,3,5 black-white; 2,4 white-black
- c_boards = {'a57fa0','3d9229','5bb8d4','904854','643c97'} -- 5 control boards
- clocks = {{'f6aacc','288fdc'},{'efc50a','700748'},{'e20ad0','e8f20b'},{'46f159','9fd6e1'},{'e95d30','788f0c'}} -- 2 clocks per board
- zones = {'cf272b','0bad24','3e111d','2219c3','e2619c'}
- play_zones = {'474235','4623c7','ebca8f','c8f47f','461759'}
- colors = {'Teal','Green', 'Orange','Red', 'Brown','Yellow', 'Blue','Purple', 'White','Pink'} -- 2 players per board
- turn_markers = {'d96edd','e9262a','94abbc','e738ff','c14ed3'}
- basic_timer = 300
- chess_pos = {{},{},{},{},{}}
- chess_guids = {{},{},{},{},{}}
- -- ================================================================
- function onload() -- spawn select timer buttons, disable boards and clocks
- for i=1,#boards,1 do -- 5
- getObjectFromGUID(boards[i]).interactable = false
- getObjectFromGUID(c_boards[i]).interactable = false
- getObjectFromGUID(clocks[i][1]).interactable = false
- getObjectFromGUID(clocks[i][2]).interactable = false
- getObjectFromGUID(turn_markers[i]).interactable = false
- local z = getObjectFromGUID(zones[i]).getObjects() -- save chess positions in case of reset
- for j, k in ipairs(z) do
- chess_pos[i][j] = k.getPosition()
- chess_guids[i][j] = k.getGUID()
- set_script(chess_guids[i][j],i) -- make players not able to interact with chess on different board
- k.lock()
- k.interactable = false
- end
- spawn_pre_buttons(i) -- spawn select timer: 5,10,15.. mins. i= board
- end
- end
- function set_script(x,n) -- chess protection
- local a = colors[n*2-1]
- local b = colors[n*2]
- local temp = 'pos = {} \nvel = {} \nang = {}'
- temp = temp .. '\nfunction onPickedUp(player_color) \nif player_color ~= \''..a..'\' and player_color ~= \''..b..'\' then \npos = self.getPosition() \nrot = self.getRotation() \n\nself.use_snap_points = false \nend \nend \n'
- temp = temp .. '\nfunction onDropped(player_color) \nif player_color ~= \''..a..'\' and player_color ~= \''..b..'\' then \nself.setPosition(pos) \nself.setRotation({0,0,0}) \nang = self.getAngularVelocity() \nvel = self.getVelocity() \nself.addTorque({-ang[\'x\'],-ang[\'y\'],-ang[\'z\']}, 4) \nself.addForce({-vel[\'x\'],-vel[\'y\'],-vel[\'z\']}, 4) \nend \nself.use_snap_points = true \nend'
- getObjectFromGUID(x).setLuaScript(temp)
- --getObjectFromGUID(x).setLuaScript('') -- debug
- end
- -- ================================================================
- -- select time for board related clocks
- function spawn_pre_buttons(x) -- x = board (1-5)
- set_timer(x,basic_timer) -- in case of restart
- getObjectFromGUID(c_boards[x]).clearButtons()
- local buttonParam = {['click_function'] = 'none', ['label'] = 'Set clock timer', ['function_owner'] = self, ['position'] = {0, 0.1, -1}, ['rotation'] = {0, 0, 0}, ['width'] = 1200, ['height'] = 200, ['font_size'] = 150}
- getObjectFromGUID(c_boards[x]).createButton(buttonParam)
- for i=1,6,1 do -- spawn select timer buttons on board x
- local buttonParam = {['click_function'] = 'timer'..i, ['label'] = (5*i)..'m', ['function_owner'] = self, ['position'] = {0.6*((-1)^i), 0.1, -0.4+0.5*math.floor((i-1)/2)}, ['rotation'] = {0, 0, 0}, ['width'] = 500, ['height'] = 200, ['font_size'] = 150}
- getObjectFromGUID(c_boards[x]).createButton(buttonParam)
- end
- local buttonParam = {['click_function'] = 'timer7', ['label'] = '60m!', ['function_owner'] = self, ['position'] = {0, 0.1, -0.4+0.5*3}, ['rotation'] = {0, 0, 0}, ['width'] = 500, ['height'] = 200, ['font_size'] = 150}
- getObjectFromGUID(c_boards[x]).createButton(buttonParam)
- end
- function timer1(obj, player) -- c_board and player color
- local t = 300
- timer_supp(obj.getGUID(), player, t)
- end
- function timer2(obj, player)
- local t = 600
- timer_supp(obj.getGUID(), player, t)
- end
- function timer3(obj, player)
- local t = 900
- timer_supp(obj.getGUID(), player, t)
- end
- function timer4(obj, player)
- local t = 1200
- timer_supp(obj.getGUID(), player, t)
- end
- function timer5(obj, player)
- local t = 1500
- timer_supp(obj.getGUID(), player, t)
- end
- function timer6(obj, player)
- local t = 1800
- timer_supp(obj.getGUID(), player, t)
- end
- function timer7(obj, player)
- local t = 3600
- timer_supp(obj.getGUID(), player, t)
- end
- -- allows to keep 7 timer functions instead of 35 (7 x5 boards)
- function timer_supp(obj_guid, player, t) -- c_board_guid color timer_time
- local succ, temp_n = protection(obj_guid, player)
- if succ == 0 then
- return
- end
- spawn_ready(temp_n)
- set_timer(temp_n, t)
- spawn_buttons(temp_n)
- spawn_reset_buttons(temp_n,0)
- end
- function set_timer(x,y)
- getObjectFromGUID(clocks[x][1]).Clock.setValue(y)
- getObjectFromGUID(clocks[x][2]).Clock.setValue(y)
- end
- -- ================================================================
- function protection(obj_guid,player)
- for q,w in ipairs(colors) do -- 10
- if player == w then -- protection
- local temp_n = math.ceil(q/2) -- (1-5)
- if c_boards[temp_n] == obj_guid then
- return 1,temp_n,q -- protection passed
- end
- break
- end
- end
- printToColor('You\'r not allowed to access that board', player, {1,1,1})
- return 0,0,0 -- 0 protection restriction
- end
- -- ================================================================
- function spawn_ready(x)
- local buttonParam = {['click_function'] = 'Ready', ['label'] = 'Ready?', ['function_owner'] = self, ['position'] = {0, 0.3, 6}, ['rotation'] = {0, 90, 0}, ['width'] = 1500, ['height'] = 300, ['font_size'] = 150}
- getObjectFromGUID(c_boards[x]).createButton(buttonParam)
- end
- function Ready(obj,player)
- local succ, temp_n = protection(obj.getGUID(), player)
- if succ == 0 then
- return
- end
- spawn_buttons(temp_n)
- spawn_reset_buttons(temp_n,0)
- spawn_pass_buttons(temp_n,1) -- White always goes first
- getObjectFromGUID(clocks[temp_n][1]).Clock.pauseStart()
- for i=1, #chess_guids[temp_n], 1 do
- if chess_guids[temp_n][i] ~= boards[temp_n] then
- getObjectFromGUID(chess_guids[temp_n][i]).unlock()
- getObjectFromGUID(chess_guids[temp_n][i]).interactable = true
- end
- end
- end
- -- ================================================================
- function spawn_buttons(x) -- x 1-5
- getObjectFromGUID(c_boards[x]).clearButtons()
- local buttonParam = {['click_function'] = 'none', ['label'] = 'Reset board?', ['function_owner'] = self, ['position'] = {0, 0.1, -1}, ['rotation'] = {0, 0, 0}, ['width'] = 1200, ['height'] = 200, ['font_size'] = 150}
- getObjectFromGUID(c_boards[x]).createButton(buttonParam)
- end
- function spawn_pass_buttons(x)
- local q = 1
- if getObjectFromGUID(clocks[x][2]).Clock.paused == false then
- q = 2
- end
- local buttonParam = {['click_function'] = 'Pass', ['label'] = 'Pass your Turn', ['function_owner'] = self, ['position'] = {4*((-1)^q), 0.3, 6}, ['rotation'] = {0, -90*((-1)^q), 0}, ['width'] = 1500, ['height'] = 300, ['font_size'] = 150}
- getObjectFromGUID(c_boards[x]).createButton(buttonParam)
- end
- function spawn_reset_buttons(x,w)
- if w == 0 then
- local buttonParam = {['click_function'] = 'Reset1', ['label'] = 'ask to\nRestart', ['function_owner'] = self, ['position'] = {-0.8, 0.1, 0.2}, ['rotation'] = {0, 90, 0}, ['width'] = 800, ['height'] = 300, ['font_size'] = 120}
- getObjectFromGUID(c_boards[x]).createButton(buttonParam)
- local buttonParam = {['click_function'] = 'Reset1', ['label'] = 'ask to\nRestart', ['function_owner'] = self, ['position'] = {0.8, 0.1, 0.2}, ['rotation'] = {0, -90, 0}, ['width'] = 800, ['height'] = 300, ['font_size'] = 120}
- getObjectFromGUID(c_boards[x]).createButton(buttonParam)
- elseif w == 1 then
- local buttonParam = {['click_function'] = 'Reset2', ['label'] = 'do you agree\nto Restart?', ['function_owner'] = self, ['position'] = {-0.8, 0.1, 0.2}, ['rotation'] = {0, 90, 0}, ['width'] = 800, ['height'] = 300, ['font_size'] = 120}
- getObjectFromGUID(c_boards[x]).createButton(buttonParam)
- else
- local buttonParam = {['click_function'] = 'Reset2', ['label'] = 'do you agree\nto Restart?', ['function_owner'] = self, ['position'] = {0.8, 0.1, 0.2}, ['rotation'] = {0, -90, 0}, ['width'] = 800, ['height'] = 300, ['font_size'] = 120}
- getObjectFromGUID(c_boards[x]).createButton(buttonParam)
- end
- end
- -- ================================================================
- function Pass(obj,player)
- local succ, temp_n, q = protection(obj.getGUID(), player)
- if succ == 0 then
- return
- end
- getObjectFromGUID(clocks[temp_n][1]).Clock.pauseStart()
- getObjectFromGUID(clocks[temp_n][2]).Clock.pauseStart()
- spawn_buttons(temp_n)
- spawn_pass_buttons(temp_n)
- spawn_reset_buttons(temp_n,0)
- flip_turn_marker(1,temp_n)
- end
- function flip_turn_marker(s,temp_n)
- local tempy = {}
- if s == 1 then
- tempy = getObjectFromGUID(turn_markers[temp_n]).getRotation()
- tempy['z'] = math.abs(tempy['z']) - 180
- getObjectFromGUID(turn_markers[temp_n]).setRotation(tempy)
- else
- tempy = getObjectFromGUID(turn_markers[temp_n]).getRotation()
- tempy['z'] = 0
- getObjectFromGUID(turn_markers[temp_n]).setRotation(tempy)
- end
- end
- -- ================================================================
- function Reset1(obj,player)
- local succ, temp_n,q = protection(obj.getGUID(), player)
- if succ == 0 then
- return
- end
- if Player[colors[q-1+2*(q%2)]].seated == true then
- spawn_buttons(temp_n)
- if getObjectFromGUID(clocks[temp_n][2]).Clock.paused == true then -- in case game did'nt start
- spawn_pass_buttons(temp_n,1)
- else
- spawn_pass_buttons(temp_n,2)
- end
- spawn_reset_buttons(temp_n,q%2+1)
- else
- getObjectFromGUID(c_boards[temp_n]).clearButtons()
- spawn_pre_buttons(temp_n)
- reset_chess(temp_n)
- end
- end
- function Reset2(obj,player)
- local succ, temp_n,q = protection(obj.getGUID(), player)
- if succ == 0 then
- return
- end
- getObjectFromGUID(c_boards[temp_n]).clearButtons()
- spawn_pre_buttons(temp_n)
- reset_chess(temp_n)
- end
- function reset_chess(temp_n)
- for i=1, #chess_guids[temp_n], 1 do
- local z = getObjectFromGUID(chess_guids[temp_n][i])
- z.setPosition(chess_pos[temp_n][i])
- z.setRotation({0,0,0})
- z.lock()
- z.interactable = false
- end
- flip_turn_marker(0,temp_n)
- end
- -- ================================================================
- -- special event tracker
- function onObjectLeaveScriptingZone(zone, leave_obj)
- for i=1, #play_zones, 1 do
- if play_zones[i] == zone.getGUID() then
- for j=1,#chess_guids[i],1 do
- if chess_guids[i][j] == leave_obj.getGUID() then
- local offset = 15.8 -- to get rid of linking coords
- if leave_obj.getDescription() == 'White' then
- leave_obj.setPosition({chess_pos[i][j]['x'] +offset*((-1)^i), chess_pos[i][j]['y'], chess_pos[i][j]['z']})
- else
- leave_obj.setPosition({chess_pos[i][j]['x'] -offset*((-1)^i), chess_pos[i][j]['y'], chess_pos[i][j]['z']})
- end
- leave_obj.setRotation({0,0,0})
- local ang = leave_obj.getAngularVelocity()
- local vel = leave_obj.getVelocity()
- leave_obj.addTorque({-ang['x'],-ang['y'],-ang['z']}, 4)
- leave_obj.addForce({-vel['x'],-vel['y'],-vel['z']}, 4)
- break
- end
- end
- break
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement