Thanks in advance to whomever is taking the time to look this over with me.
The short and sweet is that I'm trying to figure out how to best script in LUA with TFS 1.4 (unaltered source). I'm undertaking what I thought was a simple task:
Make a custom wand which consumes less mana for a custom vocation and consumes normal mana for all other vocations. (this will be expanded to all wands/rods and then a similar process for all spells for another vocation)
I've spent nearly 12 hours researching, scouring these forums, searching for any/all api and function documentation for TFS 1.4 and put simply, there's not enough documentation (or at least I'm not able to easily find it) to understand how to properly utilize the API. I'm slightly new to LUA scripting, but am familiar with BASH/Powershell scripting, so this isn't too difficult to wrap my head around; however, without the necessary TFS 1.4 API docs, I'm pretty much stuck to trial and error with TFS 1.2/1.3 documentation or even older versions of TFS (due to some old posts here which have the necessary logic, but deprecated syntax + API).
In this mini-quest, I've been successful in creating a custom wand (hijacked an existing SPR + ID), got the mana cost differences in place based on a vocation condition and have even built in a "poof" + cancel message when mana is insufficient. The last hurdle (or so I think) is getting the combat animation of the projectile + enemy hit to stop when mana is insufficient. There's probably a good chance that I've over engineered this or even done some things completely unnecessary/backwards. My goal is to learn how this works, and I'm hoping someone here can help get me across the finish line for at least this mini-quest of a wand.
Here is my current code:
As a brief note, I've attempted about 4 different ways in stopping the animation (all of which utilized nested if statements surrounding the relevant combat lines). Obviously, these all failed and I feel like I'm really close to the answer... Any constructive criticism, tips, and/or documentation links are fully welcome and appreciated.
The short and sweet is that I'm trying to figure out how to best script in LUA with TFS 1.4 (unaltered source). I'm undertaking what I thought was a simple task:
Make a custom wand which consumes less mana for a custom vocation and consumes normal mana for all other vocations. (this will be expanded to all wands/rods and then a similar process for all spells for another vocation)
I've spent nearly 12 hours researching, scouring these forums, searching for any/all api and function documentation for TFS 1.4 and put simply, there's not enough documentation (or at least I'm not able to easily find it) to understand how to properly utilize the API. I'm slightly new to LUA scripting, but am familiar with BASH/Powershell scripting, so this isn't too difficult to wrap my head around; however, without the necessary TFS 1.4 API docs, I'm pretty much stuck to trial and error with TFS 1.2/1.3 documentation or even older versions of TFS (due to some old posts here which have the necessary logic, but deprecated syntax + API).
In this mini-quest, I've been successful in creating a custom wand (hijacked an existing SPR + ID), got the mana cost differences in place based on a vocation condition and have even built in a "poof" + cancel message when mana is insufficient. The last hurdle (or so I think) is getting the combat animation of the projectile + enemy hit to stop when mana is insufficient. There's probably a good chance that I've over engineered this or even done some things completely unnecessary/backwards. My goal is to learn how this works, and I'm hoping someone here can help get me across the finish line for at least this mini-quest of a wand.
Here is my current code:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREATTACK)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
function onGetFormulaValues(player, level, magicLevel)
local min = (magicLevel * 1) + 5
local max = (magicLevel * 2) + 5
local id = player:getVocation():getId()
local manacost = player:getMaxMana()*.1
local currentmana = player:getMana()
local errorMana = "You do not have enough mana."
if currentmana < manacost then
player:sendCancelMessage(string.format("You do not have enough mana."))
local position = player:getPosition()
addEvent(Position.sendMagicEffect, 250, position, CONST_ME_POFF)
return
else
player:addManaSpent(manacost)
if id == 9 then
player:addMana(-manacost) --Values are identical only for testing. Separate values currently work.
else
player:addMana(-manacost) --Values are identical only for testing. Separate values currently work.
end
end
return -min, -max
end
combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
function onUseWeapon(player, variant)
return combat:execute(player, variant)
end
XML:
<wand id="2162" script="wand1.lua"> <!-- CUSTOM || Wand1 -->
</wand>
XML:
<item id="2162" article="a" name="Wand of Recursion">
<attribute key="description" value="Fires smoulders from the tip and may get hotter." />
<attribute key="weight" value="2500"/>
<attribute key="weaponType" value="wand"/>
<attribute key="shootType" value="fire"/>
<attribute key="range" value="5"/>
</item>
As a brief note, I've attempted about 4 different ways in stopping the animation (all of which utilized nested if statements surrounding the relevant combat lines). Obviously, these all failed and I feel like I'm really close to the answer... Any constructive criticism, tips, and/or documentation links are fully welcome and appreciated.