Updated lobby buttons.

master
Nathan Salapat 2022-01-09 15:43:56 -06:00
parent a1c79a2531
commit aea0c291bd
5 changed files with 46 additions and 37 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -1,6 +1,16 @@
local esc = minetest.formspec_escape
local function button_create(id, name, player_count, xp, pos, desc)
local function random_pos()
local pos_x = math.random(-30000,30000)
local pos_y = math.random(-100,30000)
local pos_z = math.random(-30000,30000)
local pos = (pos_x..','..pos_y..','..pos_z)
return pos
end
local function button_create(id, name, player_count, xp, pos_string, desc)
local pos = minetest.string_to_pos(pos_string)
local clean_pos = pos.x..','..pos.y..','..pos.z
local formspec =
'formspec_version[3]'..
'size[12,8.5]'..
@ -8,7 +18,7 @@ local function button_create(id, name, player_count, xp, pos, desc)
'field[6,1;5,.5;name;Map Name;'..esc(name)..']'..
'field[0.5,2;3,.5;player_count;Required # of Players;'..esc(player_count)..']'..
'field[4,2;3,.5;xp;Required XP;'..esc(xp)..']'..
'field[7.5,2;3,.5;pos;Spawn POS (x,y,z);'..esc(pos)..']'..
'field[7.5,2;3,.5;pos;Spawn POS (x,y,z);'..esc(clean_pos)..']'..
'textarea[0.5,3;10,3.5;desc;Description of map;'..esc(desc)..']'..
'button_exit[3,7;2,1;save;Submit]'..
'button_exit[6,7;2,1;discard;Unclaim]'
@ -69,26 +79,9 @@ minetest.register_node('lobby:button_0', {
local meta = minetest.get_meta(pos)
local owner = meta:get_string('owner')
local loc = meta:get_string('pos')
local pos = minetest.string_to_pos(loc)
if puncher:get_player_name() == owner then
if loc == '' then
local pos_x = math.random(-30000,30000)
local pos_y = math.random(-100,30000)
local pos_z = math.random(-30000,30000)
local pos = {x = pos_x, y = pos_y, z = pos_z}
if not minetest.is_protected(pos, puncher) then
minetest.load_area(pos)
worldedit.cube(pos, 5, 1, 5, 'levels:floor_white', false)
meta:set_string('pos', pos_x..','..pos_y..','..pos_z)
puncher:set_pos({x = pos_x, y = pos_y+2, z = pos_z})
minetest.set_node(pos, {name = 'lights:block_4'})
end
else
local x, y, z = string.match(loc, "^(-?%d+),(-?%d+),(-?%d+)$")
local pos_x = tonumber(x)
local pos_y = tonumber(y)
local pos_z = tonumber(z)
puncher:set_pos({x = pos_x, y = pos_y+2, z = pos_z})
end
puncher:set_pos(pos)
end
end,
on_receive_fields = function(pos, formname, fields, sender)
@ -98,6 +91,19 @@ minetest.register_node('lobby:button_0', {
if fields ['claim'] then
if lobby.take_xp(sender, 15) then
meta:set_string('owner', player_name)
local pos_string = random_pos()
local pos = minetest.string_to_pos(pos_string)
local run = true
while run do
if not minetest.is_protected(pos, sender) and run then
minetest.load_area(pos)
meta:set_string('pos', pos_string)
--print(dump(pos))
worldedit.cube(pos, 5, 1, 5, 'color:grey_blocks', false)
minetest.set_node(pos, {name = 'lights:block_4'})
run = false
end
end
else
minetest.chat_send_player(player_name, 'You need more XP!')
end
@ -138,6 +144,7 @@ minetest.register_node('lobby:button_0', {
local data = {}
data.level_pos = {x = pos_x, y = pos_y+2, z = pos_z}
data.xp = tonumber(fields.xp)
data.map_name = fields.name
lobby.savedata.IDs[map_id] = true
lobby.savedata.data[map_id] = data
minetest.swap_node(pos, {name = 'lobby:button_1'})
@ -189,9 +196,9 @@ minetest.register_node('lobby:button_1', {
local map_id = meta:get_string('id')
local game_data = lobby.savedata.data[map_id]
local game_pos = game_data['level_pos']
if minetest.check_player_privs(puncher:get_player_name(), { creative = true }) and puncher:get_player_control().sneak then -- change to owner
if minetest.check_player_privs(puncher:get_player_name(), { creative = true }) and puncher:get_player_control().sneak then
puncher:set_pos({x=game_pos.x+(math.random(-2,2)),y=game_pos.y,z=game_pos.z+(math.random(-2,2))})
minetest.chat_send_player(puncher:get_player_name(), 'Taking you to the level.')
minetest.chat_send_player(puncher:get_player_name(), 'Taking you to the level. Return to the lobby with /spawn')
else
local needed_players = tonumber(meta:get_string('player_count')) or 8
local objs = minetest.get_objects_inside_radius(pos, 3)
@ -236,7 +243,6 @@ minetest.register_node('lobby:button_1', {
privs.fly = nil
privs.fast = nil
privs.creative = nil
privs.worldedit = nil
privs.areas = nil
minetest.set_player_privs(map_players[i], privs)
end

View File

@ -175,7 +175,9 @@ function lobby.team_win(map_id)
end
end
lobby.map[map_id] = 0
minetest.chat_send_all('The traitor was defeated on this round in the '..map_id)
local game_data = lobby.savedata.data[map_id]
local map_name = game_data['map_name'] or map_name
minetest.chat_send_all('The traitor was defeated on this round in the '..map_name)
end
function lobby.traitor_win(traitor, map_id)
@ -208,4 +210,7 @@ function lobby.traitor_win(traitor, map_id)
lobby.game[rname] = 'lobby'
end
end
local game_data = lobby.savedata.data[map_id]
local map_name = game_data['map_name'] or map_name
minetest.chat_send_all('The traitor was victorious on this round in the '..map_name)
end

View File

@ -36,12 +36,12 @@ dofile(minetest.get_modpath('lobby')..'/player_callbacks.lua')
dofile(minetest.get_modpath('lobby')..'/shop.lua')
dofile(minetest.get_modpath('lobby')..'/tool.lua')
minetest.register_privilege("pro_player",
{description = "Completed the tutorial.",
minetest.register_privilege("pro_player", {
description = "Completed the tutorial.",
give_to_singleplayer = false})
minetest.register_privilege("builder",
{description = "Can build levels",
minetest.register_privilege("builder", {
description = "Can build levels",
give_to_singleplayer = false})
lobby.load()

View File

@ -101,18 +101,16 @@ end)
minetest.register_on_leaveplayer(function(player, timed_out)
local name = player:get_player_name()
local map_id = lobby.game[name]
if map_id ~= 'lobby' then
print (name..' left the '..map_id.. ' level')
print (map_id)
if map_id ~= 'lobby' and not string.find(map_id, 'ghost') then
local game_data = lobby.savedata.data[map_id]
local map_name = game_data['map_name'] or map_id
local traitor = lobby.traitors[map_id]
minetest.chat_send_all('somebody quit the '..map_id..' level')
minetest.chat_send_all('somebody quit the '..map_name..' level')
local player_inv = player:get_inventory()
player_inv:set_list('main', {})
if not string.find(map_id, 'ghost') then
print ('player was not a ghost, updaing map, '..map_id)
lobby.update_maps(map_id)
end
lobby.update_maps(map_id)
if traitor == name then
print ('player was the traitor on '..map_id..' team wins the round.')
lobby.team_win(map_id)
end
end