removed classes mod + added skills system

This commit is contained in:
cale 2016-07-13 19:05:56 +02:00
parent f482f9517e
commit 24cd2a7c0c
28 changed files with 483 additions and 478 deletions

View File

@ -1,322 +0,0 @@
classes = {}
classes.all_classes = {}
classes.selected = {}
classes.classes_file = minetest.get_worldpath() .. "/classes"
function classes.get_dmg(lvl)
return lvl+2
end
function classes.register_weapon(name, fromLevel, levels, def)
if not def.damage then
if def.damage_m and def.damage_d then
def.damage = math.floor(classes.get_dmg(fromLevel)*def.damage_m-def.damage_d)
end
end
for i = fromLevel, levels, 1 do
minetest.register_tool("classes:"..name .. "_lvl_" .. tostring(i), {
description = def.description.."\n For Level: ".. tostring(i).. "\n Damage: " .. tostring(def.damage+ i-fromLevel) .." \n Class: " .. def.class,
inventory_image = def.inventory_image,
wield_scale = def.wield_scale,
tool_capabilities = {
max_drop_level=3,
damage_groups = {fleshy=def.damage+ i-fromLevel},
},
class = def.class,
on_use = function(itemstack, user, pointed_thing)
if user == nil then return end
if minetest.registered_tools[itemstack:get_name()].class then print(minetest.registered_tools[itemstack:get_name()].class) end
if classes.selected[user:get_player_name()] == minetest.registered_tools[itemstack:get_name()].class then
if pointed_thing.type == "object" then
if xp.player_levels[user:get_player_name()] and xp.player_levels[user:get_player_name()] > i-1 then
pointed_thing.ref:punch(user, 10,minetest.registered_tools[itemstack:get_name()].tool_capabilities)
itemstack:add_wear(300)
print("[info]" .. user:get_player_name() .. " is fighting!")
else
cmsg.push_message_player(user, "[info] You have to be level "..tostring(i).. " to use this weapon!")
end
return itemstack
end
else
cmsg.push_message_player(user, "[info] You cant use this weapon.")
return itemstack
end
end
})
if i < levels then
minetest.register_craft({
output = "classes:"..name .. "_lvl_" .. tostring(i+1),
recipe = {
{"classes:"..name .. "_lvl_" .. tostring(i), "potions:upgrading"},
}
})
end
end
if def.recipe then
minetest.register_craft({
output = "classes:"..name .. "_lvl_" .. tostring(fromLevel),
recipe = def.recipe,
})
end
minetest.register_craft({
output = "classes:"..name .. "_lvl_" .. tostring(i),
recipe = {"classes:"..name .. "_lvl_" .. tostring(i), "classes:"..name .. "_lvl_" ..tostring(i)},
type = "toolrepair",
})
end
function classes.register_tool(name, def)
minetest.register_craftitem("classes:" .. name, {
description = def.description,
inventory_image = def.inventory_image,
wield_image = def.wield_image or def.inventory_image,
class = def.class,
range = def.range or 4,
wield_scale = def.wield_scale,
on_use = function(itemstack, user, pointed_thing)
if user == nil then return end
if classes.selected[user:get_player_name()] == def.class then
if xp.player_levels[user:get_player_name()] and xp.player_levels[user:get_player_name()] > def.lvl-1 then
def.on_use(itemstack, user, pointed_thing)
else
cmsg.push_message_player(user, "[info] You have to be level "..tostring(def.lvl).. " to use this tool!")
end
return nil
else
cmsg.push_message_player(user, "[info] You cant use this tool.")
return itemstack
end
end
})
end
-- load save
function classes.load_selected_classes()
local input = io.open(classes.classes_file, "r")
if input then
local str = input:read()
if str then
for k, v in str.gmatch(str,"(%w+)=(%w+)") do
classes.selected[k] = v
end
end
io.close(input)
end
end
function classes.save_selected_classes()
if classes.selected then
local output = io.open(classes.classes_file, "w")
local str = ""
for k, v in pairs(classes.selected) do
str = str .. k .. "=" .. v .. ","
end
str = str:sub(1, #str - 1)
output:write(str)
io.close(output)
end
end
-- cmd
minetest.register_chatcommand("class", {
params = "<class>",
description = "Set your class to <class>",
privs = {},
func = function(name, text)
if classes.selected[name] then
return true, "Your class is : ".. classes.selected[name] .. "\nYou cant switch your class. If you want to player an other class, you should ask an admin :)"
end
if classes.all_classes[text] then
classes.selected[name] = text
minetest.chat_send_all(name .. " is now a " .. text)
classes.save_selected_classes()
return true, "Your class is now "..text
else
return true, "You cant be a "..text
end
end,
})
minetest.register_chatcommand("myclass", {
params = "",
description = "This command will show you your class",
privs = {},
func = function(name, text)
if classes.selected[name] == nil then return true, "You havent coosen your class, yet!" end
return true, "Your class is "..classes.selected[name]
end,
})
classes.register_class = function(name)
classes.all_classes[name] = true
end
classes.register_class("farmer")
classes.register_class("warrior")
classes.register_class("thief")
classes.register_class("healer")
classes.load_selected_classes()
classes.register_weapon("spear",2, 12, {
description = "Spear",
inventory_image = "classes_spear.png",
wield_scale = {x = 2, y=2, z = 1},
damage_m = 1.0,
damage_d = 0,
class = "warrior",
recipe = {
{"", "default:flint", ""},
{"", "default:string_strong", ""},
{"", "default:stick", ""},
}
})
classes.register_weapon("chemical_spear",5, 17, {
description = "Chemical Spear",
inventory_image = "classes_chemical_spear.png",
wield_scale = {x = 2, y=2, z = 1},
damage_m = 1.1,
damage_d = -1,
class = "warrior"
})
classes.register_tool("shield", {
description = "Shield",
inventory_image = "classes_shield.png",
wield_scale = {x = 2, y=2, z = 1},
class = "warrior",
lvl = 5,
on_use = function(itemstack, user, pointed_thing)
user:set_armor_groups({friendly = 0})
user:set_physics_override({
speed = 0.3,
})
cmsg.push_message_player(user, "[armor] + shield")
minetest.after(3.0, function(player)
if not player or not player:is_player() then
return
end
armor.update_armor(player:get_player_name(), player)
player:set_physics_override({
speed = 1,
})
cmsg.push_message_player(player, "[armor] - shield")
end, user)
end
})
classes.register_weapon("sword",20, 30, {
description = "Sword",
inventory_image = "classes_sword.png",
wield_scale = {x = 1.5, y=1.5, z = 1},
damage_m = 1.0,
damage_d = 0,
class = "warrior",
recipe = {
{"", "default:blade", ""},
{"", "default:string_strong", ""},
{"", "furnace:iron_rod", ""},
}
})
classes.register_weapon("hoe",2, 20, {
description = "Hoe",
inventory_image = "classes_hoe.png",
wield_scale = {x = 1, y=1, z = 1},
damage_m = 0.9,
damage_d = 1,
class = "farmer",
recipe = {
{"", "furnace:iron_rod", "default:blade"},
{"", "default:string_strong", ""},
{"", "default:stick", ""},
}
})
classes.register_weapon("pitchfork",15, 30, {
description = "Pitchfork",
inventory_image = "classes_pitchfork.png",
wield_scale = {x = 1, y=1, z = 1},
damage_m = 0.95,
damage_d = 0,
class = "farmer",
recipe = {
{"furnace:iron_rod", "furnace:iron_rod", "furnace:iron_rod"},
{"", "default:string_strong", ""},
{"", "default:stick", ""},
}
})
classes.register_tool("bow", {
description = "Bow",
inventory_image = "classes_bow.png",
wield_image = "classes_bow_wield.png",
wield_scale = {x = 2.5, y=2.5, z = 1},
class = "farmer",
lvl = 0,
range = 20,
on_use = function(itemstack, user, pointed_thing)
local p = user:getpos()
p.y = p.y + 1.5
local dir = user:get_look_dir()
minetest.add_particle({
pos = p,
velocity = vector.multiply(dir, 50),
acceleration = {x=0, y=0, z=0},
expirationtime = 7,
size = 1,
collisiondetection = false,
vertical = false,
texture = "default_wood.png"
})
if pointed_thing.type == "object" then
local pt = pointed_thing.ref
if not pt or not pt:getpos() or not user then
return
end
pt:punch(user, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=classes.get_dmg(30)},
})
end
end
})
classes.register_weapon("stick",2, 30, {
description = "Stick",
inventory_image = "classes_stick.png",
wield_scale = {x = 1, y=1, z = 1},
damage_m = 0.8,
damage_d = 1,
class = "thief",
recipe = {
{"", "default:stick", ""},
{"", "default:stick", ""},
}
})
classes.register_weapon("long_stick",20, 60, {
description = "Long Stick",
inventory_image = "classes_stick.png",
wield_scale = {x = 2, y=2, z = 1},
damage_m = 0.8,
damage_d = 1,
class = "thief",
recipe = {
{"", "default:stick", ""},
{"", "default:stick", ""},
{"", "default:stick", ""},
}
})
local modpath = minetest.get_modpath("classes")
dofile(modpath.."/skills.lua")

