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

Get Level function TFS 1.2/OTX 3

paweleq2000

New Member
Joined
Feb 18, 2011
Messages
161
Reaction score
4
Hello otlanders,
I want to ask for function which give us level when we do some NPC mission.
I know for experience is doPlayerAddExp(cid,1), but need for level.
 
Solution
Try this:

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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 getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end
function Player:addLevel(amount)
    return self:addExperience(getExpForLevel(self:getLevel() + (amount and amount or 1)) - self:getExperience())
end

function...
Lua:
local function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

local function addLevel(player)
    return player:addExperience(getExpForLevel(player:getLevel()+1) - player:getExperience())
end
 
Okay, so how i can use this function? Because i got error

Code:
Lua Script Error: [Npc interface]
data/npc/scripts/Trish.lua:eek:nCreatureSay
data/npc/scripts/Trish.lua:71: attempt to call method 'addLevel' (a nil value)
stack traceback:
    [C]: in function 'addLevel'
    data/npc/scripts/Trish.lua:71: in function 'callback'
    data/npc/lib/npcsystem/npchandler.lua:412: in function 'onCreatureSay'
    data/npc/scripts/Trish.lua:7: in function <data/npc/scripts/Trish.lua:7>
 
Okay, so how i can use this function? Because i got error

Code:
Lua Script Error: [Npc interface]
data/npc/scripts/Trish.lua:eek:nCreatureSay
data/npc/scripts/Trish.lua:71: attempt to call method 'addLevel' (a nil value)
stack traceback:
    [C]: in function 'addLevel'
    data/npc/scripts/Trish.lua:71: in function 'callback'
    data/npc/lib/npcsystem/npchandler.lua:412: in function 'onCreatureSay'
    data/npc/scripts/Trish.lua:7: in function <data/npc/scripts/Trish.lua:7>

Where did you place the function?
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end

local function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

local function addLevel(player)
    return player:addExperience(getExpForLevel(player:getLevel()+1) - player:getExperience())
end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if(msgcontains(msg, 'help')) then
selfSay('You want to start {mission}?', cid)
end
    if(msgcontains(msg, 'mission')) then
       
        if(getPlayerStorageValue(cid,700) < 1) then
            selfSay('Its nice! So, Im on KingEvo by accident but nevermind. Can you help me and bring for me {70 frazzle skin}?', cid)
            talkState[talkUser] = 1
                       
        elseif (getPlayerStorageValue(cid,701) < 1) then
                selfSay('Your next mission is to bring me {70 mushroom pies}.', cid)
                talkState[talkUser] = 1
                               
        elseif (getPlayerStorageValue(cid,702) < 0) then
                selfSay('Your next mission is to bring me {70 some grimeleech wingss}.',cid)
                talkState[talkUser] = 1
                               
        elseif (getPlayerStorageValue(cid,703) < 0) then
                selfSay('Your next mission is to bring me {70 demonic fingers}.', cid)
                talkState[talkUser] = 1

    elseif (getPlayerStorageValue(cid,704) < 0) then
                selfSay('Your next mission is to bring me {70 draptor scaless}.', cid)
                talkState[talkUser] = 1
               
        elseif (getPlayerStorageValue(cid,704) == 1) then
                selfSay('I dont have more missions for you. Thanks for your help.', cid)
                talkState[talkUser] = 1
               
               
               
               
        end
        ---------------------------------------
        elseif(msgcontains(msg, '70 frazzle skin') and talkState[talkUser] == 1 and (getPlayerStorageValue(cid,700) < 1)) then
        if(doPlayerRemoveItem(cid, 22533, 70) == TRUE) then
            setPlayerStorageValue(cid,700,1)
        doPlayergetLevel(cid,1)
            selfSay('Thanks.', cid)
            talkState[talkUser] = 0
        else
            selfSay('To complete the mission you must bring me {70 frazzle skin}.', cid)
        end
        ---------------------------------------
        elseif(msgcontains(msg, '70 mushroom pies') and talkState[talkUser] == 1  and (getPlayerStorageValue(cid,701) < 1) and (getPlayerStorageValue(cid,700) == 1)) then
        if(doPlayerRemoveItem(cid, 18397, 70) == TRUE) then
            setPlayerStorageValue(cid,701,1)
        Player:addLevel(cid,2)
            selfSay('Thanks.', cid)
            talkState[talkUser] = 0
        else
            selfSay('To complete the mission you must bring me {70 mushroom pies}.', cid)
        end
        ---------------------------------------
        elseif(msgcontains(msg, '70 some grimeleech wingss') and talkState[talkUser] == 1  and (getPlayerStorageValue(cid,702) < 1) and (getPlayerStorageValue(cid,701) == 1)) then
        if(doPlayerRemoveItem(cid, 25386, 70) == TRUE) then
            setPlayerStorageValue(cid,702,1)
        Player:addLevel(2)
            selfSay('Thanks.', cid)
            talkState[talkUser] = 0
        else
            selfSay('To complete the mission you must bring me {sword}.', cid)
        end
        ---------------------------------------
        elseif(msgcontains(msg, '70 demonic fingers') and talkState[talkUser] == 1 and (getPlayerStorageValue(cid,703) < 1) and (getPlayerStorageValue(cid,702) == 1)) then
       if(doPlayerRemoveItem(cid, 13530, 70) == TRUE) then
            setPlayerStorageValue(cid,703,1)
        addLevel(cid, 2)
            doPlayerAddItem(cid, 5468, 1)
            selfSay('Thanks.', cid)
            talkState[talkUser] = 0
        else
            selfSay('To complete the mission you must bring me {70 demonic fingers}.', cid)
        end
        ------------------------------------------
    elseif(msgcontains(msg, '70 draptor scaless') and talkState[talkUser] == 1 and (getPlayerStorageValue(cid,704) < 1) and (getPlayerStorageValue(cid,703) == 1)) then
       if(doPlayerRemoveItem(cid, 13296, 70) == TRUE) then
            setPlayerStorageValue(cid,704,1)
        addLevel(player)
            doPlayerAddItem(cid, 5468, 1)
            selfSay('Thanks, It is all what i wanted from you.', cid)
            talkState[talkUser] = 0
        else
            selfSay('To complete the mission you must bring me {70 draptor scaless}.', cid)
        end
        ------------------------------------------
       
    end
