• 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 [TFS 1.3] Change Vocation

SorketROrk

Well-Known Member
Joined
Oct 14, 2020
Messages
152
Solutions
1
Reaction score
69
Location
Sweden
Hi,

I've been looking for a way to make the player change vocation on spellcast but cannot find a solution that works, hopefully someone here can help out!

Using the spell utevo res ina "panda" will also change vocation from id 1 to id 2. After the spell duration ends player should return to vocation id 1.

All help is appriciated.


Yours,
SRO
 
Solution
There could also be two spells, in that case if the player is stuck on id 2 and has to go back it can cast another spell that reverts the effect.

The idea is for only 1 class to be able to use this spell, and cannot get a promotion.
Regular spell. self target.
Lua:
local config = {
    changeFrom = {1, CONST_ME_MAGIC_GREEN}, -- {vocationId, effect}
    changeTo = {2, CONST_ME_MAGIC_BLUE},    -- {vocationId, effect}
    spellDuration = 10, -- seconds
    lookType = 123 -- panda
}

local function changeVocation(creatureId, newVocationId, effect)
    local player = Player(creatureId)
    if not player then
        return
    end
    player:setVocation(newVocationId)
    player:getPosition():sendMagicEffect(effect)
end

local...
Hi,

I've been looking for a way to make the player change vocation on spellcast but cannot find a solution that works, hopefully someone here can help out!

Using the spell utevo res ina "panda" will also change vocation from id 1 to id 2. After the spell duration ends player should return to vocation id 1.

All help is appriciated.


Yours,
SRO
The main issue I see with this, is that if the server goes offline while the spell is activated, the player will get stuck as vocation 2.

We can add a work-around for that.. but I need to know the following 2 things:

Is it only the 1 class that can use the spell?
Or multiple?
-- Trying to determine if a storage value is needed.

Can Class 1 be promoted? Or is it a single class with no promotion available?
 
The main issue I see with this, is that if the server goes offline while the spell is activated, the player will get stuck as vocation 2.

We can add a work-around for that.. but I need to know the following 2 things:

Is it only the 1 class that can use the spell?
Or multiple?
-- Trying to determine if a storage value is needed.

Can Class 1 be promoted? Or is it a single class with no promotion available?
There could also be two spells, in that case if the player is stuck on id 2 and has to go back it can cast another spell that reverts the effect.

The idea is for only 1 class to be able to use this spell, and cannot get a promotion.
 
There could also be two spells, in that case if the player is stuck on id 2 and has to go back it can cast another spell that reverts the effect.

The idea is for only 1 class to be able to use this spell, and cannot get a promotion.
Regular spell. self target.
Lua:
local config = {
    changeFrom = {1, CONST_ME_MAGIC_GREEN}, -- {vocationId, effect}
    changeTo = {2, CONST_ME_MAGIC_BLUE},    -- {vocationId, effect}
    spellDuration = 10, -- seconds
    lookType = 123 -- panda
}

local function changeVocation(creatureId, newVocationId, effect)
    local player = Player(creatureId)
    if not player then
        return
    end
    player:setVocation(newVocationId)
    player:getPosition():sendMagicEffect(effect)
end

local condition = Condition(CONDITION_OUTFIT)
condition:setTicks(config.spellDuration * 1000 - 200)
condition:setOutfit({lookType = config.lookType})

function onCastSpell(creature, variant)
    if creature:getGroup():getAccess() then
        creature:sendCancelMessage("This spell may break a god, so disallowing use.")
        return false
    end
    creature:addCondition(condition)
    changeVocation(creature:getId(), config.changeTo[1], config.changeTo[2])
    addEvent(changeVocation, 1000 * config.spellDuration, creature:getId(), config.changeFrom[1], config.changeFrom[2])
    return true
end
put in data/scripts
Lua:
local loginEvent = CreatureEvent("onLogin_fixChangeVocationIfIssue")
loginEvent:type("login")

function loginEvent.onLogin(player)
    if player:getVocation(2) then -- if you edit vocations from/to in the spell, you'll need to change these one's manually
        player:setVocation(1)
        player:removeCondition(CONDITION_OUTFIT)
    end
    return true
end

loginEvent:register()
 
Solution
Hi again, ive been having troubles with what i think is a collision between the transformation script and login/promotion scripts or even creation of characters with another id than "2" in this case.

Do you think there is another way to implement this transformation script?

I remember you mentioned if there would only be one class to use the spell and if there would be any promotions, and I can say that ive been going back and forward with ideas around this and I think my decision to make the spell available for 2 classes and also promotion being involved might have caused this problem.

New created players all get vocation 1 even if they chose differently, also when manually changing the vocation on the database, I still log in with vocation 1.


Do you think we can get transformation working somehow? With Promotions and different vocs involved that can use this spell? :)
 
Back
Top