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

Solved Prestige NPC help

Dkadsfe

Member
Joined
Apr 1, 2016
Messages
280
Reaction score
22
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 talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if(msgcontains(msg, 'prestige')) then
        selfSay('Are you ready to prestige and start a new life?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        -------CONFIGS-------
        local level = 500
        local cost = 50000
        ------/CONFIGS-------
        -----LOCALS-----
        local id = getPlayerGUID(cid)
        local name = getCreatureName(cid)
        local vocation = getPlayerVocation(cid)
        local storage = getCreatureStorage(cid, 4500)
        local Max_Rebirth = 10  --Change this for the number of rebirths

local spellReborn = {
    [1] = 'Reborn1',
    [5] = 'Reborn5',
    [10] = 'Reborn10',
    [25] = 'Reborn25',
    [50] = 'Reborn50',
    [100] = 'Reborn100',
    [250] = 'Reborn250',
    [500] = 'Reborn500'
}

        ----/LOCALS-----
        if(getPlayerLevel(cid) >= level) then
        if getCreatureStorage(cid, 85987) < Max_Rebirth then
            if(doPlayerRemoveMoney(cid, cost) == TRUE) then
                if(isInArray({5, 6, 7, 8, 9}, vocation)) then
                    doCreatureSetStorage(cid, 85987, storage == -1 and 1 or storage + 1)
                                db.executeQuery('UPDATE players SET rebirths=rebirths+'.. 1 ..' WHERE id='..getPlayerGUID(cid))
                            doBroadcastMessage("" ..  name .. " has just prestiged!", TALKTYPE_ORANGE_1)
                    doRemoveCreature(cid)
                    db.executeQuery("UPDATE `players` SET `level` = 8, `experience` = 4200")
                    db.executeQuery("UPDATE `players` SET `name` = '"..name.."' WHERE `id` ='"..id.."';")
                else
                    selfSay('Please do the promotion quest first.', cid)
                    talkState[talkUser] = 0
                end
            else
                selfSay('You don\'t have enough money. You need to pay 5 Crystal Coins to be prestiged.', cid)
                talkState[talkUser] = 0
            end
        else
            selfSay('You have reached the maximum rebirth.', cid)
            talkState[talkUser] = 0
        end
    else
        selfSay('Only characters of level 500 or higher can be prestiged.', cid)
        talkState[talkUser] = 0
    end
elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
        selfSay('Okey. Come back when you feel ready.', cid)
        talkState[talkUser] = 0
end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


Hi I need help the npc keeps taking 5cc away from players when they say hi prestige yes it does not prestige players when they are not promoted but they take 5cc away from players how do i fix this? It also does not give rebirth spells

Spells.xml
Code:
            <instant name="Reborn1" words="Exevo water wave" lvl="8" mana="500" prem="1" needweapon="0" exhaustion="800" needlearn="1" script="Reborn/water_wave.lua">
        <vocation id="5"/>
        <vocation id="6"/>
        <vocation id="7"/>
        <vocation id="8"/>
    </instant>

This error also pops up on my console, and i use sqlite
Code:
[06/04/2016 10:58:07] OTSYS_SQLITE3_PREPARE(): SQLITE ERROR: no such column: rebirths (UPDATE players SET rebirths=rebirths+1 WHERE id=21)
 
Last edited:
I fixed the above I just need help with this now
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}

local reborn = 4500 -- free storage
local spellReborn = {
    [1] = 'Reborn1',
    [2] = 'Reborn2',
    [5] = 'Reborn5',
    [7] = 'Reborn7',
    [10] = 'Reborn10',
    [100] = 'Reborn100',
    [250] = 'Reborn250',
    [500] = 'Reborn500'
}
local level = 500
local maxReborns = 10
local toLevel = 8

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 greetCallback(cid)
    Topic[cid] = nil
    return true
