From 86d184c1bdb06f1f365e533a1cb77e3ca44c93bc Mon Sep 17 00:00:00 2001 From: Kimapr Date: Tue, 17 Dec 2019 18:54:17 +0500 Subject: [PATCH] More fancy stuff. Better voting. --- init.lua | 210 +++++++++++++++++++++---------- node.lua | 35 +++++- textures/nc_ctf_barrier.png | Bin 641 -> 1837 bytes textures/nc_ctf_barrier_hole.png | Bin 0 -> 328 bytes textures/nc_ctf_telebarrier.png | Bin 0 -> 1734 bytes 5 files changed, 174 insertions(+), 71 deletions(-) create mode 100644 textures/nc_ctf_barrier_hole.png create mode 100644 textures/nc_ctf_telebarrier.png diff --git a/init.lua b/init.lua index 27306f9..822ebe4 100644 --- a/init.lua +++ b/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(" 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," 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," 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," 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," Nothing to vote for") + return + end + if not ctf.started and ctf.player_count < 2 then + minetest.chat_send_player(name," 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," You vote to end the game") + else + minetest.chat_send_player(name," 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," You vote to start the game") + else + minetest.chat_send_player(name," 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(" 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(" Enough players are here! Starting in 10 seconds") + minetest.chat_send_all(" 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(" "..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(" 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(" SOMEONE LEFT DURING CONFIGURATION. ABORTING") + if ctf.starting ~= math.huge then + minetest.chat_send_all(" 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(" 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(" 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(" 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 diff --git a/node.lua b/node.lua index 0250a39..752dd5a 100644 --- a/node.lua +++ b/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",{ } } }, - }) \ No newline at end of file + }) + +local bar, tbar = modname..":barrier",modname..":telebarrier" \ No newline at end of file diff --git a/textures/nc_ctf_barrier.png b/textures/nc_ctf_barrier.png index 1e7c271a9ed00bc196086cf7aad9dd927adadfce..e5657929b73ccfcb5de13602fb82d9e3f23f0b01 100644 GIT binary patch delta 1739 zcmV;+1~mDB1+5N{QwR|YC>NuO+WV1PCw~T&NklDTIXi+;NH!Cyz9shzZTfCX5@#QP>@s5r+?&x zBDq^d&9$5Aa~WQ)irW8iKDa7seLiO5|2Xf*O!QvQt|Tiz`Uh_P&CisWy7|GJC39Z= z3jq0X;XD!@px3tYo{e68NH z3O?Ps)nq`!S7h+1q=wkO zYcbXE6;pr5%>QxTKk=N@y0sMGGXRSTe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xhGq$7*%C!c-^Av z0mdlzRRd8?Tqe>wjBHu*+&o3q$$zaXXX!~*VsRvVmUk*JDd~$8l3QQ!df{JxymMRc zq1jn7L{Z7F#hc&nMIG)q}|Gm48R7dPTZ+ zi+E7#dun5uMW&S2PfI*kC&o@^zp*~FRBODOd zqXtZ=s{vIm<Px# diff --git a/textures/nc_ctf_barrier_hole.png b/textures/nc_ctf_barrier_hole.png new file mode 100644 index 0000000000000000000000000000000000000000..c972aad9b48656bb20585f68e134e16e93db8598 GIT binary patch literal 328 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP-k07^>S$9AGLZFajiEBiObAE1aYF-J0b5UwyNotBh zd1gt5g1e`0KzJjcI8f0BPZ!4!i_>c-2XY-U;Az|MBXPG`?uhY}*h8{coH?4_H+}z* z=sM%8YV(ECtAWgw9zTD2T(W0!(OPtJ&)&v^R}PzdnA~JGU%)(XmaISnr-kaT3`WJ5 z9wv-Y53&*>8-5qQ5vy3*keMoOQSTz{#qUn6K9;@rL*v#j7dw(QmwuaLzh2+>es8~F QIneD4p00i_>zopr0AMnB`~Uy| literal 0 HcmV?d00001 diff --git a/textures/nc_ctf_telebarrier.png b/textures/nc_ctf_telebarrier.png new file mode 100644 index 0000000000000000000000000000000000000000..c075c83c9dad6bf15c0d6c9d020a8a6e6ec4474d GIT binary patch literal 1734 zcmV;%208hOP)e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00u5eL_t(&-mO_(YV$e}oyc|w z4K0Pj$9<6ZQD+~?KHP<*`)K#kWFPTUArK0MlHlY%$j3SwOHO+4XE09uBaLRxocYnj zSh+}doE!P|k!PjI(}&2{%WVU+jYzxm@8)>$u)clP{elK)ckV`JMT`~6O7}Z9TTzM3 zYxn#_172_zm0bS0glAFt=d-1|H(UC9hDF27->*(5Hz_f8^Ry8;ZbW|G-G5`l>(v3Y zNsG!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