Created
October 23, 2017 22:28
-
-
Save ValentinFunk/6305de6b3e258dc419b38892dfcc6019 to your computer and use it in GitHub Desktop.
Pointshop 2 negative points fixer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function fixPts() | |
if not Pointshop2 or not Pointshop2.DB or not Pointshop2.DB.ConnectionPromise then | |
MsgC(Color(255, 0, 0), "ERROR: Pointshop2 is not loaded yet. Please rerun.") | |
return | |
end | |
print("[FIXPTS] -> Fetching minimum values") | |
Pointshop2.DB.ConnectionPromise:Then(function() | |
print('[FIXPTS] -> Connected to database') | |
return Pointshop2.DB.DoQuery('SELECT MIN(points) as minPoints, MIN(premiumPoints) as minPrem FROM ps2_wallet;') | |
end, function(e) | |
MsgC(Color(255, 0, 0), "ERROR: The database connection failed. Please check your setup") | |
return Promise.reject('Connection Failed') | |
end ):Then(function(res) | |
local minPts = res[1] | |
local minPoints = math.min(minPts.minPoints, 0) | |
local minPremPoints = math.min(minPts.minPrem, 0) | |
print('[FIXPTS] -> Determined minimum points ', minPoints, ' premium: ', minPremPoints) | |
local defaultPoints = Pointshop2.GetSetting( "Pointshop 2", "BasicSettings.DefaultWallet.Points" ) | |
local defaultPremiumPoints = Pointshop2.GetSetting( "Pointshop 2", "BasicSettings.DefaultWallet.PremiumPoints" ) | |
print('[FIXPTS] -> Determined default wallet ', defaultPoints, ' premium: ', defaultPremiumPoints) | |
if minPoints == 0 and minPremPoints == 0 then | |
print('[FIXPTS] -> Nobody has negative points, you probably aren\'t affected or this script already ran.') | |
return | |
end | |
local correctionPoints = -minPoints + defaultPoints | |
local correctionPremPoints = -minPremPoints + defaultPremiumPoints | |
print('[FIXPTS] -> To correct points balances we will give everyone ', correctionPoints, ' points and ', correctionPremPoints, ' premium points.') | |
return Pointshop2.DB.DoQuery(Format('UPDATE ps2_wallet SET points = points + %i, premiumPoints = premiumPoints + %i', correctionPoints, correctionPremPoints)) | |
end):Then(function() end) | |
end | |
concommand.Add("ps2_fixpoints", fixPts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment