added new xp system
This commit is contained in:
parent
2744350c47
commit
8ce447e6ca
@ -1,3 +1,4 @@
|
||||
default
|
||||
central_message
|
||||
story
|
||||
xp
|
||||
|
@ -1,3 +1,4 @@
|
||||
default
|
||||
central_message
|
||||
story
|
||||
xp
|
||||
|
@ -27,7 +27,7 @@ minetest.register_node("quests:quest_block", {
|
||||
end
|
||||
if itemstack:to_table().name == meta:get_string("item") then
|
||||
meta:set_string("infotext", "Thank you!")
|
||||
player:get_inventory():add_item("main", {name = "default:xp",count = math.random(10, 30)})
|
||||
xp.add_xp(player, math.random(3, 30))
|
||||
minetest.add_particlespawner({
|
||||
amount = 500,
|
||||
time = 5,
|
||||
@ -46,7 +46,6 @@ minetest.register_node("quests:quest_block", {
|
||||
texture = "default_xp.png",
|
||||
})
|
||||
minetest.remove_node(pos)
|
||||
cmsg.push_message_player(player, "You got some XP!")
|
||||
else
|
||||
meta:set_string("infotext", "That isnt the item I am searching for..")
|
||||
end
|
||||
@ -58,7 +57,7 @@ minetest.register_node("quests:map", {
|
||||
tiles = {"quests_map_top.png", "quests_map_top.png", "quests_map.png", "quests_map.png", "quests_map.png", "quests_map.png"},
|
||||
groups = {quest = 1, cracky = 3},
|
||||
on_punch = function(pos, node, player, pointed_thing)
|
||||
player:get_inventory():add_item("main", {name = "default:xp", count = math.random(3, 20)})
|
||||
xp.add_xp(player, math.random(3, 30))
|
||||
minetest.add_particlespawner({
|
||||
amount = 500,
|
||||
time = 5,
|
||||
@ -77,7 +76,6 @@ minetest.register_node("quests:map", {
|
||||
texture = "default_xp.png",
|
||||
})
|
||||
minetest.remove_node(pos)
|
||||
cmsg.push_message_player(player, "You got some XP!")
|
||||
end,
|
||||
})
|
||||
|
||||
|
@ -27,7 +27,7 @@ minetest.register_node("quests:quest_block", {
|
||||
end
|
||||
if itemstack:to_table().name == meta:get_string("item") then
|
||||
meta:set_string("infotext", "Thank you!")
|
||||
player:get_inventory():add_item("main", {name = "default:xp",count = math.random(10, 30)})
|
||||
xp.add_xp(player, math.random(3, 30))
|
||||
minetest.add_particlespawner({
|
||||
amount = 500,
|
||||
time = 5,
|
||||
@ -46,7 +46,6 @@ minetest.register_node("quests:quest_block", {
|
||||
texture = "default_xp.png",
|
||||
})
|
||||
minetest.remove_node(pos)
|
||||
cmsg.push_message_player(player, "You got some XP!")
|
||||
else
|
||||
meta:set_string("infotext", "That isnt the item I am searching for..")
|
||||
end
|
||||
@ -58,7 +57,7 @@ minetest.register_node("quests:map", {
|
||||
tiles = {"quests_map_top.png", "quests_map_top.png", "quests_map.png", "quests_map.png", "quests_map.png", "quests_map.png"},
|
||||
groups = {quest = 1, cracky = 3},
|
||||
on_punch = function(pos, node, player, pointed_thing)
|
||||
player:get_inventory():add_item("main", {name = "default:xp", count = math.random(3, 20)})
|
||||
xp.add_xp(player, math.random(3, 30))
|
||||
minetest.add_particlespawner({
|
||||
amount = 500,
|
||||
time = 5,
|
||||
@ -77,7 +76,6 @@ minetest.register_node("quests:map", {
|
||||
texture = "default_xp.png",
|
||||
})
|
||||
minetest.remove_node(pos)
|
||||
cmsg.push_message_player(player, "You got some XP!")
|
||||
end,
|
||||
})
|
||||
|
||||
|
16
mods/xp/LICENSE.txt
Normal file
16
mods/xp/LICENSE.txt
Normal file
@ -0,0 +1,16 @@
|
||||
License for Code
|
||||
----------------
|
||||
|
||||
Copyright (C) 2016 cd2 (cdqwertz) <cdqwertz@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
|
||||
License for Media
|
||||
-----------------
|
||||
|
||||
CC-BY-SA 3.0 UNPORTED. Created by cd2 (cdqwertz)
|
1
mods/xp/depends.txt
Normal file
1
mods/xp/depends.txt
Normal file
@ -0,0 +1 @@
|
||||
central_message
|
1
mods/xp/depends.txt~
Normal file
1
mods/xp/depends.txt~
Normal file
@ -0,0 +1 @@
|
||||
central_message
|
116
mods/xp/init.lua
Normal file
116
mods/xp/init.lua
Normal file
@ -0,0 +1,116 @@
|
||||
xp = {}
|
||||
xp.lvl = 20
|
||||
xp.player_xp = {}
|
||||
xp.player_levels = {}
|
||||
xp.xp_hud = {}
|
||||
xp.level_hud = {}
|
||||
|
||||
xp.xp_file = minetest.get_worldpath() .. "/xp"
|
||||
xp.lvl_file = minetest.get_worldpath() .. "/levels"
|
||||
|
||||
function xp.add_xp(player, num)
|
||||
if xp.player_xp[player:get_player_name()] then
|
||||
xp.player_xp[player:get_player_name()] = xp.player_xp[player:get_player_name()] + num
|
||||
else
|
||||
xp.player_xp[player:get_player_name()] = num
|
||||
end
|
||||
|
||||
cmsg.push_message_player(player, "You got "..tostring(num).. " xp!")
|
||||
|
||||
if xp.player_levels[player:get_player_name()] then
|
||||
if xp.player_xp[player:get_player_name()] > xp.lvl*xp.player_levels[player:get_player_name()] then
|
||||
xp.player_xp[player:get_player_name()] = 0
|
||||
xp.add_lvl(player)
|
||||
end
|
||||
else
|
||||
xp.player_levels[player:get_player_name()] = 1
|
||||
end
|
||||
print("[info] xp for player ".. player:get_player_name() .. " " .. xp.player_xp[player:get_player_name()].."/"..xp.lvl*xp.player_levels[player:get_player_name()].." = " .. (xp.player_xp[player:get_player_name()])/(xp.lvl*xp.player_levels[player:get_player_name()]))
|
||||
player:hud_change(xp.xp_hud[player:get_player_name()], "number", 20*((xp.player_xp[player:get_player_name()])/(xp.lvl*xp.player_levels[player:get_player_name()])))
|
||||
xp.save_xp()
|
||||
end
|
||||
|
||||
function xp.add_lvl(player)
|
||||
if xp.player_levels[player:get_player_name()] then
|
||||
xp.player_levels[player:get_player_name()] = xp.player_levels[player:get_player_name()] + 1
|
||||
else
|
||||
xp.player_levels[player:get_player_name()] = 1
|
||||
end
|
||||
xp.save_levels()
|
||||
player:hud_change(xp.level_hud[player:get_player_name()], "text", 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
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
xp.xp_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*8+16), y=-(48*2+16)},
|
||||
text = "xp_xp.png",
|
||||
number = 20*((xp.player_xp[player:get_player_name()])/(xp.lvl*xp.player_levels[player:get_player_name()])),
|
||||
})
|
||||
xp.level_hud[player:get_player_name()] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = {x=0.5,y=1},
|
||||
text = xp.player_levels[player:get_player_name()],
|
||||
number = 0xFFFFFF,
|
||||
alignment = {x=0.5,y=1},
|
||||
offset = {x=0, y=-(48*2+16)},
|
||||
})
|
||||
end)
|
||||
|
||||
function xp.load_xp()
|
||||
local input = io.open(xp.xp_file, "r")
|
||||
if input then
|
||||
local str = input:read()
|
||||
if str then
|
||||
for k, v in str.gmatch(str,"(%w+)=(%w+)") do
|
||||
xp.player_xp[k] = tonumber(v)
|
||||
end
|
||||
end
|
||||
io.close(input)
|
||||
end
|
||||
end
|
||||
|
||||
function xp.save_xp()
|
||||
if xp.player_xp then
|
||||
local output = io.open(xp.xp_file, "w")
|
||||
local str = ""
|
||||
for k, v in pairs(xp.player_xp) do
|
||||
str = str .. k .. "=" .. v .. ","
|
||||
end
|
||||
str = str:sub(1, #str - 1)
|
||||
output:write(str)
|
||||
io.close(output)
|
||||
end
|
||||
end
|
||||
|
||||
function xp.load_levels()
|
||||
local input = io.open(xp.lvl_file, "r")
|
||||
if input then
|
||||
local str = input:read()
|
||||
if str then
|
||||
for k, v in str.gmatch(str,"(%w+)=(%w+)") do
|
||||
xp.player_levels[k] = tonumber(v)
|
||||
end
|
||||
end
|
||||
io.close(input)
|
||||
end
|
||||
end
|
||||
|
||||
function xp.save_levels()
|
||||
if xp.player_xp then
|
||||
local output = io.open(xp.lvl_file, "w")
|
||||
local str = ""
|
||||
for k, v in pairs(xp.player_levels) do
|
||||
str = str .. k .. "=" .. v .. ","
|
||||
end
|
||||
str = str:sub(1, #str - 1)
|
||||
output:write(str)
|
||||
io.close(output)
|
||||
end
|
||||
end
|
||||
|
||||
xp.load_xp()
|
||||
xp.load_levels()
|
116
mods/xp/init.lua~
Normal file
116
mods/xp/init.lua~
Normal file
@ -0,0 +1,116 @@
|
||||
xp = {}
|
||||
xp.lvl = 20
|
||||
xp.player_xp = {}
|
||||
xp.player_levels = {}
|
||||
xp.xp_hud = {}
|
||||
xp.level_hud = {}
|
||||
|
||||
xp.xp_file = minetest.get_worldpath() .. "/xp"
|
||||
xp.lvl_file = minetest.get_worldpath() .. "/levels"
|
||||
|
||||
function xp.add_xp(player, num)
|
||||
if xp.player_xp[player:get_player_name()] then
|
||||
xp.player_xp[player:get_player_name()] = xp.player_xp[player:get_player_name()] + num
|
||||
else
|
||||
xp.player_xp[player:get_player_name()] = num
|
||||
end
|
||||
|
||||
cmsg.push_message_player(player, "You got "..tostring(num).. " xp!")
|
||||
|
||||
if xp.player_levels[player:get_player_name()] then
|
||||
if xp.player_xp[player:get_player_name()] > xp.lvl*xp.player_levels[player:get_player_name()] then
|
||||
xp.player_xp[player:get_player_name()] = 0
|
||||
xp.add_lvl(player)
|
||||
end
|
||||
else
|
||||
xp.player_levels[player:get_player_name()] = 1
|
||||
end
|
||||
print("[info] xp for player ".. player:get_player_name() .. " " .. xp.player_xp[player:get_player_name()].."/"..xp.lvl*xp.player_levels[player:get_player_name()].." = " .. (xp.player_xp[player:get_player_name()])/(xp.lvl*xp.player_levels[player:get_player_name()]))
|
||||
player:hud_change(xp.xp_hud[player:get_player_name()], "number", 20*((xp.player_xp[player:get_player_name()])/(xp.lvl*xp.player_levels[player:get_player_name()])))
|
||||
xp.save_xp()
|
||||
end
|
||||
|
||||
function xp.add_lvl(player)
|
||||
if xp.player_levels[player:get_player_name()] then
|
||||
xp.player_levels[player:get_player_name()] = xp.player_levels[player:get_player_name()] + 1
|
||||
else
|
||||
xp.player_levels[player:get_player_name()] = 1
|
||||
end
|
||||
xp.save_levels()
|
||||
player:hud_change(xp.level_hud[player:get_player_name()], "text", 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
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
xp.xp_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*8+16), y=-(48*2+16)},
|
||||
text = "xp_xp.png",
|
||||
number = 20*((xp.player_xp[player:get_player_name()])/(xp.lvl*xp.player_levels[player:get_player_name()])),
|
||||
})
|
||||
xp.level_hud[player:get_player_name()] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = {x=0.5,y=1},
|
||||
text = xp.player_levels[player:get_player_name()],
|
||||
number = 0xFFFFFF,
|
||||
alignment = {x=0.5,y=1},
|
||||
offset = {x=0, y=-(48*2+16)},
|
||||
})
|
||||
end)
|
||||
|
||||
function xp.load_xp()
|
||||
local input = io.open(xp.xp_file, "r")
|
||||
if input then
|
||||
local str = input:read()
|
||||
if str then
|
||||
for k, v in str.gmatch(str,"(%w+)=(%w+)") do
|
||||
xp.player_xp[k] = tonumber(v)
|
||||
end
|
||||
end
|
||||
io.close(input)
|
||||
end
|
||||
end
|
||||
|
||||
function xp.save_xp()
|
||||
if xp.player_xp then
|
||||
local output = io.open(xp.xp_file, "w")
|
||||
local str = ""
|
||||
for k, v in pairs(xp.player_xp) do
|
||||
str = str .. k .. "=" .. v .. ","
|
||||
end
|
||||
str = str:sub(1, #str - 1)
|
||||
output:write(str)
|
||||
io.close(output)
|
||||
end
|
||||
end
|
||||
|
||||
function xp.load_levels()
|
||||
local input = io.open(xp.lvl_file, "r")
|
||||
if input then
|
||||
local str = input:read()
|
||||
if str then
|
||||
for k, v in str.gmatch(str,"(%w+)=(%w+)") do
|
||||
xp.player_levels[k] = tonumber(v)
|
||||
end
|
||||
end
|
||||
io.close(input)
|
||||
end
|
||||
end
|
||||
|
||||
function xp.save_levels()
|
||||
if xp.player_xp then
|
||||
local output = io.open(xp.lvl_file, "w")
|
||||
local str = ""
|
||||
for k, v in pairs(xp.player_levels) do
|
||||
str = str .. k .. "=" .. v .. ","
|
||||
end
|
||||
str = str:sub(1, #str - 1)
|
||||
output:write(str)
|
||||
io.close(output)
|
||||
end
|
||||
end
|
||||
|
||||
xp.load_xp()
|
||||
xp.load_levels()
|
BIN
mods/xp/textures/xp_xp.png
Normal file
BIN
mods/xp/textures/xp_xp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 277 B |
Loading…
x
Reference in New Issue
Block a user