• 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.X+ Help me Optymalized my Transform System

Michcol94

Member
Joined
Sep 2, 2021
Messages
105
Reaction score
18
I am asking for help in optimizing my script, because it seems to me that with more people the engine will muddy and I have no way to test it, I expect feedback and possible code editing to optimize the transform system:
talkacktions: transform
Lua:
local SystemTransformData= {
[1] = { lvl = 1,                manaPerSec =0,
            newlookType = 397,      revertlookType =436,
            maxhp = 1000,           maxmana = 1000,
            revertmaxhp = 0,        revertmaxmana = 0,
            newvoc = 2,             revertvoc = 1,
            constforma = true,      lasttransform = false,
            constlookType = 436,    constvoc = 1,
            allbonusmaxhp = 0,      allbonusmaxmana = 0,
            effect=126,
        },
    --goku kaioken look type 397
    [2] = { lvl = 1,                manaPerSec =10,
            newlookType = 438,      revertlookType =436,
            maxhp = 1000,           maxmana = 1000,
            revertmaxhp = 1000,     revertmaxmana = 1000,
            newvoc = 3,             revertvoc = 1,
            constforma = false,     lasttransform = false,
            constlookType = 436,    constvoc = 1,
            allbonusmaxhp = 1000,   allbonusmaxmana = 1000,
            effect=127,
        },
--goku ssj looktype 438
[3] = { lvl = 1,                manaPerSec =20,
        newlookType = 404,      revertlookType =397,
        maxhp = 1000,           maxmana = 1000,
        revertmaxhp = 1000,     revertmaxmana = 1000,
        newvoc = 4,             revertvoc = 2,
        constforma = false,     lasttransform = false,
        constlookType = 436,    constvoc = 1,
        allbonusmaxhp = 2000,   allbonusmaxmana = 2000,
        effect=128,
    },
--goku ssj2 looktype 404
[4] = { lvl = 1,                manaPerSec =30,
        newlookType = 437,      revertlookType =438,
        maxhp = 1000,           maxmana = 1000,
        revertmaxhp = 1000,     revertmaxmana = 1000,
        newvoc = 5,             revertvoc = 3,
        constforma = false,     lasttransform = false,
        constlookType = 436,    constvoc = 1,
        allbonusmaxhp = 3000,   allbonusmaxmana = 3000,
        effect=129,
    },
--goku ssj3 looktype 437
[5] = { lvl = 1,                manaPerSec =40,
        newlookType = 433,      revertlookType =404,
        maxhp = 1000,           maxmana = 1000,
        revertmaxhp = 1000,     revertmaxmana = 1000,
        newvoc = 6,             revertvoc = 4,
        constforma = false,     lasttransform = false,
        constlookType = 436,    constvoc = 1,
        allbonusmaxhp = 4000,   allbonusmaxmana = 4000,
        effect=130,
    },
--goku ssj4 looktype 433
[6] = { lvl = 1,                manaPerSec =50,
        newlookType = 433,      revertlookType =437,
        maxhp = 1000,           maxmana = 1000,
        revertmaxhp = 1000,     revertmaxmana = 1000,
        newvoc = 6,             revertvoc = 5,
        constforma = false,     lasttransform = true,
        constlookType = 436,    constvoc = 1,
        allbonusmaxhp = 5000,   allbonusmaxmana = 5000,
        effect=131,
    },
}


function onSay(player, words)
    local cid = player:getId()
    local polecenie = Player(cid)
    if not polecenie then
        print("Nie mozna znalezc gracza o podanym id.")
        return false
    end
 
    local vocationobecny = polecenie:getVocation():getId()
 
    local infoData = SystemTransformData[vocationobecny]
 
    if infoData.lasttransform == true then
        polecenie:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Nie mozesz sie juz transformowac, osiagnales szczyt mozliwosci i jestes aktualnie na ostatniej transformacji!")
        elseif polecenie:getLevel() < infoData.lvl then
    
        polecenie:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Posiadasz zbyt niski lvl!")
        else
             --zwiększenie maksymalnego zdrowia i many
        polecenie:setMaxHealth(polecenie:getMaxHealth() + infoData.maxhp)
        polecenie:setMaxMana(polecenie:getMaxMana() + infoData.maxmana)
        polecenie:setHealth(polecenie:getMaxHealth())
        polecenie:addMana(polecenie:getMaxMana())
        polecenie:setOutfit({lookType=infoData.newlookType})
        polecenie:getPosition():sendMagicEffect(infoData.effect)
             --MIEJSCE NA AKTUALIZACJE KODU I DODAWANIE NOWYCH FUNKCJI PONIŻEJ--
