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

[SQL] Rebirth Querie

ares413

New Member
Joined
Apr 1, 2010
Messages
130
Reaction score
3
i need to know what exact querie to enter, so that my mysql database adds a rebirth table to players, also, how would i update that number everytime a player rebirths?

here's my rebirth script:

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

local reborn = 2500 -- free storage
local spellReborn = {
    [1] = 'Reborn1',
    [5] = 'Reborn5',
    [10] = 'Reborn10',
    [25] = 'Reborn25',
    [50] = 'Reborn50',
    [100] = 'Reborn100',
    [250] = 'Reborn250',
    [500] = 'Reborn500'
}
local level = 5000
local maxReborns = 5000
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=8,experience=4200 WHERE id=' .. g)
            else
                npcHandler:say('You\'ve reached the maximum amount of reborns.', cid)
            end
        else
            npcHandler:say('Maybe next time.', cid)
        end
        Topic[cid] = nil
    else
        if msgcontains(msg, 'reborn') then
            if getPlayerLevel(cid) >= level then
                npcHandler:say('Are you sure that you want to rebirth?',cid)
                Topic[cid] = 1
            else
                npcHandler:say('Your level isn\'t high enough. ['..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())

can anyone help? rep++
 
Add this to lib/050-funtion:
Code:
function getPlayerRebirth(cid)
    local Info = db.getResult("SELECT `Rebirths` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
        if Info:getID() ~= LUA_ERROR then
        local rebs= Info:getDataInt("Rebirths")
        Info:free()
        return rebs
    end
    return LUA_ERROR
end
function doAddRebirth(cid, rebs)
    db.executeQuery("UPDATE `players` SET `Rebirths` = `Rebirths` + " .. rebs .. " WHERE `id` = " .. getPlayerGUID(cid) .. ";")
end
function doRemoveRebirth(cid, rebs)
    db.executeQuery("UPDATE `players` SET `Rebirths` = `Rebirths` - " .. rebs .. " WHERE `id` = " .. getPlayerGUID(cid) .. ";")
end

and use this rebirth script:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}

local reborn = 2500 -- free storage
local spellReborn = {
    [1] = 'Reborn1',
    [5] = 'Reborn5',
    [10] = 'Reborn10',
    [25] = 'Reborn25',
    [50] = 'Reborn50',
    [100] = 'Reborn100',
    [250] = 'Reborn250',
    [500] = 'Reborn500'
}
local level = 5000
local maxReborns = 5000
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)
                local r = "UPDATE `players` SET `Rebirths` = `Rebirths` + " .. rebs .. " WHERE id=" .. getPlayerGUID(cid)
                local rebs = 1
                db.executeQuery(r)
                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=8,experience=4200 WHERE id=' .. g)
            else
                npcHandler:say('You\'ve reached the maximum amount of reborns.', cid)
            end
        else
            npcHandler:say('Maybe next time.', cid)
        end
        Topic[cid] = nil
    else
        if msgcontains(msg, 'reborn') then
            if getPlayerLevel(cid) >= level then
                npcHandler:say('Are you sure that you want to rebirth?',cid)
                Topic[cid] = 1
            else
                npcHandler:say('Your level isn\'t high enough. ['..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())

and execute this in your phpmyadmin:
PHP:
ALTER TABLE `players` ADD `rebirths` INT NOT NULL DEFAULT 0;
 
Back
Top