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

Spell Silence TFS 1.0

Codinablack

Dreamer
Content Editor
Joined
Dec 26, 2013
Messages
1,557
Solutions
11
Reaction score
774
I got the idea from andu and although mine doesn't use tables and a formula, mine will work on tfs 1.0 and has configurations for almost same idea of a spell....

This spell is a mute spell, basically you make the player or monster or both (in config) unable to say anything for X amount of seconds. With players being unable to say anything they are unable to cast any kind of spell.

ok so make /spells/scripts/silence.lua


Code:
local tarmonster = true -- Can we cast this spell on monsters. Default is true
local ptime = 8000 -- This is how long the spell will last on a Player. Default is 8 seconds = 8000
local mtime = 10000 -- This is how long the spell will last on a Monster. Default is 10 seconds = 10000

local pcombat = createCombatObject()
setCombatParam(pcombat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
setCombatParam(pcombat, COMBAT_PARAM_AGGRESSIVE, true)
local pcondition = createConditionObject(CONDITION_MUTED)
setConditionParam(pcondition, CONDITION_PARAM_TICKS, ptime)
setCombatCondition(pcombat, pcondition)

local mcombat = createCombatObject()
setCombatParam(mcombat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
setCombatParam(mcombat, COMBAT_PARAM_AGGRESSIVE, true)
local mcondition = createConditionObject(CONDITION_MUTED)
setConditionParam(mcondition, CONDITION_PARAM_TICKS, mtime)
setCombatCondition(mcombat, mcondition)

function onCastSpell(cid, var)
local creature = Creature(cid)
local tar = creature:getTarget()

    if tar:getCondition(CONDITION_MUTED) then
            creature:sendTextMessage(MESSAGE_STATUS_SMALL, "This creature is already muted")
        return false
    end
     if tar:isPlayer() == true then
        tar:say("^SILENCED^",TALKTYPE_MONSTER_SAY)
        doCombat(tar, pcombat, var)
        return true
     end
    if tar:isMonster() == true then
        if(tarmonster == true) then
        tar:say("^SILENCED^",TALKTYPE_MONSTER_SAY)
        doCombat(tar, mcombat, var)
        return true
        else
        creature:sendTextMessage(MESSAGE_STATUS_SMALL, "You can only use this spell on Players.")
        end
     end
end

Then in your spells.xml add this

Code:
    <instant name="Silence" words="exevo silencia" lvl="30" mana="400" prem="0" aggressive="1" selftarget="0" exhaustion="25000" group="support" groupcooldown="500" icon="126" needlearn="0"  script="silence.lua">
    <vocation name="Druid"/>
    </instant>
 
Last edited:
Nice, will for sure use it one way or Another!
I do however Think that you should write more what it does for the people who don't get it, might be the reason why you didn't get any comments. :)
Keep up the good work!

Kind Regards,
Eldin.
 
Nice, will for sure use it one way or Another!
I do however Think that you should write more what it does for the people who don't get it, might be the reason why you didn't get any comments. :)
Keep up the good work!

Kind Regards,
Eldin.

Thanks I will edit the post to explain so maybe more people can benefit from its use.
 
Nice idea :)
I guess this:
Code:
if tar:isPlayer() == true then
if tar:isMonster() == true then
if(tarmonster == true) then

Is same as:
Code:
if tar:isPlayer() then
if tar:isMonster() then
if tarmonster  then

Have nice day!
 
Why do you ask if it is a player or monster if they both are effected by the spell?

They aren't always both affected by the spell, the only reason it checks both is because of the configuration option (for otland users) on the very first line of the script, you can make it so it doesn't affect anyone but players....

Nice idea :)
I guess this:
Code:
if tar:isPlayer() == true then
if tar:isMonster() == true then
if(tarmonster == true) then

Is same as:
Code:
if tar:isPlayer() then
if tar:isMonster() then
if tarmonster  then

Have nice day!

I never did tell you thanks, thanks a whole lot man, since this I have gotten way better at .lua and that little fact right there has helped me soooo much along the way...
 
They aren't always both affected by the spell, the only reason it checks both is because of the configuration option (for otland users) on the very first line of the script, you can make it so it doesn't affect anyone but players....
Sorry bout that, I over looked that part.
 
Try this out
Code:
local tarmonster = true -- Can we cast this spell on monsters. Default is true
local ptime = 8000 -- This is how long the spell will last on a Player. Default is 8 seconds = 8000
local mtime = 10000 -- This is how long the spell will last on a Monster. Default is 10 seconds = 10000