--------------------------------------------------------------------------------------------



--------------------------------------------------------------------------------------------

        
        polecenie:setVocation(infoData.newvoc)             
        polecenie:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Transformacja udana!")
        
 
    end
end
Talkactions: Revert
Code:
local SystemTransformData= {
[1] = { lvl = 1,                manaPerSec =0,
            newlookType = 397,      revertlookType =436,
            maxhp = 1000,           maxmana = 1000,
            revertmaxhp = 0,        revertmaxmana = 0,
            newvoc = 2,             revertvoc = 1,
            constforma = true,      lasttransform = false,
            constlookType = 436,    constvoc = 1,
            allbonusmaxhp = 0,      allbonusmaxmana = 0,
            effect=126,
        },
    --goku kaioken look type 397
    [2] = { lvl = 1,                manaPerSec =10,
            newlookType = 438,      revertlookType =436,
            maxhp = 1000,           maxmana = 1000,
            revertmaxhp = 1000,     revertmaxmana = 1000,
            newvoc = 3,             revertvoc = 1,
            constforma = false,     lasttransform = false,
            constlookType = 436,    constvoc = 1,
            allbonusmaxhp = 1000,   allbonusmaxmana = 1000,
            effect=127,
        },
--goku ssj looktype 438
[3] = { lvl = 1,                manaPerSec =20,
        newlookType = 404,      revertlookType =397,
        maxhp = 1000,           maxmana = 1000,
        revertmaxhp = 1000,     revertmaxmana = 1000,
        newvoc = 4,             revertvoc = 2,
        constforma = false,     lasttransform = false,
        constlookType = 436,    constvoc = 1,
        allbonusmaxhp = 2000,   allbonusmaxmana = 2000,
        effect=128,
    },
--goku ssj2 looktype 404
[4] = { lvl = 1,                manaPerSec =30,
        newlookType = 437,      revertlookType =438,
        maxhp = 1000,           maxmana = 1000,
        revertmaxhp = 1000,     revertmaxmana = 1000,
        newvoc = 5,             revertvoc = 3,
        constforma = false,     lasttransform = false,
        constlookType = 436,    constvoc = 1,
        allbonusmaxhp = 3000,   allbonusmaxmana = 3000,
        effect=129,
    },
--goku ssj3 looktype 437
[5] = { lvl = 1,                manaPerSec =40,
        newlookType = 433,      revertlookType =404,
        maxhp = 1000,           maxmana = 1000,
        revertmaxhp = 1000,     revertmaxmana = 1000,
        newvoc = 6,             revertvoc = 4,
        constforma = false,     lasttransform = false,
        constlookType = 436,    constvoc = 1,
        allbonusmaxhp = 4000,   allbonusmaxmana = 4000,
        effect=130,
    },
--goku ssj4 looktype 433
[6] = { lvl = 1,                manaPerSec =50,
        newlookType = 433,      revertlookType =437,
        maxhp = 1000,           maxmana = 1000,
        revertmaxhp = 1000,     revertmaxmana = 1000,
        newvoc = 6,             revertvoc = 5,
        constforma = false,     lasttransform = true,
        constlookType = 436,    constvoc = 1,
        allbonusmaxhp = 5000,   allbonusmaxmana = 5000,
        effect=131,
    },
}


function onSay(player, words)
    local cid = player:getId()
    local polecenie = Player(cid)
    if not polecenie then
        print("Nie mozna znalezc gracza o podanym id.")
        return false
    end
 
    local vocationobecny = polecenie:getVocation():getId()
 
    local revertdata = SystemTransformData[vocationobecny]
    if revertdata.constforma == true then
        polecenie:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Masz stała forme nie mozesz jej cofnac!!!!")
    else
      
        polecenie:setOutfit({lookType=revertdata.revertlookType})
        polecenie:setMaxHealth(polecenie:getMaxHealth() - revertdata.revertmaxhp)
        polecenie:setMaxMana(polecenie:getMaxMana() - revertdata.revertmaxmana)
        polecenie:setVocation(revertdata.revertvoc)       
        polecenie:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Revert udany!")
    end
