• 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 TFS 1.2 Invisibility, Ghost Spell, Hide.

Gicu

Well-Known Member
Joined
Feb 26, 2011
Messages
187
Reaction score
52
-----------------START--------------
Hello ;) I see many question about this spell i make this for all. can crash so make copies!
English LOW ALERT!


-add line to spells.xml

Lua:
    <instant group="support" spellid="144" name="INV" words="INV" lvl="1" mana="1" aggressive="0" selftarget="1" cooldown="1000" groupcooldown="1000" needlearn="0" script="inv.lua">
    </instant>

-create data/spells/inv.lua

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, 63)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_INVISIBLE)
condition:setParameter(CONDITION_PARAM_TICKS, 5000)
combat:setCondition(condition)

function onCastSpell(creature, variant, isHotkey)
local player = Player(creature)

local function OMG()
    player:setGhostMode(isGhost)
         return true
  end
    addEvent(OMG, 5 * 1000)  
    local position = player:getPosition()
    local isGhost = not player:isInGhostMode()
    player:setGhostMode(isGhost)
    return combat:execute(creature, variant)
end



- addEvent(OMG, 5 * 1000) here u can change time!
- Error write!
--------------END---------------
 
In what situations does it crash?
This thing actually works, well, monsters that are immune to invisibility still follow you around after casting the spell, though they don't attack you.
 
try
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, 63)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_INVISIBLE)
condition:setParameter(CONDITION_PARAM_TICKS, 5000)
combat:setCondition(condition)

function onCastSpell(creature, variant, isHotkey)
    local player = Player(creature)
    if player == nil then return false end
    local playerId = player:getId()
    player:setGhostMode(true)
    addEvent(function()
        player = Player(playerId)
        if player == nil then return false end
        player:setGhostMode(false)
    end, 5 * 1000)
    return combat:execute(creature, variant)
end
 
try
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, 63)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_INVISIBLE)
condition:setParameter(CONDITION_PARAM_TICKS, 5000)
combat:setCondition(condition)

function onCastSpell(creature, variant, isHotkey)
    local player = Player(creature)
    if player == nil then return false end
    local playerId = player:getId()
    player:setGhostMode(true)
    addEvent(function()
        player = Player(playerId)
        if player == nil then return false end
        player:setGhostMode(false)
    end, 5 * 1000)
    return combat:execute(creature, variant)
end

Both seem to be working fine, no idea in which situations it's possible to crash since OP never stated it, but so far there's no issues on this matter.

However, neither turns away the monster aggro.
It seems like GhostMode works only on players. Monsters are already ignoring GM's by default so it seems pointless to make the GhostMode invisible to monsters too. But when we set a player invisible, he isn't ignored by the monsters so they charge him. They can't target the player nor hit him with spells, but they do follow him like if he's there.
Someone correct me if I'm wrong, but that's my idea on the issue so far.

EDIT: This is related to monsters that are immune on invisibility, those that aren't, can't see you anyways cause of the invisibility condition.
 
That can be done on 0.6.3 server?
How can I add this ghost function?
 
Both seem to be working fine, no idea in which situations it's possible to crash since OP never stated it, but so far there's no issues on this matter.

However, neither turns away the monster aggro.
It seems like GhostMode works only on players. Monsters are already ignoring GM's by default so it seems pointless to make the GhostMode invisible to monsters too. But when we set a player invisible, he isn't ignored by the monsters so they charge him. They can't target the player nor hit him with spells, but they do follow him like if he's there.
Someone correct me if I'm wrong, but that's my idea on the issue so far.

EDIT: This is related to monsters that are immune on invisibility, those that aren't, can't see you anyways cause of the invisibility condition.
The original would crash if you use the spell then log out/die before the callback executes from addEvent (5 seconds after you cast spell)
To fix the other issue, create a new group with the IgnoredByMonsters flag (flag value is 256) and use this to swap groups while the spell is active, make sure to swap X with the group id you create in Group(X). You'll also need to set group back to 1 when player logs out or dies to prevent players from being stuck with this flag and abusing it.
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, 63)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_INVISIBLE)
condition:setParameter(CONDITION_PARAM_TICKS, 5000)
combat:setCondition(condition)