end

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    elseif Topic[cid] then
        if msgcontains(msg, 'yes') then
            if getCreatureStorage(cid, reborn) < maxReborns then
                doCreatureSetStorage(cid, reborn, math.max(0, getCreatureStorage(cid, reborn)) + 1)
                for k, v in pairs(spellReborn) do
                    if getCreatureStorage(cid, reborn) == k then
                        doPlayerLearnInstantSpell(cid, v)
                        doSendMagicEffect(getThingPosition(cid), CONST_ME_FIREWORK_RED)
                        break
                    end
                end
              
                local g = getPlayerGUID(cid)
                npcHandler:releaseFocus(cid)
                doRemoveCreature(cid)
                db.executeQuery("UPDATE `players` SET level = " .. level .. " WHERE id = " .. guid .. ";")
            else
                npcHandler:say('You reached maximum amount of prestiges.', cid)
            end
        else
            npcHandler:say('Maybe next time.', cid)
        end
        Topic[cid] = nil
    else
        if msgcontains(msg, 'prestige') then
            if getPlayerLevel(cid) >= level then
                npcHandler:say('Are you sure that you want to make a prestige?',cid)
                Topic[cid] = 1
            else
                npcHandler:say('You don\'t have enough level. ['..level..']',cid)
                Topic[cid] = nil
            end
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Error is this, when a player says prestige yes he logs out but does not gain a prestige or lose levels but instead this happens
Code:
[06/04/2016 11:42:34] [Error - Npc interface]
[06/04/2016 11:42:34] data/npc/scripts/rebirth.lua:onCreatureSay
[06/04/2016 11:42:34] Description:
[06/04/2016 11:42:34] data/npc/scripts/rebirth.lua:49: attempt to concatenate global 'guid' (a nil value)
[06/04/2016 11:42:34] stack traceback:
[06/04/2016 11:42:34]     data/npc/scripts/rebirth.lua:49: in function 'callback'
[06/04/2016 11:42:34]     data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[06/04/2016 11:48:09] [Error - Npc interface] 
[06/04/2016 11:48:09] data/npc/scripts/promote.lua:onCreatureSay
[06/04/2016 11:48:09] Description: 
[06/04/2016 11:48:09] (luaGetNpcDistanceTo) Thing not found
 
Last edited:
change g to guid or guid to g xd
Code:
local g = getPlayerGUID(cid)
npcHandler:releaseFocus(cid)
doRemoveCreature(cid)
db.executeQuery("UPDATE `players` SET level = " .. level .. " WHERE id = " .. guid .. ";")
 
change g to guid or guid to g xd
Code:
local g = getPlayerGUID(cid)
npcHandler:releaseFocus(cid)
doRemoveCreature(cid)
db.executeQuery("UPDATE `players` SET level = " .. level .. " WHERE id = " .. guid .. ";")
Thanks but now it prestiges players but they dont go back to level 8 how do i fix that?

I also tried this but it did not work
Code:
db.executeQuery("UPDATE `players` SET `level` = 8 WHERE `id` = "..getPlayerGUID(cid)..";")

please can anyone help me? i still need help
 
Last edited by a moderator:
Try one of these:

Code:
db.query("UPDATE `players` SET `level` = 8 WHERE `id` = "..getPlayerGUID(cid)..";")

Code:
db.executeQuery("UPDATE `players` SET `level` = 8 WHERE `id` = "..getPlayerIdByName(getPlayerName(cid))..";")

Code:
db.query("UPDATE `players` SET `level` = 8 WHERE `id` = "..getPlayerIdByName(getPlayerName(cid))..";")
 
Post. Some. Code. Or. Errors. Plox. Pls. Plx.
The coding of the npc is above
The Errors are below
Code:
[06/04/2016 17:59:31] [Error - Npc interface]
[06/04/2016 17:59:31] data/npc/scripts/rebirth.lua:onCreatureSay
[06/04/2016 17:59:31] Description:
[06/04/2016 17:59:31] (internalGetPlayerInfo) Player not found when requesting player info #18

[06/04/2016 17:59:31] [Error - Npc interface]
[06/04/2016 17:59:31] data/npc/scripts/rebirth.lua:onCreatureSay
[06/04/2016 17:59:31] Description:
[06/04/2016 17:59:31] data/npc/scripts/rebirth.lua:49: attempt to concatenate a boolean value
[06/04/2016 17:59:31] stack traceback:
[06/04/2016 17:59:31]     data/npc/scripts/rebirth.lua:49: in function 'callback'
[06/04/2016 17:59:31]     data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[06/04/2016 17:59:31]     data/npc/scripts/rebirth.lua:23: in function <data/npc/scripts/rebirth.lua:23>
[06/04/2016 17:59:05] [Error - Npc interface]
[06/04/2016 17:59:05] data/npc/scripts/rebirth.lua:onCreatureSay
[06/04/2016 17:59:05] Description:
[06/04/2016 17:59:05] (luaGetCreatureName) Creature not found

