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

Solved [TFS 1.2] Message on Condition Drop

Caduceus

Unknown Member
Joined
May 10, 2010
Messages
321
Solutions
2
Reaction score
24
I am trying to apply a message when CONDITION_MANASHIELD wears off.

Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local condition = Condition(CONDITION_MANASHIELD)
condition:setParameter(CONDITION_PARAM_TICKS, 200000)
combat:setCondition(condition)

function onCastSpell(creature, var)
    return combat:execute(creature, var)
end

local player = Player(cid)
    if not player then
        return true
    end

if player:getCondition(CONDITION_MANASHIELD) == false then
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Mana Shield has wore off.")
end
 
I am trying to apply a message when CONDITION_MANASHIELD wears off.

Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local condition = Condition(CONDITION_MANASHIELD)
condition:setParameter(CONDITION_PARAM_TICKS, 200000)
combat:setCondition(condition)

function onCastSpell(creature, var)
    return combat:execute(creature, var)
end

local player = Player(cid)
    if not player then
        return true
    end

if player:getCondition(CONDITION_MANASHIELD) == false then
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Mana Shield has wore off.")
end
Two words.. add event
 
callback should be a function on addevent. What would work here?

Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local condition = Condition(CONDITION_MANASHIELD)
condition:setParameter(CONDITION_PARAM_TICKS, 200000)
combat:setCondition(condition)

function onCastSpell(creature, var)
local message = "Mana Shield has wore off."
local c = combat:execute(creature, var)
    if c then
    addEvent(function, 200000, message)
    end
    return c
end
 
Code:
local function ManaEvent(message)
--function here
end


function onCastSpell(creature, var)
local message = "Mana Shield has wore off."
local c = combat:execute(creature, var)
if c then
addEvent(ManaEvent, 200000, message)
end
return c
end

Also you should probably use stopEvent if someone reactivates mana shield?
And return false when Player logs out or dies?
 
I am just notifying of condition drop. Would this also affect reapplication?
I can see onDeath returning false. Would a logout also affect the duration of the addEvent?
 
Last edited:
tried this, but still not receiving a message on condition drop, but instead on cast.

Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local condition = Condition(CONDITION_MANASHIELD)
condition:setParameter(CONDITION_PARAM_TICKS, 20000)
combat:setCondition(condition)


local function ManaEvent(cid)
local player = Player(cid)
    if not player then
        return false
    end
end

function onCastSpell(creature, var)
local message = creature:sendTextMessage(MESSAGE_STATUS_SMALL, "Mana Shield has wore off.")
    combat:execute(creature, var)
    addEvent(ManaEvent, 20000, message)
return true
end
 
Last edited:
spell:
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local condition = Condition(CONDITION_MANASHIELD)
condition:setParameter(CONDITION_PARAM_TICKS, 10000) -- I made it shorter for testing, normal was 200000
combat:setCondition(condition)

function onCastSpell(creature, var)
    creature:setStorageValue(75004, 1)
    creature:registerEvent('ManaMessage')
    return combat:execute(creature, var)
end

data/creaturescripts/creaturescripts.xml
Code:
<event type="think" name="ManaMessage" script="test/mana_message.lua" />

data/creaturescripts/scripts/test/mana_message.lua

Code:
function onThink(creature)
    if creature:getStorageValue(75004) == 1 then
        if not creature:getCondition(CONDITION_MANASHIELD) then
            creature:setStorageValue(75004, 0)
            creature:say('Your mana shield has worn off!', TALKTYPE_MONSTER_SAY)
        end
    end
end
 
instead of onThink to display it you can have
addEvent(manaDrop, 20010, cid) (if 20k is duration) then
Code:
local duration = 20000
local message = "Manashield has worn off."

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local condition = Condition(CONDITION_MANASHIELD)
condition:setParameter(CONDITION_PARAM_TICKS, duration)
combat:setCondition(condition)

function manaDrop(cid)
    local player = Player(cid)
    if not player then
        return false
    end
    if not getCreatureCondition(player, CONDITION_MANASHIELD) then
        player:say(message, TALKTYPE_MONSTER_SAY)
    end
end

function onCastSpell(creature, var)
    combat:execute(creature, var)
    addEvent(manaDrop, duration+10, creature.uid)
    return true
end
doing like this it wil try to say that manashield dropped 20k ms after you cast it (if you have 20k ms duration), if its still on or player doesnt exist anymore it will do nothing, if player exists and has no manashield it will say msg

no need for special storages / onthink events etc
 
instead of onThink to display it you can have
addEvent(manaDrop, 20010, cid) (if 20k is duration) then
Code:
local duration = 20000
local message = "Manashield has worn off."

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local condition = Condition(CONDITION_MANASHIELD)
condition:setParameter(CONDITION_PARAM_TICKS, duration)
combat:setCondition(condition)

function manaDrop(cid)
    local player = Player(cid)
    if not player then
        return false
    end
    if not getCreatureCondition(player, CONDITION_MANASHIELD) then
        player:say(message, TALKTYPE_MONSTER_SAY)
    end
end

function onCastSpell(creature, var)
    combat:execute(creature, var)
    addEvent(manaDrop, duration+10, creature.uid)
    return true
end
doing like this it wil try to say that manashield dropped 20k ms after you cast it (if you have 20k ms duration), if its still on or player doesnt exist anymore it will do nothing, if player exists and has no manashield it will say msg

no need for special storages / onthink events etc

From my experience too many addEvents will lag your server pretty badly. In that script everytime the player casts the spell your are creating an addEvent. Most players do not wait for the mana shield to run out if they are paying attention so they will initiating multiple addEvents everytime they decide to refresh their mana shield even before it runs out. Multiple times for multiple mages on the server.
 
From my experience too many addEvents will lag your server pretty badly. In that script everytime the player casts the spell your are creating an addEvent. Most players do not wait for the mana shield to run out if they are paying attention so they will initiating multiple addEvents everytime they decide to refresh their mana shield even before it runs out. Multiple times for multiple mages on the server.
addEvents are only bad if you create a very large number of them, in this case if manashield lasts 200k ms each mage would cast it maybe each 100-150k ms, which is almost no addEvents at all, while ur version uses onThink, which afaik calls every second constantly...
for example ur onThink in reality pretty much looks like this..
Code:
function onThink(creature)
if creature:getStorageValue(75004) == 1 then
if not creature:getCondition(CONDITION_MANASHIELD) then
creature:setStorageValue(75004, 0)
creature:say('Your mana shield has worn off!', TALKTYPE_MONSTER_SAY)
end
end
addEvent(onThink, 1000, creature)
end
 
Back
Top