local pcombat = createCombatObject()
setCombatParam(pcombat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
setCombatParam(pcombat, COMBAT_PARAM_AGGRESSIVE, true)
local pcondition = createConditionObject(CONDITION_MUTED)
setConditionParam(pcondition, CONDITION_PARAM_TICKS, ptime)
setCombatCondition(pcombat, pcondition)

local mcombat = createCombatObject()
setCombatParam(mcombat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
setCombatParam(mcombat, COMBAT_PARAM_AGGRESSIVE, true)
local mcondition = createConditionObject(CONDITION_MUTED)
setConditionParam(mcondition, CONDITION_PARAM_TICKS, mtime)
setCombatCondition(mcombat, mcondition)

function onCastSpell(cid, var)
local creature = Creature(cid)
local tar = creature:getTarget()

    if tar:getCondition(CONDITION_MUTED) then -- check right away if muted
        creature:sendTextMessage(MESSAGE_STATUS_SMALL, "This creature is already muted")
        return false
    else -- if not muted
        if tar:isPlayer() then -- check if player
            tar:say("^SILENCED^",TALKTYPE_MONSTER_SAY)
            return doCombat(tar, pcombat, var) -- return the combat
        end
        if tar:isMonster() and tarmonster then -- check if it effects monster and if it is a monster
            tar:say("^SILENCED^",TALKTYPE_MONSTER_SAY)
            return doCombat(tar, mcombat, var) -- return the combat
        else
            creature:sendTextMessage(MESSAGE_STATUS_SMALL, "You can only use this spell on Players.")
            return false
        end
    end
end
 
Try this out
Code:
local tarmonster = true -- Can we cast this spell on monsters. Default is true
local ptime = 8000 -- This is how long the spell will last on a Player. Default is 8 seconds = 8000
local mtime = 10000 -- This is how long the spell will last on a Monster. Default is 10 seconds = 10000

local pcombat = createCombatObject()
setCombatParam(pcombat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
setCombatParam(pcombat, COMBAT_PARAM_AGGRESSIVE, true)
local pcondition = createConditionObject(CONDITION_MUTED)
setConditionParam(pcondition, CONDITION_PARAM_TICKS, ptime)
setCombatCondition(pcombat, pcondition)

local mcombat = createCombatObject()
setCombatParam(mcombat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
setCombatParam(mcombat, COMBAT_PARAM_AGGRESSIVE, true)
local mcondition = createConditionObject(CONDITION_MUTED)
setConditionParam(mcondition, CONDITION_PARAM_TICKS, mtime)
setCombatCondition(mcombat, mcondition)

function onCastSpell(cid, var)
local creature = Creature(cid)
local tar = creature:getTarget()

    if tar:getCondition(CONDITION_MUTED) then -- check right away if muted
        creature:sendTextMessage(MESSAGE_STATUS_SMALL, "This creature is already muted")
        return false
    else -- if not muted
        if tar:isPlayer() then -- check if player
            tar:say("^SILENCED^",TALKTYPE_MONSTER_SAY)
            return doCombat(tar, pcombat, var) -- return the combat
        end
        if tar:isMonster() and tarmonster then -- check if it effects monster and if it is a monster
            tar:say("^SILENCED^",TALKTYPE_MONSTER_SAY)
            return doCombat(tar, mcombat, var) -- return the combat
        else
            creature:sendTextMessage(MESSAGE_STATUS_SMALL, "You can only use this spell on Players.")
            return false
        end
    end
end


I like! Very nicely done, when I decide to rewrite this (to utilize metamethods) then I will take your edits into account. There is also better way to do combat using variable I believe, idk I just got up, still busy from the holidays. Thanks for the contribution!
 
I like! Very nicely done, when I decide to rewrite this (to utilize metamethods) then I will take your edits into account. There is also better way to do combat using variable I believe, idk I just got up, still busy from the holidays. Thanks for the contribution!
You are using metamethods already, that is what the colon ( : ) represent.
Creature & Player are metatable's similar to classes a metatable can have a contructer and it's metamethods are similar to a classes methods
Not too sure how inheritence works in lua but i believe you can inherit other metatables

Although I don't fully understand metatables in the abstract sense I am still able to define & utilizing them in a class like manner

Code:
MyMetaTable = {}
MyMetaTable.__index = MyMetaTable

setmetatable(MyMetaTable, {
    __call = function(cls, ...)
        return cls.new(...)
    end,
})
-- constructor
function MyMetaTable.new(arg) -- optional
    local self = setmetatable({}, MyMetaTable)
    self.properties = arg or nil -- if no argument is passed set it to nil
    return self
end

-- set and get methods or metamethods
function MyMetaTable:setSomething(something)
    self.properties = something
end

function MyMetaTable:getSomething()
    return self.properties
end

function MyMetaTable:setAndGetSomething(something)
    self:setSomething(something)
    return self:getSomething()
end

-- very important to emulate class like structure

return MyMetaTable -- if you don't include this then you can use it in the same file

When you save this in its own file and include it either with dofile or require, you can call it as
Code:
local mynewtable = MyMetaTable({}) -- i can pass it a value or not because im covered in the constructor

-- now i can access its metamethods
mynewtable:setSomething(x,y,z)

local x, y, z = unpack(mynewtable:getSomething())
-- etc etc..
 
Last edited:
Would be great if you could load combat objects as needed, but unfortunately they need to be loaded well in advance of anything :(
 
You are using metamethods already, that is what the colon ( : ) represent.
Creature & Player are metatable's similar to classes a metatable can have a contructer and it's metamethods are similar to a classes methods
Not too sure how inheritence works in lua but i believe you can inherit other metatables

Although I don't fully understand metatables in the abstract sense I am still able to define & utilizing them in a class like manner

Code:
MyMetaTable = {}
MyMetaTable.__index = MyMetaTable

setmetatable(MyMetaTable, {
    __call = function(cls, ...)
        return cls.new(...)
    end,
})
-- constructor
function MyMetaTable.new(arg) -- optional
    local self = setmetatable({}, MyMetaTable)
    self.properties = arg or nil -- if no argument is passed set it to nil
    return self
end

-- set and get methods or metamethods
function MyMetaTable:setSomething(something)
    self.properties = something
end

function MyMetaTable:getSomething()
    return self.properties
end

function MyMetaTable:setAndGetSomething(something)
    self:setSomething(something)
    return self:getSomething()
end

-- very important to emulate class like structure

return MyMetaTable

When you save this in its own file and include it either with dofile or require, you can call it as
Code:
local mynewtable = MyMetaTable() -- i can pass it a value or not because im covered in the constructor

-- now i can access its metamethods
mynewtable:setSomething({x,y,z})

local x, y, z = unpack(mynewtable:getSomething())
-- etc etc..

@up

this is what I was talking about, @down!

Would be great if you could load combat objects as needed, but unfortunately they need to be loaded well in advance of anything :(

Rewriting it to utilize the combat class I should have said, I guess... Thank you very very much for the example use of creating a metatable and metamethods, I am very much trying to learn how to construct these and all sample code is great for me.
 
I got the idea from andu and although mine doesn't use tables and a formula, mine will work on tfs 1.0 and has configurations for almost same idea of a spell....

This spell is a mute spell, basically you make the player or monster or both (in config) unable to say anything for X amount of seconds. With players being unable to say anything they are unable to cast any kind of spell.

ok so make /spells/scripts/silence.lua


Code:
local tarmonster = true -- Can we cast this spell on monsters. Default is true
local ptime = 8000 -- This is how long the spell will last on a Player. Default is 8 seconds = 8000
local mtime = 10000 -- This is how long the spell will last on a Monster. Default is 10 seconds = 10000

local pcombat = createCombatObject()
setCombatParam(pcombat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
setCombatParam(pcombat, COMBAT_PARAM_AGGRESSIVE, true)
local pcondition = createConditionObject(CONDITION_MUTED)
setConditionParam(pcondition, CONDITION_PARAM_TICKS, ptime)
setCombatCondition(pcombat, pcondition)

local mcombat = createCombatObject()
setCombatParam(mcombat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
setCombatParam(mcombat, COMBAT_PARAM_AGGRESSIVE, true)
local mcondition = createConditionObject(CONDITION_MUTED)
setConditionParam(mcondition, CONDITION_PARAM_TICKS, mtime)
setCombatCondition(mcombat, mcondition)

function onCastSpell(cid, var)
local creature = Creature(cid)
local tar = creature:getTarget()

    if tar:getCondition(CONDITION_MUTED) then
            creature:sendTextMessage(MESSAGE_STATUS_SMALL, "This creature is already muted")
        return false
    end
     if tar:isPlayer() == true then
        tar:say("^SILENCED^",TALKTYPE_MONSTER_SAY)
        doCombat(tar, pcombat, var)
        return true
     end
    if tar:isMonster() == true then
        if(tarmonster == true) then
        tar:say("^SILENCED^",TALKTYPE_MONSTER_SAY)
        doCombat(tar, mcombat, var)
        return true
        else
        creature:sendTextMessage(MESSAGE_STATUS_SMALL, "You can only use this spell on Players.")
        end
     end
end

Then in your spells.xml add this

Code:
    <instant name="Silence" words="exevo silencia" lvl="30" mana="400" prem="0" aggressive="1" selftarget="0" exhaustion="25000" group="support" groupcooldown="500" icon="126" needlearn="0"  script="silence.lua">
    <vocation name="Druid"/>
    </instant>
[03/01/2015 15:00:02] [Error - Spell Interface]
[03/01/2015 15:00:02] data/spells/scripts/silence.lua:eek:nCastSpell
[03/01/2015 15:00:02] Description:
[03/01/2015 15:00:02] data/spells/scripts/silence.lua:20: attempt to call global 'creature' (a nil value)
[03/01/2015 15:00:02] stack traceback:
[03/01/2015 15:00:02] data/spells/scripts/silence.lua:20: in function <data/spells/scripts/silence.lua:19>
tfs 0.3.6 / 8.60
 
[03/01/2015 15:00:02] [Error - Spell Interface]
[03/01/2015 15:00:02] data/spells/scripts/silence.lua:eek:nCastSpell
[03/01/2015 15:00:02] Description:
[03/01/2015 15:00:02] data/spells/scripts/silence.lua:20: attempt to call global 'creature' (a nil value)
[03/01/2015 15:00:02] stack traceback:
[03/01/2015 15:00:02] data/spells/scripts/silence.lua:20: in function <data/spells/scripts/silence.lua:19>
tfs 0.3.6 / 8.60
maybe he said that it works on 1.0.
 
Gr8 idea, but silence spell will be better for Sorcerer. Druids have paralyze and wild growth.
 
Back
Top