Is this code correct?

I want to display the amount of points you have on the screen, im using _Undefined’s pointshop Im not too sure if this is correct or even along the lines of it??
Can someone clarify?


function Player:PS_GetPoints()
	return self.PS_Points or 0
end

function Player:PS_HasPoints(Points)
	return self:Ps_GetPoints() >= points
end

local Points = Player:Ps_GetPoints()

function DrawHud()
draw.DrawText(Points, "ScoreboardText", ScrW() / 2 - 70, ScrH() - 63, Color(255, 0, 0, 0),TEXT_ALIGN_CENTER)
draw.RoundedBox( number cornerRadius, number x, number y, number width, number height, table color ) <---- havent finished this yet
end
hook.Add("HUDPaint", "TextDrawing", DrawHud()

The points won’t update because you only define the variable once outside the HUDPaint hook. Just draw LocalPlayer():Ps_GetPoints()
You forgot the final parenthesis for to close the hook.Add. Do not add parenthesis to the function name you want to hook, otherwise you’ll be calling the function and not passing it on as a variable.
You might want to localise ( add “local” before “function” ) the DrawHud function just in case the name is used by something else. It’s just good practise anyway.
Make sure that you’re doing all of this clientside, since you’re using drawing, otherwise you’ll get “attempt to index global draw” error, and the hook won’t run anyway.

You’re defining function Player:PS_GetPoints() and calling Player:Ps_GetPoints()…

And did you define Player?


function Player:PS_GetPoints()
	return self.PS_Points or 0
end

function Player:PS_HasPoints(Points)
	return self:Ps_GetPoints() >= points
end

local function DrawHud()
draw.DrawText(LocalPlayer():Ps_GetPoints(), "ScoreboardText", ScrW() / 2 - 70, ScrH() - 63, Color(255, 0, 0, 0),TEXT_ALIGN_CENTER)
draw.RoundedBox(3, 5, 5, 200, 100, Color(51, 58, 51, 255))
end
hook.Add("HUDPaint", "TextDrawing", DrawHud)

Hmm Good point. Think its sorted now^^? Thanks. I dont know why I added parenthesis after DrawHud
Changed the Co-ords too

Yes, make sure that you use Player = FindMetaTable( “Player” ) in order to add methods to the player metatable, and also make sure that the function player:Ps_GetPoints() exists clientside.

whoops forgot about that

[editline]18th May 2014[/editline]


Player = FindMetaTable( "Player" )

function Player:PS_GetPoints()
	return self.PS_Points or 0
end

function Player:PS_HasPoints(Points)
	return self:Ps_GetPoints() >= points
end

local function DrawHud()
draw.DrawText(LocalPlayer():Ps_GetPoints(), "ScoreboardText", ScrW() / 2 - 70, ScrH() - 63, Color(255, 0, 0, 0),TEXT_ALIGN_CENTER)
draw.RoundedBox(3, 5, 5, 200, 100, Color(51, 58, 51, 255))
end
hook.Add("HUDPaint", "TextDrawing", DrawHud) 

wait so what should I do with the function Player:Ps_GetPoints() Ive just confused myself :L

Why do you redefine functions that already exists in pointshop, which you appear to be using?
Also it should be PS_GetPoints() not Ps_GetPoints()

It’s pretty much useless. Just grab Player.PS_Points, no need to make a function for it. Also in your HasPoints function you give the argument Points but then use points the line below, it’s all caps sensitive.


Player = FindMetaTable( "Player" )

local function DrawHud()
draw.DrawText(LocalPlayer():PS_GetPoints(), "ScoreboardText", ScrW() / 2 - 70, ScrH() - 63, Color(255, 0, 0, 0),TEXT_ALIGN_CENTER)
draw.RoundedBox(3, 5, 5, 200, 100, Color(51, 58, 51, 255))
end
hook.Add("HUDPaint", "TextDrawing", DrawHud)