[06/04/2016 17:59:05] [Error - Npc interface]
[06/04/2016 17:59:05] data/npc/scripts/rebirth.lua:onCreatureSay
[06/04/2016 17:59:05] Description:
[06/04/2016 17:59:05] data/npc/scripts/rebirth.lua:49: attempt to call global 'getPlayerIdByName' (a nil value)
[06/04/2016 17:59:05] stack traceback:
[06/04/2016 17:59:05]     data/npc/scripts/rebirth.lua:49: in function 'callback'
[06/04/2016 17:59:05]     data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[06/04/2016 17:59:05]     data/npc/scripts/rebirth.lua:23: in function <data/npc/scripts/rebirth.lua:23>

[06/04/2016 17:59:05] [Error - Npc interface]
[06/04/2016 17:59:05] data/npc/scripts/rebirth.lua:onCreatureSay
[06/04/2016 17:59:06] Description:
[06/04/2016 17:59:06] (luaGetNpcDistanceTo) Thing not found

Code:
[06/04/2016 19:17:37] [Error - Npc interface]
[06/04/2016 19:17:37] data/npc/scripts/rebirth.lua:onCreatureSay
[06/04/2016 19:17:37] Description:
[06/04/2016 19:17:37] data/npc/scripts/rebirth.lua:49: attempt to concatenate global 'id' (a nil value)
[06/04/2016 19:17:37] stack traceback:
[06/04/2016 19:17:37]     data/npc/scripts/rebirth.lua:49: in function 'callback'
[06/04/2016 19:17:37]     data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[06/04/2016 19:17:37]     data/npc/scripts/rebirth.lua:23: in function <data/npc/scripts/rebirth.lua:23>
 
Last edited by a moderator:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}

local reborn = 4500 -- free storage
local spellReborn = {
    [1] = 'Reborn1',
    [2] = 'Reborn2',
    [5] = 'Reborn5',
    [7] = 'Reborn7',
    [10] = 'Reborn10',
    [100] = 'Reborn100',
    [250] = 'Reborn250',
    [500] = 'Reborn500'
}
local level = 500
local maxReborns = 10
local toLevel = 8

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 greetCallback(cid)
    Topic[cid] = nil
    return true
end

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    elseif Topic[cid] then
        if msgcontains(msg, 'yes') then
            if getCreatureStorage(cid, reborn) < maxReborns then
                doCreatureSetStorage(cid, reborn, math.max(0, getCreatureStorage(cid, reborn)) + 1)
                for k, v in pairs(spellReborn) do
                    if getCreatureStorage(cid, reborn) == k then
                        doPlayerLearnInstantSpell(cid, v)
                        doSendMagicEffect(getThingPosition(cid), CONST_ME_FIREWORK_RED)
                        break
                    end
                end
            
                player_guid = getPlayerGUID(cid)
                doRemoveCreature(cid)
                db.executeQuery("UPDATE `players` SET `level` = 8 WHERE `id` = " ..player_guid.. ";")
                npcHandler:releaseFocus(cid)
            else
                npcHandler:say('You reached maximum amount of prestiges.', cid)
            end
        else
            npcHandler:say('Maybe next time.', cid)
        end
        Topic[cid] = nil
    else
        if msgcontains(msg, 'prestige') then
            if getPlayerLevel(cid) >= level then
                npcHandler:say('Are you sure that you want to make a prestige?',cid)
                Topic[cid] = 1
            else
                npcHandler:say('You don\'t have enough level. ['..level..']',cid)
                Topic[cid] = nil
            end
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}

local reborn = 4500 -- free storage
local spellReborn = {
    [1] = 'Reborn1',
    [2] = 'Reborn2',
    [5] = 'Reborn5',
    [7] = 'Reborn7',
    [10] = 'Reborn10',
    [100] = 'Reborn100',
    [250] = 'Reborn250',
    [500] = 'Reborn500'
}
local level = 500
local maxReborns = 10
local toLevel = 8

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 greetCallback(cid)
    Topic[cid] = nil
    return true
