+ CRASHFIX: If a chest couldn't spawn any treasure the game freezed

+ Reworked rarity system, now the range is from 1 to 10 and the rarity
  gap is handled by the mod
+ Now it's possible to equip an armor from on_place too
+ BUGFIX: Chests id weren't generated properly
+ Now addchest takes the position of the node the player's looking at
  (the old cmd is now callded "addchest pos")
+ Help section corrected
+ Code cleaning
master
Giov4 2020-09-19 15:31:25 +02:00
parent cc2f71a7cf
commit 265241a3c7
6 changed files with 113 additions and 54 deletions

View File

@ -25,28 +25,34 @@ clicking it).
3) Setting the arena treasures (the items that can spawn in the 3) Setting the arena treasures (the items that can spawn in the
chests): chests):
item: the item name item: the item name
rarity: how often it will spawn in chests (the rarity gap between two rarity: how often it will spawn in chests
treasures should be at least of 2)
preciousness: in which chests it can be put, for example a chest with 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 a preciousness range 2-4 can spawn just items with a preciousness
between 2 and 4 between 2 and 4
count: the item amount count: the item amount
/skywars addtreasure <arena name> <item> <count> <rarity (min 2.0, max /skywars addtreasure <arena name> <item> <count> <rarity (min 1.0, max
1000.0)> <preciousness> 10.0)> <preciousness>
You can also use: You can also use:
/skywars addtreasure hand <arena name> <rarity (min 2.0, max 20.0)> /skywars addtreasure hand <arena name> <rarity (min 1.0, max 10.0)>
<preciousness> <preciousness>
this will get the item name and count from the one in your hand. this will get the item name and count from the one in your hand.
4) Setting the chests in the arena using: 4) Setting the chests in the arena using:
/skywars addchest <arena name> <min_preciousness> <max_preciousness> /skywars addchest <arena name> <min_preciousness> <max_preciousness>
<min_treasures_amount (min. 1)> <max_treasures_amount> <min_treasures_amount (min. 1)> <max_treasures_amount>
to add a chest use this command at the position you want it to spawn, it to add a chest that will be filled with the right treasures when the match
will automatically be filled with the right items when the match starts, this will set the position to the node you're looking at (not over it).
starts.
You can also use:
/skywars addchest pos <arena name> <min_preciousness> <max_preciousness>
<min_treasures_amount (min. 1)> <max_treasures_amount>
this will set the position over the node you're standing on.
5) Saving the map schematic using: 5) Saving the map schematic using:
@ -69,6 +75,8 @@ 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 /skywars additem <kit name> <item> <count>: with this you can add items to it
or
/skywars additem hand <kit name>
/skywars arenakit add <arena name> <kit name>: each arena has a "kits" property /skywars arenakit add <arena name> <kit name>: each arena has a "kits" property
that contains the choosable kits, with this command you add one to it that contains the choosable kits, with this command you add one to it

View File

@ -71,23 +71,24 @@ function skywars.select_random_treasures(treasure_amount, min_preciousness, max_
end end
local treasures = {} local treasures = {}
local count = 0
-- while the generated treasures are less then the desired amount -- while the generated treasures are less then the desired amount
while #treasures < treasure_amount do while #treasures < treasure_amount and #p_treasures > 0 do
for c=1,treasure_amount do for c=1,treasure_amount do
-- if there isn't a treasure -- if there isn't a treasure
if treasures[c] == nil then if treasures[c] == nil then
for t=1,#p_treasures do for t=1,#p_treasures do
local random = math.random(1, 20) local random = math.random(1, 100)
-- if the random number is a multiple of the item rarity then select it -- if the random number is a multiple of the item rarity then select it
if random % p_treasures[t].rarity == 0 then if random % (p_treasures[t].rarity * 4 + 3) == 0 then
table.insert(treasures, p_treasures[t]) table.insert(treasures, p_treasures[t])
break break
end end
end end
end end
end end
count = count + 1
end end
local itemstacks = {} local itemstacks = {}

View File

@ -7,6 +7,13 @@ for name in pairs(minetest.registered_items) do
if arena_lib.is_player_in_arena(pl_name, "skywars") and arena_lib.get_arena_by_player(pl_name).in_loading == false then if arena_lib.is_player_in_arena(pl_name, "skywars") and arena_lib.get_arena_by_player(pl_name).in_loading == false then
skywars.add_armor(minetest.get_player_by_name(pl_name), itemstack:get_name()) skywars.add_armor(minetest.get_player_by_name(pl_name), itemstack:get_name())
end end
end,
on_place = function(itemstack, user)
local pl_name = user:get_player_name()
local arena
if arena_lib.is_player_in_arena(pl_name, "skywars") and arena_lib.get_arena_by_player(pl_name).in_loading == false then
skywars.add_armor(minetest.get_player_by_name(pl_name), itemstack:get_name())
end
end end
}) })
end end

