From e93d264c9bbb68efa637d92aaf9096b7c746c245 Mon Sep 17 00:00:00 2001 From: Matt Stevens Date: Sun, 3 Aug 2014 01:42:24 +0100 Subject: [PATCH] Added additional checks to sending points. Fixes #156 --- lua/pointshop/sv_init.lua | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/lua/pointshop/sv_init.lua b/lua/pointshop/sv_init.lua index 7a6dac5..27ebefe 100644 --- a/lua/pointshop/sv_init.lua +++ b/lua/pointshop/sv_init.lua @@ -35,13 +35,28 @@ net.Receive('PS_SendPoints', function(length, ply) local other = net.ReadEntity() local points = math.Clamp(net.ReadInt(32), 0, 1000000) - if PS.Config.CanPlayersGivePoints and other and points and IsValid(other) and other:IsPlayer() and ply and IsValid(ply) and ply:IsPlayer() and ply:PS_HasPoints(points) then - ply:PS_TakePoints(points) - ply:PS_Notify('You gave ', other:Nick(), ' ', points, ' of your ', PS.Config.PointsName, '.') - - other:PS_GivePoints(points) - other:PS_Notify(ply:Nick(), ' gave you ', points, ' of their ', PS.Config.PointsName, '.') + if not PS.Config.CanPlayersGivePoints then return end + if not points or points == 0 then return end + if not other or not IsValid(other) or not other:IsPlayer() then return end + if not ply or not IsValid(ply) or not ply:IsPlayer() then return end + if not ply:PS_HasPoints(points) then + ply:PS_Notify("You can't afford to give away ", points, " of your ", PS.Config.PointsName, ".") + return + end + + ply.PS_LastGavePoints = ply.PS_LastGavePoints or 0 + if ply.PS_LastGavePoints + 5 > CurTime() then + ply:PS_Notify("Slow down! You can't give away points that fast.") + return end + + ply:PS_TakePoints(points) + ply:PS_Notify("You gave ", other:Nick(), " ", points, " of your ", PS.Config.PointsName, ".") + + other:PS_GivePoints(points) + other:PS_Notify(ply:Nick(), " gave you ", points, " of their ", PS.Config.PointsName, ".") + + ply.PS_LastGavePoints = CurTime() end) -- admin points