• 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!

TFS [1.0] Spell that hit with ShieldSkill?

Eldin

Eldin Projects
Premium User
Joined
Jun 12, 2008
Messages
1,334
Reaction score
613
Location
Sweden
Greets!

I am trying to make a "hit monster" spell with the calculation from the shield skill.
A Bonus is then if it can cause the monster to get "stunned" "stuck" for 1 second.

--

Shield Bash:

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
setCombatParam(combat, COMBAT_PARAM_USECHARGES, 1)

function onGetFormulaValues(cid, skill, attack, factor)
local skillTotal, levelTotal = skill * attack, getPlayerLevel(cid) / 2
     return -(((skillTotal * 1.0) + 1) + (levelTotal)), -(((skillTotal * 1.0) + 6) + (levelTotal))
end

setCombatCallback(combat, CALLBACK_PARAM_SKILL_SHIELD, "onGetFormulaValues")
function onCastSpell(cid, var)
      return doCombat(cid, combat, var)
end

Problem:
The idea is to take damage from the ShieldSkill (in any way possible), then (or only) make your target "stunned" for 1 second as they once again get "chocked".

Thanks in Advance.

Kind Regards,
Eldin.
 
Great News!
I have never used it that way and im yet not skilled with spells, are you able to show me?
@forgee

Thanks again.

Kind Regards,
Eldin.
 
Here is a simple example uning shielding skill instead of the weapon skill (disregarding attack value).
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
setCombatParam(combat, COMBAT_PARAM_USECHARGES, 1)

function onGetFormulaValues(cid, skill, attack, factor)
    local shielding = Player(cid):getEffectiveSkillLevel(SKILL_SHIELD)
    local skillTotal, levelTotal = shielding, getPlayerLevel(cid) / 2
    return -(((skillTotal * 1.0) + 1) + (levelTotal)), -(((skillTotal * 1.0) + 6) + (levelTotal))
end

setCombatCallback(combat, CALLBACK_PARAM_SKILL_SHIELD, "onGetFormulaValues")
function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end
I stored the player's shielding in the variable "shielding" for readability. Instead of the attack attribute you can for example get the defense from the item in the player's shield slot. If you need any more help, try to explain as detailed as possible how you would like it to work and I'll help as best I can.

Edit:
I had to look up a few methods and constants but here is another example using the defense of the shield instead of weapon attack.
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
setCombatParam(combat, COMBAT_PARAM_USECHARGES, 1)

function onGetFormulaValues(cid, skill, attack, factor)
    local player = Player(cid)
    local shield = ItemType(player:getSlotItem(SLOTP_LEFT):getId())
    local shielding, defense = player:getEffectiveSkillLevel(SKILL_SHIELD), shield:getDefense()
    local skillTotal, levelTotal = shielding * defense, getPlayerLevel(cid) / 2
    return -(((skillTotal * 1.0) + 1) + (levelTotal)), -(((skillTotal * 1.0) + 6) + (levelTotal))
end

setCombatCallback(combat, CALLBACK_PARAM_SKILL_SHIELD, "onGetFormulaValues")
function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end
I'm certainly no expert so bear with me. I think that using ItemType is the correct approach to get the defense value and I guess that the left hand is the shield but I haven't made sure so if it seems to use the weapon's defense, change SLOTP_LEFT to SLOTP_RIGHT.
 
Last edited:
I thank you for the comment as well as the help. @forgee

I did however encounter a problem: (same as when I tried myself)
Code:
Lua Script Error: [Test Interface]
data/spells/scripts/Guardian/Shield Bash.lua
LuaScriptInterface::luaSetCombatCallBack(). 0 is not a valid callback key.
stack traceback:

  [C]: in function 'setCombatCallback'
  data/spells/scripts/Guardian/Shield Bash.lua:15: in main chunk
Lua Script Error: [Spell Interface]
data/spells/scripts/Guardian/Shield Bash.lua
LuaScriptInterface::luaSetCombatCallBack(). 0 is not a valid callback key.
stack traceback:

  [C]: in function 'setCombatCallback'
  data/spells/scripts/Guardian/Shield Bash.lua:15: in main chunk

Once it works with the main thing, calculation from the Shielding Skill, im on the the next 2 things:
1. Make the Monster "Challenge" you as you took the focus.
2. Add a 0.5 (or 1) second "Stun" to the Monster as it got "Chocked".
Spell Complete.

I am happy with anything that I mentioned, the shield calculation is the most important thing as im making more Shield Scripts out of that.

Kind Regards,
Eldin.
 
I didn't notice CALLBACK_PARAM_SKILL_SHIELD. Looking at enums.h (https://github.com/otland/forgottenserver/blob/master/src/enums.h#L168-173) the valid callback key seems to be CALLBACK_PARAM_SKILLVALUE (weapon skill), which is why I used the Player methods in the first place as there is no callback for shielding.
So change CALLBACK_PARAM_SKILL_SHIELD to CALLBACK_PARAM_SKILLVALUE.
 
Its working, really appriciate it, this will help me with alot of spells for my Guardian.
Time to improve it with Challenge and Stun, Im onto it Before I ask for help, if you're bored go ahead hah. ;)

Thanks again.

Kind Regards,
Eldin.
 
Here is a simple example uning shielding skill instead of the weapon skill (disregarding attack value).
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
setCombatParam(combat, COMBAT_PARAM_USECHARGES, 1)

function onGetFormulaValues(cid, skill, attack, factor)
    local shielding = Player(cid):getEffectiveSkillLevel(SKILL_SHIELD)
    local skillTotal, levelTotal = shielding, getPlayerLevel(cid) / 2
    return -(((skillTotal * 1.0) + 1) + (levelTotal)), -(((skillTotal * 1.0) + 6) + (levelTotal))
end

setCombatCallback(combat, CALLBACK_PARAM_SKILL_SHIELD, "onGetFormulaValues")
function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end
I stored the player's shielding in the variable "shielding" for readability. Instead of the attack attribute you can for example get the defense from the item in the player's shield slot. If you need any more help, try to explain as detailed as possible how you would like it to work and I'll help as best I can.

Edit:
I had to look up a few methods and constants but here is another example using the defense of the shield instead of weapon attack.
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
setCombatParam(combat, COMBAT_PARAM_USECHARGES, 1)

function onGetFormulaValues(cid, skill, attack, factor)
    local player = Player(cid)
    local shield = ItemType(player:getSlotItem(SLOTP_LEFT):getId())
    local shielding, defense = player:getEffectiveSkillLevel(SKILL_SHIELD), shield:getDefense()
    local skillTotal, levelTotal = shielding * defense, getPlayerLevel(cid) / 2
    return -(((skillTotal * 1.0) + 1) + (levelTotal)), -(((skillTotal * 1.0) + 6) + (levelTotal))
end

setCombatCallback(combat, CALLBACK_PARAM_SKILL_SHIELD, "onGetFormulaValues")
function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end
I'm certainly no expert so bear with me. I think that using ItemType is the correct approach to get the defense value and I guess that the left hand is the shield but I haven't made sure so if it seems to use the weapon's defense, change SLOTP_LEFT to SLOTP_RIGHT.

I love the way you guys did this, Nicely done. I have been making my spells' formulas based off what I want as well, including skill and level and all that good stuff, but I noticed that the function you used for calling the shield skill specifically was "getEffectiveSkillLevel" rather than "getSkillLevel". Could you please tell me the difference between the two? I would really like to know how that works...
 
I love the way you guys did this, Nicely done. I have been making my spells' formulas based off what I want as well, including skill and level and all that good stuff, but I noticed that the function you used for calling the shield skill specifically was "getEffectiveSkillLevel" rather than "getSkillLevel". Could you please tell me the difference between the two? I would really like to know how that works...
I believe that "getEffectiveSkillLevel" returns the skill level including bonuses from equipment and spells where as "getSkillLevel" returns the base skill level.

@EldinWorld
Challenge is very simple so I'm sure you've figured that one out by now.
The stun effect is something I've been struggling with myself so I'd be very curious to hear what you come up with. It has been a while since I messed with that, though so I will probably take another pass at it soon.
 
Back
Top