RCLootCouncil Classic - CEPGP

RCLootCouncil Classic - CEPGP

7.6k Downloads

Feature request: GP discounts (with working code)

Hrogath opened this issue ยท 0 comments

commented

Hi there!

First, thanks a lot for making this addon, it's been a huge help!

The only thing missing for our use case is the GP discount. I managed to get it working with a small tweak, so I wanted to share the code here in case you'd like to include it or use the idea.

I'm not sure if I've done things quite the right way, I have plenty of experience in coding but this is my first time touching LUA and some things about it feel pretty weird. Anyway, here's my edited version of RCVFCEPGP:RCMLAwardSuccess (just the part inside the main if-clause):

local amount = CEPGP_calcGP(_, 1, itemID)

-- Matches first instance of 1 or more digits followed by %, e.g. "Minor 30%" returns "30%"
percentage = responseText:match("%d+%%") 
costModifier = 1.0

if percentage and percentage:len() > 1 then
	-- Remove the trailing %-symbol, convert to an int and divide by 100
	costModifier = tonumber(percentage:sub(0, -2)) / 100

	-- Constrain the discount between 0 and 100%
	costModifier = math.min(math.max(costModifier, 0), 1)
end

if responseText:find("free") then
	amount = 0
end

amount = costModifier * amount

CEPGP_addGP(player, amount, itemID, link, nil, responseText)