local t = {
level=700, -- level required for rebirth
RemainingLvl=8, -- {8} = level(normal) level you become after the rebirth
skull=true, -- players with white skull can ascend?
redskull=true, -- players with red skull can ascend?
prot=true, -- players must be in protection zone to ascend?
bat=true -- players must not have battle condition to ascend?
}
local function getResets(cid)
return math.max(0, getPlayerStorageValue(cid, 1020))
end
function onSay(cid, words, param)
local skull = getCreatureSkullType(cid)
if (not t.skull and skull == SKULL_WHITE) or (not t.redskull and skull == SKULL_RED) then
doPlayerSendTextMessage(cid, 22, 'You cannot ascend with a ' .. (skull == SKULL_WHITE and 'white' or 'red') .. ' skull.')
end
local pos = getThingPos(cid)
if t.prot and not getTileInfo(pos).protection then
return doPlayerSendTextMessage(cid, 22, 'You must be in a protection zone to ascend.')
elseif t.bat and hasCondition(cid, CONDITION_INFIGHT) then
return doPlayerSendTextMessage(cid, 22, 'You must lose your battle sign to ascend.')
end
local lvl = getPlayerLevel(cid)
if lvl >= t.level then
local new, newLvl = getResets(cid) + 1, math.max(t.RemainingLvl, t.RemainingLvl + lvl - t.level)
setPlayerStorageValue(cid, 1020, new)
doPlayerSetSpecialDescription(cid, '. ' .. (getPlayerSex(cid) == 0 and 'Sh' or 'H') .. 'e is on Ascension # ' .. new)
doPlayerPopupFYI(cid, 'You have ascended, and you now have ' .. new .. ' reset' .. (new == 1 and '' or 's') .. ' in total.')
doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
local pid, hp, mana = getPlayerGUID(cid), math.ceil(getCreatureMaxHealth(cid) * 0.2), math.ceil(getCreatureMaxMana(cid) * 0.2)
doRemoveCreature(cid)
db.executeQuery('UPDATE `players` SET `level` = ' .. newLvl .. ', `experience` = ' .. getExperienceForLevel(newLvl) .. ', `promotion` = 0, `health` = ' .. hp ..', `healthmax` = ' .. hp .. ', `mana` = ' .. mana .. ', `manamax` = ' .. mana .. ' WHERE `id` = ' .. pid .. ' LIMIT 1;')
else
doPlayerSendCancel(cid, 'You need to reach level ' .. t.level .. ' or higher to ascend.')
doSendMagicEffect(pos, CONST_ME_POFF)
end
return true
end