master
Code-Sploit 2021-05-14 14:16:56 +00:00
parent 63dcaf303c
commit 9d06e4560d
4 changed files with 142 additions and 0 deletions

83
api.lua Normal file
View File

@ -0,0 +1,83 @@
kitpvp = {
api = {},
kits = {}
}
function kitpvp.api.give_to_player(player, item)
-- Values nil? If so, close this function
if not player or not item then return end
-- Add it
minetest.add_item(player:get_pos(), item)
end
function kitpvp.api.kit_exists(kitname)
return kitpvp.kits[kitname] ~= nil
end
function kitpvp.api.get_kit_definition(kitname)
-- Just to be sure
if not kitpvp.api.kit_exists(kitname) then return end
return kitpvp.kits[kitname]
end
function kitpvp.api.register_kit(def)
local name = def.name
local items = def.items
local armor = def.armor
--local effects = def.effects
-- Is $def completly filled in?
if not name or not items or not armor then return end
-- Register the kit
kitpvp.kits[name] = def
end
function kitpvp.api.get_kit_names()
local kits = ""
for kit in pairs(kitpvp.kits) do
kits = kits .. kit .. ","
end
kits = string.sub(kits, 0, string.len(kits) - 1)
return kits
end
function kitpvp.api.give_kit(player, kitname)
-- Check if the kit exists
if not kitpvp.api.kit_exists(kitname) then return end
-- Make sure that $player != NULL
if not player then return end
-- Get the kit's definition
local def = kitpvp.api.get_kit_definition(kitname)
-- Add the things
-- DEFAULT items
if def.default_items then
for i=1,64 do
kitpvp.api.give_to_player(player, "mcl_mobitems:cooked_beef")
end
end
-- ARMOR
local components = {"helmet", "chestplate", "leggings", "boots"}
for i, component in pairs(components) do
i = i + 1
local item_name = "mcl_armor:" .. component .. "_" .. def.armor
kitpvp.api.give_to_player(player, item_name)
end
-- ITEMS
for i, item in pairs(def.items) do
kitpvp.api.give_to_player(player, item)
end
end

15
commands.lua Normal file
View File

@ -0,0 +1,15 @@
minetest.register_chatcommand("kit", {
description = "Gives you a kit to PvP",
func = function(name, param)
local player = minetest.get_player_by_name(name)
if not player then return end
if param == "list" then
return false, "Available kits: " .. kitpvp.api.get_kit_names()
else
kitpvp.api.give_kit(player, param)
end
end
})

14
init.lua Normal file
View File

@ -0,0 +1,14 @@
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
if modpath then modpath = modpath .. "/" end
local launch = {
"api.lua",
"kits.lua",
"commands.lua"
}
for _, item in pairs(launch) do
dofile(modpath .. item)
end

30
kits.lua Normal file
View File

@ -0,0 +1,30 @@
--[[
HOW TO ADD KITS:
kitpvp.api.register_kit({
name = agreatkitname,
items = {itemstr1, itemstr2, itemstr3},
armor = leather/chain/iron/gold/diamond/netherite
})
]]
kitpvp.api.register_kit({
name = "tank",
items = {"mcl_tools:sword_iron"},
default_items = true,
armor = "iron"
})
kitpvp.api.register_kit({
name = "archer",
items = {"mcl_tools:sword_stone", "mcl_bows:bow", "mcl_bows:arrow 10000"},
default_items = true,
armor = "gold"
})
kitpvp.api.register_kit({
name = "speedrunner",
items = {"mcl_tools:sword_stone", "mcl_potions:swiftness_2"},
default_items = true,
armor = "gold"
})