• 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 update script to tfs 1.3

Restles

fallen human nature
Joined
Jan 30, 2014
Messages
68
Solutions
1
Reaction score
35
Location
Poland
hello, i need up this to new version, is possible?
Lua:
local profesions = {
    {vocid=1, newvoc=2, mana=11, looktype=8, backhp=451, backmp=523},
}

local value = {}

function onThink(cid, interval)
    for i=1, #profesions do
        value = profesions[i]
        if(getPlayerVocation(cid) == value.vocid) then
            if(getCreatureMana(cid) >= value.mana) then
                if(getPlayerStorageValue(cid, 504205) <= os.time()) then
                    setPlayerStorageValue(cid, 504205, os.time() + 2)
                    doCreatureAddMana(cid, -value.mana)
                end
            else
                local outfit = getCreatureOutfit(cid)
                outfit.lookType = value.looktype
                doCreatureChangeOutfit(cid, outfit)
                doPlayerSetVocation(cid, value.newvoc)
                setCreatureMaxHealth(cid, getCreatureMaxHealth(cid)-value.backhp)
                doCreatureAddHealth(cid, -value.backhp)
                setCreatureMaxMana(cid, getCreatureMaxMana(cid)-value.backmp)
                doCreatureAddMana(cid, -value.backmp)
            end
        end
    end
    return true
end
 

Astir Lotus

Well-Known Member
Joined
Sep 14, 2018
Messages
46
Solutions
1
Reaction score
83
This should probably do it. Have not tested it.

Lua:
local profesions = {
    { vocid=1, newvoc=2, mana=11, looktype=8, backhp=451, backmp=523 },
}

local value = {}

function onThink(creature, interval)
    player = Player(creature)

    for i=1, #profesions do
        value = profesions[i]
        if(player:getVocation() == value.vocid) then
            if(player:getMana() >= value.mana) then
                if(player:getStorageValue(504205) <= os.time()) then
                    player:setStorageValue(504205, os.time() + 2)
                    player:addMana(-value.mana)
                end
            else
                local outfit = player:getOutfit()
                outfit.lookType = value.looktype
                player:setOutfit(outfit)
                player:setVocation(value.newvoc)
                player:setMaxHealth(getCreatureMaxHealth(cid)-value.backhp)
                player:addHealth(-value.backhp)
                player:setMaxMana(getCreatureMaxMana(cid)-value.backmp)
                player:addMana(-value.backmp)
            end
        end
    end
    return true
end
 
OP
OP
Restles

Restles

fallen human nature
Joined
Jan 30, 2014
Messages
68
Solutions
1
Reaction score
35
Location
Poland
the script does not work, but shows no errors
Post automatically merged:

Refresh
 
Last edited:
OP
OP
Restles

Restles

fallen human nature
Joined
Jan 30, 2014
Messages
68
Solutions
1
Reaction score
35
Location
Poland
can someone tell me why the script does not display errors but it doesn't work, what is wrong here?
 

Astir Lotus

Well-Known Member
Joined
Sep 14, 2018
Messages
46
Solutions
1
Reaction score
83
Try to add a print statement in the very beginning of the onThink. Right before the loop ever starts. Just to make sure it is registered.
Then add another print statement containing different text than the other one inside the loop. If it always gets to the first part of the loop, move it further in. print(value) should be a good value to print. This is to check that, if we get in the onthink event at all, we want to know how far we get in to the loop.
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,699
Solutions
408
Reaction score
3,811
This should probably do it. Have not tested it.

Lua:
local profesions = {
    { vocid=1, newvoc=2, mana=11, looktype=8, backhp=451, backmp=523 },
}

local value = {}

function onThink(creature, interval)
    player = Player(creature)

    for i=1, #profesions do
        value = profesions[i]
        if(player:getVocation() == value.vocid) then
            if(player:getMana() >= value.mana) then
                if(player:getStorageValue(504205) <= os.time()) then
                    player:setStorageValue(504205, os.time() + 2)
                    player:addMana(-value.mana)
                end
            else
                local outfit = player:getOutfit()
                outfit.lookType = value.looktype
                player:setOutfit(outfit)
                player:setVocation(value.newvoc)
                player:setMaxHealth(getCreatureMaxHealth(cid)-value.backhp)
                player:addHealth(-value.backhp)
                player:setMaxMana(getCreatureMaxMana(cid)-value.backmp)
                player:addMana(-value.backmp)
            end
        end
    end
    return true
end
the script does not work, but shows no errors
Post automatically merged:

Refresh
This line, is probably the issue.
Lua:
if(player:getVocation() == value.vocid) then
change to
Lua:
if(player:getVocation():getId() == value.vocid) then
 

Alpha

Relentless
Premium User
Joined
Apr 3, 2011
Messages
656
Solutions
36
Reaction score
461
Location
South Korea
Didn't test any of that, just corrected some stuff in the code from the dude above

Lua:
local professions = {
    {
        vocid = 1,
        newvoc = 2,
        mana = 11,
        looktype = 8,
        backhp = 451,
        backmp = 523
    },
}

local storageKey = 504205

function onThink(creature, interval)
    local player = Player(creature)
    if not player then
        return true
    end

    for _, profession in pairs(professions) do
        if player:getVocation():getId() == profession.vocid then
            if player:getMana() >= profession.mana then
                local timeNow = os.time()
                if player:getStorageValue(storageKey) <= timeNow then
                    player:setStorageValue(storageKey, timeNow + 2)
                    player:addMana(-profession.mana)
                end
            else
                local outfit = player:getOutfit()
                outfit.lookType = profession.looktype
                player:setOutfit(outfit)
                player:setVocation(profession.newvoc)
                player:setMaxHealth(player:getMaxHealth() - profession.backhp)
                player:addHealth(-profession.backhp)
                player:setMaxMana(player:getMaxMana() - profession.backmp)
                player:addMana(-profession.backmp)
            end
        end
    end
  
    return true
end
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,699
Solutions
408
Reaction score
3,811
Didn't test any of that, just corrected some stuff in the code from the dude above

Lua:
local professions = {
    {
        vocid = 1,
        newvoc = 2,
        mana = 11,
        looktype = 8,
        backhp = 451,
        backmp = 523
    },
}

local storageKey = 504205

function onThink(creature, interval)
    local player = Player(creature)
    if not player then
        return true
    end

    for _, profession in pairs(professions) do
        if player:getVocation():getId() == profession.vocid then
            if player:getMana() >= profession.mana then
                local timeNow = os.time()
                if player:getStorageValue(storageKey) <= timeNow then
                    player:setStorageValue(storageKey, timeNow + 2)
                    player:addMana(-profession.mana)
                end
            else
                local outfit = player:getOutfit()
                outfit.lookType = profession.looktype
                player:setOutfit(outfit)
                player:setVocation(profession.newvoc)
                player:setMaxHealth(player:getMaxHealth() - profession.backhp)
                player:addHealth(-profession.backhp)
                player:setMaxMana(player:getMaxMana() - profession.backmp)
                player:addMana(-profession.backmp)
            end
        end
    end
 
    return true
end
good changes.
 
Top