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

Request rebirth counter

Marilyekon

New Member
Joined
Feb 23, 2010
Messages
47
Reaction score
0
Hello. I'm almost done with my Tibia server, but I only have one thing left. Compleate rebirth system. I allready got the npc that takes you back to level 8, but if you click onn the player i it would be nice to see like this "19:21 You See Zand Graz. He's an Elder Druid. He Have Prestiged xxx times" or something like that. Do anyone know how to create a script for it? If so, it would be great! Ofc i will rep+++ You ;)
 
Srry, but the only things I'm god at is mapping. Scripting on the other hand, am I worthless on. I can put some done scripts in the respective folder, but nothing else :S
Could be nice if someone of you huys could do it for me. It would realy be estimated :p
 
In ..\npc\scripts
name-of-the-script-of-the-rebirthing-npc.lua:
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('Are you ready to reborn and start a new life?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		-------CONFIGS-------
		local level = 1000
		local cost = 10000000
		------/CONFIGS-------
		-----LOCALS-----
		local id = getPlayerGUID(cid)
		local name = getCreatureName(cid)
		local vocation = getPlayerVocation(cid)
		local storage = getCreatureStorage(cid, 85987)
		----/LOCALS-----
		if(getPlayerLevel(cid) >= level) then
			if(doPlayerRemoveMoney(cid, cost) == TRUE) then
				if(isInArray({5, 6, 7, 8}, vocation)) then
					doCreatureSetStorage(cid, 85987, storage == -1 and 1 or storage + 1)
					doRemoveCreature(cid)
					db.executeQuery("UPDATE `players` SET `level` = 8, `experience` = 4200, `promotion` = 1 WHERE `id` ='"..id.."';")
					db.executeQuery("UPDATE `players` SET `name` = '"..name.."' WHERE `id` ='"..id.."';")
				else
					selfSay('Please talk with Forgotten King and promote first.', cid)
					talkState[talkUser] = 0
				end
			else
				selfSay('You don\'t have enough money. You need to pay 10000k to be rebirthed.', 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())

In ..\creaturescripts\scripts
rebirthdescription.lua:
Lua:
function onLook(cid, thing, position, lookDistance)
	if(isPlayer(thing.uid) and thing.uid ~= cid and getCreatureStorage(thing.uid, 85987) ~= -1) then
		doPlayerSetSpecialDescription(thing.uid, (getPlayerSex(thing.uid) == PLAYERSEX_FEMALE and ".\nShe" or ".\nHe") .. " has prestiged " .. getCreatureStorage(thing.uid, 85987) .. " " .. (getCreatureStorage(thing.uid, 85987) == 1 and "time" or "times"))
	elseif(thing.uid == cid and getCreatureStorage(cid, 85987) ~= -1) then
		local message = "You see yourself."
		if(getPlayerFlagValue(cid, PLAYERFLAG_SHOWGROUPINSTEADOFVOCATION)) then
			message = message .. " You are " .. getPlayerGroupName(cid) .. "."
		elseif(getPlayerVocation(cid) ~= 0) then
			message = message .. " You are a " .. getPlayerVocationName(cid):lower() .. "."
		else
			message = message .. " You have no vocation."
		end

		if(getPlayerNameByGUID(getPlayerPartner(cid), false, false) ~= nil) then
			message = message .. " You are " .. (getPlayerSex(cid) == PLAYERSEX_FEMALE and "wife" or "husband") .. " of " .. getPlayerNameByGUID(getPlayerPartner(cid)) .. "."
		end

		if(getPlayerGuildId(cid) > 0) then
			message = message .. " You are " .. (getPlayerGuildRank(cid) == "" and "a member" or getPlayerGuildRank(cid)) .. " of the " .. getPlayerGuildName(cid)
			message = getPlayerGuildNick(cid) ~= "" and message .. " (" .. getPlayerGuildNick(cid) .. ")." or message .. "."
		end

		if(getPlayerFlagValue(cid, PLAYERCUSTOMFLAG_CANSEECREATUREDETAILS)) then
			message = message .. "\nHealth: [" .. getCreatureHealth(cid) .. " / " .. getCreatureMaxHealth(cid) .. "], Mana: [" .. getCreatureMana(cid) .. " / " .. getCreatureMaxMana(cid) .. "]."
			message = message .. "\nIP: " .. doConvertIntegerToIp(getPlayerIp(cid)) .. ", Client: " .. getClientVersion(cid) .. "."
		end

		if(getPlayerFlagValue(cid, PLAYERCUSTOMFLAG_CANSEEPOSITION)) then
			message = message .. "\nPosition: [X: " .. position.x .. "] [Y: " .. position.y .. "] [Z: " .. position.z .. "]."
		end

		return false, doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, message .. " \nYou have prestiged " .. getCreatureStorage(cid, 85987) .. " " .. (getCreatureStorage(cid, 85987) == 1 and "time." or "times."))
	end

	return true
end

