local config = {
storage = 72345 -- 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) < 90) then
storage = getCreatureStorage(cid, config.storage)
rebirthLevel = 800 <!-- This is the value you set for level for rebirth eg if you want lvl 715212 then change to 715212 -->
if (getPlayerLevel(cid) >= rebirthLevel) then
money = 150000 + (50000 * 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, 2000, {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)
local setlevel = 8 <!-- Set capacity for player upon rebirth -->
local setcap = 750 <!-- Set New capacity for rebirthed player -->
local setx = 32369 <!-- Set temple position (MUST BE SAME AS CONFIG.LUA TEMPLE POSITION) -->
local sety = 32241 <!-- Set temple position (MUST BE SAME AS CONFIG.LUA TEMPLE POSITION) -->
local setz = 7 <!-- Set temple position (MUST BE SAME AS CONFIG.LUA TEMPLE POSITION) -->
doCreatureSetStorage(cid, config.storage, getCreatureStorage(cid, config.storage) + 1)
doRemoveCreature(cid, true)
db.getResult("UPDATE `players` SET `level` = "..setlevel.." WHERE `id` = "..guid..";")
db.getResult("UPDATE `players` SET `cap` = "..setcap.. " WHERE `id` = "..guid..";")
db.getResult("UPDATE `players` SET `posx` = "..setx.. " WHERE `id` = "..guid..";")
db.getResult("UPDATE `players` SET `posy` = "..sety.. " WHERE `id` = "..guid..";")
db.getResult("UPDATE `players` SET `posz` = "..setz.. " WHERE `id` = "..guid..";")
return true
end