prefix for variables
parent
59706fd96b
commit
5594bd2340
20
api.lua
20
api.lua
|
@ -34,48 +34,48 @@ minetest.register_on_joinplayer(function(player)
|
|||
|
||||
for i,colu in ipairs({"walked","distance","login","dug","build","deaths","spoke","killed_mobs","killed_player",
|
||||
"lastlogin"}) do
|
||||
if player:get_attribute("xp_"..colu) == nil then
|
||||
player:set_attribute("xp_"..colu,0)
|
||||
if player:get_attribute(xpfw.prefix.."_"..colu) == nil then
|
||||
player:set_attribute(xpfw.prefix.."_"..colu,0)
|
||||
end
|
||||
end
|
||||
if M.player[playername]==nil then
|
||||
M.player[playername]={last_pos=player:get_pos(),} --actual position
|
||||
end
|
||||
local pm=player:get_meta()
|
||||
pm:set_int("xp_lastlogin",os.time()) -- last login time
|
||||
pm:set_int(xpfw.prefix.."_lastlogin",os.time()) -- last login time
|
||||
end
|
||||
)
|
||||
|
||||
minetest.register_on_placenode(function(pos, newnode, player, oldnode, itemstack, pointed_thing)
|
||||
if player ~= nil then
|
||||
local playername = player:get_player_name()
|
||||
player_add_attribute(player,"xp_build",1)
|
||||
player_add_attribute(player,xpfw.prefix.."_build",1)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_dieplayer(function(player, reason)
|
||||
print(dump2(reason))
|
||||
if player ~= nil then
|
||||
player_add_attribute(player,"xp_deaths",1)
|
||||
player_add_attribute(player,xpfw.prefix.."_deaths",1)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_chat_message(function(player, reason)
|
||||
if player ~= nil then
|
||||
player_add_attribute(player,"xp_spoke",1)
|
||||
player_add_attribute(player,xpfw.prefix.."_spoke",1)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_dignode(function(pos,oldnoe,player)
|
||||
if player ~= nil then
|
||||
player_add_attribute(player,"xp_dug",1)
|
||||
player_add_attribute(player,xpfw.prefix.."_dug",1)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
if player ~= nil then
|
||||
local leave=os.time()
|
||||
player_add_attribute(player,"xp_logon",player:get_attribute("xp_lastlogin")-leave)
|
||||
player_add_attribute(player,xpfw.prefix.."_logon",player:get_attribute(xpfw.prefix.."_lastlogin")-leave)
|
||||
end
|
||||
print(dump2(player:get_meta()))
|
||||
end)
|
||||
|
@ -99,7 +99,7 @@ minetest.register_globalstep(function(dtime)
|
|||
local act_pos=player:get_pos()
|
||||
local tdist=vector.distance(act_pos,playerdata.last_pos)
|
||||
if tdist > 0 then
|
||||
player_add_attribute(player,"xp_distance",tdist)
|
||||
player_add_attribute(player,xpfw.prefix.."_distance",tdist)
|
||||
playerdata.last_pos = act_pos
|
||||
end
|
||||
else
|
||||
|
@ -109,7 +109,7 @@ minetest.register_globalstep(function(dtime)
|
|||
if tvel ~= nil then
|
||||
local tvelo=vector.distance(tvel,{x=0,y=0,z=0})
|
||||
if tvelo>0 then
|
||||
player_add_attribute(player,"xp_walked",tvelo*dtime)
|
||||
player_add_attribute(player,xpfw.prefix.."_walked",tvelo*dtime)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,3 +8,4 @@ for i,configs in ipairs({"decay"}) do
|
|||
end
|
||||
end
|
||||
|
||||
xpfw.prefix=minetest.settings:get("xpfw.prefix") or "xp"
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
xpfw.prefix (Prefix for variable name) string "xp"
|
Loading…
Reference in New Issue