• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua [0.4] Ammo Enchantment

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,493
Solutions
17
Reaction score
187
Location
Brazil
Good morning guys,

I have a 7.6 server and I wanted to create an action (rune or magic) that would enchant the ammunition I'm using (it would only work for paladins) and would turn that ammunition, for a while, into something like Tibia Global's diamond arrows. This enchantment would cause the ammo to do area damage, halving single target damage. can you help me?
 
Solution
X
This alternative would help me perfectly Xikini, can you help me implement this?
buff item example
XML:
<action itemid="11111111" event="script" value="aaaaaaaa.lua"/>
LUA:
local buffTime = 10 -- seconds
local buffStorageKey = 45001

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local newTime = buffTime + os.time()
    doCreatureSetStorage(cid, buffStorageKey, newTime)
    doCreatureSay(cid, "Buffed for " .. buffTime .. " seconds!", TALKTYPE_MONSTER)
    doRemoveItem(item.uid, 1)
    return true
end

And then inside your weapon scripts, setup 2 combats. (combat1, combat2)
For this example, I've used poison arrow for the regular attack, and burst arrow for the buffed attack.
LUA:
local buffStorageKey = 45001

--...
try looking at enchant staff spell code and seeing if you can apply it to ammo slot

code for area arrows can be found in burst arrow file
 
Ammunition is stackable, so therefore cannot be enchanted or modified directly, because the moment anything regarding the stack changes (firing an arrow, moving the stack of items, or separating the stack into 2 smaller stacks) the server reverts everything back to a regular ammo stack. This is a stackable item issue, more then an ammunition issue.

A possible alternative would be to give your character a buff (using a spell/rune/item) which inside of your weapon script, could convert all ammunition into diamond arrows (visually only) by using a new combat, but would still drain the regular ammunition. (combat1 = regular ammo, single target) (combat2 = buff, aoe, half damage)
 
Ammunition is stackable, so therefore cannot be enchanted or modified directly, because the moment anything regarding the stack changes (firing an arrow, moving the stack of items, or separating the stack into 2 smaller stacks) the server reverts everything back to a regular ammo stack. This is a stackable item issue, more then an ammunition issue.

A possible alternative would be to give your character a buff (using a spell/rune/item) which inside of your weapon script, could convert all ammunition into diamond arrows (visually only) by using a new combat, but would still drain the regular ammunition. (combat1 = regular ammo, single target) (combat2 = buff, aoe, half damage)

This alternative would help me perfectly Xikini, can you help me implement this?
 
This alternative would help me perfectly Xikini, can you help me implement this?
buff item example
XML:
<action itemid="11111111" event="script" value="aaaaaaaa.lua"/>
LUA:
local buffTime = 10 -- seconds
local buffStorageKey = 45001

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local newTime = buffTime + os.time()
    doCreatureSetStorage(cid, buffStorageKey, newTime)
    doCreatureSay(cid, "Buffed for " .. buffTime .. " seconds!", TALKTYPE_MONSTER)
    doRemoveItem(item.uid, 1)
    return true
end

And then inside your weapon scripts, setup 2 combats. (combat1, combat2)
For this example, I've used poison arrow for the regular attack, and burst arrow for the buffed attack.
LUA:
local buffStorageKey = 45001

-- combat 1
local combat1 = createCombatObject()
setCombatParam(combat1, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat1, COMBAT_PARAM_TYPE, COMBAT_POISONDAMAGE)
setCombatParam(combat1, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_POISONARROW)
setCombatFormula(combat1, COMBAT_FORMULA_SKILL, 1, 0, 1, 0)

local condition = createConditionObject(CONDITION_POISON)
setConditionParam(condition, CONDITION_PARAM_DELAYED, 1)
addDamageCondition(condition, 10, 2000, -1)
setCombatCondition(combat1, condition)

-- combat 2
local combat2 = createCombatObject()
setCombatParam(combat2, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat2, COMBAT_PARAM_BLOCKSHIELD, 1)
setCombatParam(combat2, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat2, COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
setCombatParam(combat2, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_BURSTARROW)
setCombatFormula(combat2, COMBAT_FORMULA_SKILL, 1, 0, 1, 0)

local area = createCombatArea({
    {1, 1, 1},
    {1, 3, 1},
    {1, 1, 1}
})

setCombatArea(combat2, area)

function onUseWeapon(cid, var)
    if getCreatureStorage(cid, buffStorageKey) >= os.time() then
        return doCombat(cid, combat2, var) -- buffed
    end
    return doCombat(cid, combat1, var) -- regular
end
 
Solution
buff item example
XML:
<action itemid="11111111" event="script" value="aaaaaaaa.lua"/>
LUA:
local buffTime = 10 -- seconds
local buffStorageKey = 45001

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local newTime = buffTime + os.time()
    doCreatureSetStorage(cid, buffStorageKey, newTime)
    doCreatureSay(cid, "Buffed for " .. buffTime .. " seconds!", TALKTYPE_MONSTER)
    doRemoveItem(item.uid, 1)
    return true
end

And then inside your weapon scripts, setup 2 combats. (combat1, combat2)
For this example, I've used poison arrow for the regular attack, and burst arrow for the buffed attack.
LUA:
local buffStorageKey = 45001

-- combat 1
local combat1 = createCombatObject()
setCombatParam(combat1, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat1, COMBAT_PARAM_TYPE, COMBAT_POISONDAMAGE)
setCombatParam(combat1, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_POISONARROW)
setCombatFormula(combat1, COMBAT_FORMULA_SKILL, 1, 0, 1, 0)

local condition = createConditionObject(CONDITION_POISON)
setConditionParam(condition, CONDITION_PARAM_DELAYED, 1)
addDamageCondition(condition, 10, 2000, -1)
setCombatCondition(combat1, condition)

-- combat 2
local combat2 = createCombatObject()
setCombatParam(combat2, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat2, COMBAT_PARAM_BLOCKSHIELD, 1)
setCombatParam(combat2, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat2, COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
setCombatParam(combat2, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_BURSTARROW)
setCombatFormula(combat2, COMBAT_FORMULA_SKILL, 1, 0, 1, 0)

local area = createCombatArea({
    {1, 1, 1},
    {1, 3, 1},
    {1, 1, 1}
})

setCombatArea(combat2, area)

function onUseWeapon(cid, var)
    if getCreatureStorage(cid, buffStorageKey) >= os.time() then
        return doCombat(cid, combat2, var) -- buffed
    end
    return doCombat(cid, combat1, var) -- regular
end
Thank you so very much, again
 
Back
Top