function onTrade(player,npc,trade)
if (player:getFreeSlotsCount() < 1) then
player:PrintToPlayer("Not enough free space! This message is here to prevent item loss.");
do return end;
end
local itemid = hasRelic(trade,2);
local eventParams = {}; -- item1, item2, item3, num_items, currencytype, currencyamount, finalvar
local currentRelic = player:getVar("RELIC_IN_PROGRESS"); -- Stores which item has been taken from the player
local relicWait = player:getVar("RELIC_DUE_AT"); -- Stores time that relic can be retrieved after
local relicDupe = player:getVar("RELIC_MAKE_ANOTHER"); -- Stores a value that the player has acknowledged they can't hold the item they want to make yet they're making it anyway.
local count = trade:getItemCount();
local gil = trade:getGil();
local tradeOK = false;
-- Starting a stage upgrade.
-- No relics in progress, found a relic in the trade with other items, and (doesn't already own next stage, or (owns it and has acknowledged this is a bad idea))
if (currentRelic == 0 and itemid ~= nil and gil == 0 and count > 1 and (player:hasItem(itemid+1) == false or (player:hasItem(itemid+1) == true and relicDupe == 1))) then
eventParams = getRelicParameters(itemid);
-- Stage 1->2 or 2->3, 3 items + relic itself
if (count == eventParams[4] and trade:hasItemQty(eventParams[1],1) and trade:hasItemQty(eventParams[2],1) and
trade:hasItemQty(eventParams[3],1) and trade:hasItemQty(itemid,1)) then
tradeOK = true;
-- Stage 3->4, just check for attestation + relic itself
elseif (count == eventParams[4] and trade:hasItemQty(eventParams[1],1) and trade:hasItemQty(itemid,1)) then
tradeOK = true;
-- Stage 4->5, Shard + Necropschye + relic itself
elseif (count == eventParams[4] and trade:hasItemQty(eventParams[1],1) and trade:hasItemQty(eventParams[2],1) and trade:hasItemQty(itemid,1)) then
tradeOK = true;
end
-- Trade is valid, so set vars, complete trade, and give a CS
if tradeOK == true then
player:setVar("RELIC_IN_PROGRESS",itemid);
player:tradeComplete();
player:startEvent(11, itemid, eventParams[1], eventParams[2], eventParams[3], eventParams[5], eventParams[6], 0, eventParams[8]);
end
-- Already owns the next stage and hasn't acknowledged this is a bad idea yet.
elseif (itemid ~= nil and relicDupe ~= 1 and player:hasItem(itemid+1) == true) then
player:startEvent(20,itemid);
-- Trading a new relic with one already in progress. Offer cancellation.
elseif (currentRelic ~= 0 and itemid ~= nil) then
player:startEvent(87);
-- Has turned in a relic and items, has not turned in currency (no wait), so they must be bringing currency, but not 10,000 piece
elseif (currentRelic ~= 0 and relicWait == 0 and gil == 0 and itemid~=1451 and itemid~=1454 and itemid~=1457) then
eventParams = getRelicParameters(currentRelic);
-- Has currencyamount of currencytype, and nothing additional. See below for Aegis, since it's different.
if (count == eventParams[6] and trade:hasItemQty(eventParams[5],eventParams[6])) then
tradeOK = true;
-- Aegis uses all three currency types for the first 3 stages. It has currencytype 0 in these situations.
elseif (count == eventParams[6] * 3 and eventParams[5] == 0) then
-- Has currencyamount of all three currencies
if (trade:hasItemQty(1450,eventParams[6]) and trade:hasItemQty(1453,eventParams[6]) and trade:hasItemQty(1456,eventParams[6])) then
if (eventParams[5] ~= 1451 and eventParams[5] ~= 1454 and eventParams[5] ~= 1457) then -- disallow trade of 10k piece, else the gob will eat it.
tradeOK = true;
end
end
end
-- Trade is valid, so set variables, complete the trade, and give a CS to acknowledge it.
if (tradeOK == true) then
-- Stage is stored in array value 7
-- Stage 1->2, wait until next game day
if (eventParams[7] == 1) then
player:setVar("RELIC_DUE_AT",getMidnight());
-- Stage 2->3, wait RELIC_2ND_UPGRADE_WAIT_TIME (604800s / 1 week default)
elseif (eventParams[7] == 2) then
player:setVar("RELIC_DUE_AT",os.time() + RELIC_2ND_UPGRADE_WAIT_TIME);
-- Stage 3->4, wait RELIC_3RD_UPGRADE_WAIT_TIME (295200s / 3 days 10 hours default)
elseif (eventParams[7] == 3) then
player:setVar("RELIC_DUE_AT",os.time() + RELIC_3RD_UPGRADE_WAIT_TIME);
end
-- Begin currency theft workarounds...
if (count == 1) then
if (trade:hasItemQty(1451,1)) then
player:addItem(1451,1); -- R. Stripeshell
player:PrintToPlayer("You aren't supposed to actually trade it to the goblin.");
elseif (trade:hasItemQty(1454,1)) then
player:addItem(1454,1); -- R. Goldpiece
player:PrintToPlayer("You aren't supposed to actually trade it to the goblin.");
elseif (trade:hasItemQty(1457,1)) then
player:addItem(1457,1); -- 10,000 Byne Bill
player:PrintToPlayer("You aren't supposed to actually trade it to the goblin.");
end
end
-- End currency theft workarounds...
player:tradeComplete();
player:startEvent(13, currentRelic, eventParams[5], eventParams[6], 0, 0, 0, 0, eventParams[8]);
end
end
end;