• 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.3] NPC get level and add experience

flaviiojr

Active Member
Joined
Jan 20, 2017
Messages
230
Solutions
13
Reaction score
39
Hello everyone!!
I need help with the following function:
- if the player has level 8, it will level up to 400
- if the player has 100, it will level up to 400
the limit is up to level 400, no matter what level it will only level up to 400...


Thank you in advance, and I count on your help!
 
Solution
If try this function

Lua:
local function level(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local player = Player(cid)
    local exp = 1050779800 - player:getExperience()
    local level = player:getLevel()
    local req = 400
    local creature = Player(cid)
    local guid = player:getGuid()
    if level < req then
        player:addExperience(exp)
    else
        npcHandler:say('You are over level 400, BEGONE!', cid)
        keywordHandler:moveUp(2)
    end
    return true
end
I could make it when I get home, or you could edit a few things in other NPC scripts. Neither of which are hard.
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)        npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)    npcHandler:onCreatureSay(cid, type, msg)    end
function onThink()                        npcHandler:onThink()                        end
local function greetCallback(cid)
    local player = Player(cid)
    local msg = 'Be welcome, ' .. player:getName() .. '.'
    local level = player:getLevel()
    local req = 399
    npcHandler:say(msg,cid)
    npcHandler:addFocus(cid)
    return false
end
local function level(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local player = Player(cid)
    local level = player:getLevel()
    local req = 400
    local creature = Player(cid)
    local guid = player:getGuid()
    if level < req then
        player:addExperience(1050779800)
     
             
    else
        npcHandler:say('You are over level 400, BEGONE!', cid)
        keywordHandler:moveUp(2)
    end
    return true
end
keywordHandler:addKeyword({'level'}, level, {})
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:addModule(FocusModule:new())

Seeing as the post owner didnt update it, heres the code i wrote. Change the player:addExperience to whatever amount of exp you want.
 
If try this function

Lua:
local function level(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local player = Player(cid)
    local exp = 1050779800 - player:getExperience()
    local level = player:getLevel()
    local req = 400
    local creature = Player(cid)
    local guid = player:getGuid()
    if level < req then
        player:addExperience(exp)
    else
        npcHandler:say('You are over level 400, BEGONE!', cid)
        keywordHandler:moveUp(2)
    end
    return true
end
 
Solution
If try this function

Lua:
local function level(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local player = Player(cid)
    local exp = 1050779800 - player:getExperience()
    local level = player:getLevel()
    local req = 400
    local creature = Player(cid)
    local guid = player:getGuid()
    if level < req then
        player:addExperience(exp)
    else
        npcHandler:say('You are over level 400, BEGONE!', cid)
        keywordHandler:moveUp(2)
    end
    return true
end
Why get these if they are never used?
Lua:
    local creature = Player(cid)
    local guid = player:getGuid()
Also whats this about?
Code:
keywordHandler:moveUp(2)
You are missing an argument, i am sure there is no player with a cid of 2
Lua:
function KeywordHandler:moveUp(cid, steps)
And lastly you never released the focus.
@athenso, thank you, man, for the support and the script !!
@lokolokio sensational, worked perfectly! Many thanks, man !!

Thank you to everyone who helped! :oops::oops:
Actually this is a poorly written script, the result of copy and paste logic.
 
no, man, the script may be down poorly written, but the main function has been taken ...
Stop your arrogance, and congratulations to all who tried to help <3
Pointing out that something is flawed or unstable isn't considered arrogance, it is considered consideration, ignorance is arrogant tho.
 
I never said that I was an awesome scripter, but he is asking for script to add experience no matter on wich level you are, it will take you to 400, so I just add línes local exp = blablabla playeraddexperience(Cid, exp), I dont know what is the script, or what it does, I just make the function he need, where the main script does not matter to me, I just did what he asked, which would raise you to level 400 regardless of the level at which you are.
 
I never said that I was an awesome scripter, but he is asking for script to add experience no matter on wich level you are, it will take you to 400, so I just add línes local exp = blablabla playeraddexperience(Cid, exp), I dont know what is the script, or what it does, I just make the function he need, where the main script does not matter to me, I just did what he asked, which would raise you to level 400 regardless of the level at which you are.
Don't worry its quite clear you aren't. He and many others even yourself need good code otherwise you have bugged servers, I can only imagine how bugged your server is..
You will never ever learn anything from copying and pasting because you are not calculating the execution of the code.
But what does it matter, this is otland, open tibia servers is the only community I have been to that doesn't require learning and that is not a good thing because that is how communities die out.
 
Ok, my apologize and do not worry about it, I can not understood at 100% about compile, I just have elementary school and I am here to learn, but you are the first person that I see on the OTLand forum with that arrogance, maybe you are a engineer or a person with university, or career on M.I.T. or whatever but I am not, regards.

(Also I want to other ppl tell me if I am wrong for give him the specific línes that he is asking for, may the function not work properly but he was not asking for a improvement, he just need to add
specific lines and not an improvement.)
 
Back
Top