Guest User

next update

a guest
Jan 6th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.06 KB | None | 0 0
  1. local config = {
  2. price = 0, -- Price of first rebirth
  3. priceIncrease = 0, -- Works as 'price' + current rebirths * priceIncrease.
  4. rebirthLevel = 717217, -- Level for first rebirth.
  5. rebirthIncrease = 0, -- Works as 'rebirthLevel' + current rebirths * rebirthIncrease.
  6. maxRebirths = 10100, -- Number of times a player can rebirth.
  7. level = 8, -- The level the player is set to apon rebirth.
  8. healthPercent = 1.00, -- 1.00 = 100%.
  9. health = 0, -- Only used if 'healthPercent' = 0.
  10. manaPercent = 1.00, -- 1.00 = 100%.
  11. mana = 0, -- Only used if 'manaPercent' = 0.
  12. keepSkills = true, -- Wether players keep skills and level apon rebirth.
  13. skillLevel = 10, -- Only used if 'keepSkills' = false.
  14. magicLevel = 0, -- Only used if 'keepSkills' = false.
  15. capacity = 10000, -- The capacity players are set to apon rebirth.
  16. templePos = {x = 2000, y = 2000, z = 7}, -- The place where players reset to should there town id return 0.
  17. storage = 85987 -- Player storage rebirth count is kept on.
  18. }
  19. local talkState = {}
  20. local focuses = {}
  21. local function isFocused(cid)
  22. for i, v in pairs(focuses) do
  23. if(v == cid) then
  24. return true
  25. end
  26. end
  27. return false
  28. end
  29.  
  30.  
  31.  
  32. local function addFocus(cid)
  33. if(not isFocused(cid)) then
  34. table.insert(focuses, cid)
  35. end
  36. end
  37. local function removeFocus(cid)
  38. for i, v in pairs(focuses) do
  39. if(v == cid) then
  40. table.remove(focuses, i)
  41. break
  42. end
  43. end
  44. end
  45. local function lookAtFocus()
  46. for i, v in pairs(focuses) do
  47. if(isPlayer(v)) then
  48. doNpcSetCreatureFocus(v)
  49. return
  50. end
  51. end
  52. doNpcSetCreatureFocus(0)
  53. end
  54.  
  55. function onCreatureDisappear(cid)
  56. if(isFocused(cid)) then
  57. selfSay("Goodbye.")
  58. removeFocus(cid)
  59. end
  60. end
  61. local words
  62. local xx,yy
  63. function onCreatureSay(cid, type, msg)
  64. local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  65. if((msg == "hi") and not (isFocused(cid))) then
  66. selfSay("Welcome, ".. getCreatureName(cid) ..".", cid, true)
  67. selfSay("I can reborn you!", cid)
  68. addFocus(cid)
  69. talkState[talkUser] = 1
  70. elseif((isFocused(cid)) and (msg == "reborn") and ( talkState[talkUser] == 1)) then
  71. if (getCreatureStorage(cid, config.storage) < config.maxRebirths) then
  72. storage = getCreatureStorage(cid, config.storage)
  73. rebirthLevel = config.rebirthLevel + (config.rebirthIncrease * storage)
  74. if (getPlayerLevel(cid) >= rebirthLevel) then
  75. money = config.price + (config.priceIncrease * storage)
  76. if (getPlayerMoney(cid) >= money) then
  77. selfSay("Do you want me to reborn you?", cid)
  78. talkState[talkUser] = 2
  79. else
  80. selfSay("You need at least " .. money .. " gold before you can rebirth.", cid)
  81. talkState[talkUser] = 2
  82. end
  83. else
  84. selfSay("You need to be at least level " .. rebirthLevel .. " before you can rebirth.", cid)
  85. talkState[talkUser] = 1
  86. end
  87. else
  88. selfSay("It seems you can not rebirth anymore.", cid)
  89. talkState[talkUser] = 2
  90. end
  91. elseif((isFocused(cid)) and (msg == "yes") and (talkState[talkUser] == 2)) then
  92. words = getCode().z
  93. xx = getCode().x
  94. yy = getCode().y
  95. selfSay("Ok then i will reborn you. Please solve this equation: "..xx.." + "..yy.." = ??", cid)
  96. doPlayerPopupFYI(cid, ""..xx.." + "..yy.." = ??")
  97. talkState[talkUser] = 3
  98. elseif((isFocused(cid)) and (talkState[talkUser] == 3)) then
  99. if tostring(msg) == tostring(words) then
  100. selfSay("Ok then i will rebirth you.", cid)
  101. selfSay("You will now be logged out.", cid)
  102. doPlayerRemoveMoney(cid, money)
  103. addEvent(doRebirthPlayer, 2000, {cid=cid})
  104. removeFocus(cid)
  105. else
  106. selfSay("Sorry please solve the equation again: "..xx.." + "..yy.." = ??", cid)
  107. end
  108. elseif((isFocused(cid)) and (msg == "no") and (talkState[talkUser] == 2)) then
  109. selfSay("Maybe one day you will wise up and change your mind!", cid)
  110. talkState[talkUser] = 1
  111. elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
  112. selfSay("Goodbye!", cid, true)
  113. removeFocus(cid)
  114. end
  115. end
  116.  
  117. function onPlayerCloseChannel(cid)
  118. if(isFocused(cid)) then
  119. selfSay("Goodbye.")
  120. removeFocus(cid)
  121. end
  122. end
  123. function CompareString(str1,str2,counter)
  124. local up = 0
  125. for i = 1,5 do
  126. if str1[i] == str2[i] then
  127. up = up + 1
  128. end
  129. end
  130. return up
  131. end
  132. function getCode()
  133. local x
  134. local y
  135. local z
  136. x = math.random(1,9)
  137. y = math.random(1,9)
  138. z= x + y
  139. return x,y,z
  140. end
  141.  
  142. function onThink()
  143. for i, focus in pairs(focuses) do
  144. if(not isCreature(focus)) then
  145. removeFocus(focus)
  146. else
  147. local distance = getDistanceTo(focus) or -1
  148. if((distance > 4) or (distance == -1)) then
  149. selfSay("Goodbye.")
  150. removeFocus(focus)
  151. end
  152. end
  153. end
  154. lookAtFocus()
  155. end
  156.  
  157. function doRebirthPlayer(cid)
  158. cid = cid.cid
  159. if (cid == nil) then
  160. return true
  161. end
  162.  
  163. local guid = getPlayerGUID(cid)
  164.  
  165. if (config.healthPercent > 0) then
  166. health = getCreatureMaxHealth(cid) * config.healthPercent
  167. else
  168. health = config.health
  169. end
  170. if (config.manaPercent > 0) then
  171. mana = getCreatureMaxMana(cid) * config.manaPercent
  172. else
  173. mana = config.mana
  174. end
  175. if (getPlayerTown(cid) > 0) then
  176. pos = getTownTemplePosition(getPlayerTown(cid))
  177. else
  178. pos = config.templePos
  179. end
  180.  
  181.  
  182. doCreatureSetStorage(cid, config.storage, getCreatureStorage(cid, config.storage) + 1)
  183. doRemoveCreature(cid, true)
  184. db.query("UPDATE `players` SET level = " .. config.level .. " WHERE id = " .. guid .. ";")
  185. db.query("UPDATE `players` SET cap = " .. config.capacity .. " WHERE id = " .. guid .. ";")
  186. db.query("UPDATE `players` SET health = " .. health .. " WHERE id = " .. guid .. ";")
  187. db.query("UPDATE `players` SET healthmax = " .. health .. " WHERE id = " .. guid .. ";")
  188. db.query("UPDATE `players` SET mana = " .. mana .. " WHERE id = " .. guid .. ";")
  189. db.query("UPDATE `players` SET manamax = " .. mana .. " WHERE id = " .. guid .. ";")
  190.  
  191. if (not config.keepSkills) then
  192. db.query("UPDATE `players` SET maglevel = " .. config.magicLevel .. " WHERE id = " .. guid .. ";")
  193. db.query("UPDATE `player_skills` SET value = " .. config.skillLevel .. " WHERE id = " .. guid .. ";")
  194. end
  195. return true
  196. end
Advertisement
Add Comment
Please, Sign In to add comment