end
globalevents: transformsystemautomat
Lua:
local SystemTransformData= {
 [1] = { lvl = 1,                manaPerSec =0,
            newlookType = 397,      revertlookType =436,
            maxhp = 1000,           maxmana = 1000,
            revertmaxhp = 0,        revertmaxmana = 0,
            newvoc = 2,             revertvoc = 1,
            constforma = true,      lasttransform = false,
            constlookType = 436,    constvoc = 1,
            allbonusmaxhp = 0,      allbonusmaxmana = 0,
            effect=126,
        },
    --goku kaioken look type 397
    [2] = { lvl = 1,                manaPerSec =10,
            newlookType = 438,      revertlookType =436,
            maxhp = 1000,           maxmana = 1000,
            revertmaxhp = 1000,     revertmaxmana = 1000,
            newvoc = 3,             revertvoc = 1,
            constforma = false,     lasttransform = false,
            constlookType = 436,    constvoc = 1,
            allbonusmaxhp = 1000,   allbonusmaxmana = 1000,
            effect=127,
        },
--goku ssj looktype 438
[3] = { lvl = 1,                manaPerSec =20,
        newlookType = 404,      revertlookType =397,
        maxhp = 1000,           maxmana = 1000,
        revertmaxhp = 1000,     revertmaxmana = 1000,
        newvoc = 4,             revertvoc = 2,
        constforma = false,     lasttransform = false,
        constlookType = 436,    constvoc = 1,
        allbonusmaxhp = 2000,   allbonusmaxmana = 2000,
        effect=128,
    },
--goku ssj2 looktype 404
[4] = { lvl = 1,                manaPerSec =30,
        newlookType = 437,      revertlookType =438,
        maxhp = 1000,           maxmana = 1000,
        revertmaxhp = 1000,     revertmaxmana = 1000,
        newvoc = 5,             revertvoc = 3,
        constforma = false,     lasttransform = false,
        constlookType = 436,    constvoc = 1,
        allbonusmaxhp = 3000,   allbonusmaxmana = 3000,
        effect=129,
    },
--goku ssj3 looktype 437
[5] = { lvl = 1,                manaPerSec =40,
        newlookType = 433,      revertlookType =404,
        maxhp = 1000,           maxmana = 1000,
        revertmaxhp = 1000,     revertmaxmana = 1000,
        newvoc = 6,             revertvoc = 4,
        constforma = false,     lasttransform = false,
        constlookType = 436,    constvoc = 1,
        allbonusmaxhp = 4000,   allbonusmaxmana = 4000,
        effect=130,
    },
--goku ssj4 looktype 433
[6] = { lvl = 1,                manaPerSec =50,
        newlookType = 433,      revertlookType =437,
        maxhp = 1000,           maxmana = 1000,
        revertmaxhp = 1000,     revertmaxmana = 1000,
        newvoc = 6,             revertvoc = 5,
        constforma = false,     lasttransform = true,
        constlookType = 436,    constvoc = 1,
        allbonusmaxhp = 5000,   allbonusmaxmana = 5000,
        effect=131,
    },

}
function onThink(interval)
    for index, player in pairs(Game.getPlayers()) do
        if player then
            local vocation = player:getVocation():getId()
            local removedata = SystemTransformData[vocation]
            if removedata ~= nil then
                if removedata.constforma == true then
                else
                    if removedata.constforma == false then
                        local cid = player:getId()
                        local player = Player(cid)
                        if player == nil then
                            return false
                        end
                        if player:getMana() > 100 then
                        
                                player:addMana(-removedata.manaPerSec)
                            
                          
                          
                        else
                            player:setOutfit({lookType = removedata.constlookType})
                            player:setVocation(removedata.constvoc)
                            player:setMaxHealth(player:getMaxHealth() - removedata.allbonusmaxhp)
                            player:setMaxMana(player:getMaxMana() - removedata.allbonusmaxmana)
                          
                            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Miales zbyt malo many, aby utrzymac transformacje.")
                      
                        end
                    end
                end
            end
        end
    end
    return true
end
globalevents: constantmagiceffect
Lua:
local efektytabela ={
    [1]={constanteffect=100},[2]={constanteffect=100},[3]={constanteffect=100},[4]={constanteffect=305},[5]={constanteffect=305},[6]={constanteffect=336},
    }
    function onThink(interval)
    for index, player in pairs(Game.getPlayers()) do
        if player then
            local vocation = player:getVocation():getId()
            local tabela = efektytabela[vocation]
            if tabela ~= nil then

            local cid = player:getId()
            local player = Player(cid)
                if player == nil then
                    return false
                end
                if tabela.constanteffect > 101 then
                    player:getPosition():sendMagicEffect(tabela.constanteffect)
                end
            end
        end
    end
