Yatozin
New Member
- Joined
- Jun 13, 2014
- Messages
- 49
- Reaction score
- 3
just wondering if someone can help me with adding so that items can revert backwards on fails with a chance on this.
Lua:
-- Tier Upgrader by Stigma: https://otland.net/threads/tfs-0-4-1-2-tier-upgrading-system.245047/
-- Converted to TFS 1.3 Revscriptsys by Stigma
local action = Action()
local config = {
messages = {
success = {
text = 'Upgrade!',
talkType = TALKTYPE_MONSTER_SAY,
effect = CONST_ME_FIREWORK_RED
},
fail = {
text = 'Upgrade Failed.',
talkType = TALKTYPE_MONSTER_SAY,
effect = CONST_ME_POFF
},
},
gear = {
-- [key id] = {tier = item tier, upgraderType = 'key, soil, crystal, etc (whatever you want it to say, there's no limit)', chance = upgrade chance}
[2087] = {tier = 1, upgraderType = 'key', chance = 30,
items = {
-- [from id] = [to id]
[2505] = 2492,
[2160] = 2148
}
},
[2088] = {tier = 2, upgraderType = 'key', chance = 80,
items = {
[2148] = 2160
}
}
}
}
function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
-- Using player's position if the target item is located in a container, otherwise use the item's position located on the map
local pos = target:getPosition().x == 65535 and player:getPosition() or target:getPosition()
-- Make sure the player is not attempting to target a creature
if not target:isItem() then
player:sendCancelMessage('You must select an item.')
pos:sendMagicEffect(CONST_ME_POFF)
return true
end
-- Attempt to get the config based on which key id the player is using
local keyConfig = config.gear[item:getId()]
-- Adding article to full item name if possible, ex: "a sword"
local name = (target:getArticle() ~= '') and string.format('%s %s', target:getArticle(), target:getName()) or target:getName()
if keyConfig then
-- Directly attempt to access the item id to upgrade to by indexing the item list with the target item's id
local upgradeId = keyConfig.items[target:getId()]
-- Prevent attempting to upgrade an item that isn't in config
if not upgradeId then
player:sendCancelMessage(string.format('You are unable to upgrade %s with a tier %d %s.', (name == '') and 'this' or name, keyConfig.tier, keyConfig.upgraderType))
pos:sendMagicEffect(CONST_ME_POFF)
return true
end
-- Prevent attempting to upgrade a stackable item that has more than 1 in it's stack
if target:getCount() > 1 then
player:sendCancelMessage('You may only upgrade this item one at a time.')
pos:sendMagicEffect(CONST_ME_POFF)
return true
end
-- Use the "success" table in config if the random value is less than or equal to the chance, otherwise use the "fail" table
local confKey = (math.random(100) <= keyConfig.chance and 'success' or 'fail')
local resultConfig = config.messages[confKey]
pos:sendMagicEffect(resultConfig.effect)
player:say(resultConfig.text, resultConfig.talkType)
if confKey == 'success' then
target:transform(upgradeId)
end
-- Make sure to remove only 1 item in the case the upgrader is a stackable item
item:remove(1)
end
return true
end
-- Automatically register the key ids in config
for keyId, _ in pairs(config.gear) do
action:id(keyId)
end
action:register() -- Enable the action for use