Split init.lua into different files

master
Zughy 2020-12-19 13:55:23 +01:00
parent b65b102af0
commit ebc1d6ead1
6 changed files with 322 additions and 358 deletions

51
commands.lua Normal file
View File

@ -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 <arena name> [min players] [max players]
- edit <arena name>
- enable <arena name>
Other commands:
- remove <arena name>
- disable <arena>
]],
privs = { sumo_admin = true }
})

390
init.lua
View File

@ -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 <arena name> [min players] [max players]
- edit <arena name>
- enable <arena name>
Other commands:
- remove <arena name>
- disable <arena>
]],
privs = { sumo_admin = true }
})

92
items.lua Normal file
View File

@ -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,
})

34
minigame_manager.lua Normal file
View File

@ -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)

110
nodes.lua Normal file
View File

@ -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(),
})

3
privs.lua Normal file
View File

@ -0,0 +1,3 @@
minetest.register_privilege("sumo_admin", {
description = "With this you can use /sumo create, edit"
})