end

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    elseif Topic[cid] then
        if msgcontains(msg, 'yes') then
            if getCreatureStorage(cid, reborn) < maxReborns then
                doCreatureSetStorage(cid, reborn, math.max(0, getCreatureStorage(cid, reborn)) + 1)
                for k, v in pairs(spellReborn) do
                    if getCreatureStorage(cid, reborn) == k then
                        doPlayerLearnInstantSpell(cid, v)
                        doSendMagicEffect(getThingPosition(cid), CONST_ME_FIREWORK_RED)
                        break
                    end
                end
           
                player_guid = getPlayerGUID(cid)
                doRemoveCreature(cid)
                db.executeQuery("UPDATE `players` SET `level` = 8 WHERE `id` = " ..player_guid.. ";")
                npcHandler:releaseFocus(cid)
            else
                npcHandler:say('You reached maximum amount of prestiges.', cid)
            end
        else
            npcHandler:say('Maybe next time.', cid)
        end
        Topic[cid] = nil
    else
        if msgcontains(msg, 'prestige') then
            if getPlayerLevel(cid) >= level then
                npcHandler:say('Are you sure that you want to make a prestige?',cid)
                Topic[cid] = 1
            else
                npcHandler:say('You don\'t have enough level. ['..level..']',cid)
                Topic[cid] = nil
            end
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Thank you!! It works now :D thank you so much
 
:)

The reason it wasn't working is because you made the NPC release its focus before executing the database line. For future reference
 
Last edited by a moderator:
Bump! This thread is now solved! Now to the last thread I need to fix
Now I just need to figureout how to fix this for my uniserver website
https://otland.net/threads/urgent-uniserver-error.241972/#post-2342937

Before anyone asks I already tried downloading all the microsoft things and even tried factory reseting my other computer and moving the .dll file in system32 and uniserver folder but those did not work.
 
i have this error here can anyone help me?

Code:
data/npc/scripts/rebirth.lua:48: attempt to call field 'executeQuery' (a nil value)
[17:44:28.787] stack traceback:
[17:44:28.787]  data/npc/scripts/rebirth.lua:48: in function 'callback'
[17:44:28.787]  data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[17:44:28.787]  data/npc/scripts/rebirth.lua:23: in function <data/npc/scripts/rebirth.lua:23>


Here is the rebirth file

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}

local reborn = 4500 -- free storage
local spellReborn = {
    [1] = 'Reborn1',
    [2] = 'Reborn2',
    [5] = 'Reborn5',
    [7] = 'Reborn7',
    [10] = 'Reborn10',
    [100] = 'Reborn100',
    [250] = 'Reborn250',
    [500] = 'Reborn500'
}
local level = 717217
local maxReborns = 1000000
local toLevel = 1000

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 greetCallback(cid)
    Topic[cid] = nil
    return true
end

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    elseif Topic[cid] then
        if msgcontains(msg, 'yes') then
            if getCreatureStorage(cid, reborn) < maxReborns then
                doCreatureSetStorage(cid, reborn, math.max(0, getCreatureStorage(cid, reborn)) + 1)
                for k, v in pairs(spellReborn) do
                    if getCreatureStorage(cid, reborn) == k then
                        doPlayerLearnInstantSpell(cid, v)
                        doSendMagicEffect(getThingPosition(cid), CONST_ME_FIREWORK_RED)
                        break
                    end
                end
            
                player_guid = getPlayerGUID(cid)
                doRemoveCreature(cid)
                db.executeQuery("UPDATE `players` SET `level` = 1000 WHERE `id` = " ..player_guid.. ";")
                npcHandler:releaseFocus(cid)
            else
                npcHandler:say('You reached maximum amount of ascension.', cid)
            end
        else
            npcHandler:say('Maybe next time.', cid)
        end
        Topic[cid] = nil
    else
        if msgcontains(msg, 'ascend') then
            if getPlayerLevel(cid) >= level then
                npcHandler:say('Are you sure that you want to make a ascend?',cid)
                Topic[cid] = 1
            else
                npcHandler:say('You don\'t have enough level. ['..level..']',cid)
                Topic[cid] = nil
            end
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top