return true
end
Post automatically merged:

The numbers in the table are the vocation id
 
You are checking all players in game per one second, this is not a problem in talkactions, your last script that you posted with function onThink shouldbe replaced with addEvent for each player.
 
I fixed some functions to be compatible with TFS 1X, but I'm not sure if it will work

Transform:
Lua:
function onSay(player, words)
    local vocationobecny = player:getVocationId()

    local transformData = {
        [1] = {
            lvl = 1,
            manaPerSec = 0,
            newlookType = 397,
            revertlookType = 436,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 0,
            revertmaxmana = 0,
            newvoc = 2,
            revertvoc = 1,
            constforma = true,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 0,
            allbonusmaxmana = 0,
            effect = 126,
            --goku kaioken look type 397
        },
        [2] = {
            lvl = 1,
            manaPerSec = 10,
            newlookType = 438,
            revertlookType = 436,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 3,
            revertvoc = 1,
            constforma = false,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 1000,
            allbonusmaxmana = 1000,
            effect = 127,
            --goku ssj looktype 438
        },
        [3] = {
            lvl = 1,
            manaPerSec = 20,
            newlookType = 404,
            revertlookType = 397,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 4,
            revertvoc = 2,
            constforma = false,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 2000,
            allbonusmaxmana = 2000,
            effect = 128,
            --goku ssj2 looktype 404
        },
        [4] = {
            lvl = 1,
            manaPerSec = 30,
            newlookType = 437,
            revertlookType = 438,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 5,
            revertvoc = 3,
            constforma = false,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 3000,
            allbonusmaxmana = 3000,
            effect = 129,
            --goku ssj3 looktype 437
        },
        [5] = {
            lvl = 1,
            manaPerSec = 40,
            newlookType = 433,
            revertlookType = 404,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 6,
            revertvoc = 4,
            constforma = false,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 4000,
            allbonusmaxmana = 4000,
            effect = 130,
            --goku ssj4 looktype 433
        },
        [6] = {
            lvl = 1,
            manaPerSec = 50,
            newlookType = 433,
            revertlookType = 437,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 6,
            revertvoc = 5,
            constforma = false,
            lasttransform = true,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 5000,
            allbonusmaxmana = 5000,
            effect = 131,
        },
    }

    local transform = transformData[vocationobecny]

    if transform.lasttransform then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Nie mozesz sie juz transformowac, osiagnales szczyt mozliwosci i jestes aktualnie na ostatniej transformacji!")
    elseif player:getLevel() < transform.lvl then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Posiadasz zbyt niski lvl!")
    else
        player:setMaxHealth(player:getMaxHealth() + transform.maxhp)
        player:setMaxMana(player:getMaxMana() + transform.maxmana)
        player:setHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        player:setOutfit({ lookType = transform.newlookType })
        player:getPosition():sendMagicEffect(transform.effect)


        player:setVocation(transform.newvoc)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Transformacja udana!!")
    end
end
Reverter:
Lua:
function onSay(player, words, param)
    local vocationId = player:getVocation():getId()

    local SystemTransformData = {
        [1] = {
            lvl = 1,
            manaPerSec = 0,
            newlookType = 397,
            revertlookType = 436,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 0,
            revertmaxmana = 0,
            newvoc = 2,
            revertvoc = 1,
            constforma = true,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 0,
            allbonusmaxmana = 0,
            effect = 126,
        },
        [2] = {
            lvl = 1,
            manaPerSec = 10,
            newlookType = 438,
            revertlookType = 436,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 3,
            revertvoc = 1,
            constforma = false,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 1000,
            allbonusmaxmana = 1000,
            effect = 127,
        },
        [3] = {
            lvl = 1,
            manaPerSec = 20,
            newlookType = 404,
            revertlookType = 397,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 4,
            revertvoc = 2,
            constforma = false,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 2000,
            allbonusmaxmana = 2000,
            effect = 128,
        },
        [4] = {
            lvl = 1,
            manaPerSec = 30,
            newlookType = 437,
            revertlookType = 438,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 5,
            revertvoc = 3,
            constforma = false,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 3000,
            allbonusmaxmana = 3000,
            effect = 129,
        },
        [5] = {
            lvl = 1,
            manaPerSec = 40,
            newlookType = 433,
            revertlookType = 404,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 6,
            revertvoc = 4,
            constforma = false,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 4000,
            allbonusmaxmana = 4000,
            effect = 130,
        },
        [6] = {
            lvl = 1,
            manaPerSec = 50,
            newlookType = 433,
            revertlookType = 437,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 6,
            revertvoc = 5,
            constforma = false,
            lasttransform = true,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 5000,
            allbonusmaxmana = 5000,
            effect = 131,
        },
    }

    local revertdata = SystemTransformData[vocationId]
    if revertdata.constforma then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have a constant form and cannot reverse!")
    else
        player:setOutfit({ lookType = revertdata.revertlookType })
        player:setMaxHealth(player:getMaxHealth() - revertdata.revertmaxhp)
        player:setMaxMana(player:getMaxMana() - revertdata.revertmaxmana)
        player:setVocation(revertdata.revertvoc)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "successfully revert!")
    end
