comment api.lua
parent
2390c2dd78
commit
2766ceea6c
|
@ -1,6 +1,6 @@
|
|||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
||||
# Minetest Game mod: XPFW
|
||||
==========================
|
||||
|
||||
See license.txt for license information.
|
||||
|
||||
## Short description
|
||||
|
@ -34,7 +34,7 @@ Following chat commands are available:
|
|||
Set variable of user to new value
|
||||
|
||||
## Usage
|
||||
Usage (roughly):
|
||||
Usage (roughly), for Details see api.lua:
|
||||
|
||||
- xpfw.register_attribute(name,data) to register new attribute <name>
|
||||
- xpfw.player_get_attribute(player,name) Get stored value of attribute <name> for ObjectRef player
|
||||
|
|
18
api.lua
18
api.lua
|
@ -38,7 +38,9 @@ data = {name = name of attribute,
|
|||
table.insert(xpfw.attrib_recreates,name)
|
||||
end
|
||||
end
|
||||
|
||||
local player_addsub_attribute=function(player,attrib,val,maf)
|
||||
--internal use for adding and substracting values
|
||||
local oldvalue=xpfw.player_get_attribute(player,attrib)
|
||||
local att_def=xpfw.attributes[attrib]
|
||||
local new_val = oldvalue + val
|
||||
|
@ -103,15 +105,30 @@ xpfw.player_set_attribute=function(player,attrib,val)
|
|||
M.player[playername].flags[attrib]=1
|
||||
end
|
||||
xpfw.player_set_attribute_to_nil=function(player,attrib)
|
||||
--[[
|
||||
Delete attribute for player (set to nil):
|
||||
- player : ObjectRef to player
|
||||
- attrib : name of attribute
|
||||
]]
|
||||
local pm=player:get_meta()
|
||||
local playername=player:get_player_name()
|
||||
local att_def=M.player[playername].attributes[attrib]
|
||||
pm:set_float(xpfw.prefix.."_"..attrib,-1)
|
||||
end
|
||||
|
||||
xpfw.player_remove_flag=function(player,attrib)
|
||||
-- internal usage to check if attribute was changed since last abm call
|
||||
M.player[playername].flags[attrib]=nil
|
||||
end
|
||||
|
||||
xpfw.player_ping_attribute=function(player,attrib)
|
||||
--[[
|
||||
"Ping" an attribute for player:
|
||||
- player : ObjectRef to player
|
||||
- attrib : name of attribute
|
||||
used for moving averaged attributes. Get max value from definition and add to attribute, which calcs
|
||||
a moving average.
|
||||
]]
|
||||
local playername=player:get_player_name()
|
||||
local att_def=M.player[playername].attributes[attrib]
|
||||
local ping_max=att_def.max
|
||||
|
@ -164,6 +181,7 @@ xpfw.player_reset_attributes=function(player,attribute)
|
|||
end
|
||||
|
||||
xpfw.player_hud_toggle=function(name)
|
||||
-- toggle hud display for player with string <name>
|
||||
local player=minetest.get_player_by_name(name)
|
||||
local playerdata=M.player[name]
|
||||
if playerdata==nil then
|
||||
|
|
Loading…
Reference in New Issue