Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 3ce9465

Browse files
committed
Update gold() to implement optional coin and location parameters
Suggested by @pvzin: http://forums.tibiawindbot.com/showthread.php?4804
1 parent 3ddd4ba commit 3ce9465

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

src/General.lua

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,31 @@ end
112112
* Gets the total amount of visible gold you're carrying.
113113
*
114114
* @since 0.1.0
115+
* @updated 1.2.0
116+
*
117+
* @param {string} [coin] - Coin type to consider; defaults to
118+
* - all
119+
* @param {string} [location] - Where to look for gold; defaults
120+
* - to any
115121
*
116122
* @returns {number} - Total amount of gold
117123
--]]
118-
function gold()
119-
return itemcount('gold coin') +
120-
itemcount('platinum coin') * 100 +
121-
itemcount('crystal coin') * 10000
124+
function gold(coin, location)
125+
local coins = {'gold coin', 'platinum coin', 'crystal coin'}
126+
127+
-- Allows us to count only a specific coin type
128+
if coin and table.find(coins, coin:lower()) then
129+
coins = {coin}
130+
else
131+
location = coin
132+
end
133+
134+
local totalGold = 0
135+
for _, v in ipairs(coins) do
136+
totalGold = totalGold + itemcount(v, location) * itemvalue(v)
137+
end
138+
139+
return totalGold
122140
end
123141

124142
--[[

0 commit comments

Comments
 (0)