end
globalevents: constantmagiceffect:
Lua:
local efektytabela = {
    [1] = { constanteffect = 100 },
    [2] = { constanteffect = 100 },
    [3] = { constanteffect = 100 },
    [4] = { constanteffect = 305 },
    [5] = { constanteffect = 305 },
    [6] = { constanteffect = 336 },
}

function onThink(interval)
    for _, player in ipairs(Game.getPlayers()) do
        addEvent(sendMagicEffect, interval, player)
    end
    return true
end

function sendMagicEffect(player)
    if player then
        local cid = player:getId()
        local currentPlayer = Player(cid)
        if currentPlayer == nil then
            return false
        end

        local vocationId = currentPlayer:getVocation():getId()
        local tabela = efektytabela[vocationId]

        if tabela and tabela.constanteffect > 101 then
            currentPlayer:getPosition():sendMagicEffect(tabela.constanteffect)
        end
    end
end
In the last script I believe it is necessary to add the addEvent function as mentioned by the individual earlier. I'm not sure if adding or replacing onThink with addEvent is necessary, but if that doesn't work, you can try replacing it anyway.
I'm learning the latest version of TFS 1X still
 
Last edited:
I fixed some functions to be compatible with TFS 1X, but I'm not sure if it will work

Transform:
Lua:
function onSay(player, words)
    local vocationobecny = player:getVocationId()

    local transformData = {
        [1] = {
            lvl = 1,
            manaPerSec = 0,
            newlookType = 397,
            revertlookType = 436,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 0,
            revertmaxmana = 0,
            newvoc = 2,
            revertvoc = 1,
            constforma = true,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 0,
            allbonusmaxmana = 0,
            effect = 126,
            --goku kaioken look type 397
        },
        [2] = {
            lvl = 1,
            manaPerSec = 10,
            newlookType = 438,
            revertlookType = 436,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 3,
            revertvoc = 1,
            constforma = false,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 1000,
            allbonusmaxmana = 1000,
            effect = 127,
            --goku ssj looktype 438
        },
        [3] = {
            lvl = 1,
            manaPerSec = 20,
            newlookType = 404,
            revertlookType = 397,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 4,
            revertvoc = 2,
            constforma = false,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 2000,
            allbonusmaxmana = 2000,
            effect = 128,
            --goku ssj2 looktype 404
        },
        [4] = {
            lvl = 1,
            manaPerSec = 30,
            newlookType = 437,
            revertlookType = 438,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 5,
            revertvoc = 3,
            constforma = false,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 3000,
            allbonusmaxmana = 3000,
            effect = 129,
            --goku ssj3 looktype 437
        },
        [5] = {
            lvl = 1,
            manaPerSec = 40,
            newlookType = 433,
            revertlookType = 404,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 6,
            revertvoc = 4,
            constforma = false,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 4000,
            allbonusmaxmana = 4000,
            effect = 130,
            --goku ssj4 looktype 433
        },
        [6] = {
            lvl = 1,
            manaPerSec = 50,
            newlookType = 433,
            revertlookType = 437,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 6,
            revertvoc = 5,
            constforma = false,
            lasttransform = true,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 5000,
            allbonusmaxmana = 5000,
            effect = 131,
        },
    }

    local transform = transformData[vocationobecny]

    if transform.lasttransform then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Nie mozesz sie juz transformowac, osiagnales szczyt mozliwosci i jestes aktualnie na ostatniej transformacji!")
    elseif player:getLevel() < transform.lvl then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Posiadasz zbyt niski lvl!")
    else
        player:setMaxHealth(player:getMaxHealth() + transform.maxhp)
        player:setMaxMana(player:getMaxMana() + transform.maxmana)
        player:setHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        player:setOutfit({ lookType = transform.newlookType })
        player:getPosition():sendMagicEffect(transform.effect)


        player:setVocation(transform.newvoc)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Transformacja udana!!")
    end
