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

TFS 1.2 Transform System

Lopaskurwa

Active Member
Joined
Oct 6, 2017
Messages
873
Solutions
2
Reaction score
49
Hi i was searching around google and i found this transform system
Transform system [table included]
But i stuck with first part, he didn't included where should i create that lua
Code:
{["voc"] = 1, ["newVoc"] = 2, ["looktype"] = 5, ["revertLooktype"] = 4, ["level"] = 50, ["rage"] = 3, ["kiToTrans"] = 10, ["addHp"] = 200, ["addKi"] = 150, ["effectOn"] = 236, ["aura"] = 0, ["constant"] = false},
 
Solution
Global
Lua:
exhaust_transform = {}

transform = {
[1] = {voc = 1, newVoc = 5, from_looktype = 55, looktype = 99, level = 50, rage = 3, mana = 10, addHealth = 200, addMana = 150, effect = CONST_ME_SMOKE, aura = nil, constant = false}
}

Tranform
Lua:
function onSay(player, words, param, channel)
    local pid = player:getId()

    if exhaust_transform[pid] ~= nil then
        return false
    end

    local TRANS = transform[player:getVocation():getId()]

    if not TRANS then return player:sendCancelMessage("You cannot transform.") end
    if player:getLevel() < TRANS.level then return player:sendCancelMessage("You must reach level "..TRANS.level.." to transform.") end
    if player:getSoul() < TRANS.rage then return...
At the bottom of data/global.lua
I think this tutorial do not support my tfs because this part
Code:
<instant name="Transform" words="transform" lvl="1" mana="0" aggressive="0" selftarget="1" exhaustion="1000" exhaustionType="2" event="script" value="Transform.lua"/>
Is kinda stupid put words=transform to spells, but there is talkaction. Maybe can you help me convert to tfs 1.2? Because i added everything, i got some warning (not big deal) but that script don't even functional, you can type transform as many times as you want that stuff don't even work.
 
For TFS 1.2+ you can add it like this:
XML:
<instant group="support" name="Transform" words="transform" level="1" mana="0" premium="0" aggressive="0" selftarget="1" cooldown="1000" groupcooldown="1000" needlearn="0" script="Transform.lua">
        <vocation name="Knight" />
        <vocation name="Elite Knight" />
</instant>

Some small differences, instead of exhaustion its cooldown, instead of exhaustion type we use groups like attack, support, healing.
 
For TFS 1.2+ you can add it like this:
XML:
<instant group="support" name="Transform" words="transform" level="1" mana="0" premium="0" aggressive="0" selftarget="1" cooldown="1000" groupcooldown="1000" needlearn="0" script="Transform.lua">
        <vocation name="Knight" />
        <vocation name="Elite Knight" />
</instant>

Some small differences, instead of exhaustion its cooldown, instead of exhaustion type we use groups like attack, support, healing.
But i dont get it why dont i need to create anything in talkaction? Why i have to create this <instant group in spells? I didn't tried yet but still i think it not gonna work. And what's the point to put vocation name to xml?
 
The vocation bit can be removed, I think it is added to spells to get the cooldown working properly. You can add it as a talkaction but you need to code in a cooldown system, and I don't think Lua over C++ supports microtime (milliseconds) time calibrations. Or you can if you go the addEvent approach I guess.
 
The vocation bit can be removed, I think it is added to spells to get the cooldown working properly. You can add it as a talkaction but you need to code in a cooldown system, and I don't think Lua over C++ supports microtime (milliseconds) time calibrations. Or you can if you go the addEvent approach I guess.
But why if i add to spells i type transform nothing happen i can say "transform" like a regular word
 
The vocation bit can be removed, I think it is added to spells to get the cooldown working properly. You can add it as a talkaction but you need to code in a cooldown system, and I don't think Lua over C++ supports microtime (milliseconds) time calibrations. Or you can if you go the addEvent approach I guess.
Code:
-- milliseconds = os.mtime()
-- seconds = os.time()
Or maybe I misunderstood you. :D
 
Code:
-- milliseconds = os.mtime()
-- seconds = os.time()
Or maybe I misunderstood you. :D

Nope, your right. You can use os.mtime(). Weird, I though I tried it once and it didnt work.

But why if i add to spells i type transform nothing happen i can say "transform" like a regular word

Try adding it as a talkaction then.
XML:
<talkaction words="transform" script="Transform.lua" />

Lua:
-- 1 second cooldown
local uniqueStorage = 76981
if os.mtime() < uniqueStorage then
    player:sendCancelMessage("Spell on cooldown...")
    return false
end
player:setStorage(uniqueStorage, os.mtime() + 1000)

-- Custom code here...

onCastSpell(cid, var) needs to be onSay(cid)
 
Last edited:
Nope, your right. You can use os.mtime(). Weird, I though I tried it once and it didnt work.



Try adding it as a talkaction then.
XML:
<talkaction words="transform" script="Transform.lua" />

Lua:
-- 1 second cooldown
local uniqueStorage = 76981
if os.mtime() < uniqueStorage then
    player:sendCancelMessage("Spell on cooldown...")
    return false
