so basicily i have done some meta functions to set add and change the player XP networked int
And now im triying to add XP to the player using killer:AddXp(80) wich is a meta function that sets the networked int to the ammount i put
Anyway everytime i try to call killer:AddXp(80) my player XP doesnt change at all
i seriously dont know whats the problem with this so ill leave the code here
[LUA]
function meta:AddXp( amount )
local current_xp = self:GetXp()
self:SetXp( current_xp + amount )
end
function meta:AddSkillPoints( amount )
local current_SkillPoints = self:GetSkillPoints()
self:SkillPoints( current_skillpoints + amount )
end
function meta:SetXp( amount )
self:AddNonTempSH( "Xp", amount )
self:SaveXp()
end
function meta:SetSkillPoints( amount )
self:SetNetworkedInt( "SkillPoints", amount )
self:SaveXp()
end
function meta:SetLevel( amount )
self:SetNetworkedInt( "Level", amount )
self:SaveXp()
end
function meta:SaveXp()
local experience = self:GetXp()
self:SetPData( "xp", experience )
local SkillPoints = self:GetSkillPoints()
self:SetPData("SkillPoints", SkillPoints)
local level = self:GetLevel()
self:SetPData("Level", level)
end
function meta:SaveXpTXT()
file.Write( gmod.GetGamemode().Name .."/Xp/".. string.gsub(self:SteamID(), ":", "_") ..".txt", self:GetXpString() )
end
function meta:TakeXp( amount )
self:AddXp( -amount )
end
function meta:GetXp()
return self:GetSHVar( "Xp" )
end
function meta:GetLevel()
return self:GetNetworkedInt( "Level" )
end
function meta:GetSkillPoints()
return self:GetNetworkedInt( "SkillPoints" )
end
if (SERVER) then
AddCSLuaFile( "meta" )
XP_STARTAMOUNT = 50
SP_STARTAMOUNT = 50
LVL_START = 0
function xFirstSpawn( ply )
local experience = ply:GetPData( "xp" )
local sp = ply:GetPData("SkillPoints")
local lvl = ply:GetPData("level")
if experience == nil then
ply:SetPData("xp", XP_STARTAMOUNT)
ply:SetXp( XP_STARTAMOUNT )
ply:SetPData("SkillPoints",SP_STARTAMOUNT)
ply:SetSkillPoints( SP_STARTAMOUNT )
ply:SetPData("level", LVL_START)
ply:SetLevel( LVL_START)
else
ply:SetXp( experience )
ply:SetXp( XP_STARTAMOUNT )
ply:SetLevel( LVL_START)
end
end
hook.Add( "PlayerInitialSpawn", "xPlayerInitialSpawn", xFirstSpawn )
function PrintXp( pl )
pl:ChatPrint( "Your xp is: " .. pl:GetXp() )
end
function xPlayerDisconnect( ply )
print("Player Disconnect: Xp saved to SQLLite and TXT")
ply:SaveXp()
ply:SaveXpTXT()
end
concommand.Add( "xp_get", PrintXp )
end
[/LUA]
Heres the code im using to call it
[LUA]
function GiveEXP( victim, weapon, killer) -- function with args
local gainedxp = math.random(50,90)
local xpneeded = math.random(10,150)
local gainedmoney = math.random(50,150)
local xp = killer:GetXp()
killer:AddXp(80)
if killer:GetXp() >= xpneeded * (killer:GetLevel() + 1) then -- if the killers exp is over the xp needed * next level number.
for k, v in pairs(player.GetAll()) do -- loop, check the wiki for more info on these.
if v != killer then -- check if v is not the killer, as we don't want to show that message to the killer, he has his own.
v:ChatPrint("[XP] .. .. has reached level ".. killer:GetLevel" from killing ".. victim:Nick() ..".") -- The message.
killer:SendLua("surface.PlaySound(\"level/Level.wav\")")
end
end
killer:SetLevel()("level",killer:GetLevel() + 1 )
killer:SetSHVar("SkillPoints", killer:GetSHVar("SkillPoints") + 1) -- add a skill point every time player level up
killer:ChatPrint("[XP] Level UP! ")
end
end
hook.Add("OnNPCDeath", "GiveEXPOnDeath", GiveEXP) -- hook to PlayerDeath.
[/LUA]
Have you defined meta?
[lua]
local meta = FindMetaTable( "Player" )
[/lua]
Is meta even defined?
:ninja:
yeah at the thole start of the file
i just copied the functions to see if anyone noticed anything wrong
Nevermind i was using AddXp Wrong
on the function GiveXp
Sorry, you need to Log In to post a reply to this thread.