• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Best reborn system

Amiroslo

Excellent OT User
Joined
Jul 28, 2009
Messages
6,768
Solutions
5
Reaction score
769
This is the best reborn system you will ever use [If you use it correctly OFC].
I have had this system in my OT. I had to work a lot on it. It saves rebs in the DB.

What this system includes:
Reborns gets saved into your DB.
Check your reborns by talkaction.
Check others reborn by looking at them [onlook function]
Reborn using NPC
Remove/Add rebs from DB [This wont change his current hp/mana, just the rebs number]

How TO?:
1- Open data/lib/050-function and add this on top:
Code:
--Rebirth function by Amiroslo
function getRebornsDone(cid)
    local Info = db.getResult("SELECT `reborns` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
       if Info:getID() ~= LUA_ERROR then
    local reborns= Info:getDataInt("reborns")
        return reborns
    end
return LUA_ERROR
end

function doAddReborns(cid) -- Adds 1 reb
    db.executeQuery("UPDATE `players` SET `reborns` = `reborns` + 1 WHERE id = " .. getPlayerGUID(cid) .. ";")
end

function doRemoveReborns(cid) -- Removes 1 reb
    db.executeQuery("UPDATE `players` SET `reborns` = `reborns` - 1 WHERE id = " .. getPlayerGUID(cid) .. ";")
end
Now go to data/creaturescripts/ and open creaturescripts.xml and add:
Code:
<event type="look" name="rebirth" event="script" value="reblook.lua"/>

Now go to data/creaturescripts/scripts and CREATE a new file called reblook.lua and this in it:
Code:
function onLook(cid, thing, position, lookDistance)
    if isPlayer(thing.uid) then
        doPlayerSetSpecialDescription(thing.uid, (getPlayerSex(thing.uid) == 0 and "\nShe" or "\nHe") .. " has: ["..getRebornsDone(thing.uid).."] Rebirths.")
            return true
    end
  
    if(thing.uid == cid) then
        doPlayerSetSpecialDescription(thing.uid, "\nYou have done: ["..getRebornsDone(thing.uid).."] Rebirths.")
    end
        return true
end

Now go to data/creaturescripts/scripts/ and open login.lua and add this:
Code:
registerCreatureEvent(cid, "rebirth")
OVER
Code:
registerCreatureEvent(cid, "Mail")

Now head to data/npc/ and CREATE a new file called Reborn Statue.xml and add this inside:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Reborn Statue" script="reb.lua" walkinterval="0" floorchange="0">
    <health now="100" max="100"/>
    <look typeex="8780"/>
    <parameters>
        <parameter key="message_greet" value="Hello |PLAYERNAME|. Do you want to {reborn}?!"/>
        <parameter key="message_farewell" value="Farewell!"/>
    </parameters>
</npc>

Now go to data/npc/scripts/ and CREATE a new file called reb.lua and add this in it:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}

local level = 999999
local maxReborns = 10000

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 getRebornsDone(cid) < maxReborns then
                doAddReborns(cid) -- adds 1 reborn

                local g = getPlayerGUID(cid)
                npcHandler:releaseFocus(cid)
                doRemoveCreature(cid)
                db.executeQuery('UPDATE players SET level=100,experience=15219400 WHERE id=' .. g)
            else
                npcHandler:say('You reached 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 make reborn?',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())

Now go to data/talkactions/talkactions.xml open it and add:
Code:
    <talkaction log="no" words="!reborns;!reborn" event="script" value="rebtalk.lua"/>

Now go to data/talkactions/scripts/ and CREATE a new file called rebtalk.lua and add this in it:
Code:
function onSay(cid, words, param)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Youve done ' .. (getRebornsDone(cid)) .. ' reborns.')  
    return true
end[/COLOR]

Goto your phpmyadmin and select your DB and add this colum:
Code:
 ALTER TABLE `players` ADD `rebirth` int(10) unsigned NOT NULL DEFAULT '0';

Restart your server and REMEMBER to add the NPC in the map. It may be invsible in RME but it will show in game.

Tested on 0.3.6pl1 and works 100%

Thank you :)
 
Last edited:
Ohhhh true. I totally missed that. Thanks!
 
This is the best reborn system you will ever use [If you use it correctly OFC].
I have had this system in my OT. I had to work a lot on it. It saves rebs in the DB.

What this system includes:
Reborns gets saved into your DB.
Check your reborns by talkaction.
Check others reborn by looking at them [onlook function]
Reborn using NPC
Remove/Add rebs from DB [This wont change his current hp/mana, just the rebs number]

How TO?:
1- Open data/lib/050-function and add this on top:
Code:
--Rebirth function by Amiroslo
function getRebornsDone(cid)
    local Info = db.getResult("SELECT `reborns` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
       if Info:getID() ~= LUA_ERROR then
    local reborns= Info:getDataInt("reborns")
        return reborns
    end
return LUA_ERROR
end

function doAddReborns(cid) -- Adds 1 reb
    db.executeQuery("UPDATE `players` SET `reborns` = `reborns` + 1 WHERE id = " .. getPlayerGUID(cid) .. ";")
end

function doRemoveReborns(cid) -- Removes 1 reb
    db.executeQuery("UPDATE `players` SET `reborns` = `reborns` - 1 WHERE id = " .. getPlayerGUID(cid) .. ";")
end
Now go to data/creaturescripts/ and open creaturescripts.xml and add:
Code:
<event type="look" name="rebirth" event="script" value="reblook.lua"/>

Now go to data/creaturescripts/scripts and CREATE a new file called reblook.lua and this in it:
Code:
function onLook(cid, thing, position, lookDistance)
    if isPlayer(thing.uid) then
        doPlayerSetSpecialDescription(thing.uid, (getPlayerSex(thing.uid) == 0 and "\nShe" or "\nHe") .. " has: ["..getRebornsDone(thing.uid).."] Rebirths.")
            return true
    end
 
    if(thing.uid == cid) then
        doPlayerSetSpecialDescription(thing.uid, "\nYou have done: ["..getRebornsDone(thing.uid).."] Rebirths.")
    end
        return true
end

Now go to data/creaturescripts/scripts/ and open login.lua and add this:
Code:
registerCreatureEvent(cid, "rebirth")
OVER
Code:
registerCreatureEvent(cid, "Mail")

Now head to data/npc/ and CREATE a new file called Reborn Statue.xml and add this inside:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Reborn Statue" script="reb.lua" walkinterval="0" floorchange="0">
    <health now="100" max="100"/>
    <look typeex="8780"/>
    <parameters>
        <parameter key="message_greet" value="Hello |PLAYERNAME|. Do you want to {reborn}?!"/>
        <parameter key="message_farewell" value="Farewell!"/>
    </parameters>
</npc>

Now go to data/npc/scripts/ and CREATE a new file called reb.lua and add this in it:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}

local level = 999999
local maxReborns = 10000

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 getRebornsDone(cid) < maxReborns then
                doAddReborns(cid) -- adds 1 reborn

                local g = getPlayerGUID(cid)
                npcHandler:releaseFocus(cid)
                doRemoveCreature(cid)
                db.executeQuery('UPDATE players SET level=100,experience=15219400 WHERE id=' .. g)
            else
                npcHandler:say('You reached 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 make reborn?',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())

Now go to data/talkactions/talkactions.xml open it and add:
Code:
    <talkaction log="no" words="!reborns;!reborn" event="script" value="rebtalk.lua"/>

Now go to data/talkactions/scripts/ and CREATE a new file called rebtalk.lua and add this in it:
Code:
function onSay(cid, words, param)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Youve done ' .. (getRebornsDone(cid)) .. ' reborns.') 
    return true
end[/COLOR]

Goto your phpmyadmin and select your DB and add this colum:
Code:
 ALTER TABLE `players` ADD `rebirth` int(10) unsigned NOT NULL DEFAULT '0';

Restart your server and REMEMBER to add the NPC in the map. It may be invsible in RME but it will show in game.

Tested on 0.3.6pl1 and works 100%

Thank you :)
near "unsigned": syntax error:
You forgot 1 important thing in your script, the column :)
Code:
ALTER TABLE `players`
ADD `rebirth` int(10) unsigned NOT NULL DEFAULT '0';
near "unsigned": syntax error:
 
[24/12/2014 14:15:39] sqlite3_step(): SQLITE ERROR: cannot start a transaction within a transaction
[24/12/2014 14:15:46] Error during getDataInt(rebirth).
[24/12/2014 14:11:41] OTSYS_SQLITE3_PREPARE(): SQLITE ERROR: no such column:
reborns (UPDATE "players" SET "reborns" = "reborns" + 1 WHERE id = 17;)
24/12/2014 14:11:41] sqlite3_step(): SQLITE ERROR: cannot commit transaction - SQL statements in progress
[24/12/2014 14:11:41] sqlite3_step(): SQLITE ERROR: cannot start a transaction within a transaction
[24/12/2014 14:11:43] Error during getDataInt(reborns).
these are my problems
 
These queries are really meant for sql and not sqlite as the commands differ slightly, also normally you can't make drastic changes to the structure of the database while it is in use meaning while the game server is running.

This rebirth system could have been restructured in a different way so that changes made can be updated with a simple reload while in game.
However this is not my release, so your best bet is to use

Code:
local reborns= Info:getDataInt("reborns")

to this
Code:
local reborns= Info:getDataInt("rebirth")

Whether you alter the database or the method you will need to restart the server
Changed it and nothing changed
 
What is the error?
i said there aren't any errors on console but when player 1 looks at player 2 he can see his rebirths 0 even if he have 100 he will see 0 and i can't look on myself to see rebirths
 
If ppls doing rebirth, they get something? like mana and hp? xD
 
No, they keep their mana and hp, but they learn new spell on x reborns @TibiaFX
 
Last edited:

Similar threads

Back
Top