end
Reverter:
Lua:
function onSay(player, words, param)
    local vocationId = player:getVocation():getId()

    local SystemTransformData = {
        [1] = {
            lvl = 1,
            manaPerSec = 0,
            newlookType = 397,
            revertlookType = 436,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 0,
            revertmaxmana = 0,
            newvoc = 2,
            revertvoc = 1,
            constforma = true,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 0,
            allbonusmaxmana = 0,
            effect = 126,
        },
        [2] = {
            lvl = 1,
            manaPerSec = 10,
            newlookType = 438,
            revertlookType = 436,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 3,
            revertvoc = 1,
            constforma = false,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 1000,
            allbonusmaxmana = 1000,
            effect = 127,
        },
        [3] = {
            lvl = 1,
            manaPerSec = 20,
            newlookType = 404,
            revertlookType = 397,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 4,
            revertvoc = 2,
            constforma = false,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 2000,
            allbonusmaxmana = 2000,
            effect = 128,
        },
        [4] = {
            lvl = 1,
            manaPerSec = 30,
            newlookType = 437,
            revertlookType = 438,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 5,
            revertvoc = 3,
            constforma = false,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 3000,
            allbonusmaxmana = 3000,
            effect = 129,
        },
        [5] = {
            lvl = 1,
            manaPerSec = 40,
            newlookType = 433,
            revertlookType = 404,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 6,
            revertvoc = 4,
            constforma = false,
            lasttransform = false,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 4000,
            allbonusmaxmana = 4000,
            effect = 130,
        },
        [6] = {
            lvl = 1,
            manaPerSec = 50,
            newlookType = 433,
            revertlookType = 437,
            maxhp = 1000,
            maxmana = 1000,
            revertmaxhp = 1000,
            revertmaxmana = 1000,
            newvoc = 6,
            revertvoc = 5,
            constforma = false,
            lasttransform = true,
            constlookType = 436,
            constvoc = 1,
            allbonusmaxhp = 5000,
            allbonusmaxmana = 5000,
            effect = 131,
        },
    }

    local revertdata = SystemTransformData[vocationId]
    if revertdata.constforma then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have a constant form and cannot reverse!")
    else
        player:setOutfit({ lookType = revertdata.revertlookType })
        player:setMaxHealth(player:getMaxHealth() - revertdata.revertmaxhp)
        player:setMaxMana(player:getMaxMana() - revertdata.revertmaxmana)
        player:setVocation(revertdata.revertvoc)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "successfully revert!")
    end
end
globalevents: constantmagiceffect:
Lua:
local efektytabela = {
    [1] = { constanteffect = 100 },
    [2] = { constanteffect = 100 },
    [3] = { constanteffect = 100 },
    [4] = { constanteffect = 305 },
    [5] = { constanteffect = 305 },
    [6] = { constanteffect = 336 },
}

function onThink(interval)
    for _, player in ipairs(Game.getPlayers()) do
        addEvent(sendMagicEffect, interval, player)
    end
    return true
end

function sendMagicEffect(player)
    if player then
        local vocationId = player:getVocation():getId()
        local tabela = efektytabela[vocationId]

        if tabela and tabela.constanteffect > 101 then
            player:getPosition():sendMagicEffect(tabela.constanteffect)
        end
    end
end
In the last script I believe it is necessary to add the addEvent function as mentioned by the individual earlier. I'm not sure if adding or replacing onThink with addEvent is necessary, but if that doesn't work, you can try replacing it anyway.
I'm learning the latest version of TFS 1X still
Sure, sure, construct these tables every time these two functions are executed, why not.
This addEvent in onThink will only double the delay between execution (if interval is 1 sec, it will execute after 2, 1 sec for onThink and 1 sec for addEvent).
Not to mention using player metadata as addEvent parameter.

Let me tell you... Big fan.
Lua:
            local cid = player:getId()
            local player = Player(cid)
                if player == nil then
                    return false
                end
 
Last edited:
Improvement with crash possibility and fuk up function, from script with table loaded once, you created function creating all the time the same table, this is fuk optimize and logic not improvement. Xd

Btw.. Don't send userdata in addEvent.

Better solution is just add addEvent in transform function with cache.. instend of globalevent.
 
Back
Top