end   
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

i checked a lot of variants to use this function in this code
 
Try this:

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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 getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end
function Player:addLevel(amount)
    return self:addExperience(getExpForLevel(self:getLevel() + (amount and amount or 1)) - self:getExperience())
end

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local player = Player(cid)
    if not player then
        return
    end
  
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    if(msgcontains(msg, 'help')) then
        selfSay('You want to start {mission}?', cid)
    end
  
    if(msgcontains(msg, 'mission')) then    
        if(getPlayerStorageValue(cid,700) < 1) then
            selfSay('Its nice! So, Im on KingEvo by accident but nevermind. Can you help me and bring for me {70 frazzle skin}?', cid)
            talkState[talkUser] = 1
        elseif (getPlayerStorageValue(cid,701) < 1) then
            selfSay('Your next mission is to bring me {70 mushroom pies}.', cid)
            talkState[talkUser] = 1             
        elseif (getPlayerStorageValue(cid,702) < 0) then
            selfSay('Your next mission is to bring me {70 some grimeleech wingss}.',cid)
            talkState[talkUser] = 1         
        elseif (getPlayerStorageValue(cid,703) < 0) then
            selfSay('Your next mission is to bring me {70 demonic fingers}.', cid)
            talkState[talkUser] = 1
        elseif (getPlayerStorageValue(cid,704) < 0) then
            selfSay('Your next mission is to bring me {70 draptor scaless}.', cid)
            talkState[talkUser] = 1
        elseif (getPlayerStorageValue(cid,704) == 1) then
            selfSay('I dont have more missions for you. Thanks for your help.', cid)
            talkState[talkUser] = 1
        end
    ---------------------------------------
    elseif(msgcontains(msg, '70 frazzle skin') and talkState[talkUser] == 1 and (getPlayerStorageValue(cid,700) < 1)) then
        if(doPlayerRemoveItem(cid, 22533, 70) == TRUE) then
            setPlayerStorageValue(cid,700,1)
            doPlayergetLevel(cid,1)
            selfSay('Thanks.', cid)
            talkState[talkUser] = 0
        else
            selfSay('To complete the mission you must bring me {70 frazzle skin}.', cid)
        end
    ---------------------------------------
    elseif(msgcontains(msg, '70 mushroom pies') and talkState[talkUser] == 1  and (getPlayerStorageValue(cid,701) < 1) and (getPlayerStorageValue(cid,700) == 1)) then
        if(doPlayerRemoveItem(cid, 18397, 70) == TRUE) then
            setPlayerStorageValue(cid,701,1)
            player:addLevel(2)
            selfSay('Thanks.', cid)
            talkState[talkUser] = 0
        else
            selfSay('To complete the mission you must bring me {70 mushroom pies}.', cid)
        end
    ---------------------------------------
    elseif(msgcontains(msg, '70 some grimeleech wingss') and talkState[talkUser] == 1  and (getPlayerStorageValue(cid,702) < 1) and (getPlayerStorageValue(cid,701) == 1)) then
    if(doPlayerRemoveItem(cid, 25386, 70) == TRUE) then
        setPlayerStorageValue(cid,702,1)
        player:addLevel(2)
        selfSay('Thanks.', cid)
        talkState[talkUser] = 0
    else
        selfSay('To complete the mission you must bring me {sword}.', cid)
    end
    ---------------------------------------
    elseif(msgcontains(msg, '70 demonic fingers') and talkState[talkUser] == 1 and (getPlayerStorageValue(cid,703) < 1) and (getPlayerStorageValue(cid,702) == 1)) then
    if(doPlayerRemoveItem(cid, 13530, 70) == TRUE) then
        setPlayerStorageValue(cid,703,1)
        player:addLevel(2)
        doPlayerAddItem(cid, 5468, 1)
        selfSay('Thanks.', cid)
        talkState[talkUser] = 0
    else
        selfSay('To complete the mission you must bring me {70 demonic fingers}.', cid)
    end
    ------------------------------------------
    elseif(msgcontains(msg, '70 draptor scaless') and talkState[talkUser] == 1 and (getPlayerStorageValue(cid,704) < 1) and (getPlayerStorageValue(cid,703) == 1)) then
        if(doPlayerRemoveItem(cid, 13296, 70) == TRUE) then
            setPlayerStorageValue(cid,704,1)
            player:addLevel(1)
            doPlayerAddItem(cid, 5468, 1)
            selfSay('Thanks, It is all what i wanted from you.', cid)
            talkState[talkUser] = 0
        else
            selfSay('To complete the mission you must bring me {70 draptor scaless}.', cid)
        end
    ------------------------------------------ 
    end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
Back
Top