(Care : My english suck, sorry for that, not my primary language)
Hi, i'm working on a bounty system for darkrp.
I'm a newbie to Lua, and i have a big problem, everything worked and i started working on the vgui, with a lot of fail, directly inside the gamemode (yup noob error), i finally stopped & started working on a separated lua file.
But since then, my bounty system doesn't work anymore.
It's probably a simple nooby fail but i don't know how to fix it and stopped working on that before i start to feel the urge to bang my head on my desk.
Console return if i try to get the amount of the bounty on me :
[QUOTE]
] prime_onmyface
]
[ERROR] gamemodes/darkrp/gamemode/init.lua:25: attempt to call method 'GetPrime' (a nil value)
1. unknown - gamemodes/darkrp/gamemode/init.lua:25
2. unknown - lua/includes/modules/concommand.lua:69
][/QUOTE]
init.lua
[CODE]
function FirstSpawn( ply )
local prime = ply:GetPData("prime")
if prime == nil then
ply:SetPData("prime", 0)
ply:SetPrime( 0 )
else
ply:SetPrime( prime )
end
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )
function PrintPrime( pl )
pl:ChatPrint("Votre tete vaut: " .. pl:GetPrime())
end
function SetPrime( pl)
pl:Setprime(10)
end
concommand.Add("primeset",Setprime)
concommand.Add("prime_onmyface",PrintPrime)
[/CODE]
sh_player.lua (included in init.lua)
[CODE]local meta = FindMetaTable("Player")
function meta:AddPrime(amount)
local current_bounty = self:GetPrime()
self:SetPrime( current_bounty + amount )
end
function meta:SetPrime(amount)
self:SetNetworkedInt( "prime", amount )
self:SavePrime()
end
function meta:SavePrime()
local bounty = self:GetPrime()
self:SetPData("prime", bounty)
end
function meta:TakePrime(amount)
self:AddPrime(-amount)
end
function meta:GetPrime()
return self:GetNetworkedInt( "prime" )
end
[/CODE]
Thanx for reading
Is sh_player.lua included before or after that block of code?
Before
Solved, it was an IDE problem.
Sorry, you need to Log In to post a reply to this thread.