diff --git a/mods/capturetheflag/ctf/cli.lua b/mods/capturetheflag/ctf/cli.lua index 851af38..e36f754 100644 --- a/mods/capturetheflag/ctf/cli.lua +++ b/mods/capturetheflag/ctf/cli.lua @@ -127,19 +127,7 @@ minetest.register_chatcommand("join", { params = "team name", description = "Add to team", func = function(name, param) - local player = cf.player(name) - - if not player then - player = {name=name} - end - - if not cf.setting("players_can_change_team") and (not player.team or player.team=="") then - minetest.chat_send_player(name,"You are not allowed to switch teams, traitor!",false) - end - - if cf.add_user(param,player) == true then - minetest.chat_send_all(name.." has joined team "..param) - end + cf.join(name, param, false) end, }) minetest.register_chatcommand("list_teams", { diff --git a/mods/capturetheflag/ctf/init.lua b/mods/capturetheflag/ctf/init.lua index 1516bc7..a6f3217 100644 --- a/mods/capturetheflag/ctf/init.lua +++ b/mods/capturetheflag/ctf/init.lua @@ -111,8 +111,32 @@ function cf.player(name) return cf.players[name] end --- add a user to a team -function cf.add_user(team,user) +-- Player joins team +function cf.join(name, team, force) + if not name or name == "" or not team or team == "" then + return false + end + + local player = cf.player(name) + + if not player then + player = {name = name} + end + + if not force and not cf.setting("players_can_change_team") and (not player.team or player.team == "") then + minetest.chat_send_player(name, "You are not allowed to switch teams, traitor!") + return false + end + + if cf.add_user(team, player) == true then + minetest.chat_send_all(name.." has joined team "..team) + return true + end + return false +end + +-- Add a player to a team in data structures +function cf.add_user(team, user) local _team = cf.team(team) local _user = cf.player(user.name) if _team and user and user.name then diff --git a/mods/capturetheflag/ctf_turret/depends.txt b/mods/capturetheflag/ctf_turret/depends.txt new file mode 100644 index 0000000..a7176f2 --- /dev/null +++ b/mods/capturetheflag/ctf_turret/depends.txt @@ -0,0 +1 @@ +ctf \ No newline at end of file diff --git a/mods/turret/init.lua b/mods/capturetheflag/ctf_turret/init.lua similarity index 74% rename from mods/turret/init.lua rename to mods/capturetheflag/ctf_turret/init.lua index 1641b30..3a00b3e 100644 --- a/mods/turret/init.lua +++ b/mods/capturetheflag/ctf_turret/init.lua @@ -1,6 +1,6 @@ ARROW_DAMAGE = 2 ARROW_VELOCITY = 2 -minetest.register_node("turret:turret", { +minetest.register_node("ctf_turret:turret", { description = "Team Turret", tiles = { "default_stone.png", @@ -40,7 +40,7 @@ minetest.register_node("turret:turret", { }) minetest.register_abm({ - nodenames = {"turret:turret"}, + nodenames = {"ctf_turret:turret"}, interval = 0.25, chance = 4, action = function(pos, node) @@ -82,7 +82,7 @@ minetest.register_abm({ } -- Create bullet entity - local bullet=minetest.env:add_entity({x=pos.x,y=pos.y+0.5,z=pos.z}, "turret:arrow_entity") + local bullet=minetest.env:add_entity({x=pos.x,y=pos.y+0.5,z=pos.z}, "ctf_turret:arrow_entity") -- Set velocity bullet:setvelocity({x=calc.x * ARROW_VELOCITY,y=calc.y * ARROW_VELOCITY,z=calc.z * ARROW_VELOCITY}) @@ -102,36 +102,35 @@ THROWING_ARROW_ENTITY={ textures = {"bullet.png"}, lastpos={}, collisionbox = {-0.17,-0.17,-0.17,0.17,0.17,0.17}, -} --- Arrow_entity.on_step()--> called when arrow is moving -THROWING_ARROW_ENTITY.on_step = function(self, dtime) - self.timer=self.timer+dtime - local pos = self.object:getpos() - local node = minetest.env:get_node(pos) - if self.timer > 2 then - self.object:remove() - end - -- When arrow is away from player (after 0.2 seconds): Cause damage to mobs and players - if self.timer>0.2 then - local objs = minetest.env:get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1.5) - for k, obj in pairs(objs) do - if obj:is_player() then - obj:set_hp(obj:get_hp()-ARROW_DAMAGE) - self.object:remove() + on_step = function(self, dtime) + self.timer=self.timer+dtime + local pos = self.object:getpos() + if self.timer > 2 then + self.object:remove() + end + + if self.timer > 0.2 then + local objs = minetest.env:get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1.5) + for k, obj in pairs(objs) do + if obj:is_player() then + obj:set_hp(obj:get_hp() - ARROW_DAMAGE) + self.object:remove() + end end end + + local node = minetest.env:get_node(pos) + if node.name ~= "air" and node.name ~= "ctf_turret:turret" then + --minetest.env:add_item(self.lastpos, "throwing:arrow") + self.object:remove() + end end - - if node.name ~= "air" and node.name ~= "turret:turret" then - minetest.env:add_item(self.lastpos, 'throwing:arrow') - self.object:remove() - end -end +} -minetest.register_entity("turret:arrow_entity", THROWING_ARROW_ENTITY) +minetest.register_entity("ctf_turret:arrow_entity", THROWING_ARROW_ENTITY) minetest.register_craft({ - output = "turret:turret", + output = "ctf_turret:turret", recipe = { {"default:mese_crystal", "default:gold_ingot", "default:mese_crystal"}, {"default:gold_ingot", "default:mese_crystal", "default:gold_ingot"}, diff --git a/mods/turret/sounds/Where to get sound.txt b/mods/capturetheflag/ctf_turret/sounds/Where to get sound.txt similarity index 100% rename from mods/turret/sounds/Where to get sound.txt rename to mods/capturetheflag/ctf_turret/sounds/Where to get sound.txt diff --git a/mods/turret/sounds/laser.ogg b/mods/capturetheflag/ctf_turret/sounds/laser.ogg similarity index 100% rename from mods/turret/sounds/laser.ogg rename to mods/capturetheflag/ctf_turret/sounds/laser.ogg diff --git a/mods/turret/textures/bullet.png b/mods/capturetheflag/ctf_turret/textures/bullet.png similarity index 100% rename from mods/turret/textures/bullet.png rename to mods/capturetheflag/ctf_turret/textures/bullet.png diff --git a/mods/turret/depends.txt b/mods/turret/depends.txt deleted file mode 100644 index 8038fbb..0000000 --- a/mods/turret/depends.txt +++ /dev/null @@ -1,2 +0,0 @@ -default -capturetheflag \ No newline at end of file