end
player:setStorage(uniqueStorage, os.mtime() + 1000)

-- Custom code here...

onCastSpell(cid, var) needs to be onSay(cid)
But cooldown is is not important it's not some kind of skill that i can do it dmg with it. Because why you need cooldown for transform if there is limited numbers of transforms like example you're 50lvl and you have transform so i type transform and there is no point to do cooldown anymore. And anyway this cooldown function have disadvantage in pvp so if you get revert because of mana and you have to type transform couple times you'll be in cooldown and everyone will blame it "wtf is this shit". So to make it clear is it same code if i transport from spells to talkaction? Does transform.lua will work properly in talkaction?
 
But cooldown is is not important it's not some kind of skill that i can do it dmg with it. Because why you need cooldown for transform if there is limited numbers of transforms like example you're 50lvl and you have transform so i type transform and there is no point to do cooldown anymore. And anyway this cooldown function have disadvantage in pvp so if you get revert because of mana and you have to type transform couple times you'll be in cooldown and everyone will blame it "wtf is this shit". So to make it clear is it same code if i transport from spells to talkaction? Does transform.lua will work properly in talkaction?

Ahh, yeah. Then screw cooldowns. It should work fine as a talkaction, no idea why the creator decided to make it a spell.
Should work fine as a talkaction, just rename onCastSpell to onSay.
 
Ahh, yeah. Then screw cooldowns. It should work fine as a talkaction, no idea why the creator decided to make it a spell.
Should work fine as a talkaction, just rename onCastSpell to onSay.
Still doesn't work like nothing happening i can type transform as many times as i want it's like a regular word. Something is wrong, have no idea what
 
Still doesn't work like nothing happening i can type transform as many times as i want it's like a regular word. Something is wrong, have no idea what

Let me see the code you added in data/talkaction/scripts
 
Global.lua
Lua:
exhaust_transform = {}
Trans = {
[1] = {voc = 1, newVoc = 2, looktype = 5, level = 50, rage = 3, mana = 10, addHealth = 200, addMana = 150, effect = CONST_ME_SMOKE, aura = nil, constant = false},
[2] = {voc = 2, newVoc = 3, looktype = 6, level = 130, rage = 5, mana = 50, addHealth = 450, addMana = 300, effect = CONST_ME_HOLY, aura = nil, constant = false}
}

Talkaction: Transform
Lua:
function onSay(player, words, param, channel)
    if exhaust_transform[pid] ~= nil then
        return false
    end
    TRANS = Trans[player:getVocation():getId()]
 
    if not TRANS then return player:sendCancelMessage("You cannot transform.") end
 
    if player:getLevel() < TRANS.level then return player:sendCancelMessage("You must reach level "..TRANS.level.." to transform.") end
 
    if player:getSoul() < TRANS.rage then return player:sendCancelMessage("You need "..TRANS.rage.." to transform.") end
    if player:getMana() < TRANS.mana then return player:sendCancelMessage("You need "..TRANS.mana.." to transform.") end
 
    if TRANS.constant then
        player:setOutfit({looktype = TRANS.looktype})
    else
        player:setOutfit({looktype = TRANS.looktype}, false)
    end
 
    local pid = player:getId()
    exhaust_transform[pid] = 1
    player:addSoul(-TRANS.rage)
    player:setMaxHealth(TRANS.addHealth)
    player:setMaxMana(TRANS.mana)
    player:addHealth(TRANS.addHealth)
    player:addMana(TRANS.addMana)
    player:getPosition():sendMagicEffect(TRANS.effect)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have transformed!")
    player:setVocation(TRANS.newVoc)
    player:save()
    addEvent(removeExhaust, 5 * 1000, pid)
return true
end
function removeExhaust(pid)
    exhaust_transform[pid] = nil
end

Talkaction: Revert
Lua:
function onSay(player, words, param, channel)
    if exhaust_transform[pid] ~= nil then
        return false
    end
 
    TRANS = Trans[player:getVocation():getId() - 1]
 
    if not TRANS then return player:sendCancelMessage("You cannot revert.") end
 
    if TRANS.constant then
        player:setOutfit({looktype = TRANS.looktype})
    else
        player:setOutfit({looktype = TRANS.looktype}, false)
    end
 
    local pid = player:getId()
    exhaust_transform[pid] = 1
    player:setMaxHealth(TRANS.addHealth)
    player:setMaxMana(TRANS.mana)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have reverted!")
    player:setVocation(TRANS.voc)
    player:save()
    addEvent(removeExhaust, 5 * 1000, pid)
return true
end
function removeExhaust(pid)
    exhaust_transform[pid] = nil
end

GlobalEvent
Lua:
function onThink(interval)
    local players = Game.getPlayers()
    for i, v in ipairs(players) do
        player = Player(v)
        if player then
            TRANS = Trans[player:getVocation():getId()]
            if TRANS then
                if TRANS.aura ~= nil then
                    player:getPosition():sendMagicEffect(TRANS.aura)
                end
            end
        end
    end
