Hello, so I have been trying to use net messages and I’ve been getting various problems whilst trying to create a sort of mana system
that will set the player’s mana to a number, get the player’s current mana for drawing part of the hud, and taking/giving mana to the
So far I have several different files that contain the code I will post shortly. I have a serverside file sv_playerinit_ext that has the functions that give/take
and get the player’s mana.
function meta:GetMana(num) return self.Mana or 0 end function meta:SetMana(num) net.Start("PlayerSetmana") net.WriteEntity(self) net.WriteInt(num, 32) net.Send(self) self.Mana = num end function meta:AddMana(num) self:SetMana(self:GetMana()+num) end
Then I have anther file that is clientside that draws a box that is red, that basically represents the player’s mana. The below is called cl_initialize.lua.
net.Receive("PlayerSetmana", function(len) energy = LocalPlayer():GetMana() draw.RoundedBoxEx(4, 40, 40, math.Clamp(energy, 0, 100), 100, Color(255, 0, 0, 255), false, false, false, false) end)
The error I’m currently getting is this: [attempt to call method GetMana a nil value] the error is located in cl_initialize line 3.
If anyone could give me some pointers as to what I’m doing wrong I would be greatful. I’ve been changing things around for several hours now
and I feel like an idiot for not realizing my mistake by now.
As a last note, I tried using the idea on a money system from here:
to create this, and this may be why I’m messing up so badly.