Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local config = {
- price = 0, -- Price of first rebirth
- priceIncrease = 0, -- Works as 'price' + current rebirths * priceIncrease.
- rebirthLevel = 717217, -- Level for first rebirth.
- rebirthIncrease = 0, -- Works as 'rebirthLevel' + current rebirths * rebirthIncrease.
- maxRebirths = 10100, -- Number of times a player can rebirth.
- level = 8, -- The level the player is set to apon rebirth.
- healthPercent = 1.00, -- 1.00 = 100%.
- health = 0, -- Only used if 'healthPercent' = 0.
- manaPercent = 1.00, -- 1.00 = 100%.
- mana = 0, -- Only used if 'manaPercent' = 0.
- keepSkills = true, -- Wether players keep skills and level apon rebirth.
- skillLevel = 10, -- Only used if 'keepSkills' = false.
- magicLevel = 0, -- Only used if 'keepSkills' = false.
- capacity = 10000, -- The capacity players are set to apon rebirth.
- templePos = {x = 2000, y = 2000, z = 7}, -- The place where players reset to should there town id return 0.
- storage = 85987 -- Player storage rebirth count is kept on.
- }
- local talkState = {}
- 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
- local words
- local xx,yy
- function onCreatureSay(cid, type, msg)
- local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
- if((msg == "hi") and not (isFocused(cid))) then
- selfSay("Welcome, ".. getCreatureName(cid) ..".", cid, true)
- selfSay("I can reborn you!", cid)
- addFocus(cid)
- talkState[talkUser] = 1
- elseif((isFocused(cid)) and (msg == "reborn") and ( talkState[talkUser] == 1)) then
- if (getCreatureStorage(cid, config.storage) < config.maxRebirths) then
- storage = getCreatureStorage(cid, config.storage)
- rebirthLevel = config.rebirthLevel + (config.rebirthIncrease * storage)
- if (getPlayerLevel(cid) >= rebirthLevel) then
- money = config.price + (config.priceIncrease * storage)
- if (getPlayerMoney(cid) >= money) then
- selfSay("Do you want me to reborn you?", cid)
- talkState[talkUser] = 2
- else
- selfSay("You need at least " .. money .. " gold before you can rebirth.", cid)
- talkState[talkUser] = 2
- end
- else
- selfSay("You need to be at least level " .. rebirthLevel .. " before you can rebirth.", cid)
- talkState[talkUser] = 1
- end
- else
- selfSay("It seems you can not rebirth anymore.", cid)
- talkState[talkUser] = 2
- end
- elseif((isFocused(cid)) and (msg == "yes") and (talkState[talkUser] == 2)) then
- words = getCode().z
- xx = getCode().x
- yy = getCode().y
- selfSay("Ok then i will reborn you. Please solve this equation: "..xx.." + "..yy.." = ??", cid)
- doPlayerPopupFYI(cid, ""..xx.." + "..yy.." = ??")
- talkState[talkUser] = 3
- elseif((isFocused(cid)) and (talkState[talkUser] == 3)) then
- if tostring(msg) == tostring(words) 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)
- else
- selfSay("Sorry please solve the equation again: "..xx.." + "..yy.." = ??", cid)
- end
- elseif((isFocused(cid)) and (msg == "no") and (talkState[talkUser] == 2)) then
- selfSay("Maybe one day you will wise up and change your mind!", cid)
- talkState[talkUser] = 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 CompareString(str1,str2,counter)
- local up = 0
- for i = 1,5 do
- if str1[i] == str2[i] then
- up = up + 1
- end
- end
- return up
- end
- function getCode()
- local x
- local y
- local z
- x = math.random(1,9)
- y = math.random(1,9)
- z= x + y
- return x,y,z
- 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)
- if (config.healthPercent > 0) then
- health = getCreatureMaxHealth(cid) * config.healthPercent
- else
- health = config.health
- end
- if (config.manaPercent > 0) then
- mana = getCreatureMaxMana(cid) * config.manaPercent
- else
- mana = config.mana
- end
- if (getPlayerTown(cid) > 0) then
- pos = getTownTemplePosition(getPlayerTown(cid))
- else
- pos = config.templePos
- end
- doCreatureSetStorage(cid, config.storage, getCreatureStorage(cid, config.storage) + 1)
- doRemoveCreature(cid, true)
- db.query("UPDATE `players` SET level = " .. config.level .. " WHERE id = " .. guid .. ";")
- db.query("UPDATE `players` SET cap = " .. config.capacity .. " WHERE id = " .. guid .. ";")
- db.query("UPDATE `players` SET health = " .. health .. " WHERE id = " .. guid .. ";")
- db.query("UPDATE `players` SET healthmax = " .. health .. " WHERE id = " .. guid .. ";")
- db.query("UPDATE `players` SET mana = " .. mana .. " WHERE id = " .. guid .. ";")
- db.query("UPDATE `players` SET manamax = " .. mana .. " WHERE id = " .. guid .. ";")
- if (not config.keepSkills) then
- db.query("UPDATE `players` SET maglevel = " .. config.magicLevel .. " WHERE id = " .. guid .. ";")
- db.query("UPDATE `player_skills` SET value = " .. config.skillLevel .. " WHERE id = " .. guid .. ";")
- end
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment