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

Rebirth system + "token" system

Joriku

Working in the mines, need something?
Joined
Jul 16, 2016
Messages
1,077
Solutions
15
Reaction score
370
Location
Sweden
YouTube
Joriku
Hi,
so thanks to my dear friend Taoprox. I got this system working over half a year ago for my project running [1.3] OTBR 12.72.

OBS! Keep in mind, this was written simply to match my current server and may need work. If you can not write Lua, this script is NOT for you.
Also, keep in mind. This system is not perfectly written. This will put out the Idea of the current system onto the community and it's users.

What is it?
It's a Rebirth system, giving out a "token" which means a value of 1 into storage that can be converted over to more max hp/mana. (Damage formula is out of function, meaning it's not working or even implemented.)

NPC, here comes the part where we add the required token point and going through with the player rebirth.
You can convert this NPC onto REV using this guide:
(If you can't do this part, this system is not for you)

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

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, 'rebirth')) then
        selfSay('When you rebirth, you can enter the rebirth area hidden under the throne right next to us.', cid)
        selfSay('Are you ready to rebirth and start a new life?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        -------CONFIGS-------
        local level = 1000
        local cost = 750000
        ------/CONFIGS-------
        -----LOCALS-----
        local id = getPlayerGUID(cid)
        local name = getCreatureName(cid)
        local vocation = getPlayerVocation(cid)
        local storage = getPlayerStorageValue(cid, 85988)
        local skillPoints = getPlayerStorageValue(cid, 23000)
        local maxRebirth = 10  --Change this for the number of rebirths

        ----/LOCALS-----
        if(getPlayerLevel(cid) >= level) then
        if getPlayerStorageValue(cid, 85988) < maxRebirth then
            if(doPlayerRemoveMoney(cid, cost) == TRUE) then
                if(isInArray({5, 6, 7, 8}, vocation)) then
                    local player = Player(cid)
                    player:setStorageValue(85988, storage == -1 and 1 or storage + 1)
                    player:setStorageValue(23000, skillPoints == -1 and 1 or skillPoints + 1)
                    db.query('UPDATE players SET rebirths=rebirths+'.. 1 ..' WHERE id='..getPlayerGUID(cid))
                    Game.broadcastMessage("Player: " ..  name .. " just became an newborn!", MESSAGE_STATUS_WARNING)
                    doRemoveCreature(cid)
                    db.query("UPDATE `players` SET `level` = 8, `experience` = 4200, `healthmax` = 185, `health` = 185, `manamax` = 90, `mana` = 90, `cap` = 470 WHERE `id` = "..id)
                    db.query("UPDATE `players` SET `name` = '"..name.."' WHERE `id` ='"..id.."';")
                else
                    selfSay('Please talk with the Forgotten King and be promoted first.', cid)
                    talkState[talkUser] = 0
                end
            else
                selfSay('You don\'t have enough money. You need to pay 750k to be rebirthed.', cid)
                talkState[talkUser] = 0
            end
        else
            selfSay('You have reached the maximum rebirth.', cid)
            talkState[talkUser] = 0
        end
    else
        selfSay('Only characters of level 1000 or higher can be rebirthed.', 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())

Now, we move over to the part where the bonuses happens. This is a system for once the player levels up.
This config should be pretty easy to understand.
Lua:
local storages = {
    ["23001"] = "hp",
    ["23002"] = "mana",
}

local vocations = {
    [1] = {
        hp = 5,
        mana = 30,
    },
    [2] = {
        hp = 5,
        mana = 30,
    },
    [3] = {
        hp = 10,
        mana = 15,
    },
    [4] = {
        hp = 15,
        mana = 5,
    },
    [5] = {
        hp = 5,
        mana = 30,
    },
    [6] = {
        hp = 5,
        mana = 30,
    },
    [7] = {
        hp = 10,
        mana = 15,
    },
    [8] = {
        hp = 15,
        mana = 5,
    },
}


local config = {
    type = COMBAT_DEATHDAMAGE,
    rounds = 3, -- How many rounds
    time = 500 -- How fast it should be
}

local leveleffect = CreatureEvent("level_up_effect")

local function castSpellTo(cid)
    local player = Player(cid)
    if not player then
        return true
    end
    if player then
        local pos = player:getPosition()
        player:getPosition():sendMagicEffect(math.random(29, 30, 31, 196, 197, 198, 199))
    end
end

function leveleffect.onAdvance(player, skill, oldLevel, newLevel)
    if oldLevel < newLevel then
 
        local creature = Creature(player:getId())
 
        player:say("Skill UP!", TALKTYPE_MONSTER_SAY)
        for i = 1, config.rounds do
            addEvent(castSpellTo, config.time * (i -1), player:getId())
        end
  
        if skill == SKILL_LEVEL then
            local playerVoc = player:getVocation():getId()
            for storage, baseType in pairs(storages) do
                local rebirthValue = player:getStorageValue(storage)
                if rebirthValue > 0 then
                    local baseGain = vocations[playerVoc][baseType]
                    if baseType == "hp" then
                        local bonusHP = math.floor(baseGain * (rebirthValue / 20)) + 3
                        local baseMaxHP = creature:getMaxHealth()
                        local newMaxHealth = baseMaxHP + bonusHP
                        creature:setMaxHealth(newMaxHealth)
                        creature:setHealth(newMaxHealth)
                    elseif baseType == "mana" then
                        local bonusMana = math.floor(baseGain * (rebirthValue / 20)) + 3
                        local baseMaxMana = player:getMaxMana()
                        local newMaxMana = baseMaxMana + bonusMana
                        player:setMaxMana(newMaxMana)
                        player:addMana(bonusMana)
                    end
                end
            end
        end
        return true
    end
end

leveleffect:register()

Now once we've gotten the health/mana under control above, let's go ahead and add the registering type for the skillPoints.
Lua:
local skillPoint = CreatureEvent("skillpoints_level")

local storages = {
    ["23001"] = {type = "hp"},
}

local vocations = {
    [1] = {
        hp = "5",
        mana = "30",
    },
    [2] = {
        hp = "5",
        mana = "30",
    },
    [3] = {
        hp = "10",
        mana = "15",
    },
    [4] = {
        hp = "15",
        mana = "5",
    },
    [5] = {
        hp = "5",
        mana = "30",
    },
    [6] = {
        hp = "5",
        mana = "30",
    },
    [7] = {
        hp = "10",
        mana = "15",
    },
    [8] = {
        hp = "15",
        mana = "5",
    },
}

function skillPoint.onAdvance(cid, skill, oldLevel, newLevel)
    if skill == SKILL_LEVEL and newLevel > oldLevel then
        local player = Player(cid)
        local creature = Creature(cid)
        local playerVoc = player:getVocation():getId()
        for storage, data in pairs(storages) do
            local baseType = data["type"]
            local rebirthValue = Player:getStorageValue(storage)
            if rebirthValue > 0 then
                print(baseType)
                print(playerVoc)
                local baseGain = vocations[playerVoc][baseType]
                if baseType == "hp" then
                    local bonusHP = math.floor(baseGain * (1 + (rebirthValue / 20)))
                    local baseMaxHP = creature:getMaxHealth()
                    local newMaxHealth = baseMaxHP + bonusHP
                    creature:setMaxHealth(newMaxHealth)
                    creature:setHealth(newMaxHealth)
                end
            end
        end
    end
    return true
end

skillPoint:register()

Now onto the spending of the current points, the points are locked by 10. Which means that you'll not be able to gain more then 10 rebirths (10 talent points). Any point spent is removed and added onto the value of the health/mana chosen. A player can chose to do 10 different hp/mana points.
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 config = {
    ["skillpoint"] = 23000,
    ["health"] = 23001, -- Storage for health, taking 1 point and adding formula health
    ["mana"] = 23002, -- Storage for mana, taking 1 point and adding formula mana
    ["damage"] = 23003, -- Storage for bonus damage, taking 1 point and adding 1% more max damage
    ["reset"] = 22999, -- Storage for reset, this resets all bonuses and restores the users earned skill points
}

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
  
    local player = Player(cid)
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    local id = getPlayerGUID(cid)
  
    if(msgcontains(msg, 'rebirth points')) then
        selfSay('When you rebirth, you can spend your skill points on rewards. Some of them being more {health}, {mana} or you can {reset} your points.', cid)
    elseif(msgcontains(msg, 'health')) then
        selfSay('When you rebirth, you can spend your skill points on rewards. One of them being more health.', cid)
        selfSay('Are you sure you want to spend your point on more maxHealth?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'mana')) then
        selfSay('When you rebirth, you can spend your skill points on rewards. One of them being more mana.', cid)
        selfSay('Are you sure you want to spend your point on more maxMana?', cid)
        talkState[talkUser] = 2
    elseif(msgcontains(msg, 'reset')) then
        selfSay('Are you sure you want to reset all your skillpoints?.', cid)
        talkState[talkUser] = 3
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        local skillPoints = player:getStorageValue(config.skillpoint)
        if skillPoints >= 1 then
            player:setStorageValue(config.skillpoint, skillPoints - 1)
            local skillStorage = player:getStorageValue(config.health)
            player:setStorageValue(config.health, skillStorage == -1 and 1 or skillStorage + 1)
            doSendMagicEffect(getCreaturePosition(cid), 184)
            selfSay('Congratulations, you spent one of your skillpoints for more maxhealth!', cid)
            return true
        else
            selfSay('I am sorry bud, you got no skillpoints.', cid)
            return false
        end
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
        local skillPoints = player:getStorageValue(config.skillpoint)
        if skillPoints >= 1 then
            player:setStorageValue(config.skillpoint, skillPoints - 1)
            local skillStorage = player:getStorageValue(config.mana)
            player:setStorageValue(config.mana, skillStorage == -1 and 1 or skillStorage + 1)
            doSendMagicEffect(getCreaturePosition(cid), 184)
            selfSay('Congratulations, you spent one of your skillpoints for more maxmana!', cid)
            return true
        else
            selfSay('I am sorry bud, you got no skillpoints.', cid)
            return false
        end
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 3) then
        selfSay('Warning, this will set your level back to 8 do you still want to continue?', cid)
        selfSay('If you still want to continue, write {I Agree}.', cid)
        talkState[talkUser] = 4
    elseif(msgcontains(msg, 'i agree') and talkState[talkUser] == 4) then
        doRemoveCreature(cid)
        db.query("UPDATE `players` SET `level` = 8, `experience` = 4200, `healthmax` = 185, `health` = 185, `manamax` = 90, `mana` = 90, `cap` = 470 WHERE `id` = "..id)
        db.query("UPDATE `player_storage` SET `value` = -1 WHERE `key` = 23001 AND `player_id` = " .. id .. ";")
        db.query("UPDATE `player_storage` SET `value` = -1 WHERE `key` = 23002 AND `player_id` = " .. id .. ";")
        db.query("UPDATE `player_storage` SET `value` = -1 WHERE `key` = 23003 AND `player_id` = " .. id .. ";")
        local newSkillPoints = player:getStorageValue(85988)
        db.query("UPDATE `player_storage` SET `value` = ".. newSkillPoints .." WHERE `key` = 23000 AND `player_id` = " .. id .. ";")
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Back
Top