+ Code cleaning

+ Bug fixes
+ Cmds corrections
+ Comments corrections
master
Giov4 2020-10-11 15:22:54 +02:00
parent a9784285e8
commit fa68f4db40
11 changed files with 76 additions and 81 deletions

View File

@ -7,7 +7,6 @@ Don't change the variables names if you don't know what you're doing!
-- ARENA LIB'S SETTINGS --
@ -48,23 +47,20 @@ skywars_settings.build_permission = "build"
-- HUDS SETTINGS --
--[[ COORDINATES SYSTEM
For X and Y, 0.0 and 1.0 represent opposite edges of the game window, for example:
* [0.0, 0.0] is the top left corner of the game window
* [1.0, 1.0] is the bottom right of the game window
* [0.5, 0.5] is the center of the game window
--]]
-- Real coordinates:
-- a unit of measurement which is roughly around 64 pixels, but
-- varies based on the screen density and scaling settings of the client.
-- The texture background for the kit menu.
skywars_settings.hud__kit_background = "Kits.png"
-- The x position of the first buttons row.
-- The x position offset from the background border of the first buttons row
-- in real coordinates, the bigger it is the righter the row will be placed.
skywars_settings.starting_x = 1.7
-- The y position of the first buttons row.
-- The y position offset from the background border of the first buttons row
-- in real coordinates, the bigger it is the lower the row will be placed.
skywars_settings.starting_y = 6.9
-- The horizontal distance between buttons in real coordinates.
@ -76,9 +72,7 @@ skywars_settings.distance_y = 3
-- The amount of buttons in a row.
skywars_settings.buttons_per_row = 3
-- The buttons width in real coordinates,
-- a unit of measurement which is roughly around 64 pixels, but
-- varies based on the screen density and scaling settings of the client.
-- The buttons width in real coordinates.
skywars_settings.buttons_width = 2
-- The buttons height in real coordinates.

View File

@ -1,6 +1,3 @@
(If you find it uncomfortable to read the tutorial from the chat
you can read it from a file in the mod folder called TUTORIAL.txt)
These are the steps to follow in order to create and configure an
arena:
@ -24,15 +21,15 @@ clicking it).
3) Setting the arena treasures (the items that can spawn in the
chests):
item: the item name
rarity: how often it will spawn in chests
preciousness: in which chests it can be put, for example a chest with
a preciousness range 2-4 can spawn just items with a preciousness
between 2 and 4
count: the item amount
/skywars addtreasure <arena name> <item> <count> <rarity (min 1.0, max
10.0)> <preciousness>
item: the item name
rarity: how often it will spawn in chests
preciousness: in which chests it can be put, for example a chest with
a preciousness range 2-4 can just spawn items with a preciousness
between 2 and 4
count: the item amount
You can also use:
/skywars addtreasure hand <arena name> <rarity (min 1.0, max 10.0)>
@ -58,9 +55,9 @@ this will set the position over the node you're standing on.
/skywars pos1 <arena name>
/skywars pos2 <arena name>
in order to kill players that go out of the map, you have to define a
map area; to do so, simply specify its corners by using
/skywars pos1 and /skywars pos2.
in order to kill players that go out of the map and to properly save the changes
made to the arena you have to define a map area; to do so, simply specify its
corners by using: /skywars pos1 and /skywars pos2.
! WARNING !
To modify a map you must use use /skywars reset <arena name> and then disable
@ -75,7 +72,7 @@ you'll have to reset it until the map is clear).
/skywars createkit <kit name> <texture name>: texture name is the texture
that the kit button will have in the selector menu at the start of the match,
it must be a file name that you put in the <SKYWARS MOD FOLDER>/textures folder.
it must be a file name that you put in the "<SKYWARS MOD FOLDER>/textures" folder.
/skywars additem <kit name> <item> <count>: with this you can add items to it
or
@ -92,6 +89,6 @@ that contains the choosable kits, with this command you add one to it.
Once you've done this you can click the sign and start playing :).
You can use /help skywars to read all the commands.
You should use /help skywars to read all the commands.
To modify the game settings (such as the messages prefix or the
hub spawn point) you can edit the SETTINGS.lua file.
hub spawn point) you can edit the "<SKYWARD MOD FOLDER>/SETTINGS.lua" file.

