More fancy stuff. Better voting.
This commit is contained in:
parent
bd7ab9dcd6
commit
86d184c1bd
210
init.lua
210
init.lua
|
@ -41,33 +41,47 @@ end
|
|||
function ctf.spawn(name,pos,call)
|
||||
local ref = minetest.get_player_by_name(name)
|
||||
ref:set_pos(TELEPORT_ROOM)
|
||||
local n = math.random()
|
||||
local pl = ctf.players[name]
|
||||
if pl.transid then
|
||||
minetest.chat_send_player("<TELEPORT> Cancelling previous transportation")
|
||||
end
|
||||
pl.transid = n
|
||||
pos = {x=f(pos.x),y=f(pos.y),z=f(pos.z)}
|
||||
call = call or function()end
|
||||
local limit = SPAWNFALL_LIMIT
|
||||
minetest.chat_send_player(name,"<TELEPORT> Configuring transportation processor...")
|
||||
minetest.emerge_area({x=pos.x,y=pos.y-limit,z=pos.z},{x=pos.x,y=pos.y+limit,z=pos.z},function(bp,act,crem)
|
||||
if crem > 0 then return end
|
||||
minetest.chat_send_player(name,"<TELEPORT> Done. Sending transport coordinates...")
|
||||
local off = 0
|
||||
while off > -limit do
|
||||
if minetest.get_node({x=pos.x,y=pos.y+off,z=pos.z}).name ~= "air" then
|
||||
minetest.after(30,function()
|
||||
minetest.emerge_area({x=pos.x,y=pos.y-limit,z=pos.z},{x=pos.x,y=pos.y+limit,z=pos.z},function(bp,act,crem)
|
||||
if crem > 0 then return end
|
||||
pl = ctf.players[name]
|
||||
if not pl then return end
|
||||
if pl.transid ~= n then
|
||||
return
|
||||
end
|
||||
pl.transid = nil
|
||||
minetest.chat_send_player(name,"<TELEPORT> Done. Sending transport coordinates...")
|
||||
local off = 0
|
||||
while off > -limit do
|
||||
if minetest.get_node({x=pos.x,y=pos.y+off,z=pos.z}).name ~= "air" then
|
||||
off = off + 1
|
||||
break
|
||||
end
|
||||
off = off - 1
|
||||
end
|
||||
while off < limit do
|
||||
if minetest.get_node({x=pos.x,y=pos.y+off,z=pos.z}).name == "air" then
|
||||
break
|
||||
end
|
||||
off = off + 1
|
||||
break
|
||||
end
|
||||
off = off - 1
|
||||
end
|
||||
while off < limit do
|
||||
if minetest.get_node({x=pos.x,y=pos.y+off,z=pos.z}).name == "air" then
|
||||
break
|
||||
local apos = {x=pos.x,y=pos.y+off,z=pos.z}
|
||||
local ref = minetest.get_player_by_name(name)
|
||||
if ref then
|
||||
ref:set_pos(apos)
|
||||
call(ref,apos)
|
||||
end
|
||||
off = off + 1
|
||||
end
|
||||
local apos = {x=pos.x,y=pos.y+off,z=pos.z}
|
||||
local ref = minetest.get_player_by_name(name)
|
||||
if ref then
|
||||
ref:set_pos(apos)
|
||||
call(ref,apos)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
|
@ -90,16 +104,31 @@ minetest.register_on_chat_message(function(name, message)
|
|||
end)
|
||||
|
||||
minetest.register_chatcommand("vote",{
|
||||
desc = "Vote to end the game",
|
||||
privs = {interact = true},
|
||||
desc = "Vote to do things",
|
||||
func = function(name,param)
|
||||
if ctf.ended then
|
||||
minetest.chat_send_player(name,"<DEMOCRACY> Nothing to vote for")
|
||||
return
|
||||
end
|
||||
if not ctf.started and ctf.player_count < 2 then
|
||||
minetest.chat_send_player(name,"<DEMOCRACY> Not enough players")
|
||||
return
|
||||
end
|
||||
local pl = ctf.players[name]
|
||||
pl.voted = not pl.voted
|
||||
ctf.voted_count = pl.voted and (ctf.voted_count+1) or (ctf.voted_count-1)
|
||||
if pl.voted then
|
||||
minetest.chat_send_player(name,"You vote to end the game")
|
||||
if ctf.started then
|
||||
if pl.voted then
|
||||
minetest.chat_send_player(name,"<DEMOCRACY> You vote to end the game")
|
||||
else
|
||||
minetest.chat_send_player(name,"<DEMOCRACY> You vote to NOT end the game")
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(name,"You vote to NOT end the game")
|
||||
if pl.voted then
|
||||
minetest.chat_send_player(name,"<DEMOCRACY> You vote to start the game")
|
||||
else
|
||||
minetest.chat_send_player(name,"<DEMOCRACY> You vote to NOT start the game")
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
@ -108,6 +137,8 @@ include("node")
|
|||
ctf.crystals(teams)
|
||||
|
||||
local bar_c = minetest.get_content_id(modname..":barrier")
|
||||
local hbar_c = minetest.get_content_id(modname..":barrier_hole")
|
||||
local tbar_c = minetest.get_content_id(modname..":telebarrier")
|
||||
local air_c = minetest.get_content_id("air")
|
||||
|
||||
local abs = math.abs
|
||||
|
@ -116,15 +147,15 @@ local function distance(a,b)
|
|||
end
|
||||
|
||||
minetest.register_on_generated(function(minp,maxp,seed)
|
||||
if vector.distance(TELEPORT_ROOM,vector.divide(vector.add(minp,maxp),2)) < 2000 then
|
||||
local vm,mip,map = minetest.get_mapgen_object("voxelmanip")
|
||||
local ar = VoxelArea:new{MinEdge=mip,MaxEdge=map}
|
||||
local d = vm:get_data()
|
||||
local vm,mip,map = minetest.get_mapgen_object("voxelmanip")
|
||||
local d = vm:get_data()
|
||||
local ar = VoxelArea:new{MinEdge=mip,MaxEdge=map}
|
||||
if vector.distance(TELEPORT_ROOM,vector.divide(vector.add(minp,maxp),2)) < 4000 then
|
||||
for x=minp.x,maxp.x do
|
||||
for y=minp.y,maxp.y do
|
||||
for z=minp.z,maxp.z do
|
||||
local i = ar:index(x,y,z)
|
||||
if vector.distance({x=x,y=y,z=z},TELEPORT_ROOM) > math.random(8,10) then
|
||||
if vector.distance({x=x,y=y,z=z},TELEPORT_ROOM) > 12 then
|
||||
d[i] = bar_c
|
||||
else
|
||||
d[i] = air_c
|
||||
|
@ -132,25 +163,42 @@ minetest.register_on_generated(function(minp,maxp,seed)
|
|||
end
|
||||
end
|
||||
end
|
||||
vm:set_data(d)
|
||||
vm:write_to_map()
|
||||
for x=minp.x,maxp.x do
|
||||
for y=minp.y,maxp.y do
|
||||
for z=minp.z,maxp.z do
|
||||
local i = ar:index(x,y,z)
|
||||
local c = false
|
||||
for x1=x-1,x+1 do
|
||||
for y1=y-1,y+1 do
|
||||
for z1=z-1,z+1 do
|
||||
if ar:contains(x1,y1,z1) and d[ar:index(x1,y1,z1)] == air_c then
|
||||
if d[i] == bar_c then
|
||||
d[i] = (x%3 == 0 or y%3 == 0 or z%3 == 0) and tbar_c or bar_c
|
||||
c=true
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if distance(vector.divide(vector.add(minp,maxp),2),ctf.spawnpoint) > FIELD_RADIUS then
|
||||
local vm,mip,map = minetest.get_mapgen_object("voxelmanip")
|
||||
local ar = VoxelArea:new{MinEdge=mip,MaxEdge=map}
|
||||
local d = vm:get_data()
|
||||
for x=minp.x,maxp.x do
|
||||
for y=minp.y,maxp.y do
|
||||
for z=minp.z,maxp.z do
|
||||
local i = ar:index(x,y,z)
|
||||
d[i] = bar_c
|
||||
d[i] = math.random(3) == 1 and hbar_c or bar_c
|
||||
end
|
||||
end
|
||||
end
|
||||
vm:set_data(d)
|
||||
vm:write_to_map()
|
||||
end
|
||||
end
|
||||
vm:set_data(d)
|
||||
vm:calc_lighting()
|
||||
vm:write_to_map(false)
|
||||
end)
|
||||
|
||||
function ctf.set_team_text(name)
|
||||
|
@ -158,7 +206,7 @@ function ctf.set_team_text(name)
|
|||
assert(pl)
|
||||
local team = teams[pl.team]
|
||||
print(pl.team,team)
|
||||
ctf.set_text(name,"You're member of "..tostring(team.desc).." team\n",team.colornum)
|
||||
ctf.set_text(name,"You're member of "..tostring(team.desc).." team\n/vote to end the game",team.colornum)
|
||||
end
|
||||
|
||||
function ctf.join(team,name)
|
||||
|
@ -190,7 +238,7 @@ minetest.register_on_joinplayer(function(ref)
|
|||
local name = ref:get_player_name()
|
||||
local id = ref:hud_add{
|
||||
name = "stat",
|
||||
text = "Game is not started yet\nWaiting for more players to begin",
|
||||
text = "Game is not started yet\n/vote to start the game",
|
||||
number = 0xFFFFFF,
|
||||
alignment = {x=-1,y=1},
|
||||
offset = {x=-20,y=20},
|
||||
|
@ -270,23 +318,31 @@ do
|
|||
end
|
||||
|
||||
function ctf.start()
|
||||
if ctf.starting == math.huge or ctf.starting == -math.huge then
|
||||
if ctf.starting and (ctf.voted_count/ctf.player_count) < 0.5 then
|
||||
minetest.chat_send_all("<INFO + DEMOCRACY> Aborting")
|
||||
ctf.starting = -math.huge
|
||||
return
|
||||
end
|
||||
if ctf.started or ctf.ended then
|
||||
return
|
||||
end
|
||||
for k,v in pairs(ctf.players) do
|
||||
if v.voted then
|
||||
v.voted = false
|
||||
ctf.voted_count = ctf.voted_count - 1
|
||||
end
|
||||
end
|
||||
ctf.ended = false
|
||||
local tc = math.max(2,math.floor(ctf.player_count/PLAYERS_PER_TEAM))
|
||||
if ctf.player_count >= 2 and not ctf.starting then
|
||||
if ctf.player_count >= 2 and not ctf.starting and (ctf.voted_count/ctf.player_count) >= 0.5 then
|
||||
ctf.starting = minetest.get_server_uptime()+10
|
||||
minetest.chat_send_all("<INFO> Enough players are here! Starting in 10 seconds")
|
||||
minetest.chat_send_all("<INFO + DEMOCRACY> Most players are ready. Starting the game in 10...")
|
||||
do
|
||||
local n = 10
|
||||
local function f()
|
||||
if not ctf.starting or ctf.starting == -math.huge then ctf.starting = false return end
|
||||
local n2=math.ceil(ctf.starting-minetest.get_server_uptime())
|
||||
if n2 ~= n and n2 > 0 then
|
||||
n=n2
|
||||
minetest.chat_send_all("<INFO> "..n.."...")
|
||||
end
|
||||
if n2 > 0 then
|
||||
minetest.after(0.2,f)
|
||||
end
|
||||
end
|
||||
f()
|
||||
end
|
||||
elseif ctf.starting and not (ctf.player_count >= 2) then
|
||||
ctf.starting = false
|
||||
minetest.chat_send_all("<INFO> Not enough players now. Aborting.")
|
||||
|
@ -309,18 +365,18 @@ function ctf.start()
|
|||
ctf.set_team_text(name)
|
||||
end
|
||||
local z = SPAWN_DIST
|
||||
local pos = vector.add(SPAWNPOINT,{x=ur(z),y=0,z=ur(z)})
|
||||
ctf.spawnpoint = pos
|
||||
local pos = ctf.spawnpoint
|
||||
pos = vector.add(pos,SPAWN_OFFSET)
|
||||
local pc = 0
|
||||
local call = function(ref,pos)
|
||||
pc = pc + 1
|
||||
if pc < ctf.player_count then return end
|
||||
if ctf.starting == -math.huge then
|
||||
minetest.chat_send_all("<TELEPORT + INFO> SOMEONE LEFT DURING CONFIGURATION. ABORTING")
|
||||
if ctf.starting ~= math.huge then
|
||||
minetest.chat_send_all("<TELEPORT + INFO> SOMETHING HAPPENED. ABORTING")
|
||||
ctf.teams = {}
|
||||
for k,v in pairs(ctf.players) do
|
||||
v.team = nil
|
||||
ctf.set_text(k,"Game is not started yet\n/vote to start the game")
|
||||
end
|
||||
ctf.starting = false
|
||||
ctf.started = false
|
||||
|
@ -329,7 +385,16 @@ function ctf.start()
|
|||
end
|
||||
ctf.starting = false
|
||||
ctf.started = true
|
||||
for k,v in pairs(ctf.players) do
|
||||
if v.voted then
|
||||
v.voted = false
|
||||
ctf.voted_count = ctf.voted_count - 1
|
||||
end
|
||||
end
|
||||
minetest.chat_send_all("<INFO> The game begins!")
|
||||
for k,v in pairs(ctf.players) do
|
||||
ctf.explode_inv(minetest.get_player_by_name(k))
|
||||
end
|
||||
for tname,team in pairs(ctf.teams) do
|
||||
local crystals = CRYSTALS_PER_TEAM
|
||||
while crystals > 0 do
|
||||
|
@ -357,6 +422,7 @@ function ctf.start()
|
|||
local y = PLAYER_DIST
|
||||
local pos = vector.add(pos,{x=ur(y),y=0,z=ur(y)})
|
||||
local ref = minetest.get_player_by_name(name)
|
||||
ctf.explode_inv(minetest.get_player_by_name(name))
|
||||
ctf.spawn(name,pos,call)
|
||||
end
|
||||
end
|
||||
|
@ -367,6 +433,11 @@ do
|
|||
local f
|
||||
function f()
|
||||
minetest.emerge_area(vector.subtract(TELEPORT_ROOM,{x=20,y=20,z=20}),vector.add(TELEPORT_ROOM,{x=20,y=20,z=20}))
|
||||
if #minetest.get_connected_players() == 0 and not (ctf.started or ctf.ended or ctf.starting) then
|
||||
local z = SPAWN_DIST
|
||||
local pos = vector.add(SPAWNPOINT,{x=ur(z),y=0,z=ur(z)})
|
||||
ctf.spawnpoint = pos
|
||||
end
|
||||
minetest.after(5,f)
|
||||
end
|
||||
f()
|
||||
|
@ -396,13 +467,6 @@ do
|
|||
end
|
||||
if ctf.started and not ctf.ended then
|
||||
ctf.check_win()
|
||||
elseif ctf.voted_count > 0 then
|
||||
for k,v in pairs(ctf.players) do
|
||||
if v.voted then
|
||||
v.voted = false
|
||||
ctf.voted_count = ctf.voted_count - 1
|
||||
end
|
||||
end
|
||||
end
|
||||
minetest.after(1,f)
|
||||
end
|
||||
|
@ -433,14 +497,28 @@ function ctf.check_win()
|
|||
elseif vout then
|
||||
minetest.chat_send_all("<INFO> Majority of players voted to end the game")
|
||||
for k,v in pairs(ctf.players) do
|
||||
ctf.set_text(k,"Game is not started yet\nWaiting for more players to begin")
|
||||
ctf.set_text(k,"Game is not started yet\n/vote to start the game")
|
||||
end
|
||||
end
|
||||
minetest.chat_send_all("<INFO> The game is finished")
|
||||
ctf.teams = {}
|
||||
do
|
||||
local z = SPAWN_DIST
|
||||
local pos = vector.add(SPAWNPOINT,{x=ur(z),y=0,z=ur(z)})
|
||||
ctf.spawnpoint = pos
|
||||
end
|
||||
for k,v in pairs(ctf.players) do
|
||||
if v.voted then
|
||||
v.voted = false
|
||||
ctf.voted_count = ctf.voted_count - 1
|
||||
end
|
||||
v.team = nil
|
||||
end
|
||||
minetest.after(3,function()ctf.started = false ctf.ended = false end)
|
||||
ctf.explode_inv(minetest.get_player_by_name(k))
|
||||
ctf.spawn(k,vector.add(ctf.spawnpoint,SPAWN_OFFSET))
|
||||
end
|
||||
minetest.after(5,function()
|
||||
ctf.started = false
|
||||
ctf.ended = false
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
35
node.lua
35
node.lua
|
@ -1,6 +1,6 @@
|
|||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local nodecore
|
||||
= nodecore
|
||||
local nodecore, minetest
|
||||
= nodecore, minetest
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local modname = minetest.get_current_modname()
|
||||
|
@ -80,11 +80,34 @@ function ctf.crystals(teams)
|
|||
end
|
||||
end
|
||||
|
||||
minetest.register_node(modname..":barrier",{
|
||||
minetest.register_node(modname..":telebarrier",{
|
||||
light_source = 14,
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
drawtype="normal",
|
||||
tiles = {
|
||||
{name = "nc_ctf_telebarrier.png",
|
||||
animation={
|
||||
type = "vertical_frames",
|
||||
|
||||
aspect_w = 16,
|
||||
aspect_h = 16,
|
||||
|
||||
length = 0.25,
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_node(modname..":barrier_hole",{
|
||||
drawtype="normal",
|
||||
use_texture_alpha=true,
|
||||
tiles = {"nc_ctf_barrier_hole.png"},
|
||||
})
|
||||
|
||||
minetest.register_node(modname..":barrier",{
|
||||
light_source = 14,
|
||||
paramtype = "light",
|
||||
drawtype="normal",
|
||||
tiles = {
|
||||
{name = "nc_ctf_barrier.png",
|
||||
animation={
|
||||
|
@ -97,4 +120,6 @@ minetest.register_node(modname..":barrier",{
|
|||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
local bar, tbar = modname..":barrier",modname..":telebarrier"
|
Binary file not shown.
Before Width: | Height: | Size: 641 B After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 328 B |
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
Loading…
Reference in New Issue