Skip to content

Commit

Permalink
cleanup: simplify some account functions and fix console error (opent…
Browse files Browse the repository at this point in the history
…ibiabr#3110)

Removes a duplicate function.
Fixed console error related to missing string.format.
  • Loading branch information
omarcopires authored Nov 13, 2024
1 parent f34cb83 commit 73f5c5a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 30 deletions.
13 changes: 1 addition & 12 deletions data/libs/compat/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -618,18 +618,7 @@ function getPlayerGUIDByName(name)
end

function getAccountNumberByPlayerName(name)
local player = Player(name)
if player then
return player:getAccountId()
end

local resultId = db.storeQuery("SELECT `account_id` FROM `players` WHERE `name` = " .. db.escapeString(name))
if resultId ~= false then
local accountId = Result.getNumber(resultId, "account_id")
Result.free(resultId)
return accountId
end
return 0
return Game.getPlayerAccountId(name)
end

getPlayerAccountBalance = getPlayerBalance
Expand Down
15 changes: 0 additions & 15 deletions data/libs/functions/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,6 @@ function getRateFromTable(t, level, default)
return default
end

function getAccountNumberByPlayerName(name)
local player = Player(name)
if player ~= nil then
return player:getAccountId()
end

local resultId = db.storeQuery("SELECT `account_id` FROM `players` WHERE `name` = " .. db.escapeString(name))
if resultId ~= false then
local accountId = Result.getNumber(resultId, "account_id")
Result.free(resultId)
return accountId
end
return 0
end

function getMoneyCount(string)
local b, e = string:find("%d+")
local money = b and e and tonumber(string:sub(b, e)) or -1
Expand Down
15 changes: 15 additions & 0 deletions data/libs/functions/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,18 @@ function Game.getTimeInWords(seconds)
end
return timeStr
end

function Game.getPlayerAccountId(name)
local player = Player(name)
if player then
return player:getAccountId()
end

local resultId = db.storeQuery("SELECT `account_id` FROM `players` WHERE `name` = " .. db.escapeString(name))
if resultId then
local accountId = result.getNumber(resultId, "account_id")
result.free(resultId)
return accountId
end
return 0
end
2 changes: 1 addition & 1 deletion data/scripts/creaturescripts/player/login.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function playerLoginGlobal.onLogin(player)
end

-- Send Recruiter Outfit
local resultId = db.storeQuery("SELECT `recruiter` FROM `accounts` WHERE `id`= " .. getAccountNumberByPlayerName(getPlayerName(player)))
local resultId = db.storeQuery("SELECT `recruiter` FROM `accounts` WHERE `id`= " .. Game.getPlayerAccountId(getPlayerName(player)))
if resultId then
local recruiterStatus = Result.getNumber(resultId, "recruiter")
local sex = player:getSex()
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/globalevents/update_guild_war_status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local updateGuildWarStatus = GlobalEvent("UpdateGuildWarStatus")

function updateGuildWarStatus.onThink(interval)
local currentTime = os.time()
db.query("UPDATE `guild_wars` SET `status` = 4, `ended` = %d WHERE `status` = 1 AND `ended` != 0 AND `ended` < %d", currentTime, currentTime)
db.query(string.format("UPDATE `guild_wars` SET `status` = 4, `ended` = %d WHERE `status` = 1 AND `ended` != 0 AND `ended` < %d", currentTime, currentTime))
return true
end

Expand Down
2 changes: 1 addition & 1 deletion data/scripts/talkactions/gm/ban.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function ban.onSay(player, words, param)
return true
end

local accountId = getAccountNumberByPlayerName(playerName)
local accountId = Game.getPlayerAccountId(playerName)
if accountId == 0 then
return true
end
Expand Down

0 comments on commit 73f5c5a

Please sign in to comment.