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

CreatureEvent Level UP script, "You advanced to level 35 in 3 minutes and 10 seconds".

Ahilphino

Excellent OT User
Joined
Jun 5, 2013
Messages
1,666
Solutions
1
Reaction score
723
SCRIPT IS FOR TFS 1.X

what does this script do?
simply adds another message when you level up and it looks like this:
11:21 It took you 9 seconds to advance in level from your last advance.
11:21 You advanced from Level 1129 to Level 1130.
11:24 It took you 3 minutes and 16 seconds to advance in level from your last advance.
11:24 You advanced from Level 1130 to Level 1131.
3vGtGUcTd.png


ok so the script is really easy and it can be done better by more experienced ppl. but i saw it in a server and i loved that feature so I made it for myself and I will post it here so more servers can use it :)

also the timestring function is from someone else on otland.

creaturescripts\scripts\timelevel.lua
Code:
function timeString(timeDiff)
    local dateFormat = {
        {"day", timeDiff / 60 / 60 / 24},
        {"hour", timeDiff / 60 / 60 % 24},
        {"minute", timeDiff / 60 % 60},
        {"second", timeDiff % 60}
    }

    local out = {}
    for k, t in ipairs(dateFormat) do
        local v = math.floor(t[2])
        if(v > 0) then
            table.insert(out, (k < #dateFormat and (#out > 0 and ', ' or '') or ' and ') .. v .. ' ' .. t[1] .. (v ~= 1 and 's' or ''))
        end
    end
    local ret = table.concat(out)
    if ret:len() < 16 and ret:find("second") then
        local a, b = ret:find(" and ")
        ret = ret:sub(b+1)
    end

    return ret
end

function onAdvance(player, skill, oldlevel, newlevel)
    if skill ~= SKILL_LEVEL then
        return true
    end

    oldtime = player:getStorageValue(3499)
    timenow = os.time()
    if oldtime == -1 then
        player:setStorageValue(3499, timenow)
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It took you " .. timeString(timenow - oldtime) .. " to advance in level from your last advance.")
        player:setStorageValue(3499, timenow)
    end
    return true
end

also add this in login.lua
Code:
player:registerEvent("timelevel")

and in creaturescripts.xml
Code:
<event type="advance" name="timelevel" script="timelevel.lua"/>

that's it! now it will work! it's made for tfs 1.x!!!!!



TO SCRIPTERS:
if someone that knows how to remove level advance from sources this could be much better and have only white text with this text, if you know how to remove it from sources please post! :) and if u wanna improve the code please post ur editions since im quite bad :)
Code:
You advanced to level 35 in 3 minutes and 10 seconds. (we could just make 1 line like this with source change)
 
Last edited:
it's easy to remove it from sources.
just open all the source files and search for "you advanced .." and check the results.
And from there either remove them, or comment them with //
 
in player.cpp
void Player::addExperience(Creature* source, uint64_t exp, bool sendText/* = false*/)

delete this:
Code:
        std::ostringstream ss;
        ss << "You advanced from Level " << prevLevel << " to Level " << level << '.';
        sendTextMessage(MESSAGE_EVENT_ADVANCE, ss.str());
 
Can someone do a source version of this script?
So instead of removing it from sources it could actually be sourced :p

Edit: The script is not working in TFS 1.2 unfortunaly :/
 
Last edited:
there is not much difference if this is sourced or scripted
the difference is the script is already done, sourced's not
 
Actually there is a good difference...

Script = Not Working in TFS 1.2 (idk about others)

Sourced = I think Works for all 3 TFS (1.0, 1.1, 1.2)
 
well script works i am thinking for newest tfs
just deleete the thing marcelo posted in sources and u can change the message type and the message in the script like this
Code:
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You advanced to level "..newlevel.. " in " .. timeString(timenow - oldtime) .. ".")

and u also might wanna set the storagevalue on their firstlogin so the first lvl shows up correctly if u delete it from source
 
Last edited:
I tested, it gave-me no errors but nothing happened also...

I removed the source sentences to check if the message would popup but nothing happened...

I'll give it another try tomorrow and use prints to find out whats wrong
 
Back
Top