View File

@ -49,11 +49,11 @@ end)
arena_lib.on_load("skywars", function(arena)
skywars.reset_map(arena)
minetest.after(skywars_settings.loading_time, function()
-- trying to prevent the lava-water reaction or whatever happens
-- after the first reset from modifing the map
skywars.reset_map(arena)
skywars.place_chests(arena)
skywars.fill_chests(arena)
-- trying to prevent the lava-water reaction or whatever happens
-- after the first reset from modifing the map
end)
for pl_name in pairs(arena.players) do
@ -65,10 +65,6 @@ arena_lib.on_load("skywars", function(arena)
if minetest.get_node(node_pos).name == "air" then
minetest.add_node(node_pos, {name="default:glass"})
minetest.after(skywars_settings.loading_time, function()
minetest.add_node(node_pos, {name="air"})
end)
end
end
@ -88,7 +84,7 @@ arena_lib.on_load("skywars", function(arena)
set_glass({x = 0,y = 1,z = -1})
end)
-- teleports the player back to in the glass
-- teleports the player back in the glass
minetest.after(1, function()
player:set_pos(pl_pos)
end)
@ -104,9 +100,11 @@ arena_lib.on_start("skywars", function(arena)
local player = minetest.get_player_by_name(pl_name)
skywars.generate_HUD(arena, pl_name)
player:set_physics_override({speed=arena.players[pl_name].speed, gravity=1, jump=1})
-- saving original speed
arena.players[pl_name].speed = player:get_physics_override().speed
player:set_physics_override({speed=skywars_settings.player_speed, gravity=1, jump=1})
skywars.activate_enderpearl(player, arena)
end
end)
@ -149,7 +147,8 @@ arena_lib.on_death("skywars", function(arena, pl_name, reason)
arena_lib.send_message_players_in_arena(arena, skywars_settings.prefix .. skywars.T("@1 was killed by @2", pl_name, killer))
-- arena.HUDs[killer].players_killed[1] == HUD ID
-- arena.HUDs[killer].players_killed[2] == players amount
reason.object:hud_change(arena.HUDs[killer].players_killed[1], "text", tostring(arena.HUDs[killer].players_killed[2] + 1))
arena.HUDs[killer].players_killed[2] = arena.HUDs[killer].players_killed[2] + 1
reason.object:hud_change(arena.HUDs[killer].players_killed[1], "text", tostring(arena.HUDs[killer].players_killed[2]))
end
end

View File

@ -1,6 +1,6 @@
minetest.register_on_joinplayer(function(player)
if skywars_settings.remove_armors_on_join and minetest.get_modpath("3d_armor") then
minetest.after(4, function() armor:remove_all(player) end)
minetest.after(5, function() armor:remove_all(player) end)
end
end)

View File

@ -1,5 +1,13 @@
function skywars.block_enderpearl(player, arena)
if minetest.get_modpath("enderpearl") ~= "" and minetest.get_modpath("enderpearl") ~= nil then
if minetest.get_modpath("enderpearl") then
enderpearl.block_teleport(player, skywars_settings.celebration_time + 10)
end
end
function skywars.activate_enderpearl(player, arena)
if minetest.get_modpath("enderpearl") then
enderpearl.block_teleport(player, 0)
end
end

View File

@ -85,11 +85,10 @@ function skywars.update_players_counter(arena, players_updated)
pl_amount = pl_amount-1
end
-- updating the player counter HUD
-- updating the players counter HUD
for pl_name in pairs(arena.players) do
local player = minetest.get_player_by_name(pl_name)
-- if the temp property doesn't exists then return
if arena.match_players == nil then return end
player:hud_change(arena.HUDs[pl_name].players_count, "text", tostring(arena.players_amount) .. "/" .. tostring(arena.match_players))

View File

@ -38,21 +38,21 @@ local function create_formspec(arena)
goto continue
end
-- if offset_x has reached its maximum amount then reset it and increase offset_y
if offset_x == distance_x * (buttons_per_row-1) then
offset_y = offset_y + distance_y
offset_x = 0
else
offset_x = offset_x + distance_x
end
local kit_items = ""
-- generating the item description (a list of all the items in the kit)
if kits[name].items then
if kits[name].items and kits[name].items[1] then
-- if offset_x has reached its maximum amount then reset it and increase offset_y
if offset_x == distance_x * (buttons_per_row-1) then
offset_y = offset_y + distance_y
offset_x = 0
else
offset_x = offset_x + distance_x
end
-- generating the kit description (a list of all the items in the kit)
for j=1, #kits[name].items do
local item_name = kits[name].items[j].name
-- if the string is "mod:item" it becomes "item"
-- if the string is "mod:item_name" it becomes "item name"
if string.match(item_name, ":") then
local split_name = string.split(item_name, ":")
item_name = string.gsub(split_name[2], "_", " ")

View File

@ -1,4 +1,4 @@
-- reordering the corner's position so that pos1 is smaller than pos2
-- reordering the corners positions so that pos1 is smaller than pos2
local function reorder_positions(pos1, pos2)
local temp
@ -26,12 +26,12 @@ end
-- returns the arena where the player's in
local function get_arena_by_pos(pos)
for i, arena in pairs(arena_lib.mods["skywars"].arenas) do
if arena.pos1.x == nil or arena.pos2.x == nil then goto continue end
local map_area = VoxelArea:new{MinEdge = arena.pos1, MaxEdge = arena.pos2}
local serialized_pos = minetest.serialize(pos)
if map_area:contains(pos.x, pos.y, pos.z) then
return arena
@ -52,7 +52,7 @@ local function save_block(arena, pos, node)
if not maps[arena.name] then maps[arena.name] = {} end
if not maps[arena.name].blocks then maps[arena.name].blocks = {} end
-- if this block has not been changed yet
-- if this block has not been changed yet then save it
if maps[arena.name].blocks[serialized_pos] == nil then
maps[arena.name].blocks[serialized_pos] = node
skywars.overwrite_maps(maps)

View File

@ -52,15 +52,15 @@ function(cmd)
3) Setting the arena treasures (the items that can spawn in the
chests):
item: the item name
rarity: how often it will spawn in chests
preciousness: in which chests it can be put, for example a chest with
a preciousness range 2-4 can spawn just items with a preciousness
between 2 and 4
count: the item amount
/skywars addtreasure <arena name> <item> <count> <rarity (min 1.0, max
10.0)> <preciousness>
item: the item name
rarity: how often it will spawn in chests
preciousness: in which chests it can be put, for example a chest with
a preciousness range 2-4 can just spawn items with a preciousness
between 2 and 4
count: the item amount
You can also use:
/skywars addtreasure hand <arena name> <rarity (min 1.0, max 10.0)>
@ -86,9 +86,9 @@ function(cmd)
/skywars pos1 <arena name>
/skywars pos2 <arena name>
in order to kill players that go out of the map, you have to define a
map area; to do so, simply specify its corners by using
/skywars pos1 and /skywars pos2.
in order to kill players that go out of the map and to properly save the changes
made to the arena you have to define a map area; to do so, simply specify its
corners by using: /skywars pos1 and /skywars pos2.
! WARNING !
To modify a map you must use use /skywars reset <arena name> and then disable
@ -103,7 +103,7 @@ function(cmd)
/skywars createkit <kit name> <texture name>: texture name is the texture
that the kit button will have in the selector menu at the start of the match,
it must be a file name that you put in the <SKYWARS MOD FOLDER>/textures folder.
it must be a file name that you put in the "<SKYWARS MOD FOLDER>/textures" folder.
/skywars additem <kit name> <item> <count>: with this you can add items to it
or
@ -119,9 +119,9 @@ function(cmd)
Once you've done this you can click the sign and start playing :).
You can use /help skywars to read all the commands.
You should use /help skywars to read all the commands.
To modify the game settings (such as the messages prefix or the
hub spawn point) you can edit the SETTINGS.lua file.
hub spawn point) you can edit the "<SKYWARD MOD FOLDER>/SETTINGS.lua" file.
]])
end)
@ -145,21 +145,18 @@ function(cmd)
-- list of the arenas
cmd:sub("list", function(name)
arena_lib.print_arenas(name, "skywars")
end)
-- info on a specific arena
cmd:sub("info :arena", function(name, arena_name)
arena_lib.print_arena_info(name, "skywars", arena_name)
end)
-- this sets the spawns using the player position
cmd:sub("setspawn :arena", function(name, arena)
arena_lib.set_spawner(name, "skywars", arena)
end)
@ -409,7 +406,7 @@ function(cmd)
skywars.print_msg(sender, skywars.T("Treasures list:"))
for i=1, #arena.treasures do
local treasure = arena.treasures[i]
if treasure.name == treasure_name then
if treasure.name:match(treasure_name) then
skywars.print_msg(sender, "ID: " .. arena.treasures[i].id .. ".\n" ..
skywars.T(
"name: @1 @nrarity: @2 @npreciousness: @3 @ncount: @4",
@ -964,7 +961,7 @@ function(cmd)
end, {
description = [[
(Use /help skywars)
(/help skywars)
Arena_lib:
@ -983,23 +980,22 @@ end, {
<preciousness>
- addtreasure hand <arena name> <rarity (min 1.0, max 10.0)>
<preciousness>
- gettreasures <arena name>
- searchtreasure <arena name> <treasure name>: shows all the treasures with that name
- removetreasure <arena name> <treasure name>: remove all treasures with than name
- removetreasure hand <arena name>
- removetreasure id <arena name> <treasure id>
- gettreasures <arena name>
- searchtreasure <arena name> <treasure name>: shows all the treasures with that name
- copytreasures <(from) arena name> <(to) arena name>
- addchest <arena name> <min_preciousness> <max_preciousness>
<min_treasures_amount (min. 1)> <max_treasures_amount>
- addchest pos <arena name> <min_preciousness> <max_preciousness>
<min_treasures_amount (min. 1)> <max_treasures_amount>
- removechest
- removechest id <id>
- getchests <arena name>
- removechest <arena name>: removes the chest you're looking at
- removechest id <id>
- pos1 <arena name>
- pos2 <arena name>
- reset <arena name>
- getpos
- createkit <kit name> <texture name>
- deletekit <kit name>
- additem <kit name> <item> <count>
@ -1011,12 +1007,13 @@ end, {
- getkits
- resetkit <kit name>
- getitems <kit name>
- copykits <arena1> <arena2>
- copykits <(from) arena name> <(to) arena name>
Debug:
Debug (don't use them if you don't know what you're doing):
- clearmapstable: clears the changed blocks table of each map without resetting them
- getpos
]],
privs = { skywars_admin = true }
})

View File

@ -18,6 +18,7 @@ arena_lib.register_minigame("skywars", {
queue_waiting_time = skywars_settings.queue_waiting_time,
temp_properties = {
HUDs = {},
-- the original amount of players in the arena
match_players = 0,
time_passed = 0
},

View File

@ -1,4 +1,4 @@
name = skywars
description = Skywars is a PvP minigame where players battle each other on floating islands until there is only one survivor remaining. Each player spawns on their own island and when the round begins must prepare for battle before crossing to the other islands and fighting.
depends = arena_lib, default
optional_depends = exschem, enderpearl, 3d_armor
optional_depends = enderpearl, 3d_armor