function onCastSpell(creature, variant, isHotkey)
    local player = Player(creature)
    if player == nil then return false end
    local playerId = player:getId()
    player:setGhostMode(true)
    player:setGroup(Group(X))
    addEvent(function()
        player = Player(playerId)
        if player == nil then return false end
        player:setGhostMode(false)
        player:setGroup(Group(1))
    end, 5 * 1000)
    return combat:execute(creature, variant)
end

This is placed in creaturescripts (make sure to register them both in login.lua and the XML file)
Again, remember to replace the X with the group id you create.
Lua:
function onDeath(creature)
    local player = Player(creature)
    if not player then
        return true
    end
    if player:getGroup():getId() == X then
        player:setGroup(Group(1))
    end
    return true
end
function onLogout(player)
    if player:getGroup():getId() == X then
        player:setGroup(Group(1))
    end
    return true
end
 
The original would crash if you use the spell then log out/die before the callback executes from addEvent (5 seconds after you cast spell)
To fix the other issue, create a new group with the IgnoredByMonsters flag (flag value is 256) and use this to swap groups while the spell is active, make sure to swap X with the group id you create in Group(X). You'll also need to set group back to 1 when player logs out or dies to prevent players from being stuck with this flag and abusing it.
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, 63)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_INVISIBLE)
condition:setParameter(CONDITION_PARAM_TICKS, 5000)
combat:setCondition(condition)

function onCastSpell(creature, variant, isHotkey)
    local player = Player(creature)
    if player == nil then return false end
    local playerId = player:getId()
    player:setGhostMode(true)
    player:setGroup(Group(X))
    addEvent(function()
        player = Player(playerId)
        if player == nil then return false end
        player:setGhostMode(false)
        player:setGroup(Group(1))
    end, 5 * 1000)
    return combat:execute(creature, variant)
end

This is placed in creaturescripts (make sure to register them both in login.lua and the XML file)
Again, remember to replace the X with the group id you create.
Lua:
function onDeath(creature)
    local player = Player(creature)
    if not player then
        return true
    end
    if player:getGroup():getId() == X then
        player:setGroup(Group(1))
    end
    return true
end
function onLogout(player)
    if player:getGroup():getId() == X then
        player:setGroup(Group(1))
    end
    return true
end


I've tried logging out and so far it doesn't crash. I'm using OTX3 btw, but better safe than sorry. I've used your code and added a return false so the player can't logout during the spell at all.

Lua:
function onLogout(player)
    if player:getGroup():getId() == 7 then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'You can not logout during invisibility.')
        return false
    end
    return true
end

Crashing from a death simply doesn't seem possible, since during invisibility the player is immune to any kind of damage, he can't be targeted or hit, not even fields do any damage.

As for the new group I've tried that one as well as experimented a bit with flag generators and overall it seems to be a bit buggy.
If there was a mob hitting you before casting the spell, he'll continue following you around. The ignoring seems to be true for mobs that are out of view & range to spot you. However, those mobs will continue to ignore you even after the spell wears off and you start hitting them. Only once you push them or re-enter their spot/view radius do they start moving and targeting you.

Not sure if this is the same on TFS too or it's just an OTX issue. Anyways, I will probably still use the new group ID idea as that gives me the option to also limit the player from using offensive spells/attacking while invisible.
 
Last edited:
That can be done on 0.6.3 server?
How can I add this ghost function?

No idea TBH, when I was searching up for a true invisibility spell couple of years ago most of them required some sort of source edits to work somewhat right or a bunch of longer codes. I was kinda surprised when I added this script and it actually worked, wasn't really expecting it.
 
No idea TBH, when I was searching up for a true invisibility spell couple of years ago most of them required some sort of source edits to work somewhat right or a bunch of longer codes. I was kinda surprised when I added this script and it actually worked, wasn't really expecting it.
Yeah i was surprised too, for this reason i ask haha, well thx anyway!
 
Back
Top