In login.lua:
Lua:
	registerCreatureEvent(cid, "RebirthDescription")

In creaturescripts.xml:
XML:
	<event type="look" name="RebirthDescription" event="script" value="rebirthdescription.lua"/>
 
Last edited:
A problem with urs...
The storage neutral vaalue is -1...
So the first time he reborn, he wont have the special description with the reborned times = 1, because the value of the storage will be -1 + 1 = 0....

2. The only thing u do was fix my script, so THANKS...!!!
 
Check again:
Code:
doCreatureSetStorage(cid, 85987, [COLOR="red"]storage == -1 and 1 or storage + 1[/COLOR])
The red part means that if the storage value is -1 it will become 1, otherwise it will just add +1 to the actual storage.
 
I'm using tfs 0.3.6 ,8.6. I can log in now, but when i walk to the rebirth npc witn my normal char, I get tibia debug. But when i walk to him with my god i don't get debug. What could possible be wrong? (No errors in the console)
 
Try with this. It's your NPC but with the storages added...
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('Are you ready to be reborn?', cid) 
                talkState[talkUser] = 1 

        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then 
        -------CONFIGS-------
        local level     =   1000
        local cost      =   10000000
        ------/CONFIGS-------
        -----LOCALS-----
        local id = getPlayerGUID(cid)
        local name = getCreatureName(cid)
        local vocation = getPlayerVocation(cid)
		local storage = getCreatureStorage(cid, 85987)
        ----/LOCALS-----
                if getPlayerLevel(cid) >= level then 
                        if doPlayerRemoveMoney(cid,cost) == TRUE then 
                                if vocation == 5 then 
										doCreatureSetStorage(cid, 85987, storage == -1 and 1 or storage + 1)
                                        doRemoveCreature(cid) 
                                        db.executeQuery("UPDATE `players` SET `level` = 8, `experience` = 4200, `promotion` = 1 WHERE `id` ='"..id.."';") 
                                        db.executeQuery("UPDATE `players` SET `name` = '"..name.."' WHERE `id` ='"..id.."';")  
                                elseif vocation == 6 then 
										doCreatureSetStorage(cid, 85987, storage == -1 and 1 or storage + 1)
                                        doRemoveCreature(cid) 
                                        db.executeQuery("UPDATE `players` SET `level` = 8, `experience` = 4200, `promotion` = 1 WHERE `id` ='"..id.."';") 
                                        db.executeQuery("UPDATE `players` SET `name` = '"..name.."' WHERE `id` ='"..id.."';") 
                                elseif vocation == 7 then 
										doCreatureSetStorage(cid, 85987, storage == -1 and 1 or storage + 1)
                                        doRemoveCreature(cid) 
                                        db.executeQuery("UPDATE `players` SET `level` = 8, `experience` = 4200, `promotion` = 1 WHERE `id` ='"..id.."';") 
                                        db.executeQuery("UPDATE `players` SET `name` = '"..name.."' WHERE `id` ='"..id.."';")
                                elseif vocation == 8 then 
										doCreatureSetStorage(cid, 85987, storage == -1 and 1 or storage + 1)
                                        doRemoveCreature(cid) 
                                        db.executeQuery("UPDATE `players` SET `level` = 8, `experience` = 4200, `promotion` = 1 WHERE `id` ='"..id.."';") 
                                        db.executeQuery("UPDATE `players` SET `name` = '"..name.."' WHERE `id` ='"..id.."';") 
                                else
                                        selfSay('Please talk with forgotten king and promote first.', cid)
                                        talkState[talkUser] = 0
                                end
                        else
                                selfSay('You dont have enough money. You need to pay 10000k to be rebirthed.', 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 are ready.', cid) 
                talkState[talkUser] = 0
        end 
        return TRUE 
end 

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

The debug shows up when walking to the NPC or when talking to it?
 
Last edited:
You tried with the last NPC I posted? If the problem persists something may be wrong with your npc libs.
 
Hello, I can rebirth, But i dont get the rebirth counts...

Code:
[1:44:42.666] [Error - NpcScript Interface]
[1:44:42.673] data/npc/scripts/rebirth.lua:onCreatureSay
[1:44:42.673] Description:
[1:44:42.673] (luaDoCreatureSetStorage) Creature not found
 
Right. My bad. 'doCreatureSetStorage' has to be before 'doRemoveCreature'. It's fixed now.
>>1214574

[11:20:54.648] [Error - CreatureScript Interface]
[11:20:54.648] data/creaturescripts/scripts/rebirthdescription.lua:eek:nLook
[11:20:54.656] Description:
[11:20:54.656] data/creaturescripts/scripts/rebirthdescription.lua:3: attempt to compare number with boolean
[11:20:54.656] stack traceback:
[11:20:54.656] data/creaturescripts/scripts/rebirthdescription.lua:3: in function <data/creaturescripts/scripts/rebirthdescription.lua:2>
 
Last edited:
Back
Top Bottom