Advertisement
Rochet2

Query DB all the time ("bad")

Dec 11th, 2013
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.92 KB | None | 0 0
  1. local function GetVotePoints(player) -- Returns player's vote points or 0
  2.     local Q = WorldDBQuery("SELECT vp FROM votepoints WHERE accID = "..player:GetAccountId())
  3.     if(Q) then
  4.         return Q:GetColumn(0):GetULong()
  5.     end
  6.     return 0
  7. end
  8.  
  9. local function UpdateVotePoints(player, change) -- Updates player's vote points with the change (IE -5)
  10.     if ((change or 0) == 0) then
  11.         return -- change was nothing, dont do anything
  12.     end
  13.     local accID = player:GetAccountId()
  14.     local newvp = GetVotePoints(player) + change
  15.     if (newvp <= 0) then
  16.         WorldDBQuery("DELETE FROM votepoints WHERE accID = "..accID) -- Remove from DB if vp is 0
  17.     else
  18.         WorldDBQuery("REPLACE INTO votepoints (accID, vp) VALUES ("..accID..", "..newvp..")") -- update / create new data
  19.     end
  20. end
  21.  
  22. -- any code here that uses GetVotePoints(player) to get the vote points and/or UpdateVotePoints(player, change)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement