• 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 0.X Adding some kind of exhaust to the script.

Aurolio

New Member
Joined
Aug 26, 2018
Messages
45
Reaction score
3
Hi all,

I am trying to implement an exhaust for the rebirth system I am working with.
What I would like to do is place an exhaust of 10 hours for players that are rebirth 10 or higher. Now, what I mean by that is:

1. Player has rebirth 10 or higher.
2. He goes to the Rebirth NPC and do a rebirth.
3. After he's done his rebirth, npc puts an exhaust of 10hours on the player so that the next rebirth can be done after 10 hours have passed.

I was trying to do it on my own, but it seems the script is just too complicated for me to edit it in such manner.

Here is the rebirth script I am trying to edit:

Code:
local config = {
    price = 0, -- Price of first rebirth
    priceIncrease = 0, -- Works as 'price' + current rebirths * priceIncrease.
    rebirthLevel = 450, -- Level for first rebirth.
    rebirthIncrease = 0, -- Works as 'rebirthLevel' + current rebirths * rebirthIncrease.
    maxRebirths = 1000, -- Number of times a player can rebirth.
    level = 1000, -- The level the player is set to apon rebirth.
    healthPercent = 0.50, -- 1.00 = 100%.
    health = 100, -- Only used if 'healthPercent' = 0.
    manaPercent = 0.50, -- 1.00 = 100%.
    mana = 100, -- Only used if 'manaPercent' = 0.
    keepSkills = true, -- Wether players keep skills and level apon rebirth.
    skillLevel = 10, -- Only used if 'keepSkills' = false.
    magicLevel = 0, -- Only used if 'keepSkills' = false.
    capacity = 10000, -- The capacity players are set to apon rebirth.
    templePos = {x = 2000, y = 2000, z = 7}, -- The place where players reset to should there town id return 0.
    storage = 85987 -- Player storage rebirth count is kept on.
}
 
