aboutsummaryrefslogtreecommitdiff
path: root/gamemode/inventorysystem/skills
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/inventorysystem/skills')
-rw-r--r--gamemode/inventorysystem/skills/cl_skills.lua13
-rw-r--r--gamemode/inventorysystem/skills/sh_skillcommon.lua17
-rw-r--r--gamemode/inventorysystem/skills/sh_skills.lua12
3 files changed, 27 insertions, 15 deletions
diff --git a/gamemode/inventorysystem/skills/cl_skills.lua b/gamemode/inventorysystem/skills/cl_skills.lua
index 31d4470..b5e4620 100644
--- a/gamemode/inventorysystem/skills/cl_skills.lua
+++ b/gamemode/inventorysystem/skills/cl_skills.lua
@@ -4,19 +4,8 @@ local sc = nrequire("sh_skillcommon.lua")
--the gui elements
local elements = {}
---return level, frac
-local xpmult = 1.5 --the lower, the more lvl per xp
-local levelfunc = function(val)
- local curlvl = math.log(val,xpmult)
- local prevlvlxp = xpmult ^ math.floor(curlvl)
- local nextlvlxp = xpmult ^ (math.floor(curlvl) + 1)
- local sp = nextlvlxp - prevlvlxp
- local frac = (val - prevlvlxp) / ((sp ~= 0) and sp or 1) --don't divide by 0
- return math.floor(curlvl), frac
-end
-
local set_xp_of = function(name,ammt)
- local lvl,frac = levelfunc(ammt)
+ local lvl,frac = sc.levelfunc(ammt)
elements[name].label:SetText(string.format("%s : %d (%2.5f%%)",name,lvl,frac))
elements[name].bar:SetFraction(frac)
end
diff --git a/gamemode/inventorysystem/skills/sh_skillcommon.lua b/gamemode/inventorysystem/skills/sh_skillcommon.lua
index 9c022eb..e0db95a 100644
--- a/gamemode/inventorysystem/skills/sh_skillcommon.lua
+++ b/gamemode/inventorysystem/skills/sh_skillcommon.lua
@@ -73,4 +73,21 @@ function lib.SkillList()
return skills
end
+local xpmult = 1.5 --the lower, the more lvl per xp
+function lib.levelfunc(val)
+ local curlvl = math.log(val,xpmult)
+ local prevlvlxp = xpmult ^ math.floor(curlvl)
+ local nextlvlxp = xpmult ^ (math.floor(curlvl) + 1)
+ local sp = nextlvlxp - prevlvlxp
+ local frac = (val - prevlvlxp) / ((sp ~= 0) and sp or 1) --don't divide by 0
+ return math.floor(curlvl), frac
+end
+
+function pmeta:GetSkill(name)
+ local loc = self:HasItem(name)
+ if not loc then return 0 end
+ local item = self:GetItem(loc)
+ return lib.levelfunc(item.ammt)
+end
+
return lib
diff --git a/gamemode/inventorysystem/skills/sh_skills.lua b/gamemode/inventorysystem/skills/sh_skills.lua
index 3c212bf..43137a8 100644
--- a/gamemode/inventorysystem/skills/sh_skills.lua
+++ b/gamemode/inventorysystem/skills/sh_skills.lua
@@ -117,10 +117,13 @@ end
inv.Has = function(self,string_or_compare_func)
local socf = string_or_compare_func
if type(socf) == "string" and self.skills[socf] then
- return self.skills[socf]
+ return {socf}
elseif type(socf) == "function" then
+ local fi = {}
for k,v in pairs(self.skills) do
- if socf(v) then return k end
+ fi.name = k
+ fi.ammt = v
+ if socf(fi) then return {k} end
end
else
return nil
@@ -132,7 +135,10 @@ inv.Remove = function(self,position)
end
inv.Get = function(self,position)
- return self.skills[position[1]]
+ local fi = {}
+ fi.name = position[1]
+ fi.ammt = self.skills[position[1]]
+ return fi
end
inv.Serialize = function(self)