View File

@ -31,28 +31,33 @@ function(cmd)
3) Setting the arena treasures (the items that can spawn in the 3) Setting the arena treasures (the items that can spawn in the
chests): chests):
item: the item name item: the item name
rarity: how often it will spawn in chests (the rarity gap between two rarity: how often it will spawn in chests
treasures should be at least of 2)
preciousness: in which chests it can be put, for example a chest with 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 a preciousness range 2-4 can spawn just items with a preciousness
between 2 and 4 between 2 and 4
count: the item amount count: the item amount
/skywars addtreasure <arena name> <item> <count> <rarity (min 2.0, max /skywars addtreasure <arena name> <item> <count> <rarity (min 1.0, max
1000.0)> <preciousness> 10.0)> <preciousness>
You can also use: You can also use:
/skywars addtreasure hand <arena name> <rarity (min 2.0, max 20.0)> /skywars addtreasure hand <arena name> <rarity (min 1.0, max 10.0)>
<preciousness> <preciousness>
this will get the item name and count from the one in your hand. this will get the item name and count from the one in your hand.
4) Setting the chests in the arena using: 4) Setting the chests in the arena using:
/skywars addchest <arena name> <min_preciousness> <max_preciousness> /skywars addchest <arena name> <min_preciousness> <max_preciousness>
<min_treasures_amount (min. 1)> <max_treasures_amount> <min_treasures_amount (min. 1)> <max_treasures_amount>
to add a chest use this command at the position you want it to spawn, it to add a chest that will be filled with the right treasures when the match
will automatically be filled with the right items when the match starts, this will set the position to the node you're looking at (not over it).
starts.
You can also use:
/skywars addchest pos <arena name> <min_preciousness> <max_preciousness>
<min_treasures_amount (min. 1)> <max_treasures_amount>
this will set the position over the node you're standing on.
5) Saving the map schematic using: 5) Saving the map schematic using:
@ -96,7 +101,6 @@ function(cmd)
-- create arena
cmd:sub("create :arena", function(name, arena_name) cmd:sub("create :arena", function(name, arena_name)
arena_lib.create_arena(name, "skywars", arena_name) arena_lib.create_arena(name, "skywars", arena_name)
end) end)
@ -109,7 +113,6 @@ function(cmd)
-- remove arena
cmd:sub("remove :arena", function(name, arena_name) cmd:sub("remove :arena", function(name, arena_name)
arena_lib.remove_arena(name, "skywars", arena_name) arena_lib.remove_arena(name, "skywars", arena_name)
end) end)
@ -137,27 +140,18 @@ function(cmd)
cmd:sub("setspawn :arena", function(name, arena)
arena_lib.set_spawner(name, "skywars", arena)
end)
-- this sets the arena's sign
cmd:sub("setsign :arena", function(sender, arena) cmd:sub("setsign :arena", function(sender, arena)
arena_lib.set_sign(sender, nil, nil, "skywars", arena) arena_lib.set_sign(sender, nil, nil, "skywars", arena)
end) end)
-- enter editor mode
cmd:sub("edit :arena", function(sender, arena) cmd:sub("edit :arena", function(sender, arena)
arena_lib.enter_editor(sender, "skywars", arena) arena_lib.enter_editor(sender, "skywars", arena)
end) end)
-- enable and disable arenas
cmd:sub("enable :arena", function(name, arena) cmd:sub("enable :arena", function(name, arena)
arena_lib.enable_arena(name, "skywars", arena) arena_lib.enable_arena(name, "skywars", arena)
end) end)
@ -193,11 +187,11 @@ function(cmd)
elseif count <= 0 then elseif count <= 0 then
skywars.print_error(sender, skywars.T("Count has to be greater than 0!")) skywars.print_error(sender, skywars.T("Count has to be greater than 0!"))
return return
elseif rarity < 2 then elseif rarity < 1 then
skywars.print_error(sender, skywars.T("Rarity has to be greater than 2!")) skywars.print_error(sender, skywars.T("Rarity has to be greater than 0!"))
return return
elseif rarity > 20 then elseif rarity > 10 then
skywars.print_error(sender, skywars.T("Rarity has to be smaller than 21!")) skywars.print_error(sender, skywars.T("Rarity has to be smaller than 11!"))
return return
elseif ItemStack(treasure_name):is_known() == false then elseif ItemStack(treasure_name):is_known() == false then
skywars.print_error(sender, skywars.T("@1 doesn't exist!", treasure_name)) skywars.print_error(sender, skywars.T("@1 doesn't exist!", treasure_name))
@ -236,11 +230,11 @@ function(cmd)
return return
end end
end end
if rarity < 2 then if rarity < 1 then
skywars.print_error(sender, skywars.T("Rarity has to be greater than 2!")) skywars.print_error(sender, skywars.T("Rarity has to be greater than 0!"))
return return
elseif rarity > 20 then elseif rarity > 10 then
skywars.print_error(sender, skywars.T("Rarity has to be smaller than 21!")) skywars.print_error(sender, skywars.T("Rarity has to be smaller than 11!"))
return return
elseif treasure_name == "" then elseif treasure_name == "" then
skywars.print_error(sender, skywars.T("Your hand is empty!")) skywars.print_error(sender, skywars.T("Your hand is empty!"))
@ -275,10 +269,9 @@ function(cmd)
end end
for i=1, #arena.treasures do for i=1, #arena.treasures do
if arena.treasures[i].name == treasure_name then if arena.treasures[i] and arena.treasures[i].name == treasure_name then
table.remove(arena.treasures, i) table.remove(arena.treasures, i)
found = true found = true
break
end end
end end
arena_lib.change_arena_property(sender, "skywars", arena_name, "treasures", arena.treasures, false) arena_lib.change_arena_property(sender, "skywars", arena_name, "treasures", arena.treasures, false)
@ -311,6 +304,7 @@ function(cmd)
if i == treasure_id then if i == treasure_id then
treasure_name = arena.treasures[i].name treasure_name = arena.treasures[i].name
table.remove(arena.treasures, i) table.remove(arena.treasures, i)
break
end end
end end
arena_lib.change_arena_property(sender, "skywars", arena_name, "treasures", arena.treasures, false) arena_lib.change_arena_property(sender, "skywars", arena_name, "treasures", arena.treasures, false)
@ -408,18 +402,18 @@ function(cmd)
cmd:sub("addchest :arena :minpreciousness:int :maxpreciousness:int :tmin:int :tmax:int", cmd:sub("addchest pos :arena :minpreciousness:int :maxpreciousness:int :tmin:int :tmax:int",
function(sender, arena_name, min_preciousness, max_preciousness, t_min, t_max) function(sender, arena_name, min_preciousness, max_preciousness, t_min, t_max)
local id, arena = arena_lib.get_arena_by_name("skywars", arena_name) local id, arena = arena_lib.get_arena_by_name("skywars", arena_name)
local pos = vector.floor(minetest.get_player_by_name(sender):get_pos()) local pos = vector.round(minetest.get_player_by_name(sender):get_pos())
local chest = local chest =
{ {
pos = {x = pos.x, y= pos.y + 1, z = pos.z}, pos = pos,
min_preciousness = min_preciousness, min_preciousness = min_preciousness,
max_preciousness = max_preciousness, max_preciousness = max_preciousness,
min_treasures = t_min, min_treasures = t_min,
max_treasures = t_max, max_treasures = t_max,
id = #arena.chests+1 id = arena.chests[#arena.chests].id + 1
} }
if arena_lib.is_arena_in_edit_mode(arena_name) then if arena_lib.is_arena_in_edit_mode(arena_name) then
@ -447,6 +441,53 @@ function(cmd)
end) end)
cmd:sub("addchest :arena :minpreciousness:int :maxpreciousness:int :tmin:int :tmax:int",
function(sender, arena_name, min_preciousness, max_preciousness, t_min, t_max)
local id, arena = arena_lib.get_arena_by_name("skywars", arena_name)
local player = minetest.get_player_by_name(sender)
local look_dir = player:get_look_dir()
local pos_head = vector.add(player:get_pos(), {x=0, y=1.5, z=0})
local result, pos = minetest.line_of_sight(vector.add(pos_head, vector.divide(look_dir, 4)), vector.add(pos_head, vector.multiply(look_dir, 10)))
if result then skywars.print_error(sender, skywars.T("You're not looking at anything!")) end
local chest =
{
pos = pos,
min_preciousness = min_preciousness,
max_preciousness = max_preciousness,
min_treasures = t_min,
max_treasures = t_max,
id = arena.chests[#arena.chests].id + 1
}
if arena_lib.is_arena_in_edit_mode(arena_name) then
skywars.print_error(sender, skywars.T("Nobody must be in the editor!"))
return
elseif arena == nil then
skywars.print_error(sender, skywars.T("Arena not found!"))
return
end
if arena.enabled == true then
arena_lib.disable_arena(sender, "skywars", arena_name)
if arena.enabled == true then
skywars.print_error(sender, skywars.T("@1 must be disabled!", arena_name))
return
end
end
if t_min <= 0 or t_max <= 0 then
skywars.print_error(sender, skywars.T("The minimum or maximum amount of treasures has to be greater than 0!"))
return
end
skywars.print_msg(sender, skywars.T("Chest added!"))
table.insert(arena.chests, chest)
arena_lib.change_arena_property(sender, "skywars", arena_name, "chests", arena.chests, false)
end)
cmd:sub("getchests :arena", function(sender, arena_name) cmd:sub("getchests :arena", function(sender, arena_name)
local id, arena = arena_lib.get_arena_by_name("skywars", arena_name) local id, arena = arena_lib.get_arena_by_name("skywars", arena_name)
local found = false local found = false
@ -831,10 +872,10 @@ function(cmd)
end, { end, {
description = [[ description = [[
(Use /help skywars)
Arena_lib: Arena_lib:
- tutorial
- create <arena name> [min players] [max players] - create <arena name> [min players] [max players]
- edit <arena name> - edit <arena name>
- remove <arena name> - remove <arena name>
@ -845,12 +886,12 @@ end, {
Skywars commands: Skywars commands:
- tutorial
- addtreasure <arena name> <item> <count> <rarity (min 2.0, max 20.0)> - addtreasure <arena name> <item> <count> <rarity (min 1.0, max 10.0)>
<preciousness> <preciousness>
- addtreasure hand <arena name> <rarity (min 2.0, max 20.0)> - addtreasure hand <arena name> <rarity (min 1.0, max 10.0)>
<preciousness> <preciousness>
- removetreasure <arena name> <treasure name> - removetreasure <arena name> <treasure name>: remove all treasures with than name
- removetreasure id <arena name> <treasure id> - removetreasure id <arena name> <treasure id>
- gettreasures <arena name> - gettreasures <arena name>
- searchtreasure <arena name> <treasure name>: shows all the treasures with that name - searchtreasure <arena name> <treasure name>: shows all the treasures with that name

View File

@ -5,8 +5,8 @@
Arena not found!=Arena non trovata! Arena not found!=Arena non trovata!
Count has to be greater than 0!=La quantità deve essere maggiore di 0 Count has to be greater than 0!=La quantità deve essere maggiore di 0
Rarity has to be greater than 2!=La rarità deve essere maggiore di 2! Rarity has to be greater than 0!=La rarità deve essere maggiore di 0!
Rarity has to be smaller than 21!=La rarità deve essere minore di 21! Rarity has to be smaller than 11!=La rarità deve essere minore di 11!
@1 doesn't exist!=@1 non esiste! @1 doesn't exist!=@1 non esiste!
Your hand is empty!=La tua mano è vuota Your hand is empty!=La tua mano è vuota
Treasure not found!=Tesoro non trovato! Treasure not found!=Tesoro non trovato!
@ -22,6 +22,7 @@ Chest added!=Cassa aggiunta!
Chest removed!=Cassa rimossa! Chest removed!=Cassa rimossa!
Chest not found!=Cassa non trovata! Chest not found!=Cassa non trovata!
Chest list:=Lista delle casse: Chest list:=Lista delle casse:
You're not looking at anything!=Non stai guardando nulla!
ID: @1 - POSITION: @2=ID: @1 - POSIZIONE: @2 ID: @1 - POSITION: @2=ID: @1 - POSIZIONE: @2
Position saved!=Posizione salvata Position saved!=Posizione salvata
Schematic @1 created! (Saved in @2)=Schematica @1 creata! (Salvata in @2) Schematic @1 created! (Saved in @2)=Schematica @1 creata! (Salvata in @2)

View File

@ -5,14 +5,15 @@
Arena not found!= Arena not found!=
Count has to be greater than 0!= Count has to be greater than 0!=
Rarity has to be greater than 2!= Rarity has to be greater than 0!=
Rarity has to be smaller than 21!= Rarity has to be smaller than 11!=
@1 doesn't exist!= @1 doesn't exist!=
Your hand is empty!= Your hand is empty!=
Treasure added!= Treasure added!=
Treasure removed!= Treasure removed!=
Treasure not found!= Treasure not found!=
Treasures list:= Treasures list:=
You're not looking at anything!=
The minimum or maximum amount of treasures has to be greater than 0!= The minimum or maximum amount of treasures has to be greater than 0!=
First arena not found!= First arena not found!=
Second arena not found!= Second arena not found!=