View File

@ -1,149 +0,0 @@
classes.skills = {}
classes.skills.all = {}
classes.skills.energy = {}
classes.skills.energy_hud = {}
minetest.register_on_joinplayer(function(player)
if not player then
return
end
classes.skills.energy_hud[player:get_player_name()] = player:hud_add({
hud_elem_type = "statbar",
position = {x=0.5,y=1.0},
size = {x=16, y=16},
offset = {x=-(32*5), y=-(48*2+32+8)},
text = "classes_skills_energy.png",
number = 0,
})
classes.skills.energy[player:get_player_name()] = 40
end)
function classes.skills.change_energy(player, v)
classes.skills.energy[player:get_player_name()] = classes.skills.energy[player:get_player_name()] + v
local val = 0
if classes.skills.energy[player:get_player_name()] > 39 then
val = 0
else
val = classes.skills.energy[player:get_player_name()]
end
player:hud_change(classes.skills.energy_hud[player:get_player_name()], "number",val)
end
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime;
if timer >=0.5 then
for _, player in pairs(minetest.get_connected_players()) do
if classes.skills.energy[player:get_player_name()] < 40 then
classes.skills.change_energy(player, 1)
if classes.skills.energy[player:get_player_name()] > 39 then
cmsg.push_message_player(player, "[energy] Your energy is full!")
end
end
end
timer = 0
end
end)
function classes.skills.register_skill(name, def)
minetest.register_craftitem("classes:skill_" .. name, {
description = def.description,
inventory_image = def.img,
class = def.class,
on_use = function(itemstack, user, pointed_thing)
if user == nil then return end
if classes.selected[user:get_player_name()] == def.class then
if xp.player_levels[user:get_player_name()] and xp.player_levels[user:get_player_name()] > def.lvl-1 then
if classes.skills.energy[user:get_player_name()] > def.energy -1 then
def.on_use(itemstack, user, pointed_thing)
classes.skills.change_energy(user, -def.energy)
else
cmsg.push_message_player(user, "[WARNING] You dont have enought energy to use this skill!")
end
else
cmsg.push_message_player(user, "[info] You have to be level "..tostring(def.lvl).. " to use this skill!")
end
return nil
else
cmsg.push_message_player(user, "[info] You cant use this skill.")
return itemstack
end
end
})
table.insert(classes.skills.all, "classes:skill_" .. name)
end
minetest.register_craftitem("classes:skill_book", {
description = "Skill Book",
inventory_image = "classes_skills_book.png",
on_use = function(itemstack, user, pointed_thing)
if user == nil then return end
user:get_inventory():add_item("main", classes.skills.all[math.random(#classes.skills.all)])
itemstack:take_item()
return itemstack
end
})
table.insert(default.treasure_chest_items, "classes:skill_book")
classes.skills.register_skill("super_jump", {
description = "Super Jump\nLevel: 15\nClass: thief\nTime: 7.0\nEffect: gravity = 0.1\nEnergy: 10",
img = "classes_skills_super_jump.png",
class = "thief",
lvl = 15,
energy = 10,
on_use = function(itemstack, user, pointed_thing)
user:set_physics_override({
gravity = 0.1,
})
cmsg.push_message_player(user, "[skill] + super jump")
minetest.after(7.0, function(player)
if not player or not player:is_player() then
return
end
player:set_physics_override({
gravity = 1,
})
cmsg.push_message_player(player, "[skill] - super jump")
end, user)
end
})
classes.skills.register_skill("lift", {
description = "Lift\nLevel: 25\nClass: thief\nTime: 2.0\nEffect: gravity = -0.5\nEnergy: 20",
img = "classes_skills_lift.png",
class = "thief",
lvl = 25,
energy = 20,
on_use = function(itemstack, user, pointed_thing)
user:set_physics_override({
gravity = -0.5,
})
cmsg.push_message_player(user, "[skill] + lift")
minetest.after(2.0, function(player)
if not player or not player:is_player() then
return
end
player:set_physics_override({
gravity = 1,
})
cmsg.push_message_player(player, "[skill] - lift")
end, user)
end
})
classes.skills.register_skill("heal", {
description = "Heal\nLevel: 13\nClass: farmer\nEffect: hp + 4\nEnergy: 15",
img = "classes_skills_heal.png",
class = "farmer",
lvl = 13,
energy = 15,
on_use = function(itemstack, user, pointed_thing)
user:set_hp(user:get_hp()+4)
cmsg.push_message_player(user, "[skill][hp] + 4")
end
})

View File

@ -1,2 +1,2 @@
classes skills
blueprint blueprint

View File

@ -3,12 +3,12 @@ legendary_items.rare_weapons = {}
legendary_items.register_rare_weapon = function(name, forlevel, def) legendary_items.register_rare_weapon = function(name, forlevel, def)
table.insert(legendary_items.rare_weapons, name) table.insert(legendary_items.rare_weapons, name)
minetest.register_tool(":legendary_items:"..name, { minetest.register_tool(":legendary_items:"..name, {
description = def.description.."\n For Level: ".. tostring(forlevel).. "\n Damage: " .. tostring(def.damage+classes.get_dmg(forlevel)) .. "\n Rare Item", description = def.description.."\n For Level: ".. tostring(forlevel).. "\n Damage: " .. tostring(def.damage+skills.get_dmg(forlevel)) .. "\n Rare Item",
inventory_image = def.inventory_image, inventory_image = def.inventory_image,
wield_scale = def.wield_scale, wield_scale = def.wield_scale,
tool_capabilities = { tool_capabilities = {
max_drop_level=3, max_drop_level=3,
damage_groups = {fleshy=def.damage+classes.get_dmg(forlevel)}, damage_groups = {fleshy=def.damage+skills.get_dmg(forlevel)},
}, },
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
if user == nil then return end if user == nil then return end
@ -26,7 +26,7 @@ legendary_items.register_rare_weapon = function(name, forlevel, def)
}) })
table.insert(def.materials, "default:ruby") table.insert(def.materials, "default:ruby")
blueprint.register_blueprint(name, { blueprint.register_blueprint(name, {
description = def.description .. "\n For Level: ".. tostring(forlevel).. "\n Damage: " .. tostring(def.damage+classes.get_dmg(forlevel)) .. "\n Rare Item", description = def.description .. "\n For Level: ".. tostring(forlevel).. "\n Damage: " .. tostring(def.damage+skills.get_dmg(forlevel)) .. "\n Rare Item",
materials = def.materials, materials = def.materials,
out = "legendary_items:"..name, out = "legendary_items:"..name,
color = "yellow" color = "yellow"

View File

@ -1,3 +1,3 @@
classes skills
default default
xp xp

View File

@ -11,7 +11,7 @@ function mobs.register_mob(name, def)
if not def.hp then if not def.hp then
if def.lvl and def.hits then if def.lvl and def.hits then
def.hp = classes.get_dmg(def.lvl)*def.hits def.hp = skills.get_dmg(def.lvl)*def.hits
end end
end end

144
mods/skills/abilities.lua Normal file
View File

@ -0,0 +1,144 @@
skills.abilities = {}
skills.abilities.all = {}
skills.abilities.energy = {}
skills.abilities.energy_hud = {}
minetest.register_on_joinplayer(function(player)
if not player then
return
end
skills.abilities.energy_hud[player:get_player_name()] = player:hud_add({
hud_elem_type = "statbar",
position = {x=0.5,y=1.0},
size = {x=16, y=16},
offset = {x=-(32*5), y=-(48*2+32+8)},
text = "skills_abilities_energy.png",
number = 0,
})
skills.abilities.energy[player:get_player_name()] = 40
end)
function skills.abilities.change_energy(player, v)
skills.abilities.energy[player:get_player_name()] = skills.abilities.energy[player:get_player_name()] + v
local val = 0
if skills.abilities.energy[player:get_player_name()] > 39 then
val = 0
else
val = skills.abilities.energy[player:get_player_name()]
end
player:hud_change(skills.abilities.energy_hud[player:get_player_name()], "number",val)
end
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime;
if timer >=0.5 then
for _, player in pairs(minetest.get_connected_players()) do
if skills.abilities.energy[player:get_player_name()] < 40 then
skills.abilities.change_energy(player, 1)
if skills.abilities.energy[player:get_player_name()] > 39 then
cmsg.push_message_player(player, "[energy] Your energy is full!")
end
end
end
timer = 0
end
end)
function skills.abilities.register_skill(name, def)
minetest.register_craftitem("skills:ability_" .. name, {
description = def.description,
inventory_image = def.img,
skill = def.skill,
on_use = function(itemstack, user, pointed_thing)
if user == nil then return end
if skills.lvls[user:get_player_name()] and skills.lvls[user:get_player_name()][def.skill] > def.lvl-1 then
if skills.abilities.energy[user:get_player_name()] > def.energy -1 then
def.on_use(itemstack, user, pointed_thing)
skills.abilities.change_energy(user, -def.energy)
else
cmsg.push_message_player(user, "[WARNING] You dont have enought energy to use this ability!")
end
else
cmsg.push_message_player(user, "[info] You have to be " .. def.skill .. " level "..tostring(def.lvl).. " to use this ability!")
end
return nil
end
})
table.insert(skills.abilities.all, "skills:abilities_" .. name)
end
minetest.register_craftitem("skills:skill_book", {
description = "Ability Book",
inventory_image = "skills_abilities_book.png",
on_use = function(itemstack, user, pointed_thing)
if user == nil then return end
user:get_inventory():add_item("main", skills.abilities.all[math.random(#skills.abilities.all)])
itemstack:take_item()
return itemstack
end
})
table.insert(default.treasure_chest_items, "skills:skill_book")
skills.abilities.register_skill("super_jump", {
description = "Super Jump\nLevel: 15\nskill: thief\nTime: 7.0\nEffect: gravity = 0.1\nEnergy: 10",
img = "skills_abilities_super_jump.png",
skill = "thief",
lvl = 15,
energy = 10,
on_use = function(itemstack, user, pointed_thing)
user:set_physics_override({
gravity = 0.1,
})
cmsg.push_message_player(user, "[skill] + super jump")
minetest.after(7.0, function(player)
if not player or not player:is_player() then
return
end
player:set_physics_override({
gravity = 1,
})
cmsg.push_message_player(player, "[skill] - super jump")
end, user)
end
})
skills.abilities.register_skill("lift", {
description = "Lift\nLevel: 25\nskill: thief\nTime: 2.0\nEffect: gravity = -0.5\nEnergy: 20",
img = "skills_abilities_lift.png",
skill = "thief",
lvl = 25,
energy = 20,
on_use = function(itemstack, user, pointed_thing)
user:set_physics_override({
gravity = -0.5,
})
cmsg.push_message_player(user, "[skill] + lift")
minetest.after(2.0, function(player)
if not player or not player:is_player() then
return
end
player:set_physics_override({
gravity = 1,
})
cmsg.push_message_player(player, "[skill] - lift")
end, user)
end
})
skills.abilities.register_skill("heal", {
description = "Heal\nLevel: 13\nskill: farmer\nEffect: hp + 4\nEnergy: 15",
img = "skills_abilities_heal.png",
skill = "farmer",
lvl = 13,
energy = 15,
on_use = function(itemstack, user, pointed_thing)
user:set_hp(user:get_hp()+4)
cmsg.push_message_player(user, "[skill][hp] + 4")
end
})

324
mods/skills/init.lua Normal file
View File

@ -0,0 +1,324 @@
skills = {}
skills.all_skills = {}
skills.selected = {}
skills.lvls = {}
skills.skills_file = minetest.get_worldpath() .. "/skills"
minetest.register_on_newplayer(function(player)
skills.lvls[player:get_player_name()] = {}
for s,a in pairs(skills.all_skills) do
skills.lvls[player:get_player_name()][s] = 1
end
end)
function skills.get_dmg(lvl)
return lvl+2
end
function skills.get_text(name)
local str = ""
for s,l in pairs(skills.lvls[name]) do
str = str .. s .. " : " .. l .. " "
end
return str
end
function skills.register_weapon(name, fromLevel, levels, def)
if not def.damage then
if def.damage_m and def.damage_d then
def.damage = math.floor(skills.get_dmg(fromLevel)*def.damage_m-def.damage_d)
end
end
for i = fromLevel, levels, 1 do
minetest.register_tool("skills:"..name .. "_lvl_" .. tostring(i), {
description = def.description.."\n For Level: ".. tostring(i).. "\n Damage: " .. tostring(def.damage+ i-fromLevel) .." \n Skill: " .. def.skill,
inventory_image = def.inventory_image,
wield_scale = def.wield_scale,
tool_capabilities = {
max_drop_level=3,
damage_groups = {fleshy=def.damage+ i-fromLevel},
},
skill = def.skill,
on_use = function(itemstack, user, pointed_thing)
if user == nil then return end
if pointed_thing.type == "object" then
if skills.lvls[user:get_player_name()] and skills.lvls[user:get_player_name()][def.skill] > i-1 then
pointed_thing.ref:punch(user, 10,minetest.registered_tools[itemstack:get_name()].tool_capabilities)
itemstack:add_wear(300)
print("[info]" .. user:get_player_name() .. " is fighting!")
else
cmsg.push_message_player(user, "[info] You have to be " .. def.skill .. " level "..tostring(i).. " to use this weapon!")
end
return itemstack
end
end
})
if i < levels then
minetest.register_craft({
output = "skills:"..name .. "_lvl_" .. tostring(i+1),
recipe = {
{"skills:"..name .. "_lvl_" .. tostring(i), "potions:upgrading"},
}
})
end
end
if def.recipe then
minetest.register_craft({
output = "skills:"..name .. "_lvl_" .. tostring(fromLevel),
recipe = def.recipe,
})
end
minetest.register_craft({
output = "skills:"..name .. "_lvl_" .. tostring(i),
recipe = {"skills:"..name .. "_lvl_" .. tostring(i), "skills:"..name .. "_lvl_" ..tostring(i)},
type = "toolrepair",
})
end
function skills.register_tool(name, def)
minetest.register_craftitem("skills:" .. name, {
description = def.description,
inventory_image = def.inventory_image,
wield_image = def.wield_image or def.inventory_image,
skill = def.skill,
range = def.range or 4,
wield_scale = def.wield_scale,
on_use = function(itemstack, user, pointed_thing)
if user == nil then return end
if skills.lvls[user:get_player_name()] and skills.lvls[user:get_player_name()][def.skill] > def.lvl-1 then
def.on_use(itemstack, user, pointed_thing)
else
cmsg.push_message_player(user, "[info] You have to be " .. def.skill .. " level "..tostring(def.lvl).. " to use this tool!")
end
return nil
end
})
end
-- load save
function skills.load_skills()
local input = io.open(skills.skills_file, "r")
if input then
local str = input:read()
if minetest.deserialize(str) then
skills.lvls = minetest.deserialize(str)
end
io.close(input)
end
end
function skills.save_skills()
if skills.lvls then
local output = io.open(skills.skills_file, "w")
local str = minetest.serialize(skills.lvls)
output:write(str)
io.close(output)
end
end
-- cmd
minetest.register_chatcommand("skill", {
params = "<skill>",
description = "Level up <skill>",
privs = {},
func = function(name, text)
if text == "show" then
cmsg.push_message_player(minetest.get_player_by_name(name), "[skills] " .. skills.get_text(name))
return true,"Done"
end
if not(skills.lvls[name]) then
return false, "[ERROR] Please contact an admin."
end
if skills.lvls[name][text] then
local count = 0
for s,l in pairs(skills.lvls[name]) do
count = count + (l-1)
end
print(count)
print(xp.player_levels[name])
if xp.player_levels[name] > count then
skills.lvls[name][text] = skills.lvls[name][text] + 1
skills.save_skills()
cmsg.push_message_player(minetest.get_player_by_name(name), "[skills] " .. skills.get_text(name))
return true, "You leveled up " ..text
else
return true, "You cant level up "..text .. " at the moment."
end
else
return true, "You cant level up "..text
end
end,
})
skills.register_skill = function(name)
skills.all_skills[name] = true
end
skills.register_skill("farmer")
skills.register_skill("warrior")
skills.register_skill("thief")
skills.register_skill("miner")
skills.load_skills()
skills.register_weapon("spear",2, 12, {
description = "Spear",
inventory_image = "skills_spear.png",
wield_scale = {x = 2, y=2, z = 1},
damage_m = 1.0,
damage_d = 0,
skill = "warrior",
recipe = {
{"", "default:flint", ""},
{"", "default:string_strong", ""},
{"", "default:stick", ""},
}
})
skills.register_weapon("chemical_spear",5, 17, {
description = "Chemical Spear",
inventory_image = "skills_chemical_spear.png",
wield_scale = {x = 2, y=2, z = 1},
damage_m = 1.1,
damage_d = -1,
skill = "warrior"
})
skills.register_tool("shield", {
description = "Shield",
inventory_image = "skills_shield.png",
wield_scale = {x = 2, y=2, z = 1},
skill = "warrior",
lvl = 5,
on_use = function(itemstack, user, pointed_thing)
user:set_armor_groups({friendly = 0})
user:set_physics_override({
speed = 0.3,
})
cmsg.push_message_player(user, "[armor] + shield")
minetest.after(3.0, function(player)
if not player or not player:is_player() then
return
end
armor.update_armor(player:get_player_name(), player)
player:set_physics_override({
speed = 1,
})
cmsg.push_message_player(player, "[armor] - shield")
end, user)
end
})
skills.register_weapon("sword",20, 30, {
description = "Sword",
inventory_image = "skills_sword.png",
wield_scale = {x = 1.5, y=1.5, z = 1},
damage_m = 1.0,
damage_d = 0,
skill = "warrior",
recipe = {
{"", "default:blade", ""},
{"", "default:string_strong", ""},
{"", "furnace:iron_rod", ""},
}
})
skills.register_weapon("hoe",2, 20, {
description = "Hoe",
inventory_image = "skills_hoe.png",
wield_scale = {x = 1, y=1, z = 1},
damage_m = 0.9,
damage_d = 1,
skill = "farmer",
recipe = {
{"", "furnace:iron_rod", "default:blade"},
{"", "default:string_strong", ""},
{"", "default:stick", ""},
}
})
skills.register_weapon("pitchfork",15, 30, {
description = "Pitchfork",
inventory_image = "skills_pitchfork.png",
wield_scale = {x = 1, y=1, z = 1},
damage_m = 0.95,
damage_d = 0,
skill = "farmer",
recipe = {
{"furnace:iron_rod", "furnace:iron_rod", "furnace:iron_rod"},
{"", "default:string_strong", ""},
{"", "default:stick", ""},
}
})
skills.register_tool("bow", {
description = "Bow",
inventory_image = "skills_bow.png",
wield_image = "skills_bow_wield.png",
wield_scale = {x = 2.5, y=2.5, z = 1},
skill = "farmer",
lvl = 0,
range = 20,
on_use = function(itemstack, user, pointed_thing)
local p = user:getpos()
p.y = p.y + 1.5
local dir = user:get_look_dir()
minetest.add_particle({
pos = p,
velocity = vector.multiply(dir, 50),
acceleration = {x=0, y=0, z=0},
expirationtime = 7,
size = 1,
collisiondetection = false,
vertical = false,
texture = "default_wood.png"
})
if pointed_thing.type == "object" then
local pt = pointed_thing.ref
if not pt or not pt:getpos() or not user then
return
end
pt:punch(user, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=skills.get_dmg(30)},
})
end
end
})
skills.register_weapon("stick",2, 30, {
description = "Stick",
inventory_image = "skills_stick.png",
wield_scale = {x = 1, y=1, z = 1},
damage_m = 0.8,
damage_d = 1,
skill = "thief",
recipe = {
{"", "default:stick", ""},
{"", "default:stick", ""},
}
})
skills.register_weapon("long_stick",20, 60, {
description = "Long Stick",
inventory_image = "skills_stick.png",
wield_scale = {x = 2, y=2, z = 1},
damage_m = 0.8,
damage_d = 1,
skill = "thief",
recipe = {
{"", "default:stick", ""},
{"", "default:stick", ""},
{"", "default:stick", ""},
}
})
local modpath = minetest.get_modpath("skills")
dofile(modpath.."/abilities.lua")

View File

Before

Width:  |  Height:  |  Size: 280 B

After

Width:  |  Height:  |  Size: 280 B

View File

Before

Width:  |  Height:  |  Size: 202 B

After

Width:  |  Height:  |  Size: 202 B

View File

Before

Width:  |  Height:  |  Size: 278 B

After

Width:  |  Height:  |  Size: 278 B

View File

Before

Width:  |  Height:  |  Size: 292 B

After

Width:  |  Height:  |  Size: 292 B

View File

Before

Width:  |  Height:  |  Size: 269 B

After

Width:  |  Height:  |  Size: 269 B

View File

Before

Width:  |  Height:  |  Size: 213 B

After

Width:  |  Height:  |  Size: 213 B

View File

Before

Width:  |  Height:  |  Size: 287 B

After

Width:  |  Height:  |  Size: 287 B

View File

Before

Width:  |  Height:  |  Size: 232 B

After

Width:  |  Height:  |  Size: 232 B

View File

Before

Width:  |  Height:  |  Size: 229 B

After

Width:  |  Height:  |  Size: 229 B

View File

Before

Width:  |  Height:  |  Size: 175 B

After

Width:  |  Height:  |  Size: 175 B

View File

Before

Width:  |  Height:  |  Size: 203 B

After

Width:  |  Height:  |  Size: 203 B

View File

Before

Width:  |  Height:  |  Size: 241 B

After

Width:  |  Height:  |  Size: 241 B

View File

Before

Width:  |  Height:  |  Size: 238 B

After

Width:  |  Height:  |  Size: 238 B

View File

Before

Width:  |  Height:  |  Size: 207 B

After

Width:  |  Height:  |  Size: 207 B

View File

Before

Width:  |  Height:  |  Size: 175 B

After

Width:  |  Height:  |  Size: 175 B

View File

Before

Width:  |  Height:  |  Size: 229 B

After

Width:  |  Height:  |  Size: 229 B

View File

Before

Width:  |  Height:  |  Size: 265 B

After

Width:  |  Height:  |  Size: 265 B

View File

@ -8,6 +8,12 @@ xp.level_hud = {}
xp.xp_file = minetest.get_worldpath() .. "/xp" xp.xp_file = minetest.get_worldpath() .. "/xp"
xp.lvl_file = minetest.get_worldpath() .. "/levels" xp.lvl_file = minetest.get_worldpath() .. "/levels"
xp.custom_level_system = false
function xp.set_level_hud_text(player, str)
player:hud_change(xp.level_hud[player:get_player_name()], "text", str)
end
function xp.get_xp(lvl, x) function xp.get_xp(lvl, x)
return (xp.lvl * lvl) / x return (xp.lvl * lvl) / x
end end
@ -45,7 +51,9 @@ function xp.add_lvl(player)
xp.player_levels[player:get_player_name()] = 1 xp.player_levels[player:get_player_name()] = 1
end end
xp.save_levels() xp.save_levels()
player:hud_change(xp.level_hud[player:get_player_name()], "text", xp.player_levels[player:get_player_name()]) if not(xp.custom_level_system) then
player:hud_change(xp.level_hud[player:get_player_name()], "text", xp.player_levels[player:get_player_name()])
end
cmsg.push_message_player(player, "Level up! You are now Level " .. tostring(xp.player_levels[player:get_player_name()])) cmsg.push_message_player(player, "Level up! You are now Level " .. tostring(xp.player_levels[player:get_player_name()]))
end end