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

Could someone help me making this spell works for tfs 1.0?

Bagko

luis
Joined
May 16, 2009
Messages
4
Reaction score
0
Location
mexico
local combat = Combat()
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, true)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_RED)

local function resetGroup(cid)
local player = Player(cid)
if not player then
return
end
player:setGroup(Group(1))
end

local function sendEffects(cid)
local player = Player(cid)
if not player then
return
end
if player:getGroup():getId() == 4 then
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
addEvent(sendEffects, 1000, cid)
end
end

function onCastSpell(creature, variant)
local player = creature:getPlayer()
if not player then
return false
end
player:setGroup(Group(4))
addEvent(resetGroup, 5000, player:getId())
sendEffects(player:getId())
return combat:execute(creature, variant)
end
 
Damn son. Been here since 2009 but still don't know how to use code tags? Also, what about this makes it not work in TFS 1.0? It looks like all the methods you need existed then and now.

First, though. Groups are not hardcoded, and if you are using the default, it looks like this, there is no group 4.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<groups>
    <group id="1" name="player" flags="0" access="0" maxdepotitems="0" maxvipentries="0" />
    <group id="2" name="gamemaster" flags="137438953471" access="1" maxdepotitems="0" maxvipentries="200" />
    <group id="3" name="god" flags="272730398714" access="1" maxdepotitems="0" maxvipentries="200" />
</groups>

That said I looked. If I was having problems with this script I'd probably do this:
Lua:
-- Why is this even a spell?
-- This should be a Rune or a secret talkaction only for testing
--  And why the fuck is it an AGGRESSIVE spell?

local DEBUG_NORMAL_PLAYER = 1
local DEBUG_DESIRED_GROUP = 3

-- Will this work without adding something else?
-- Seems like spells require more to even function
local combat = Combat()
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, true)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_RED)

local function resetGroup(cid)
    print("resetGroup called!")
    local player = Player(cid)
    if not player then
        return
    end
    player:setGroup(Group(DEBUG_NORMAL_PLAYER))
end

local function sendEffects(cid)
    print("sendEffects called!")

    local player = Player(cid)
    if not player then
        return
    end
    if player:getGroup():getId() == DEBUG_DESIRED_GROUP then
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
        --[[
            sendEffects calls sendEffects ->

            this is called recursion
                and if you didn't already know that
                you most definitely should not be using it
                it can be dangerous

            it may be safe here with a check
                but caution is advised
        ]]
        addEvent(sendEffects, 1000, cid)
    end
end

function onCastSpell(creature, variant)
    local player = Player(creature:getId())
    if not player then
        return false
    end
    print("DEBUGGING STUFF!")
    --[[
        Sets player to CM? But CM doesn't exist anymore does it?
        Guessing this is going by ID in xml file
            which only has Player, GM, and God now
            Tutor, Senior Tutor, and CM are gone for some reason

        player:setGroup(Group(4))
    ]]
    print("Player is group: " .. player:getGroup():getId())

    player:setGroup(Group(DEBUG_DESIRED_GROUP))
    print("Player is now group: " .. player:getGroup():getId())

    -- send Effects
    sendEffects(player:getId())

    -- Adds a delayed use of resetGroup function
    addEvent(resetGroup, 5000, player:getId())

    return combat:execute(creature, variant)
end



If I was playing around with this myself for whatever reason, I'd make it as simple as possible first. Code using intense healing spell as template:

Lua:
local DEBUG_PLAYER = 1
local DEBUG_GOD = 3

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HOLYAREA)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, 0)

function onGetFormulaValues() return 1, 1 end
setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
    local player = Player(cid)
    if not player then return false end

    local function swapGroup(player, newgroup)
        local pname = player:getName()
        local cname = player:getGroup():getName()
        player:setGroup(Group(newgroup))

        local gname = Group(player:getGroup():getId()):getName()
        local message = string.format("%s the %s is now a %s", pname, cname, gname)
        print(message)
    end

    -- current group
    local cgroup = player:getGroup():getId()
    if (cgroup == DEBUG_PLAYER) then
        swapGroup(DEBUG_GOD)
    elseif (cgroup == DEBUG_GOD) then
        swapGroup(DEBUG_PLAYER)
    end

    return doCombat(cid, combat, var)
end
 
Last edited:
Back
Top