[TFS 1.3] NPC get level and add experience

flaviiojr

Active Member
Joined
Jan 20, 2017
Messages
230
Best answers
13
Reaction score
35
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!
 

athenso

Average Coder
Joined
May 31, 2011
Messages
124
Best answers
1
Reaction score
12
I could make it when I get home, or you could edit a few things in other NPC scripts. Neither of which are hard.
 
OP
flaviiojr

flaviiojr

Active Member
Joined
Jan 20, 2017
Messages
230
Best answers
13
Reaction score
35
I could make it when I get home, or you could edit a few things in other NPC scripts. Neither of which are hard.
I could do the modification and test in another npc, I'm just having difficulty in doing this function!
Thank's very so much !!

@athenso
 

athenso

Average Coder
Joined
May 31, 2011
Messages
124
Best answers
1
Reaction score
12
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.
 

Creon

Well-Known Member
Joined
Aug 25, 2009
Messages
690
Best answers
0
Reaction score
84
Location
United States
Is there a way of setting player at a certain level, instead of just adding X amount of experience?
 

lokolokio

Well-Known Member
Joined
Jan 7, 2009
Messages
179
Best answers
10
Reaction score
51
Location
Mexico
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
 

athenso

Average Coder
Joined
May 31, 2011
Messages
124
Best answers
1
Reaction score
12
If the above function didn't work I will make one when I get home, to set to a specific level
 
OP
flaviiojr

flaviiojr

Active Member
Joined
Jan 20, 2017
Messages
230
Best answers
13
Reaction score
35
@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:
 

Linxsis

Banned User
Joined
Nov 18, 2017
Messages
243
Best answers
10
Reaction score
81
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.
 
OP
flaviiojr

flaviiojr

Active Member
Joined
Jan 20, 2017
Messages
230
Best answers
13
Reaction score
35
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
 

athenso

Average Coder
Joined
May 31, 2011
Messages
124
Best answers
1
Reaction score
12
I took this script from my Rebirth npc. So yes I did copy it, but from myself. That is why player and guid are called as I never deleted them out. The whole npc was written from this.

OTX 3.7 Rebirth with Onlook
 

Linxsis

Banned User
Joined
Nov 18, 2017
Messages
243
Best answers
10
Reaction score
81
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.
 

lokolokio

Well-Known Member
Joined
Jan 7, 2009
Messages
179
Best answers
10
Reaction score
51
Location
Mexico
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.
 

Linxsis

Banned User
Joined
Nov 18, 2017
Messages
243
Best answers
10
Reaction score
81
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.
 

lokolokio

Well-Known Member
Joined
Jan 7, 2009
Messages
179
Best answers
10
Reaction score
51
Location
Mexico
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.)
 
Top