Fix variants of class items being allowed to drop
This commit is contained in:
parent
93693a8dfd
commit
d973815a18
7 changed files with 112 additions and 49 deletions
|
@ -11,6 +11,22 @@ function ctf_classes.register(cname, def)
|
|||
if def.properties.can_capture == nil then
|
||||
def.properties.can_capture = true
|
||||
end
|
||||
|
||||
def.properties.initial_stuff = def.properties.initial_stuff or {}
|
||||
|
||||
if not def.properties.item_blacklist then
|
||||
def.properties.item_blacklist = {}
|
||||
for i=1, #def.properties.initial_stuff do
|
||||
table.insert(def.properties.item_blacklist, def.properties.initial_stuff[i])
|
||||
end
|
||||
end
|
||||
|
||||
if def.properties.additional_item_blacklist then
|
||||
for i=1, #def.properties.additional_item_blacklist do
|
||||
table.insert(def.properties.item_blacklist, def.properties.additional_item_blacklist[i])
|
||||
end
|
||||
end
|
||||
|
||||
def.properties.speed = def.properties.speed or 1
|
||||
def.properties.max_hp = def.properties.max_hp or 20
|
||||
end
|
||||
|
|
|
@ -42,7 +42,7 @@ function ctf_classes.show_gui(name, player)
|
|||
end
|
||||
fs[#fs + 1] = "]"
|
||||
|
||||
for i, item in pairs(class.properties.items or {}) do
|
||||
for i, item in pairs(class.properties.initial_stuff) do
|
||||
fs[#fs + 1] = "item_image["
|
||||
fs[#fs + 1] = tostring(i * 0.5 - 0.4)
|
||||
fs[#fs + 1] = ",2.25;0.5,0.5;"
|
||||
|
|
|
@ -21,7 +21,7 @@ ctf_classes.register("knight", {
|
|||
max_hp = 30,
|
||||
speed = 0.90,
|
||||
|
||||
items = {
|
||||
initial_stuff = {
|
||||
"default:sword_steel",
|
||||
},
|
||||
|
||||
|
@ -39,11 +39,16 @@ ctf_classes.register("shooter", {
|
|||
cons = {},
|
||||
color = "#c60",
|
||||
properties = {
|
||||
items = {
|
||||
initial_stuff = {
|
||||
"shooter:rifle",
|
||||
"shooter:grapple_gun_loaded",
|
||||
},
|
||||
|
||||
additional_item_blacklist = {
|
||||
"shooter:grapple_gun",
|
||||
"shooter:grapple_hook",
|
||||
},
|
||||
|
||||
allowed_guns = {
|
||||
"shooter:pistol",
|
||||
"shooter:rifle",
|
||||
|
@ -64,7 +69,7 @@ ctf_classes.register("medic", {
|
|||
cons = {},
|
||||
color = "#0af",
|
||||
properties = {
|
||||
items = {
|
||||
initial_stuff = {
|
||||
"ctf_bandages:bandage 20",
|
||||
},
|
||||
|
||||
|
@ -82,11 +87,15 @@ ctf_classes.register("rocketeer", {
|
|||
cons = {},
|
||||
color = "#fa0",
|
||||
properties = {
|
||||
items = {
|
||||
initial_stuff = {
|
||||
"shooter:rocket_gun_loaded",
|
||||
"shooter:rocket 4",
|
||||
},
|
||||
|
||||
additional_item_blacklist = {
|
||||
"shooter:rocket_gun",
|
||||
},
|
||||
|
||||
allowed_guns = {
|
||||
"shooter:pistol",
|
||||
"shooter:smg",
|
||||
|
|
|
@ -1,28 +1,3 @@
|
|||
give_initial_stuff.register_stuff_provider(function(player)
|
||||
local class = ctf_classes.get(player)
|
||||
return class.properties.items or {}
|
||||
end, 1)
|
||||
|
||||
ctf_classes.register_on_changed(function(player, old, new)
|
||||
local inv = player:get_inventory()
|
||||
|
||||
if old then
|
||||
local items = old.properties.items or {}
|
||||
for i = 1, #items do
|
||||
inv:remove_item("main", ItemStack(items[i]))
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
assert(new)
|
||||
|
||||
local items = new.properties.items or {}
|
||||
for i = 1, #items do
|
||||
inv:add_item("main", ItemStack(items[i]))
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local function stack_list_to_map(stacks)
|
||||
local map = {}
|
||||
for i = 1, #stacks do
|
||||
|
@ -31,12 +6,42 @@ local function stack_list_to_map(stacks)
|
|||
return map
|
||||
end
|
||||
|
||||
-- Returns true if the item shouldn't be allowed to be dropped etc
|
||||
local function is_class_blacklisted(player, itemname)
|
||||
local class = ctf_classes.get(player)
|
||||
local items = stack_list_to_map(class.properties.item_blacklist or {})
|
||||
return items[itemname]
|
||||
end
|
||||
|
||||
|
||||
give_initial_stuff.register_stuff_provider(function(player)
|
||||
local class = ctf_classes.get(player)
|
||||
return class.properties.initial_stuff or {}
|
||||
end, 1)
|
||||
|
||||
ctf_classes.register_on_changed(function(player, old, new)
|
||||
local inv = player:get_inventory()
|
||||
|
||||
if old then
|
||||
local items = old.properties.item_blacklist or {}
|
||||
for i = 1, #items do
|
||||
inv:remove_item("main", ItemStack(items[i]))
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
assert(new)
|
||||
|
||||
local items = new.properties.initial_stuff or {}
|
||||
for i = 1, #items do
|
||||
inv:add_item("main", ItemStack(items[i]))
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local old_item_drop = minetest.item_drop
|
||||
minetest.item_drop = function(itemstack, player, pos)
|
||||
local class = ctf_classes.get(player)
|
||||
|
||||
local items = stack_list_to_map(class.properties.items or {})
|
||||
if items[itemstack:get_name()] then
|
||||
if is_class_blacklisted(player, itemstack:get_name()) then
|
||||
minetest.chat_send_player(player:get_player_name(),
|
||||
"You're not allowed to drop class items!")
|
||||
return itemstack
|
||||
|
@ -47,10 +52,7 @@ end
|
|||
|
||||
local old_is_allowed = ctf_map.is_item_allowed_in_team_chest
|
||||
ctf_map.is_item_allowed_in_team_chest = function(listname, stack, player)
|
||||
local class = ctf_classes.get(player)
|
||||
|
||||
local items = stack_list_to_map(class.properties.items or {})
|
||||
if items[stack:get_name()] then
|
||||
if is_class_blacklisted(player, stack:get_name()) then
|
||||
minetest.chat_send_player(player:get_player_name(),
|
||||
"You're not allowed to put class items in the chest!")
|
||||
return false
|
||||
|
@ -58,3 +60,7 @@ ctf_map.is_item_allowed_in_team_chest = function(listname, stack, player)
|
|||
return old_is_allowed(listname, stack, player)
|
||||
end
|
||||
end
|
||||
|
||||
dropondie.register_drop_filter(function(player, itemname)
|
||||
return not is_class_blacklisted(player, itemname)
|
||||
end)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
name = ctf_classes
|
||||
depends = ctf, ctf_flag, ctf_colors, ctf_map_core, physics, shooter, hpregen, give_initial_stuff
|
||||
depends = ctf, ctf_flag, ctf_colors, ctf_map_core, physics, shooter, hpregen, give_initial_stuff, dropondie
|
||||
description = Adds classes, including knight, shooter, and medic
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue