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

Lua Spell Condition Parameter

mackerel

Well-Known Member
Joined
Apr 26, 2017
Messages
398
Solutions
18
Reaction score
72
There is a little problem with my spell and I would appreciate some help since I've been stuck on this one;

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, 6)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)

local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_SKILL_SWORD, 20)
setConditionParam(condition, CONDITION_PARAM_MANAGAIN, -5)

setCombatCondition(combat, condition)

The problem is with condition parameter, it either adds skill_sword +20 or takes player mana -5 but they do not work at the same time and I don't know why;

this:

Lua:
setConditionParam(condition, CONDITION_PARAM_SKILL_SWORD, 20)
setConditionParam(condition, CONDITION_PARAM_MANAGAIN, -5)

I also tried to do this:

Lua:
local condition = createConditionObject(CONDITION_ATTRIBUTES and CONDITION_REGENERATION)

but that didn't work

Also, if you know how to stop the conditions when the player has 10 mana or less please let me know
 
Last edited:
just put
Lua:
doPlayerAddMana(cid, mana, ...)
doPlayerAddManaSpent(cid, mana)
 
just put
Lua:
doPlayerAddMana(cid, mana, ...)
doPlayerAddManaSpent(cid, mana)

Right, we can use functions O:

I've fixed it anyway (partially), now I don't know if we can actually stop the conditions when player has less than 100 mana. A loop is something I really want to avoid here, and preferably would love to do this in spells folder.

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, 6)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)

local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_SKILL_SWORD, 20)
setCombatCondition(combat, condition)

local condition = createConditionObject(CONDITION_REGENERATION)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_MANAGAIN, -5)
setCombatCondition(combat, condition)

function onCastSpell(cid, var)
    if getPlayerStorageValue(cid, 1001) ~= 1 then
        doCombat(cid, combat, var)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "ON")
        setPlayerStorageValue(cid, 1001, 1)
    else
        doRemoveCondition(cid, CONDITION_ATTRIBUTES)
        doRemoveCondition(cid, CONDITION_REGENERATION)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "OFF")
        setPlayerStorageValue(cid, 1001, -1)
    end
    return true
end
 
Right, we can use functions O:

I've fixed it anyway (partially), now I don't know if we can actually stop the conditions when player has less than 100 mana. A loop is something I really want to avoid here, and preferably would love to do this in spells folder.

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, 6)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)

local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_SKILL_SWORD, 20)
setCombatCondition(combat, condition)

local condition = createConditionObject(CONDITION_REGENERATION)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_MANAGAIN, -5)
setCombatCondition(combat, condition)

function onCastSpell(cid, var)
    if getPlayerStorageValue(cid, 1001) ~= 1 then
        doCombat(cid, combat, var)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "ON")
        setPlayerStorageValue(cid, 1001, 1)
    else
        doRemoveCondition(cid, CONDITION_ATTRIBUTES)
        doRemoveCondition(cid, CONDITION_REGENERATION)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "OFF")
        setPlayerStorageValue(cid, 1001, -1)
    end
    return true
end

No ide what server you are using but with 1.x the correct way is using creaturescripts onHealthChange / onManaChange.
If you are using 0.4 and might work on 0.3 aswell you got onStatsChange
 
There is a little problem with my spell and I would appreciate some help since I've been stuck on this one;

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, 6)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)

local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_SKILL_SWORD, 20)
setConditionParam(condition, CONDITION_PARAM_MANAGAIN, -5)

setCombatCondition(combat, condition)

The problem is with condition parameter, it either adds skill_sword +20 or takes player mana -5 but they do not work at the same time and I don't know why;

this:

Lua:
setConditionParam(condition, CONDITION_PARAM_SKILL_SWORD, 20)
setConditionParam(condition, CONDITION_PARAM_MANAGAIN, -5)

I also tried to do this:

Lua:
local condition = createConditionObject(CONDITION_ATTRIBUTES and CONDITION_REGENERATION)

but that didn't work

Also, if you know how to stop the conditions when the player has 10 mana or less please let me know

CONDITION_PARAM_MANAGAIN is a CONDITION_REGENERATION and CONDITION_PARAM_SKILL_SWORD is a CONDITION_ATTRIBUTES
Some examples
regen
forgottenserver/player.lua at 508cdd0aedbf7042ad2ff0b7b6be99f9b963c921 · otland/forgottenserver · GitHub

attributes
forgottenserver/train.lua at 4c66b60fdd320669b086bc2fbb6d784138b84530 · otland/forgottenserver · GitHub
 
No ide what server you are using but with 1.x the correct way is using creaturescripts onHealthChange / onManaChange.
If you are using 0.4 and might work on 0.3 aswell you got onStatsChange

TFS 1.0

I did as you said, but something is wrong with the code

1. Added to login.lua this:

Lua:
player:registerEvent("test")

2. Added to creaturescripts.xml this:

Lua:
<event type="manachange" name="test" script="test.lua"/>

3. My test.lua

Lua:
function onManaChange(creature, attacker, manaChange)
    print("first check")
    if getPlayerStorageValue(cid, 1001) == -1 then
        return false
    end
 
    if Player(cid) and manaChange < 100 then
        print("works")
    else
        print("nope")
    end
end

The "first check" does not even come up in the console when using utevo lux to burn mana or mana potion to regenerate mana

Also, do we need to register that event within login.lua when using this function?


P.S. This spell is selftarget


Yes, already changed to CONDITION_REGENERATION/CONDITION_ATTRIBUTES, thanks anyway.
 
Last edited:
TFS 1.0

I did as you said, but something is wrong with the code

1. Added to login.lua this:

Lua:
player:registerEvent("test")

2. Added to creaturescripts.xml this:

Lua:
<event type="manachange" name="test" script="test.lua"/>

3. My test.lua

Lua:
function onManaChange(creature, attacker, manaChange)
    print("first check")
    if getPlayerStorageValue(cid, 1001) == -1 then
        return false
    end
 
    if Player(cid) and manaChange < 100 then
        print("works")
    else
        print("nope")
    end
end

The "first check" does not even come up in the console when using utevo lux to burn mana or mana potion to regenerate mana

Also, do we need to register that event within login.lua when using this function?


P.S. This spell is selftarget



Yes, already changed to CONDITION_REGENERATION/CONDITION_ATTRIBUTES, thanks anyway.

Did you restart the server?
Depending on what rev you got the function might be named onChangeMana (Rename onChangeHealth/Mana to onMana/HealthChange · otland/forgottenserver@4343f34 · GitHub)
 
Did you restart the server?
Depending on what rev you got the function might be named onChangeMana (Rename onChangeHealth/Mana to onMana/HealthChange · otland/forgottenserver@4343f34 · GitHub)

Using /reload command, but it works when I change the function to something different- error shows up O:

Also, onMana = error

Just downloaded from github the latest TFS 1.0 version to make sure.

Checked the source and it is the correct one:

Types:

(tmpStr == "logout")
(tmpStr == "think")
(tmpStr == "preparedeath")
(tmpStr == "death")
(tmpStr == "kill")
(tmpStr == "advance")
(tmpStr == "modalwindow")
(tmpStr == "textedit")
(tmpStr == "healthchange")
(tmpStr == "manachange")
(tmpStr == "extendedopcode")

Functions:

return "onLogin";
return "onLogout";
return "onThink";
return "onPrepareDeath";
return "onDeath";
return "onKill";
return "onAdvance";
return "onModalWindow";
return "onTextEdit";
return "onHealthChange";
return "onManaChange";
return "onExtendedOpcode";

It seems like it does not work for spells/conditions?

Health Issue:
onHealthChange: Doesn't execute for healing · Issue #1226 · otland/forgottenserver · GitHub

Mana Issue:
onManaChange for spells · Issue #1211 · otland/forgottenserver · GitHub

According to this link, the creature has to be registered but I did that in login.lua |:

Interface:Creature Events · otland/forgottenserver Wiki · GitHub
 
Last edited:
Using /reload command, but it works when I change the function to something different- error shows up O:

Also, onMana = error

Just downloaded from github the latest TFS 1.0 version to make sure.

Checked the source and it is the correct one:

Types:



Functions:



It seems like it does not work for spells/conditions?

Health Issue:
onHealthChange: Doesn't execute for healing · Issue #1226 · otland/forgottenserver · GitHub

Mana Issue:
onManaChange for spells · Issue #1211 · otland/forgottenserver · GitHub

According to this link, the creature has to be registered but I did that in login.lua |:

Interface:Creature Events · otland/forgottenserver Wiki · GitHub

Humm yeah thats true, tought it had been implemented ;o
What I would do in that case and if I felt I really needed something like that would be to try and implement that for spells, using a loop won't be good if you got alot of players etc
 
Back
Top