local focuses = {}
local function isFocused(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            return true
        end
    end
    return false
end
 
local function addFocus(cid)
    if(not isFocused(cid)) then
        table.insert(focuses, cid)
    end
end
local function removeFocus(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            table.remove(focuses, i)
            break
        end
    end
end
local function lookAtFocus()
    for i, v in pairs(focuses) do
        if(isPlayer(v)) then
            doNpcSetCreatureFocus(v)
            return
        end
    end
    doNpcSetCreatureFocus(0)
end
 
function onCreatureDisappear(cid)
    if(isFocused(cid)) then
        selfSay("Goodbye.")
        removeFocus(cid)
    end
end
 
function onCreatureSay(cid, type, msg)
    if((msg == "hi") and not (isFocused(cid))) then
        selfSay("Welcome, ".. getCreatureName(cid) ..".", cid, true)
        selfSay("I can {rebirth} you!", cid)
        addFocus(cid)
        status = 1
    elseif((isFocused(cid)) and (msg == "rebirth") and (status == 1)) then
        if (getCreatureStorage(cid, config.storage) < config.maxRebirths) then
            storage = getCreatureStorage(cid, config.storage)
            rebirthLevel = config.rebirthLevel + (config.rebirthIncrease * storage)
            if (getPlayerLevel(cid) >= rebirthLevel) then
                money = config.price + (config.priceIncrease * storage)
                if (getPlayerMoney(cid) >= money) then
                    selfSay("I can rebirth you for " .. money .. " gold.", cid)
                    selfSay("Do you want me to rebirth you?", cid)
                    status = 2
                else
                    selfSay("You need at least " .. money .. " gold before you can rebirth.", cid)
                    status = 1
                end
            else
                selfSay("You need to be at least level " .. rebirthLevel .. " before you can rebirth.", cid)
                status = 1
            end
        else
            selfSay("It seems you can not rebirth anymore.", cid)
            status = 1
        end
    elseif((isFocused(cid)) and (msg == "yes") and (status == 2)) then
        selfSay("Ok then i will rebirth you.", cid)
        selfSay("You will now be logged out.", cid)
        doPlayerRemoveMoney(cid, money)
        addEvent(doRebirthPlayer, 0, {cid=cid})
        removeFocus(cid)
    elseif((isFocused(cid)) and (msg == "no") and (status == 2)) then
        selfSay("Maybe one day you will wise up and change your mind!", cid)
        status = 1
    elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
        selfSay("Goodbye!", cid, true)
        removeFocus(cid)
    end
end
 
function onPlayerCloseChannel(cid)
    if(isFocused(cid)) then
        selfSay("Goodbye.")
        removeFocus(cid)
    end
end
 
function onThink()
    for i, focus in pairs(focuses) do
        if(not isCreature(focus)) then
            removeFocus(focus)
        else
            local distance = getDistanceTo(focus) or -1
            if((distance > 4) or (distance == -1)) then
                selfSay("Goodbye.")
                removeFocus(focus)
            end
        end
    end
    lookAtFocus()
end
 
function doRebirthPlayer(cid)
    cid = cid.cid
    if (cid == nil) then
        return true
    end
 
    local guid = getPlayerGUID(cid)
 
    if (config.healthPercent > 0) then
        health = getCreatureMaxHealth(cid) * config.healthPercent
    else
        health = config.health
    end
    if (config.manaPercent > 0) then
        mana = getCreatureMaxMana(cid) * config.manaPercent
    else
        mana = config.mana
    end
    if (getPlayerTown(cid) > 0) then
        pos = getTownTemplePosition(getPlayerTown(cid))
    else
        pos = config.templePos
    end
 
 
    doCreatureSetStorage(cid, config.storage, math.max(0, getCreatureStorage(cid, config.storage)) + 1)
    doRemoveCreature(cid, true)
    db.executeQuery("UPDATE `players` SET level = " .. config.level .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET cap = " .. config.capacity .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET health = " .. health .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET healthmax = " .. health .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET mana = " .. mana .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET manamax = " .. mana .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posx = " .. pos.x .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posy = " .. pos.y .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posz = " .. pos.z .. " WHERE id = " .. guid .. ";")
    
 
    if (not config.keepSkills) then
        db.executeQuery("UPDATE `players` SET maglevel = " .. config.magicLevel .. " WHERE id = " .. guid .. ";")
        db.executeQuery("UPDATE `player_skills` SET value = " .. config.skillLevel .. " WHERE id = " .. guid .. ";")
    end
    return true
end


Thanks in advance.
 
Solution
S
for 'textcool' you'll want to change the math.floor to math.ceil, otherwise when you're less then 1 hour it'll show '0 hours to rebirth again'.
Probably want to place that sentence as an elseif statement as well, so people don't get that message if they type a word incorrectly.
Thank you,
Code:
local config = {
    cooldownStorage = 83934 -- be sure it is not used
    cooldown = 10 * 60 * 60 -- in hours
    price = 0, -- Price of first rebirth
    priceIncrease = 0, -- Works as 'price' + current rebirths * priceIncrease.
    rebirthLevel = 450, -- Level for first rebirth.
    rebirthIncrease = 0, -- Works as 'rebirthLevel' + current rebirths * rebirthIncrease.
    maxRebirths = 1000, -- Number of times a player can rebirth...
try this , sorry if it didn't work iam not very good in 0.X
Code:
local config = {
    cooldownStorage = 83934 -- be sure it is not used
    cooldown = 10 * 60 * 60 -- in hours
    price = 0, -- Price of first rebirth
    priceIncrease = 0, -- Works as 'price' + current rebirths * priceIncrease.
    rebirthLevel = 450, -- Level for first rebirth.
    rebirthIncrease = 0, -- Works as 'rebirthLevel' + current rebirths * rebirthIncrease.
    maxRebirths = 1000, -- Number of times a player can rebirth.
    level = 1000, -- The level the player is set to apon rebirth.
    healthPercent = 0.50, -- 1.00 = 100%.
    health = 100, -- Only used if 'healthPercent' = 0.
    manaPercent = 0.50, -- 1.00 = 100%.
    mana = 100, -- Only used if 'manaPercent' = 0.
    keepSkills = true, -- Wether players keep skills and level apon rebirth.
    skillLevel = 10, -- Only used if 'keepSkills' = false.
    magicLevel = 0, -- Only used if 'keepSkills' = false.
    capacity = 10000, -- The capacity players are set to apon rebirth.
    templePos = {x = 2000, y = 2000, z = 7}, -- The place where players reset to should there town id return 0.
    storage = 85987 -- Player storage rebirth count is kept on.
}
 
local focuses = {}
local function isFocused(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            return true
        end
    end
    return false
end
 
local function addFocus(cid)
    if(not isFocused(cid)) then
        table.insert(focuses, cid)
    end
end
local function removeFocus(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            table.remove(focuses, i)
            break
        end
    end
end
local function lookAtFocus()
    for i, v in pairs(focuses) do
        if(isPlayer(v)) then
            doNpcSetCreatureFocus(v)
            return
        end
    end
    doNpcSetCreatureFocus(0)
end
 
function onCreatureDisappear(cid)
    if(isFocused(cid)) then
        selfSay("Goodbye.")
        removeFocus(cid)
    end
end
 
function onCreatureSay(cid, type, msg)
    if((msg == "hi") and not (isFocused(cid))) then
        selfSay("Welcome, ".. getCreatureName(cid) ..".", cid, true)
        selfSay("I can {rebirth} you!", cid)
        addFocus(cid)
        status = 1
    elseif((isFocused(cid)) and (msg == "rebirth") and (status == 1)) then
        if (getCreatureStorage(cid, config.storage) < config.maxRebirths) then
            storage = getCreatureStorage(cid, config.storage)
            rebirthLevel = config.rebirthLevel + (config.rebirthIncrease * storage)
            if (getPlayerLevel(cid) >= rebirthLevel) then
                money = config.price + (config.priceIncrease * storage)
                if (getPlayerMoney(cid) >= money) then
                    selfSay("I can rebirth you for " .. money .. " gold.", cid)
                    selfSay("Do you want me to rebirth you?", cid)
                    status = 2
                else
                    selfSay("You need at least " .. money .. " gold before you can rebirth.", cid)
                    status = 1
                end
            else
                selfSay("You need to be at least level " .. rebirthLevel .. " before you can rebirth.", cid)
                status = 1
            end
        else
            selfSay("It seems you can not rebirth anymore.", cid)
            status = 1
        end
    elseif((isFocused(cid)) and (msg == "yes") and (status == 2)) and getCreatureStorage(cid, cooldownStorage) <= os.time() then
        setPlayerStorageValue(cid, cooldownStorage, os.time() + cooldown)
        selfSay("Ok then i will rebirth you.", cid)
        selfSay("You will now be logged out.", cid)
        doPlayerRemoveMoney(cid, money)
        addEvent(doRebirthPlayer, 0, {cid=cid})
        removeFocus(cid)
        else
        local textcool = math.floor((getCreatureStorageValue(cid, cooldownStorage) - os.time()) / 3600)
        selfSay("You have to wait for " .. textcool .. " hours to rebirth again", cid)
    elseif((isFocused(cid)) and (msg == "no") and (status == 2)) then
        selfSay("Maybe one day you will wise up and change your mind!", cid)
        status = 1
    elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
        selfSay("Goodbye!", cid, true)
        removeFocus(cid)
    end
end
 
function onPlayerCloseChannel(cid)
    if(isFocused(cid)) then
        selfSay("Goodbye.")
        removeFocus(cid)
    end
end
 
function onThink()
    for i, focus in pairs(focuses) do
        if(not isCreature(focus)) then
            removeFocus(focus)
        else
            local distance = getDistanceTo(focus) or -1
            if((distance > 4) or (distance == -1)) then
                selfSay("Goodbye.")
                removeFocus(focus)
            end
        end
    end
    lookAtFocus()
end
 
function doRebirthPlayer(cid)
    cid = cid.cid
    if (cid == nil) then
        return true
    end
 
    local guid = getPlayerGUID(cid)
 
    if (config.healthPercent > 0) then
        health = getCreatureMaxHealth(cid) * config.healthPercent
    else
        health = config.health
    end
    if (config.manaPercent > 0) then
        mana = getCreatureMaxMana(cid) * config.manaPercent
    else
        mana = config.mana
    end
    if (getPlayerTown(cid) > 0) then
        pos = getTownTemplePosition(getPlayerTown(cid))
    else
        pos = config.templePos
    end
 
 
    doCreatureSetStorage(cid, config.storage, math.max(0, getCreatureStorage(cid, config.storage)) + 1)
    doRemoveCreature(cid, true)
    db.executeQuery("UPDATE `players` SET level = " .. config.level .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET cap = " .. config.capacity .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET health = " .. health .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET healthmax = " .. health .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET mana = " .. mana .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET manamax = " .. mana .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posx = " .. pos.x .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posy = " .. pos.y .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posz = " .. pos.z .. " WHERE id = " .. guid .. ";")
    
 
    if (not config.keepSkills) then
        db.executeQuery("UPDATE `players` SET maglevel = " .. config.magicLevel .. " WHERE id = " .. guid .. ";")
        db.executeQuery("UPDATE `player_skills` SET value = " .. config.skillLevel .. " WHERE id = " .. guid .. ";")
    end
    return true
end
 
That's the error I get:

[11:53:31.767] [Error - LuaInterface::loadFile] data/npc/scripts/rebirth.lua:100: 'end' expected (to close 'if' at line 63) near 'elseif'
[11:53:31.767] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scripts/rebirth.lua
[11:53:31.768] data/npc/scripts/rebirth.lua:100: 'end' expected (to close 'if' at line 63) near 'elseif'


Also, there isn't anything about this script running when player is rebirth 10 or above (but this one should be easy enough to add). Thanks.
 
Last edited:
Code:
local config = {
    cooldownStorage = 83934 -- be sure it is not used
    cooldown = 10 * 60 * 60 -- in hours
    price = 0, -- Price of first rebirth
    priceIncrease = 0, -- Works as 'price' + current rebirths * priceIncrease.
    rebirthLevel = 450, -- Level for first rebirth.
    rebirthIncrease = 0, -- Works as 'rebirthLevel' + current rebirths * rebirthIncrease.
    maxRebirths = 1000, -- Number of times a player can rebirth.
    level = 1000, -- The level the player is set to apon rebirth.
    healthPercent = 0.50, -- 1.00 = 100%.
    health = 100, -- Only used if 'healthPercent' = 0.
    manaPercent = 0.50, -- 1.00 = 100%.
    mana = 100, -- Only used if 'manaPercent' = 0.
    keepSkills = true, -- Wether players keep skills and level apon rebirth.
    skillLevel = 10, -- Only used if 'keepSkills' = false.
    magicLevel = 0, -- Only used if 'keepSkills' = false.
    capacity = 10000, -- The capacity players are set to apon rebirth.
    templePos = {x = 2000, y = 2000, z = 7}, -- The place where players reset to should there town id return 0.
    storage = 85987 -- Player storage rebirth count is kept on.
}
 
local focuses = {}
local function isFocused(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            return true
        end
    end
    return false
end
 
local function addFocus(cid)
    if(not isFocused(cid)) then
        table.insert(focuses, cid)
    end
end
local function removeFocus(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            table.remove(focuses, i)
            break
        end
    end
end
local function lookAtFocus()
    for i, v in pairs(focuses) do
        if(isPlayer(v)) then
            doNpcSetCreatureFocus(v)
            return
        end
    end
    doNpcSetCreatureFocus(0)
end
 
function onCreatureDisappear(cid)
    if(isFocused(cid)) then
        selfSay("Goodbye.")
        removeFocus(cid)
    end
end
 
function onCreatureSay(cid, type, msg)
    if((msg == "hi") and not (isFocused(cid))) then
        selfSay("Welcome, ".. getCreatureName(cid) ..".", cid, true)
        selfSay("I can {rebirth} you!", cid)
        addFocus(cid)
        status = 1
    elseif((isFocused(cid)) and (msg == "rebirth") and (status == 1)) then
        if (getCreatureStorage(cid, config.storage) < config.maxRebirths) then
            storage = getCreatureStorage(cid, config.storage)
            rebirthLevel = config.rebirthLevel + (config.rebirthIncrease * storage)
            if (getPlayerLevel(cid) >= rebirthLevel) then
                money = config.price + (config.priceIncrease * storage)
                if (getPlayerMoney(cid) >= money) then
                    selfSay("I can rebirth you for " .. money .. " gold.", cid)
                    selfSay("Do you want me to rebirth you?", cid)
                    status = 2
                else
                    selfSay("You need at least " .. money .. " gold before you can rebirth.", cid)
                    status = 1
                end
            else
                selfSay("You need to be at least level " .. rebirthLevel .. " before you can rebirth.", cid)
                status = 1
            end
        else
            selfSay("It seems you can not rebirth anymore.", cid)
            status = 1
        end
    elseif((isFocused(cid)) and (msg == "yes") and (status == 2)) and getCreatureStorage(cid, cooldownStorage) <= os.time() then
        if (getCreatureStorage(cid, config.storage) < 10) then
        setCreatureStorageValue(cid, config.cooldownStorage, os.time() + cooldown)
        selfSay("Ok then i will rebirth you.", cid)
        selfSay("You will now be logged out.", cid)
        doPlayerRemoveMoney(cid, money)
        addEvent(doRebirthPlayer, 0, {cid=cid})
        removeFocus(cid)
        end
        selfSay("Ok then i will rebirth you.", cid)
        selfSay("You will now be logged out.", cid)
        doPlayerRemoveMoney(cid, money)
        addEvent(doRebirthPlayer, 0, {cid=cid})
        removeFocus(cid)
    elseif((isFocused(cid)) and (msg == "no") and (status == 2)) then
        selfSay("Maybe one day you will wise up and change your mind!", cid)
        status = 1
    elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
        selfSay("Goodbye!", cid, true)
        removeFocus(cid)
        else
        local textcool = math.floor((getCreatureStorageValue(cid, cooldownStorage) - os.time()) / 3600)
        selfSay("You have to wait for " .. textcool .. " hours to rebirth again", cid)
    end
end
 
function onPlayerCloseChannel(cid)
    if(isFocused(cid)) then
        selfSay("Goodbye.")
        removeFocus(cid)
    end
end
 
function onThink()
    for i, focus in pairs(focuses) do
        if(not isCreature(focus)) then
            removeFocus(focus)
        else
            local distance = getDistanceTo(focus) or -1
            if((distance > 4) or (distance == -1)) then
                selfSay("Goodbye.")
                removeFocus(focus)
            end
        end
    end
    lookAtFocus()
end
 
function doRebirthPlayer(cid)
    cid = cid.cid
    if (cid == nil) then
        return true
    end
 
    local guid = getPlayerGUID(cid)
 
    if (config.healthPercent > 0) then
        health = getCreatureMaxHealth(cid) * config.healthPercent
    else
        health = config.health
    end
    if (config.manaPercent > 0) then
        mana = getCreatureMaxMana(cid) * config.manaPercent
    else
        mana = config.mana
    end
    if (getPlayerTown(cid) > 0) then
        pos = getTownTemplePosition(getPlayerTown(cid))
    else
        pos = config.templePos
    end
 
 
    doCreatureSetStorage(cid, config.storage, math.max(0, getCreatureStorage(cid, config.storage)) + 1)
    doRemoveCreature(cid, true)
    db.executeQuery("UPDATE `players` SET level = " .. config.level .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET cap = " .. config.capacity .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET health = " .. health .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET healthmax = " .. health .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET mana = " .. mana .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET manamax = " .. mana .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posx = " .. pos.x .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posy = " .. pos.y .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posz = " .. pos.z .. " WHERE id = " .. guid .. ";")
    
 
    if (not config.keepSkills) then
        db.executeQuery("UPDATE `players` SET maglevel = " .. config.magicLevel .. " WHERE id = " .. guid .. ";")
        db.executeQuery("UPDATE `player_skills` SET value = " .. config.skillLevel .. " WHERE id = " .. guid .. ";")
    end
    return true
end
 
Last edited by a moderator:
for 'textcool' you'll want to change the math.floor to math.ceil, otherwise when you're less then 1 hour it'll show '0 hours to rebirth again'.
Probably want to place that sentence as an elseif statement as well, so people don't get that message if they type a word incorrectly.
 
for 'textcool' you'll want to change the math.floor to math.ceil, otherwise when you're less then 1 hour it'll show '0 hours to rebirth again'.
Probably want to place that sentence as an elseif statement as well, so people don't get that message if they type a word incorrectly.
Thank you,
Code:
local config = {
    cooldownStorage = 83934 -- be sure it is not used
    cooldown = 10 * 60 * 60 -- in hours
    price = 0, -- Price of first rebirth
    priceIncrease = 0, -- Works as 'price' + current rebirths * priceIncrease.
    rebirthLevel = 450, -- Level for first rebirth.
    rebirthIncrease = 0, -- Works as 'rebirthLevel' + current rebirths * rebirthIncrease.
    maxRebirths = 1000, -- Number of times a player can rebirth.
    level = 1000, -- The level the player is set to apon rebirth.
    healthPercent = 0.50, -- 1.00 = 100%.
    health = 100, -- Only used if 'healthPercent' = 0.
    manaPercent = 0.50, -- 1.00 = 100%.
    mana = 100, -- Only used if 'manaPercent' = 0.
    keepSkills = true, -- Wether players keep skills and level apon rebirth.
    skillLevel = 10, -- Only used if 'keepSkills' = false.
    magicLevel = 0, -- Only used if 'keepSkills' = false.
    capacity = 10000, -- The capacity players are set to apon rebirth.
    templePos = {x = 2000, y = 2000, z = 7}, -- The place where players reset to should there town id return 0.
    storage = 85987 -- Player storage rebirth count is kept on.
}

local focuses = {}
local function isFocused(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            return true
        end
    end
    return false
end

local function addFocus(cid)
    if(not isFocused(cid)) then
        table.insert(focuses, cid)
    end
end
local function removeFocus(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            table.remove(focuses, i)
            break
        end
    end
end
local function lookAtFocus()
    for i, v in pairs(focuses) do
        if(isPlayer(v)) then
            doNpcSetCreatureFocus(v)
            return
        end
    end
    doNpcSetCreatureFocus(0)
end

function onCreatureDisappear(cid)
    if(isFocused(cid)) then
        selfSay("Goodbye.")
        removeFocus(cid)
    end
end

function onCreatureSay(cid, type, msg)
    if((msg == "hi") and not (isFocused(cid))) then
        selfSay("Welcome, ".. getCreatureName(cid) ..".", cid, true)
        selfSay("I can {rebirth} you!", cid)
        addFocus(cid)
        status = 1
    elseif((isFocused(cid)) and (msg == "rebirth") and (status == 1)) then
        if (getCreatureStorage(cid, config.storage) < config.maxRebirths) then
            storage = getCreatureStorage(cid, config.storage)
            rebirthLevel = config.rebirthLevel + (config.rebirthIncrease * storage)
            if (getPlayerLevel(cid) >= rebirthLevel) then
                money = config.price + (config.priceIncrease * storage)
                if (getPlayerMoney(cid) >= money) then
                    selfSay("I can rebirth you for " .. money .. " gold.", cid)
                    selfSay("Do you want me to rebirth you?", cid)
                    status = 2
                else
                    selfSay("You need at least " .. money .. " gold before you can rebirth.", cid)
                    status = 1
                end
            else
                selfSay("You need to be at least level " .. rebirthLevel .. " before you can rebirth.", cid)
                status = 1
            end
        else
            selfSay("It seems you can not rebirth anymore.", cid)
            status = 1
        end
    elseif((isFocused(cid)) and (msg == "yes") and (status == 2)) and getCreatureStorage(cid, cooldownStorage) <= os.time() then
        if (getCreatureStorage(cid, config.storage) < 10) then
        setCreatureStorageValue(cid, config.cooldownStorage, os.time() + cooldown)
        selfSay("Ok then i will rebirth you.", cid)
        selfSay("You will now be logged out.", cid)
        doPlayerRemoveMoney(cid, money)
        addEvent(doRebirthPlayer, 0, {cid=cid})
        removeFocus(cid)
        end
        selfSay("Ok then i will rebirth you.", cid)
        selfSay("You will now be logged out.", cid)
        doPlayerRemoveMoney(cid, money)
        addEvent(doRebirthPlayer, 0, {cid=cid})
        removeFocus(cid)
    elseif((isFocused(cid)) and (msg == "no") and (status == 2)) then
        selfSay("Maybe one day you will wise up and change your mind!", cid)
        status = 1
    elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
        selfSay("Goodbye!", cid, true)
        removeFocus(cid)
        elseif getCreatureStorage(cid, cooldownStorage) >= os.time() then
        local textcool = math.ceil((getCreatureStorageValue(cid, cooldownStorage) - os.time()) / 3600)
        selfSay("You have to wait for " .. textcool .. " hours to rebirth again", cid)
    end
end

function onPlayerCloseChannel(cid)
    if(isFocused(cid)) then
        selfSay("Goodbye.")
        removeFocus(cid)
    end
end

function onThink()
    for i, focus in pairs(focuses) do
        if(not isCreature(focus)) then
            removeFocus(focus)
        else
            local distance = getDistanceTo(focus) or -1
            if((distance > 4) or (distance == -1)) then
                selfSay("Goodbye.")
                removeFocus(focus)
            end
        end
    end
    lookAtFocus()
end

function doRebirthPlayer(cid)
    cid = cid.cid
    if (cid == nil) then
        return true
    end

    local guid = getPlayerGUID(cid)

    if (config.healthPercent > 0) then
        health = getCreatureMaxHealth(cid) * config.healthPercent
    else
        health = config.health
    end
    if (config.manaPercent > 0) then
        mana = getCreatureMaxMana(cid) * config.manaPercent
    else
        mana = config.mana
    end
    if (getPlayerTown(cid) > 0) then
        pos = getTownTemplePosition(getPlayerTown(cid))
    else
        pos = config.templePos
    end


    doCreatureSetStorage(cid, config.storage, math.max(0, getCreatureStorage(cid, config.storage)) + 1)
    doRemoveCreature(cid, true)
    db.executeQuery("UPDATE `players` SET level = " .. config.level .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET cap = " .. config.capacity .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET health = " .. health .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET healthmax = " .. health .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET mana = " .. mana .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET manamax = " .. mana .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posx = " .. pos.x .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posy = " .. pos.y .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posz = " .. pos.z .. " WHERE id = " .. guid .. ";")
   

    if (not config.keepSkills) then
        db.executeQuery("UPDATE `players` SET maglevel = " .. config.magicLevel .. " WHERE id = " .. guid .. ";")
        db.executeQuery("UPDATE `player_skills` SET value = " .. config.skillLevel .. " WHERE id = " .. guid .. ";")
    end
    return true
end

-- little typo removed
 
Last edited by a moderator:
Solution
Hi guys, sorry for late reply. I've been working all day.

Here is the error I get now:

[23:45:38.812] [Error - NpcScript Interface]
[23:45:38.814] data/npc/scripts/rebirth.lua:eek:nCreatureSay
[23:45:38.814] Description:
[23:45:38.815] data/npc/scripts/rebirth.lua:92: attempt to perform arithmetic on global 'cooldown' (a nil value)
[23:45:38.816] stack traceback:
[23:45:38.816] data/npc/scripts/rebirth.lua:92: in function <data/npc/scripts/rebirth.lua:62>

Thanks for your help!
 
Okay I fixed it, that's the code now:

Code:
local config = {
    cooldownStorage = 83934, -- be sure it is not used
    cooldown = 10 * 60 * 60, -- in hours
    price = 0, -- Price of first rebirth
    priceIncrease = 0, -- Works as 'price' + current rebirths * priceIncrease.
    rebirthLevel = 450, -- Level for first rebirth.
    rebirthIncrease = 0, -- Works as 'rebirthLevel' + current rebirths * rebirthIncrease.
    maxRebirths = 1000, -- Number of times a player can rebirth.
    level = 1000, -- The level the player is set to apon rebirth.
    healthPercent = 0.50, -- 1.00 = 100%.
    health = 100, -- Only used if 'healthPercent' = 0.
    manaPercent = 0.50, -- 1.00 = 100%.
    mana = 100, -- Only used if 'manaPercent' = 0.
    keepSkills = true, -- Wether players keep skills and level apon rebirth.
    skillLevel = 10, -- Only used if 'keepSkills' = false.
    magicLevel = 0, -- Only used if 'keepSkills' = false.
    capacity = 10000, -- The capacity players are set to apon rebirth.
    templePos = {x = 2000, y = 2000, z = 7}, -- The place where players reset to should there town id return 0.
    storage = 85987 -- Player storage rebirth count is kept on.
}

local focuses = {}
local function isFocused(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            return true
        end
    end
    return false
end

local function addFocus(cid)
    if(not isFocused(cid)) then
        table.insert(focuses, cid)
    end
end
local function removeFocus(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            table.remove(focuses, i)
            break
        end
    end
end
local function lookAtFocus()
    for i, v in pairs(focuses) do
        if(isPlayer(v)) then
            doNpcSetCreatureFocus(v)
            return
        end
    end
    doNpcSetCreatureFocus(0)
end

function onCreatureDisappear(cid)
    if(isFocused(cid)) then
        selfSay("Goodbye.")
        removeFocus(cid)
    end
end

function onCreatureSay(cid, type, msg)
    if((msg == "hi") and not (isFocused(cid))) then
        selfSay("Welcome, ".. getCreatureName(cid) ..".", cid, true)
        selfSay("I can {rebirth} you!", cid)
        addFocus(cid)
        status = 1
    elseif((isFocused(cid)) and (msg == "rebirth") and (status == 1)) then
        if (getCreatureStorage(cid, config.storage) < config.maxRebirths) then
            storage = getCreatureStorage(cid, config.storage)
            rebirthLevel = config.rebirthLevel + (config.rebirthIncrease * storage)
            if (getPlayerLevel(cid) >= rebirthLevel) then
                money = config.price + (config.priceIncrease * storage)
                if (getPlayerMoney(cid) >= money) then
                    selfSay("I can rebirth you for " .. money .. " gold.", cid)
                    selfSay("Do you want me to rebirth you?", cid)
                    status = 2
                else
                    selfSay("You need at least " .. money .. " gold before you can rebirth.", cid)
                    status = 1
                end
            else
                selfSay("You need to be at least level " .. rebirthLevel .. " before you can rebirth.", cid)
                status = 1
            end
        else
            selfSay("It seems you can not rebirth anymore.", cid)
            status = 1
        end
    elseif((isFocused(cid)) and (msg == "yes") and (status == 2)) and getCreatureStorage(cid, config.cooldownStorage) <= os.time() then
        if (getCreatureStorage(cid, config.storage) >= 10) then
        doCreatureSetStorage(cid, config.cooldownStorage, os.time() + config.cooldown)
        selfSay("Ok then i will rebirth you.", cid)
        selfSay("You will now be logged out.", cid)
        doPlayerRemoveMoney(cid, money)
        addEvent(doRebirthPlayer, 0, {cid=cid})
        removeFocus(cid)
        end
        selfSay("Ok then i will rebirth you.", cid)
        selfSay("You will now be logged out.", cid)
        doPlayerRemoveMoney(cid, money)
        addEvent(doRebirthPlayer, 0, {cid=cid})
        removeFocus(cid)
    elseif((isFocused(cid)) and (msg == "no") and (status == 2)) then
        selfSay("Maybe one day you will wise up and change your mind!", cid)
        status = 1
    elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
        selfSay("Goodbye!", cid, true)
        removeFocus(cid)
        elseif getCreatureStorage(cid, config.cooldownStorage) >= os.time() then
        local textcool = math.ceil((getCreatureStorage(cid, config.cooldownStorage) - os.time()) / 3600)
        selfSay("You have to wait for " .. textcool .. " hours to rebirth again", cid)
    end
end

function onPlayerCloseChannel(cid)
    if(isFocused(cid)) then
        selfSay("Goodbye.")
        removeFocus(cid)
    end
end

function onThink()
    for i, focus in pairs(focuses) do
        if(not isCreature(focus)) then
            removeFocus(focus)
        else
            local distance = getDistanceTo(focus) or -1
            if((distance > 4) or (distance == -1)) then
                selfSay("Goodbye.")
                removeFocus(focus)
            end
        end
    end
    lookAtFocus()
end

function doRebirthPlayer(cid)
    cid = cid.cid
    if (cid == nil) then
        return true
    end

    local guid = getPlayerGUID(cid)

    if (config.healthPercent > 0) then
        health = getCreatureMaxHealth(cid) * config.healthPercent
    else
        health = config.health
    end
    if (config.manaPercent > 0) then
        mana = getCreatureMaxMana(cid) * config.manaPercent
    else
        mana = config.mana
    end
    if (getPlayerTown(cid) > 0) then
        pos = getTownTemplePosition(getPlayerTown(cid))
    else
        pos = config.templePos
    end


    doCreatureSetStorage(cid, config.storage, math.max(0, getCreatureStorage(cid, config.storage)) + 1)
    doRemoveCreature(cid, true)
    db.executeQuery("UPDATE `players` SET level = " .. config.level .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET cap = " .. config.capacity .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET health = " .. health .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET healthmax = " .. health .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET mana = " .. mana .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET manamax = " .. mana .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posx = " .. pos.x .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posy = " .. pos.y .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posz = " .. pos.z .. " WHERE id = " .. guid .. ";")
  

    if (not config.keepSkills) then
        db.executeQuery("UPDATE `players` SET maglevel = " .. config.magicLevel .. " WHERE id = " .. guid .. ";")
        db.executeQuery("UPDATE `player_skills` SET value = " .. config.skillLevel .. " WHERE id = " .. guid .. ";")
    end
    return true
end


The script works, it puts cooldown on, but now I get this error:

23:57:51.556] [Error - NpcScript Interface]
[23:57:51.557] In a timer event called from:
[23:57:51.558] data/npc/scripts/rebirth.lua:eek:nCreatureSay
[23:57:51.558] Description:
[23:57:51.558] (internalGetPlayerInfo) Player not found when requesting player info #18

[23:57:51.559] [Error - NpcScript Interface]
[23:57:51.559] In a timer event called from:
[23:57:51.560] data/npc/scripts/rebirth.lua:eek:nCreatureSay
[23:57:51.560] Description:
[23:57:51.561] (luaGetCreatureMaxHealth) Creature not found

[23:57:51.561] [Error - NpcScript Interface]
[23:57:51.561] In a timer event called from:
[23:57:51.562] data/npc/scripts/rebirth.lua:eek:nCreatureSay
[23:57:51.562] Description:
[23:57:51.562] data/npc/scripts/rebirth.lua:147: attempt to perform arithmetic on a boolean value
[23:57:51.563] stack traceback:
[23:57:51.563] data/npc/scripts/rebirth.lua:147: in function <data/npc/scripts/rebirth.lua:138>
 
Okay I fixed it, that's the code now:

Code:
local config = {
    cooldownStorage = 83934, -- be sure it is not used
    cooldown = 10 * 60 * 60, -- in hours
    price = 0, -- Price of first rebirth
    priceIncrease = 0, -- Works as 'price' + current rebirths * priceIncrease.
    rebirthLevel = 450, -- Level for first rebirth.
    rebirthIncrease = 0, -- Works as 'rebirthLevel' + current rebirths * rebirthIncrease.
    maxRebirths = 1000, -- Number of times a player can rebirth.
    level = 1000, -- The level the player is set to apon rebirth.
    healthPercent = 0.50, -- 1.00 = 100%.
    health = 100, -- Only used if 'healthPercent' = 0.
    manaPercent = 0.50, -- 1.00 = 100%.
    mana = 100, -- Only used if 'manaPercent' = 0.
    keepSkills = true, -- Wether players keep skills and level apon rebirth.
    skillLevel = 10, -- Only used if 'keepSkills' = false.
    magicLevel = 0, -- Only used if 'keepSkills' = false.
    capacity = 10000, -- The capacity players are set to apon rebirth.
    templePos = {x = 2000, y = 2000, z = 7}, -- The place where players reset to should there town id return 0.
    storage = 85987 -- Player storage rebirth count is kept on.
}

local focuses = {}
local function isFocused(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            return true
        end
    end
    return false
end

local function addFocus(cid)
    if(not isFocused(cid)) then
        table.insert(focuses, cid)
    end
end
local function removeFocus(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            table.remove(focuses, i)
            break
        end
    end
end
local function lookAtFocus()
    for i, v in pairs(focuses) do
        if(isPlayer(v)) then
            doNpcSetCreatureFocus(v)
            return
        end
    end
    doNpcSetCreatureFocus(0)
end

function onCreatureDisappear(cid)
    if(isFocused(cid)) then
        selfSay("Goodbye.")
        removeFocus(cid)
    end
end

function onCreatureSay(cid, type, msg)
    if((msg == "hi") and not (isFocused(cid))) then
        selfSay("Welcome, ".. getCreatureName(cid) ..".", cid, true)
        selfSay("I can {rebirth} you!", cid)
        addFocus(cid)
        status = 1
    elseif((isFocused(cid)) and (msg == "rebirth") and (status == 1)) then
        if (getCreatureStorage(cid, config.storage) < config.maxRebirths) then
            storage = getCreatureStorage(cid, config.storage)
            rebirthLevel = config.rebirthLevel + (config.rebirthIncrease * storage)
            if (getPlayerLevel(cid) >= rebirthLevel) then
                money = config.price + (config.priceIncrease * storage)
                if (getPlayerMoney(cid) >= money) then
                    selfSay("I can rebirth you for " .. money .. " gold.", cid)
                    selfSay("Do you want me to rebirth you?", cid)
                    status = 2
                else
                    selfSay("You need at least " .. money .. " gold before you can rebirth.", cid)
                    status = 1
                end
            else
                selfSay("You need to be at least level " .. rebirthLevel .. " before you can rebirth.", cid)
                status = 1
            end
        else
            selfSay("It seems you can not rebirth anymore.", cid)
            status = 1
        end
    elseif((isFocused(cid)) and (msg == "yes") and (status == 2)) and getCreatureStorage(cid, config.cooldownStorage) <= os.time() then
        if (getCreatureStorage(cid, config.storage) >= 10) then
        doCreatureSetStorage(cid, config.cooldownStorage, os.time() + config.cooldown)
        selfSay("Ok then i will rebirth you.", cid)
        selfSay("You will now be logged out.", cid)
        doPlayerRemoveMoney(cid, money)
        addEvent(doRebirthPlayer, 0, {cid=cid})
        removeFocus(cid)
        end
        selfSay("Ok then i will rebirth you.", cid)
        selfSay("You will now be logged out.", cid)
        doPlayerRemoveMoney(cid, money)
        addEvent(doRebirthPlayer, 0, {cid=cid})
        removeFocus(cid)
    elseif((isFocused(cid)) and (msg == "no") and (status == 2)) then
        selfSay("Maybe one day you will wise up and change your mind!", cid)
        status = 1
    elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
        selfSay("Goodbye!", cid, true)
        removeFocus(cid)
        elseif getCreatureStorage(cid, config.cooldownStorage) >= os.time() then
        local textcool = math.ceil((getCreatureStorage(cid, config.cooldownStorage) - os.time()) / 3600)
        selfSay("You have to wait for " .. textcool .. " hours to rebirth again", cid)
    end
end

function onPlayerCloseChannel(cid)
    if(isFocused(cid)) then
        selfSay("Goodbye.")
        removeFocus(cid)
    end
end

function onThink()
    for i, focus in pairs(focuses) do
        if(not isCreature(focus)) then
            removeFocus(focus)
        else
            local distance = getDistanceTo(focus) or -1
            if((distance > 4) or (distance == -1)) then
                selfSay("Goodbye.")
                removeFocus(focus)
            end
        end
    end
    lookAtFocus()
end

function doRebirthPlayer(cid)
    cid = cid.cid
    if (cid == nil) then
        return true
    end

    local guid = getPlayerGUID(cid)

    if (config.healthPercent > 0) then
        health = getCreatureMaxHealth(cid) * config.healthPercent
    else
        health = config.health
    end
    if (config.manaPercent > 0) then
        mana = getCreatureMaxMana(cid) * config.manaPercent
    else
        mana = config.mana
    end
    if (getPlayerTown(cid) > 0) then
        pos = getTownTemplePosition(getPlayerTown(cid))
    else
        pos = config.templePos
    end


    doCreatureSetStorage(cid, config.storage, math.max(0, getCreatureStorage(cid, config.storage)) + 1)
    doRemoveCreature(cid, true)
    db.executeQuery("UPDATE `players` SET level = " .. config.level .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET cap = " .. config.capacity .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET health = " .. health .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET healthmax = " .. health .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET mana = " .. mana .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET manamax = " .. mana .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posx = " .. pos.x .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posy = " .. pos.y .. " WHERE id = " .. guid .. ";")
    db.executeQuery("UPDATE `players` SET posz = " .. pos.z .. " WHERE id = " .. guid .. ";")
  

    if (not config.keepSkills) then
        db.executeQuery("UPDATE `players` SET maglevel = " .. config.magicLevel .. " WHERE id = " .. guid .. ";")
        db.executeQuery("UPDATE `player_skills` SET value = " .. config.skillLevel .. " WHERE id = " .. guid .. ";")
    end
    return true
end


The script works, it puts cooldown on, but now I get this error:

23:57:51.556] [Error - NpcScript Interface]
[23:57:51.557] In a timer event called from:
[23:57:51.558] data/npc/scripts/rebirth.lua:eek:nCreatureSay
[23:57:51.558] Description:
[23:57:51.558] (internalGetPlayerInfo) Player not found when requesting player info #18

[23:57:51.559] [Error - NpcScript Interface]
[23:57:51.559] In a timer event called from:
[23:57:51.560] data/npc/scripts/rebirth.lua:eek:nCreatureSay
[23:57:51.560] Description:
[23:57:51.561] (luaGetCreatureMaxHealth) Creature not found

[23:57:51.561] [Error - NpcScript Interface]
[23:57:51.561] In a timer event called from:
[23:57:51.562] data/npc/scripts/rebirth.lua:eek:nCreatureSay
[23:57:51.562] Description:
[23:57:51.562] data/npc/scripts/rebirth.lua:147: attempt to perform arithmetic on a boolean value
[23:57:51.563] stack traceback:
[23:57:51.563] data/npc/scripts/rebirth.lua:147: in function <data/npc/scripts/rebirth.lua:138>
Try this.
I changed this
Lua:
addEvent(doRebirthPlayer, 0, {cid=cid})
.
.
.
cid = cid.cid
if (cid == nil) then
    return true
end
to this
Lua:
addEvent(doRebirthPlayer, 0, cid)
.
.
.
if isPlayer(cid) then
.
.
end
Lua:
local config = {
	cooldownStorage = 83934, -- be sure it is not used
	cooldown = 10 * 60 * 60, -- in hours
	price = 0, -- Price of first rebirth
	priceIncrease = 0, -- Works as 'price' + current rebirths * priceIncrease.
	rebirthLevel = 450, -- Level for first rebirth.
	rebirthIncrease = 0, -- Works as 'rebirthLevel' + current rebirths * rebirthIncrease.
	maxRebirths = 1000, -- Number of times a player can rebirth.
	level = 1000, -- The level the player is set to apon rebirth.
	healthPercent = 0.50, -- 1.00 = 100%.
	health = 100, -- Only used if 'healthPercent' = 0.
	manaPercent = 0.50, -- 1.00 = 100%.
	mana = 100, -- Only used if 'manaPercent' = 0.
	keepSkills = true, -- Wether players keep skills and level apon rebirth.
	skillLevel = 10, -- Only used if 'keepSkills' = false.
	magicLevel = 0, -- Only used if 'keepSkills' = false.
	capacity = 10000, -- The capacity players are set to apon rebirth.
	templePos = {x = 2000, y = 2000, z = 7}, -- The place where players reset to should there town id return 0.
	storage = 85987 -- Player storage rebirth count is kept on.
}

local focuses = {}
local function isFocused(cid)
	for i, v in pairs(focuses) do
		if(v == cid) then
			return true
		end
	end
	return false
end

local function addFocus(cid)
	if(not isFocused(cid)) then
		table.insert(focuses, cid)
	end
end
local function removeFocus(cid)
	for i, v in pairs(focuses) do
		if(v == cid) then
			table.remove(focuses, i)
			break
		end
	end
end
local function lookAtFocus()
	for i, v in pairs(focuses) do
		if(isPlayer(v)) then
			doNpcSetCreatureFocus(v)
			return
		end
	end
	doNpcSetCreatureFocus(0)
end

function onCreatureDisappear(cid)
	if(isFocused(cid)) then
		selfSay("Goodbye.")
		removeFocus(cid)
	end
end

function onCreatureSay(cid, type, msg)
	if((msg == "hi") and not (isFocused(cid))) then
		selfSay("Welcome, ".. getCreatureName(cid) ..".", cid, true)
		selfSay("I can {rebirth} you!", cid)
		addFocus(cid)
		status = 1
	elseif((isFocused(cid)) and (msg == "rebirth") and (status == 1)) then
		if (getCreatureStorage(cid, config.storage) < config.maxRebirths) then
			storage = getCreatureStorage(cid, config.storage)
			rebirthLevel = config.rebirthLevel + (config.rebirthIncrease * storage)
			if (getPlayerLevel(cid) >= rebirthLevel) then
				money = config.price + (config.priceIncrease * storage)
				if (getPlayerMoney(cid) >= money) then
					selfSay("I can rebirth you for " .. money .. " gold.", cid)
					selfSay("Do you want me to rebirth you?", cid)
					status = 2
				else
					selfSay("You need at least " .. money .. " gold before you can rebirth.", cid)
					status = 1
				end
			else
				selfSay("You need to be at least level " .. rebirthLevel .. " before you can rebirth.", cid)
				status = 1
			end
		else
			selfSay("It seems you can not rebirth anymore.", cid)
			status = 1
		end
	elseif((isFocused(cid)) and (msg == "yes") and (status == 2)) and getCreatureStorage(cid, config.cooldownStorage) <= os.time() then
		if (getCreatureStorage(cid, config.storage) >= 10) then
			doCreatureSetStorage(cid, config.cooldownStorage, os.time() + config.cooldown)
			selfSay("Ok then i will rebirth you.", cid)
			selfSay("You will now be logged out.", cid)
			doPlayerRemoveMoney(cid, money)
			addEvent(doRebirthPlayer, 0, cid)
			removeFocus(cid)
		end
		selfSay("Ok then i will rebirth you.", cid)
		selfSay("You will now be logged out.", cid)
		doPlayerRemoveMoney(cid, money)
		addEvent(doRebirthPlayer, 0, cid)
		removeFocus(cid)
	elseif((isFocused(cid)) and (msg == "no") and (status == 2)) then
		selfSay("Maybe one day you will wise up and change your mind!", cid)
		status = 1
	elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
		selfSay("Goodbye!", cid, true)
		removeFocus(cid)
	elseif getCreatureStorage(cid, config.cooldownStorage) >= os.time() then
		local textcool = math.ceil((getCreatureStorage(cid, config.cooldownStorage) - os.time()) / 3600)
		selfSay("You have to wait for " .. textcool .. " hours to rebirth again", cid)
	end
end

function onPlayerCloseChannel(cid)
	if(isFocused(cid)) then
		selfSay("Goodbye.")
		removeFocus(cid)
	end
end

function onThink()
	for i, focus in pairs(focuses) do
		if(not isCreature(focus)) then
			removeFocus(focus)
		else
			local distance = getDistanceTo(focus) or -1
			if((distance > 4) or (distance == -1)) then
				selfSay("Goodbye.")
				removeFocus(focus)
			end
		end
	end
	lookAtFocus()
end

function doRebirthPlayer(cid)
	if isPlayer(cid) then
		
		local guid = getPlayerGUID(cid)
		
		if (config.healthPercent > 0) then
			health = getCreatureMaxHealth(cid) * config.healthPercent
		else
			health = config.health
		end
		if (config.manaPercent > 0) then
			mana = getCreatureMaxMana(cid) * config.manaPercent
		else
			mana = config.mana
		end
		if (getPlayerTown(cid) > 0) then
			pos = getTownTemplePosition(getPlayerTown(cid))
		else
			pos = config.templePos
		end
		
		
		doCreatureSetStorage(cid, config.storage, math.max(0, getCreatureStorage(cid, config.storage)) + 1)
		doRemoveCreature(cid, true)
		db.executeQuery("UPDATE `players` SET level = " .. config.level .. " WHERE id = " .. guid .. ";")
		db.executeQuery("UPDATE `players` SET cap = " .. config.capacity .. " WHERE id = " .. guid .. ";")
		db.executeQuery("UPDATE `players` SET health = " .. health .. " WHERE id = " .. guid .. ";")
		db.executeQuery("UPDATE `players` SET healthmax = " .. health .. " WHERE id = " .. guid .. ";")
		db.executeQuery("UPDATE `players` SET mana = " .. mana .. " WHERE id = " .. guid .. ";")
		db.executeQuery("UPDATE `players` SET manamax = " .. mana .. " WHERE id = " .. guid .. ";")
		db.executeQuery("UPDATE `players` SET posx = " .. pos.x .. " WHERE id = " .. guid .. ";")
		db.executeQuery("UPDATE `players` SET posy = " .. pos.y .. " WHERE id = " .. guid .. ";")
		db.executeQuery("UPDATE `players` SET posz = " .. pos.z .. " WHERE id = " .. guid .. ";")
		
		
		if (not config.keepSkills) then
			db.executeQuery("UPDATE `players` SET maglevel = " .. config.magicLevel .. " WHERE id = " .. guid .. ";")
			db.executeQuery("UPDATE `player_skills` SET value = " .. config.skillLevel .. " WHERE id = " .. guid .. ";")
		end
	end
	return true
end
 

Similar threads

Back
Top