From ebc1d6ead1bee5f79b951746be75d13588ce37be Mon Sep 17 00:00:00 2001 From: Zughy <4279489-marco_a@users.noreply.gitlab.com> Date: Sat, 19 Dec 2020 13:55:23 +0100 Subject: [PATCH] Split init.lua into different files --- commands.lua | 51 ++++++ init.lua | 390 ++++--------------------------------------- items.lua | 92 ++++++++++ minigame_manager.lua | 34 ++++ nodes.lua | 110 ++++++++++++ privs.lua | 3 + 6 files changed, 322 insertions(+), 358 deletions(-) create mode 100644 commands.lua create mode 100644 items.lua create mode 100644 minigame_manager.lua create mode 100644 nodes.lua create mode 100644 privs.lua diff --git a/commands.lua b/commands.lua new file mode 100644 index 0000000..441722f --- /dev/null +++ b/commands.lua @@ -0,0 +1,51 @@ +ChatCmdBuilder.new("sumo", function(cmd) + + -- create arena + cmd:sub("create :arena", function(name, arena_name) + arena_lib.create_arena(name, "sumo", arena_name) + end) + + cmd:sub("create :arena :minplayers:int :maxplayers:int", function(name, arena_name, min_players, max_players) + arena_lib.create_arena(name, "sumo", arena_name, min_players, max_players) + end) + + -- remove arena + cmd:sub("remove :arena", function(name, arena_name) + arena_lib.remove_arena(name, "sumo", arena_name) + end) + + -- list of the arenas + cmd:sub("list", function(name) + arena_lib.print_arenas(name, "sumo") + end) + + -- enter editor mode + cmd:sub("edit :arena", function(sender, arena) + arena_lib.enter_editor(sender, "sumo", arena) + end) + + -- enable and disable arenas + cmd:sub("enable :arena", function(name, arena) + arena_lib.enable_arena(name, "sumo", arena) + end) + + cmd:sub("disable :arena", function(name, arena) + arena_lib.disable_arena(name, "sumo", arena) + end) + +end, { + description = [[ + + (/help sumo) + + Use this to configure your arena: + - create [min players] [max players] + - edit + - enable + + Other commands: + - remove + - disable + ]], + privs = { sumo_admin = true } +}) diff --git a/init.lua b/init.lua index ed4d11f..2774a7f 100644 --- a/init.lua +++ b/init.lua @@ -1,365 +1,39 @@ -- local value settings -local player_speed = 2 --when in the minigame -local player_jump = 1.3 --when in the minigame -local stick_knockback = 30 --multiplier for how hard the stick hits -local stick_vault_reach = 3 -- how close to the pointed node must the player be to vault -local stick_vault_timeout = 1 -- int timer for how long the vault cannot be used after it is used -local allow_swap_distance = 3 -- if an opponent is within this distance, then if the player uses the pushstick with the shift key pressed, the players switch positions. +local player_speed = 2 -- when in the minigame +local player_jump = 1.3 -- when in the minigame + arena_lib.register_minigame("sumo", { + prefix = "[Sumo] ", + hub_spawn_point = { x = 0, y = 20, z = 0 }, + show_minimap = false, + time_mode = 2, + join_while_in_progress = false, + keep_inventory = false, + in_game_physics = { + speed = player_speed, + jump = player_jump, + sneak = false, + }, + + hotbar = { + slots = 1, + background_image = "sumo_gui_hotbar.png" + }, + + disabled_damage_types = {"punch"}, + + --player_properties = {}, + }) + + +dofile(minetest.get_modpath("sumo") .. "/commands.lua") +dofile(minetest.get_modpath("sumo") .. "/items.lua") +dofile(minetest.get_modpath("sumo") .. "/minigame_manager.lua") +dofile(minetest.get_modpath("sumo") .. "/nodes.lua") +dofile(minetest.get_modpath("sumo") .. "/privs.lua") + if not minetest.get_modpath("lib_chatcmdbuilder") then dofile(minetest.get_modpath("sumo") .. "/chatcmdbuilder.lua") end - - - - minetest.register_craftitem("sumo:pushstick", { - description = "Push Stick", - inventory_image = "default_stick.png", - stack_max = 1, - wield_scale = {x = 2, y = 2, z = 2}, - on_use = function(itemstack, user, pointed_thing) - local sound = 'swish'..math.random(1,4) - minetest.sound_play(sound, { - pos = user:get_pos(), - max_hear_distance = 5, - gain = 10.0, - }) - - if pointed_thing == nil then return end - if pointed_thing.type == 'object' then - if minetest.is_player(pointed_thing.ref) == true then - - local dir = user:get_look_dir() - local keys = user:get_player_control() - local swap = false - local hitted_pos = pointed_thing.ref:get_pos() - local hitter_pos = user:get_pos() - if keys.sneak and vector.distance(hitted_pos,hitter_pos) < 3 then - swap = true - user:move_to(hitted_pos, true) - pointed_thing.ref:move_to(hitter_pos, true) - pointed_thing.ref:add_player_velocity(vector.multiply({x = -dir.x, y = dir.y, z= -dir.z}, stick_knockback/2)) - else - pointed_thing.ref:add_player_velocity(vector.multiply(dir, stick_knockback)) - if not swap then - local sound = 'thwack'..math.random(1,3) - minetest.sound_play(sound, { - pos = user:get_pos(), - max_hear_distance = 10, - gain = 10.0, - }) - local sound = 'hurt'..math.random(1,2) - minetest.sound_play(sound, { - to_player = pointed_thing.ref:get_player_name(), - pos = user:get_pos(), - gain = 10.0, - }) - end - end - - end - end - - end, - on_drop = function() end, - on_place = function(itemstack, placer, pointed_thing) - if pointed_thing == nil then return end - if pointed_thing.type == 'node' then - - if vector.distance(pointed_thing.under, placer:get_pos()) < stick_vault_reach then - local first_use = false - local imeta = itemstack:get_meta() - local old_time = imeta:get_int('old_time') - local current_time = minetest.get_gametime() - if old_time == 0 or old_time == nil then - first_use = true - end - if first_use or current_time > old_time + stick_vault_timeout then - local lookvect = placer:get_look_dir() - local pushvect = vector.normalize( {x=lookvect.x, z=lookvect.z, y= math.sqrt(1-(lookvect.y*lookvect.y))}) - --gives a unit vector that is 90 deg offset in the vert direction - local force = 10 * vector.length(vector.normalize( {x=lookvect.x, z=lookvect.z, y= 0})) - - placer:add_player_velocity(vector.multiply(pushvect, force)) - --update the staff time for next check - local sound = 'jump'..math.random(1,2) - minetest.sound_play(sound, { - pos = placer:get_pos(), - max_hear_distance = 10, - gain = 10.0, - }) - - imeta:set_int('old_time', current_time) - return itemstack - end - end - end - end, - - }) - - minetest.register_node("sumo:player_killer_air", { - description = "Sumo Arena Player Killer Air", - drawtype = "airlike", - paramtype = "light", - sunlight_propagates = true, - - walkable = false, - pointable = true, - diggable = true, - buildable_to = false, - drop = "", - damage_per_second = 40, - groups = {oddly_breakable_by_hand = 1}, - }) - - - minetest.register_node("sumo:player_killer_water_source", { - description = "Sumo Arena Player Killer Water Source", - drawtype = "liquid", - waving = 3, - tiles = { - { - name = "default_water_source_animated.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 2.0, - }, - }, - { - name = "default_water_source_animated.png", - backface_culling = true, - animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 2.0, - }, - }, - }, - damage_per_second = 40, - alpha = 191, - paramtype = "light", - walkable = false, - pointable = false, - diggable = false, - buildable_to = true, - is_ground_content = false, - drop = "", - drowning = 1, - liquidtype = "source", - liquid_alternative_flowing = "sumo:player_killer_water_flowing", - liquid_alternative_source = "sumo:player_killer_water_source", - liquid_viscosity = 1, - post_effect_color = {a = 103, r = 30, g = 60, b = 90}, - groups = {water = 3, liquid = 3, cools_lava = 1}, - sounds = default.node_sound_water_defaults(), - }) - - minetest.register_node("sumo:player_killer_water_flowing", { - description = "Sumo Arena Player Killer Water Flowing", - drawtype = "flowingliquid", - waving = 3, - tiles = {"default_water.png"}, - special_tiles = { - { - name = "default_water_flowing_animated.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 0.5, - }, - }, - { - name = "default_water_flowing_animated.png", - backface_culling = true, - animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 0.5, - }, - }, - }, - damage_per_second = 200, - alpha = 191, - paramtype = "light", - walkable = false, - pointable = false, - diggable = false, - buildable_to = true, - is_ground_content = false, - drop = "", - drowning = 1, - liquidtype = "flowing", - liquid_alternative_flowing = "sumo:player_killer_water_flowing", - liquid_alternative_source = "sumo:player_killer_water_source", - liquid_viscosity = 1, - post_effect_color = {a = 103, r = 30, g = 60, b = 90}, - groups = {water = 3, liquid = 3, not_in_creative_inventory = 1, - cools_lava = 1}, - sounds = default.node_sound_water_defaults(), - }) - - - - - - - - - arena_lib.register_minigame("sumo", { - prefix = "[Sumo] ", - hub_spawn_point = { x = 0, y = 20, z = 0 }, - show_minimap = false, - time_mode = 2, - join_while_in_progress = false, - keep_inventory = false, - in_game_physics = { - speed = player_speed, - jump = player_jump, - sneak = false, - }, - - hotbar = { - slots = 1, - background_image = "sumo_gui_hotbar.png" - }, - - disabled_damage_types = {"punch"}, - - player_properties = { - - - }, - - }) - - - arena_lib.on_load("sumo", function(arena) - - local item = ItemStack("sumo:pushstick") - - for pl_name, stats in pairs(arena.players) do - local player = minetest.get_player_by_name(pl_name) - player:get_inventory():set_stack("main", 1, item) - end - - end) - - arena_lib.on_time_tick('sumo', function(arena) - return - - end) - - --if the game times out - arena_lib.on_timeout('sumo', function(arena) - local winner_names = {} - for p_name, p_stats in pairs(arena.players) do - table.insert(winner_names, p_name) - end - - - arena_lib.load_celebration('sumo', arena, winner_names) - - end) - - - - - - - arena_lib.on_death('sumo', function(arena, p_name, reason) - arena_lib.remove_player_from_arena(p_name, 1) - - end) - - - - - - minetest.register_privilege("sumo_admin", { - description = "With this you can use /sumo create, edit" - }) - - - - - ChatCmdBuilder.new("sumo", function(cmd) - - -- create arena - - - -- create arena - cmd:sub("create :arena", function(name, arena_name) - arena_lib.create_arena(name, "sumo", arena_name) - end) - - - - cmd:sub("create :arena :minplayers:int :maxplayers:int", function(name, arena_name, min_players, max_players) - arena_lib.create_arena(name, "sumo", arena_name, min_players, max_players) - end) - - - - -- remove arena - cmd:sub("remove :arena", function(name, arena_name) - arena_lib.remove_arena(name, "sumo", arena_name) - end) - - - - -- list of the arenas - cmd:sub("list", function(name) - arena_lib.print_arenas(name, "sumo") - end) - - - - - - - - - -- enter editor mode - cmd:sub("edit :arena", function(sender, arena) - arena_lib.enter_editor(sender, "sumo", arena) - end) - - - - -- enable and disable arenas - cmd:sub("enable :arena", function(name, arena) - arena_lib.enable_arena(name, "sumo", arena) - end) - - - - cmd:sub("disable :arena", function(name, arena) - arena_lib.disable_arena(name, "sumo", arena) - end) - - end, { - description = [[ - - (/help sumo) - - Use this to configure your arena: - - create [min players] [max players] - - edit - - enable - - Other commands: - - remove - - disable - ]], - privs = { sumo_admin = true } - }) diff --git a/items.lua b/items.lua new file mode 100644 index 0000000..5dd608c --- /dev/null +++ b/items.lua @@ -0,0 +1,92 @@ +local stick_knockback = 30 --multiplier for how hard the stick hits +local stick_vault_reach = 3 -- how close to the pointed node must the player be to vault +local stick_vault_timeout = 1 -- int timer for how long the vault cannot be used after it is used +-- local allow_swap_distance = 3 -- if an opponent is within this distance, then if the player uses the pushstick with the shift key pressed, the players switch positions. + + +minetest.register_craftitem("sumo:pushstick", { + description = "Push Stick", + inventory_image = "default_stick.png", + stack_max = 1, + wield_scale = {x = 2, y = 2, z = 2}, + on_drop = function() end, + + on_use = function(itemstack, user, pointed_thing) + local sound = 'swish'..math.random(1,4) + minetest.sound_play(sound, { + pos = user:get_pos(), + max_hear_distance = 5, + gain = 10.0, + }) + + if pointed_thing == nil then return end + if pointed_thing.type == 'object' then + if minetest.is_player(pointed_thing.ref) == true then + + local dir = user:get_look_dir() + local keys = user:get_player_control() + local swap = false + local hitted_pos = pointed_thing.ref:get_pos() + local hitter_pos = user:get_pos() + if keys.sneak and vector.distance(hitted_pos,hitter_pos) < 3 then + swap = true + user:move_to(hitted_pos, true) + pointed_thing.ref:move_to(hitter_pos, true) + pointed_thing.ref:add_player_velocity(vector.multiply({x = -dir.x, y = dir.y, z= -dir.z}, stick_knockback/2)) + else + pointed_thing.ref:add_player_velocity(vector.multiply(dir, stick_knockback)) + if not swap then + local sound = 'thwack'..math.random(1,3) + minetest.sound_play(sound, { + pos = user:get_pos(), + max_hear_distance = 10, + gain = 10.0, + }) + local sound = 'hurt'..math.random(1,2) + minetest.sound_play(sound, { + to_player = pointed_thing.ref:get_player_name(), + pos = user:get_pos(), + gain = 10.0, + }) + end + end + + end + end + end, + + on_place = function(itemstack, placer, pointed_thing) + if pointed_thing == nil then return end + if pointed_thing.type == 'node' then + + if vector.distance(pointed_thing.under, placer:get_pos()) < stick_vault_reach then + local first_use = false + local imeta = itemstack:get_meta() + local old_time = imeta:get_int('old_time') + local current_time = minetest.get_gametime() + if old_time == 0 or old_time == nil then + first_use = true + end + if first_use or current_time > old_time + stick_vault_timeout then + local lookvect = placer:get_look_dir() + local pushvect = vector.normalize( {x=lookvect.x, z=lookvect.z, y= math.sqrt(1-(lookvect.y*lookvect.y))}) + --gives a unit vector that is 90 deg offset in the vert direction + local force = 10 * vector.length(vector.normalize( {x=lookvect.x, z=lookvect.z, y= 0})) + + placer:add_player_velocity(vector.multiply(pushvect, force)) + --update the staff time for next check + local sound = 'jump'..math.random(1,2) + minetest.sound_play(sound, { + pos = placer:get_pos(), + max_hear_distance = 10, + gain = 10.0, + }) + + imeta:set_int('old_time', current_time) + return itemstack + end + end + end + end, + +}) diff --git a/minigame_manager.lua b/minigame_manager.lua new file mode 100644 index 0000000..edf1140 --- /dev/null +++ b/minigame_manager.lua @@ -0,0 +1,34 @@ +arena_lib.on_load("sumo", function(arena) + + local item = ItemStack("sumo:pushstick") + + for pl_name, stats in pairs(arena.players) do + local player = minetest.get_player_by_name(pl_name) + player:get_inventory():set_stack("main", 1, item) + end + +end) + + + +arena_lib.on_time_tick('sumo', function(arena) + return +end) + + + +--if the game times out +arena_lib.on_timeout('sumo', function(arena) + local winner_names = {} + for p_name, p_stats in pairs(arena.players) do + table.insert(winner_names, p_name) + end + + arena_lib.load_celebration('sumo', arena, winner_names) +end) + + + +arena_lib.on_death('sumo', function(arena, p_name, reason) + arena_lib.remove_player_from_arena(p_name, 1) +end) diff --git a/nodes.lua b/nodes.lua new file mode 100644 index 0000000..160c7b8 --- /dev/null +++ b/nodes.lua @@ -0,0 +1,110 @@ +minetest.register_node("sumo:player_killer_air", { + description = "Sumo Arena Player Killer Air", + drawtype = "airlike", + paramtype = "light", + sunlight_propagates = true, + + walkable = false, + pointable = true, + diggable = true, + buildable_to = false, + drop = "", + damage_per_second = 40, + groups = {oddly_breakable_by_hand = 1}, +}) + + + +minetest.register_node("sumo:player_killer_water_source", { + description = "Sumo Arena Player Killer Water Source", + drawtype = "liquid", + waving = 3, + tiles = { + { + name = "default_water_source_animated.png", + backface_culling = false, + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 2.0, + }, + }, + { + name = "default_water_source_animated.png", + backface_culling = true, + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 2.0, + }, + }, + }, + damage_per_second = 40, + alpha = 191, + paramtype = "light", + walkable = false, + pointable = false, + diggable = false, + buildable_to = true, + is_ground_content = false, + drop = "", + drowning = 1, + liquidtype = "source", + liquid_alternative_flowing = "sumo:player_killer_water_flowing", + liquid_alternative_source = "sumo:player_killer_water_source", + liquid_viscosity = 1, + post_effect_color = {a = 103, r = 30, g = 60, b = 90}, + groups = {water = 3, liquid = 3, cools_lava = 1}, + sounds = default.node_sound_water_defaults(), +}) + + + +minetest.register_node("sumo:player_killer_water_flowing", { + description = "Sumo Arena Player Killer Water Flowing", + drawtype = "flowingliquid", + waving = 3, + tiles = {"default_water.png"}, + special_tiles = { + { + name = "default_water_flowing_animated.png", + backface_culling = false, + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 0.5, + }, + }, + { + name = "default_water_flowing_animated.png", + backface_culling = true, + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 0.5, + }, + }, + }, + damage_per_second = 200, + alpha = 191, + paramtype = "light", + walkable = false, + pointable = false, + diggable = false, + buildable_to = true, + is_ground_content = false, + drop = "", + drowning = 1, + liquidtype = "flowing", + liquid_alternative_flowing = "sumo:player_killer_water_flowing", + liquid_alternative_source = "sumo:player_killer_water_source", + liquid_viscosity = 1, + post_effect_color = {a = 103, r = 30, g = 60, b = 90}, + groups = {water = 3, liquid = 3, not_in_creative_inventory = 1, + cools_lava = 1}, + sounds = default.node_sound_water_defaults(), +}) diff --git a/privs.lua b/privs.lua new file mode 100644 index 0000000..8d8d851 --- /dev/null +++ b/privs.lua @@ -0,0 +1,3 @@ +minetest.register_privilege("sumo_admin", { + description = "With this you can use /sumo create, edit" +})