versão do servidor
TFS 0.3.6
Versão 8.54
Se no lugar do item for uma spell (tipo um buff com storage) também não teria problema.
fiz por mod por precisar usar actionscripts e creaturescripts, então crie um xml com o nome qualquer na pasta mods e cole o código, todas as configurações estão no inicio, e o ID do item pode ser configurada na tag da action.
<?xml version="1.0" encoding="UTF-8"?>
<mod name="SpellLife" enabled="yes" author="Miiller" forum="XTibia.com">
<!-- Configs and Functions -->
<config name="SpellLifeConfig"><![CDATA[
config = {
vocationIds = {76}, -- quais vocação pode usar
level = 100, -- que level é preciso para usar
cooldownSeconds = 60, -- quantos segundos é preciso esperar para usar novamente
emptyStorage = 54154, -- uma storage que não esteja sendo usada no seu servidor
otherEmptyStorage = 54155, -- outra storage que não esteja sendo usada no seu servidor
durationSeconds = 10, -- quanto tempo durara a spell
effect = 10 -- qual efeito mostrara conforme esta sobre o efeito da spell
}
function startSpellLife(cid, seconds)
if not isCreature(cid) then return true end
if seconds == config.durationSeconds then doPlayerSetStorageValue(cid, config.emptyStorage, 1) end
if getPlayerStorageValue(cid, config.emptyStorage) == -1 then
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return true
end
if seconds == 0 then
doPlayerSetStorageValue(cid, config.emptyStorage, -1)
return true
end
doSendMagicEffect(getThingPos(cid), config.effect)
addEvent(startSpellLife, 1000, cid, seconds-1)
end
]]></config>
<!-- configure abaixo o id do item -->
<action itemid="2525" event="script"><![CDATA[
domodlib('SpellLifeConfig')
function onUse(cid, item, fromPosition, itemEx, toPosition)
if not isInArray(config.vocationIds, getPlayerVocation(cid)) then
return doPlayerSendCancel(cid, "Sua vocação não pode usar esta spell.")
end
if getPlayerLevel(cid) < config.level then
return doPlayerSendCancel(cid, "É necessário level " .. config.level .. " para usar esta spell.")
end
if exhaustion.check(cid, config.otherEmptyStorage) then
return doPlayerSendCancel(cid, "É necessário esperar " .. config.cooldownSeconds .. " segundos para usar esta spell novamente.")
end
exhaustion.set(cid, config.otherEmptyStorage, config.cooldownSeconds)
startSpellLife(cid, config.durationSeconds)
doRemoveItem(item.uid, 1)
return true
end
]]></action>
<creaturescript type="statschange" name="SpellLife" event="script"><![CDATA[
domodlib('SpellLifeConfig')
function onStatsChange(cid, attacker, type, combat, value)
if type == STATSCHANGE_HEALTHLOSS then
if getCreatureHealth(cid) - value <= 0 then
if getPlayerStorageValue(cid, config.emptyStorage) == 1 then
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doPlayerSetStorageValue(cid, config.emptyStorage, -1)
return false
end
end
end
return true
end
]]></creaturescript>
<creaturescript type="login" name="SpellLifeLogin" event="script"><![CDATA[
function onLogin(cid)
registerCreatureEvent(cid, "SpellLife")
return true
end
]]></creaturescript>
</mod>
Fico no aguardo caso estiver algum bug
Editado Outubro 17 por Miiller
Vou testar e mandar o resultado.
Deu um erro no console quando eu dou use no item:
[Error - Action Interface]buffer:onUseDescription:[string "loadBuffer"]:3: attempt to index global 'config' (a nil value)stack traceback:[string "loadBuffer"]:3: in function <[string "loadBuffer"]:2>[Error - Action Interface]buffer:onUseDescription:[string "loadBuffer"]:3: attempt to index global 'config' (a nil value)stack traceback:[string "loadBuffer"]:3: in function <[string "loadBuffer"]:2>
Coloquei tudo aquilo que você mandou no Mods, só mudei o ID do item.
Não tem que colocar nada na pasta creaturescripts e actions não, né?
Editado Outubro 16 por Allangod
ve se mudou algo
Agora o server nem abre.
amigo desculpe a demora, tive q baixar o tfs 8.54 e fazer testes, mas agora esta 100%, segue abaixo o mod:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="SpellLife" enabled="yes" author="Miiller" forum="XTibia.com">
<!-- Configs and Functions -->
<config name="SpellLifeConfig"><![CDATA[
config = {
vocationIds = {76}, -- quais vocação pode usar
level = 100, -- que level é preciso para usar
cooldownSeconds = 60, -- quantos segundos é preciso esperar para usar novamente
emptyStorage = 54154, -- uma storage que não esteja sendo usada no seu servidor
otherEmptyStorage = 54155, -- outra storage que não esteja sendo usada no seu servidor
durationSeconds = 10, -- quanto tempo durara a spell
effect = 10 -- qual efeito mostrara conforme esta sobre o efeito da spell
}
function startSpellLife(cid, seconds)
if not isCreature(cid) then return true end
if seconds == config.durationSeconds then doPlayerSetStorageValue(cid, config.emptyStorage, 1) end
if getPlayerStorageValue(cid, config.emptyStorage) == -1 then
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return true
end
if seconds == 0 then
doPlayerSetStorageValue(cid, config.emptyStorage, -1)
return true
end
doSendMagicEffect(getThingPos(cid), config.effect)
addEvent(startSpellLife, 1000, cid, seconds-1)
end
]]></config>
<!-- configure abaixo o id do item -->
<action itemid="2525" event="script"><![CDATA[
domodlib('SpellLifeConfig')
function onUse(cid, item, fromPosition, itemEx, toPosition)
if not isInArray(config.vocationIds, getPlayerVocation(cid)) then
return doPlayerSendCancel(cid, "Sua vocação não pode usar esta spell.")
end
if getPlayerLevel(cid) < config.level then
return doPlayerSendCancel(cid, "É necessário level " .. config.level .. " para usar esta spell.")
end
if exhaustion.check(cid, config.otherEmptyStorage) then
return doPlayerSendCancel(cid, "É necessário esperar " .. config.cooldownSeconds .. " segundos para usar esta spell novamente.")
end
exhaustion.set(cid, config.otherEmptyStorage, config.cooldownSeconds)
startSpellLife(cid, config.durationSeconds)
doRemoveItem(item.uid, 1)
return true
end
]]></action>
<creaturescript type="statschange" name="SpellLife" event="script"><![CDATA[
domodlib('SpellLifeConfig')
function onStatsChange(cid, attacker, type, combat, value)
if type == STATSCHANGE_HEALTHLOSS then
if getCreatureHealth(cid) - value <= 0 then
if getPlayerStorageValue(cid, config.emptyStorage) == 1 then
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doPlayerSetStorageValue(cid, config.emptyStorage, -1)
return false
end
end
end
return true
end
]]></creaturescript>
<creaturescript type="login" name="SpellLifeLogin" event="script"><![CDATA[
function onLogin(cid)
registerCreatureEvent(cid, "SpellLife")
return true
end
]]></creaturescript>
</mod>
Funcinou perfeitamente, valeu.
info
Grupo: Lorde
Registrado: 22/07/12
Posts: 2.2k
Reputação: +453
Char no Tibia: Kissy

Tópico Movido
Este tópico foi movido de "OTServ → Suporte OTServ → Suporte Scripting"
para "OTServ → Suporte OTServ → Suporte Scripting → Pedidos e dúvidas resolvidos - Scripting".





info
Grupo: Cavaleiro
Registrado: 04/09/12
Posts: 185
Reputação: +2
Gostaria de uma spell onde o player ao dar use em um item (um ID configurado por mim), quando chega-se ao hp 0, ele healaria todo o HP. Só que quando ele usar esse Item, ele terá 10seg para chegar ao hp 0, caso contrário o efeito sumirá. Gostaria que esse item pudesse ser usado somente por uma vocation (76) e que tivesse um cooldown de 1minuto.
OBS: Seria possível fazer com que se ele usar esse item 5 vezes, o cooldown seria de 10minutos?