return true
end
 
Last edited by a moderator:
Is there any error messages in the console on startup or when you do the talkaction?
I see there is a 5 seconds cooldown system added to it, you could try to remove it just to have less code to work with.

Not sure if its wise to return cancel messages in a talkaction

Instead of
Lua:
then return player:sendCancelMessage("You cannot revert.") end

Do like:
Lua:
if something then
    player:sendCancelMessage("Cancel message.")
    return true
end

Right after
Code:
function onSay(player, words, param, channel)
Add:
Lua:
print("Executed talkaction") --This will appear in console for debugging purpose

Do some tests to figure out whats going on.
 
I have never had an issue with it. It will allow the talkaction to be said in normal chat without anything executing.
 
Global.lua
Lua:
exhaust_transform = {}
Trans = {
[1] = {voc = 1, newVoc = 2, looktype = 5, level = 50, rage = 3, mana = 10, addHealth = 200, addMana = 150, effect = CONST_ME_SMOKE, aura = nil, constant = false},
[2] = {voc = 2, newVoc = 3, looktype = 6, level = 130, rage = 5, mana = 50, addHealth = 450, addMana = 300, effect = CONST_ME_HOLY, aura = nil, constant = false}
}

Talkaction: Transform
Lua:
function onSay(player, words, param, channel)
    if exhaust_transform[pid] ~= nil then
        return false
    end
    TRANS = Trans[player:getVocation():getId()]
 
    if not TRANS then return player:sendCancelMessage("You cannot transform.") end
 
    if player:getLevel() < TRANS.level then return player:sendCancelMessage("You must reach level "..TRANS.level.." to transform.") end
 
    if player:getSoul() < TRANS.rage then return player:sendCancelMessage("You need "..TRANS.rage.." to transform.") end
    if player:getMana() < TRANS.mana then return player:sendCancelMessage("You need "..TRANS.mana.." to transform.") end
 
    if TRANS.constant then
        player:setOutfit({looktype = TRANS.looktype})
    else
        player:setOutfit({looktype = TRANS.looktype}, false)
    end
 
    local pid = player:getId()
    exhaust_transform[pid] = 1
    player:addSoul(-TRANS.rage)
    player:setMaxHealth(TRANS.addHealth)
    player:setMaxMana(TRANS.mana)
    player:addHealth(TRANS.addHealth)
    player:addMana(TRANS.addMana)
    player:getPosition():sendMagicEffect(TRANS.effect)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have transformed!")
    player:setVocation(TRANS.newVoc)
    player:save()
    addEvent(removeExhaust, 5 * 1000, pid)
return true
end
function removeExhaust(pid)
    exhaust_transform[pid] = nil
end

Talkaction: Revert
Lua:
function onSay(player, words, param, channel)
    if exhaust_transform[pid] ~= nil then
        return false
    end
 
    TRANS = Trans[player:getVocation():getId() - 1]
 
    if not TRANS then return player:sendCancelMessage("You cannot revert.") end
 
    if TRANS.constant then
        player:setOutfit({looktype = TRANS.looktype})
    else
        player:setOutfit({looktype = TRANS.looktype}, false)
    end
 
    local pid = player:getId()
    exhaust_transform[pid] = 1
    player:setMaxHealth(TRANS.addHealth)
    player:setMaxMana(TRANS.mana)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have reverted!")
    player:setVocation(TRANS.voc)
    player:save()
    addEvent(removeExhaust, 5 * 1000, pid)
return true
end
function removeExhaust(pid)
    exhaust_transform[pid] = nil
end

GlobalEvent
Lua:
function onThink(interval)
    local players = Game.getPlayers()
    for i, v in ipairs(players) do
        player = Player(v)
        if player then
            TRANS = Trans[player:getVocation():getId()]
            if TRANS then
                if TRANS.aura ~= nil then
                    player:getPosition():sendMagicEffect(TRANS.aura)
                end
            end
        end
    end
return true
end
If i put that code into global event my code doesn't activate or he can't read that script, dunno how to explain.
Untitled.png

Is there any error messages in the console on startup or when you do the talkaction?
I see there is a 5 seconds cooldown system added to it, you could try to remove it just to have less code to work with.

Not sure if its wise to return cancel messages in a talkaction

Instead of
Lua:
then return player:sendCancelMessage("You cannot revert.") end

Do like:
Lua:
if something then
    player:sendCancelMessage("Cancel message.")
    return true
end

Right after
Code:
function onSay(player, words, param, channel)
Add:
Lua:
print("Executed talkaction") --This will appear in console for debugging purpose

Do some tests to figure out whats going on.
With that old trans system my log doesn't send any error or warning eveything seems to be fine.
P.S sorry for slow response i was in hospital for 4 days.
 
you're supposed to create a new lua file in globalevents/scripts/xxxx.lua (where xxxx is your filename)
then you register the file in globalevents.xml by using
XML:
<globalevent type="think" name="aura" script="xxxx.lua" />
 
Back
Top