Advertisement
Guest User

Untitled

a guest
Mar 17th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.57 KB | None | 0 0
  1. <?xml version="1.0"?>
  2.  
  3. <npc name="NOME DO NPC" script="data/npc/scripts/NOME DO SCRIPT.lua" access="3" walkinterval="2000" lookdir="2">
  4.     <mana now="800" max="800"/>
  5.     <health now="200" max="200"/>
  6. <look type="110" head="1" body="1" legs="1" feet="1" addons="0"/>
  7. </npc>
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14. --Script
  15.  
  16.  
  17. --[[ Account Manager by Flyckks ]]--
  18.  
  19.  
  20. local keywordHandler = KeywordHandler:new()
  21. local npcHandler = NpcHandler:new(keywordHandler)
  22. NpcSystem.parseParameters(npcHandler)
  23. local talkState = {}
  24.  
  25. function onCreatureAppear(cid)                          npcHandler:onCreatureAppear(cid) end
  26. function onCreatureDisappear(cid)                       npcHandler:onCreatureDisappear(cid) end
  27. function onCreatureSay(cid, type, msg)                  npcHandler:onCreatureSay(cid, type, msg) end
  28. function onThink()                                      npcHandler:onThink() end
  29.  
  30. npcHandler:setMessage(MESSAGE_GREET, "Hello, type {account} to create a new account.")
  31.  
  32. --[[Esta parte deve estar como TRUE, no Config.Lua, mas desative o account manager. ]]--
  33. local config =
  34. {
  35.     newPlayerChooseVoc = getConfigValue("newPlayerChooseVoc"),
  36.     newPlayerSpawnPosX = getConfigValue("newPlayerSpawnPosX"),
  37.     newPlayerSpawnPosY = getConfigValue("newPlayerSpawnPosY"),
  38.     newPlayerSpawnPosZ = getConfigValue("newPlayerSpawnPosZ"),
  39.     newPlayerTownId = getConfigValue("newPlayerTownId"),
  40.     newPlayerLevel = getConfigValue("newPlayerLevel"),
  41.     newPlayerMagicLevel = getConfigValue("newPlayerMagicLevel"),
  42.     generateAccountNumber = getConfigValue("generateAccountNumber")
  43. }
  44.  
  45. local account =
  46. {
  47.     name = {},
  48.     pass = {}
  49. }
  50.  
  51. local character =
  52. {
  53.     name = {},
  54.     voc = {},
  55.     sex = {}
  56. }
  57.  
  58.  
  59. --[[Aqui somente modifique, caso queira que o jogador ja crie se personagem. ]]--
  60.  
  61.  
  62. local toBe = 0
  63. local capMax = 400
  64. local voc =
  65. {
  66.     ["sorcerer"] = 1,
  67.     ["druid"] = 2,
  68.     ["paladin"] = 3,
  69.     ["knight"] = 4
  70. }
  71. function creatureSayCallback(cid, type, msg)
  72.  
  73.  
  74. --[[
  75.  
  76. Aqui fica todas as funções do NPC, tudo que está com "disable_", ao remover o disable, você torna esta função acessivel, caso queira habilitar criação de personagens.
  77.  
  78.  
  79.                 doTeleportThing(cid, {x = posX, y = posY, z = posZ}, true)
  80.  
  81. Nesta parte, coloque as posições que o jogador será teleportado, após criar a conta, um local sem acesso, onde seja obrigado deslogar.
  82. Removendo esta linha, ele não é teleportado, e fica junto ao npc.
  83.  
  84.  ]]--
  85.  
  86.  
  87.     if(not npcHandler:isFocused(cid)) then
  88.         return false
  89.     end
  90.     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
  91.     if msgcontains(msg, "account") then
  92.         npcHandler:say("What would you like your password to be?", cid)
  93.         talkState[talkUser] = 1
  94.     elseif talkState[talkUser] == 1 then
  95.         if msg ~= "" or msg ~= nil then
  96.             toBe = string.gsub(msg, "[!'·#$%&/()=?¿¡.*\|;:,><{}]", "")
  97.             npcHandler:say(toBe .. " is it {yes} or {no}?", cid)
  98.             talkState[talkUser] = 2
  99.         else
  100.             npcHandler:say("What would you like your password to be?", cid)
  101.         end
  102.     elseif talkState[talkUser] == 2 and msgcontains(msg, "no") then
  103.         npcHandler:say("What would you like your password to be?", cid)
  104.         talkState[talkUser] = 1
  105.     elseif talkState[talkUser] == 2 and msgcontains(msg, "yes") then
  106.         account.pass[cid] = toBe
  107.         if config.generateAccountNumber then
  108.             toBe = string.format("%s%s%s%s%s%s%s", math.random(1, 9), math.random(1, 9), math.random(1, 9), math.random(1, 9), math.random(1, 9), math.random(1, 9), math.random(1, 9))
  109.             local query = db.getResult("select id from accounts where name = " .. toBe .. ";")
  110.             if query:getID() == -1 then
  111.                 account.name[cid] = toBe
  112.                 local query_ = db.executeQuery("insert into accounts (name, password) values (" .. db.escapeString(account.name[cid]) .. ", " .. db.escapeString(account.pass[cid]) .. ");")
  113.                 if query_ then
  114.                     npcHandler:say("Your account has been created, but remember your account name: {" .. account.name[cid] .. "} and password: {" .. account.pass[cid] .. "}!", cid)
  115.                     talkState[talkUser] = 0
  116.                 else
  117.                     npcHandler:say("Your account cannot be created.", cid)
  118.                     talkState[talkUser] = 0
  119.                 end
  120.             end
  121.         else
  122.             npcHandler:say("What would you like your account name to be?", cid)
  123.             talkState[talkUser] = 3
  124.         end
  125.     elseif talkState[talkUser] == 3 then
  126.         if msg ~= "" or msg ~= nil then
  127.             toBe = string.gsub(msg, "[!·#$%&¬/()=?'¿¡.*\|;:,><{}]", "")
  128.             if toBe == account.pass[cid] then
  129.                 npcHandler:say("Your account name cannot be the same as your password.", cid)
  130.                 talkState[talkUser] = 3
  131.             else
  132.                 npcHandler:say(toBe .. " is it {yes} or {no}?", cid)
  133.                 talkState[talkUser] = 4
  134.             end
  135.         else
  136.             npcHandler:say("What would you like your account name to be?", cid)
  137.         end
  138.     elseif talkState[talkUser] == 4 and msgcontains(msg, "no") then
  139.         npcHandler:say("Od... then what would you like your account name to be?", cid)
  140.         talkState[talkUser] = 3
  141.     elseif talkState[talkUser] == 4 and msgcontains(msg, "yes") then
  142.         local query = db.getResult("select id from accounts where name = " .. db.escapeString(toBe) .. ";")
  143.         local deny = false
  144.         if query:getID() ~= -1 then
  145.             deny = true
  146.             query:free()
  147.         end
  148.         if deny then
  149.             npcHandler:say("An account with that name already exists, please try another account name.", cid)
  150.             talkState[talkUser] = 3
  151.         else
  152.             account.name[cid] = toBe
  153.             local query = db.executeQuery("insert into accounts (name, password) values (" .. db.escapeString(account.name[cid]) .. ", " .. db.escapeString(account.pass[cid]) .. ");")
  154.             if query then
  155.                 npcHandler:say("Your account has been created, you may it now, but remember your account name: {" .. account.name[cid] .. "} and password: {" .. account.pass[cid] .. "}, access your account on website to crete your first character!", cid)
  156.                 doTeleportThing(cid, {x = posX, y = posY, z = posZ}, true)
  157.                 talkState[talkUser] = 0
  158.             else
  159.                 npcHandler:say("Your account cannot be created.", cid)
  160.                 talkState[talkUser] = 0
  161.             end
  162.         end
  163.     elseif msgcontains(msg, "disable_manage") then
  164.         account.name[cid] = (account.name[cid] or getPlayerAccount(cid))
  165.         local query = db.getResult("select password from accounts where name = " .. db.escapeString(account.name[cid]) .. ";")
  166.         if query:getID() ~= -1 then
  167.             account.pass[cid] = (account.pass[cid] or query:getDataString("password"))
  168.             query:free()
  169.         end
  170.         npcHandler:say("You can {change} your pass or create a new {character}.", cid)
  171.         talkState[talkUser] = 5
  172.     elseif msgcontains(msg, "change") then
  173.         npcHandler:say("Tell me your new password please.", cid)
  174.         talkState[talkUser] = 6
  175.     elseif talkState[talkUser] == 6 then
  176.         if msg ~= "" or msg ~= nil then
  177.             toBe = string.gsub(msg, "[!'·#$%&/()=?¿¡.*\|;:,><{}]", "")
  178.             if string.len(toBe) < 6 then
  179.                 npcHandler:say("That password is too short, at least 6 digits are required. Please select a longer password.", cid)
  180.             else
  181.                 npcHandler:say("Should {" .. toBe .. "} be your new password?", cid)
  182.                 talkState[talkUser] = 7
  183.             end
  184.         else
  185.             npcHandler:say("What would you like your new password to be?", cid)
  186.         end
  187.     elseif talkState[talkUser] == 7 and msgcontains(msg, "no") then
  188.         npcHandler:say("Then not.", cid)
  189.         talkState[talkUser] = 0
  190.     elseif talkState[talkUser] == 7 and msgcontains(msg, "yes") then
  191.         local query = db.executeQuery("update accounts set password = " .. db.escapeString(toBe) .. " where name = " .. db.escapeString(getPlayerAccount(cid)).. ";")
  192.         if query then
  193.             npcHandler:say("Your password has been changed.", cid)
  194.             talkState[talkUser] = 0
  195.         else
  196.             npcHandler:say("Your password cannot be changed.", cid)
  197.             talkState[talkUser] = 0
  198.         end
  199.     elseif msgcontains(msg, "disable_character") then
  200.         local query = db.getResult("select count(id) as count from players where account_id = " .. getPlayerAccountId(cid) .. ";")
  201.         if query:getID() ~= -1 then
  202.             local t = query:getDataInt("count")
  203.             if t >= 15 then
  204.                 npcHandler:say("Your account reach the limit of 15 players, you need delete a character if you want to create a new one.", cid)
  205.                 talkState[talkUser] = 0
  206.             else
  207.                 npcHandler:say("What would you like as your character name?", cid)
  208.                 talkState[talkUser] = 8
  209.             end
  210.             query:free()
  211.         end
  212.     elseif talkState[talkUser] == 8 then
  213.         if msg ~= "" or msg ~= nil then
  214.             toBe = string.gsub(msg, "[!'·#$%&/()=?¿¡.*\|;:,><{}]", "")
  215.             if string.len(toBe) < 4 then
  216.                 npcHandler:say("Your name you want is too short, please select a longer name.", cid)
  217.             elseif string.len(toBe) > 20 then
  218.                 npcHandler:say("Your name you want is too long, please select a longer name.", cid)
  219.             elseif string.sub(toBe, 0, 4) == "god " or isInArray({"gm ", "cm "}, string.sub(toBe, 0, 3)) then
  220.                 npcHandler:say("Your character is not a staff member, please tell me another name!", cid)
  221.             elseif string.sub(toBe, 0, 1) == string.sub(toBe, 0, 1):lower() then
  222.                 npcHandler:say("Your name can not be the first letter in lower case.", cid)
  223.             else
  224.                 local query = db.getResult("select id from players where name = " .. db.escapeString(toBe) .. ";")
  225.                 if query:getID() ~= - 1 then
  226.                     npcHandler:say("A player with that name already exists, please choose another name.", cid)
  227.                     query:free()
  228.                 else
  229.                     npcHandler:say(toBe .. " is it {yes} or {no}?", cid)
  230.                     talkState[talkUser] = 9
  231.                 end
  232.             end
  233.         else
  234.             npcHandler:say("What would you like as your character name?", cid)
  235.         end
  236.     elseif talkState[talkUser] == 9 and msgcontains(msg, "no") then
  237.         npcHandler:say("What else would you like to name your character?", cid)
  238.         talkState[talkUser] = 8
  239.     elseif talkState[talkUser] == 9 and msgcontains(msg, "yes") then
  240.         character.name[cid] = toBe
  241.         npcHandler:say("Should your character be a {male} or a {female}.", cid)
  242.         talkState[talkUser] = 10
  243.     elseif talkState[talkUser] == 10 and msgcontains(msg, "male") or msgcontains(msg, "female") then
  244.         toBe = (msg == "male" and 1 or 0)
  245.         npcHandler:say("A " .. msg .. ", are you sure?", cid)
  246.         talkState[talkUser] = 11
  247.     elseif talkState[talkUser] == 11 and msgcontains(msg, "no") then
  248.         npcHandler:say("Tell me... would you like to be a {male} or a {female}?", cid)
  249.         talkState[talkUser] = 10
  250.     elseif talkState[talkUser] == 11 and msgcontains(msg, "yes") then
  251.         character.sex[cid] = toBe
  252.         if config.newPlayerChooseVoc then
  253.             npcHandler:say("What do you want to be... {sorcerer}, {druid}, {paladin} or {knight}.", cid)
  254.             talkState[talkUser] = 12
  255.         else
  256.             character.voc[cid] = 0
  257.             local query = db.executeQuery("insert into players (id, name, world_id, group_id, account_id, level, vocation, health, healthmax, experience, lookbody, lookfeet, lookhead, looklegs, looktype, lookaddons, maglevel, mana, manamax, manaspent, soul, town_id, posx, posy, posz, conditions, cap, sex, lastlogin, lastip, skull, skulltime, save, rank_id, guildnick, lastlogout, blessings, online) VALUES (NULL, " .. db.escapeString(character.name[cid]) .. ", " .. getConfigValue("worldId") .. ", 1, " .. getAccountIdByAccount(account.name[cid]) .. ", " .. config.newPlayerLevel .. ", " .. character.voc[cid] .. ", " .. getVocationInfo(character.voc[cid]).healthGain * config.newPlayerLevel .. ", " .. getVocationInfo(character.voc[cid]).healthGain * config.newPlayerLevel .. ", " .. (config.newPlayerLevel < 2 and 0 or getExperienceForLevel(config.newPlayerLevel)) .. ", 68, 76, 78, 39, " .. (character.sex[cid] == 1 and 136 or 128) .. ", 0, " .. config.newPlayerMagicLevel .. ", 0, 0, 0, 100, " .. config.newPlayerTownId .. ", " .. config.newPlayerSpawnPosX .. ", " .. config.newPlayerSpawnPosY .. ", " .. config.newPlayerSpawnPosZ .. ", 0, " .. capMax + getVocationInfo(character.voc[cid]).capacity * config.newPlayerLevel .. ", " .. character.sex[cid] .. ", 0, 0, 0, 0, 1, 0, '', 0, 0, 0);")
  258.             if query then
  259.                 npcHandler:say("Your character has been created.", cid)
  260.                 talkState[talkUser] = 0
  261.             else
  262.                 npcHandler:say("Your character couldn't be created, please try again.", cid)
  263.                 talkState[talkUser] = 5
  264.             end
  265.         end
  266.     elseif talkState[talkUser] == 12 then
  267.         if voc[msg] then
  268.             npcHandler:say("So you would like to be " .. msg .. "... are you sure?", cid)
  269.             toBe = voc[msg]
  270.             talkState[talkUser] = 13
  271.         else
  272.             npcHandler:say("I don't understand what vocation you would like to be... could you please repeat it?", cid)
  273.         end
  274.     elseif talkState[talkUser] == 13 and msgcontains(msg, "no") then
  275.         npcHandler:say("No? Then what would you like to be?", cid)
  276.         talkState[talkUser] = 12
  277.     elseif talkState[talkUser] == 13 and msgcontains(msg, "yes") then
  278.         character.voc[cid] = toBe
  279.         local query = db.executeQuery("insert into players (id, name, world_id, group_id, account_id, level, vocation, health, healthmax, experience, lookbody, lookfeet, lookhead, looklegs, looktype, lookaddons, maglevel, mana, manamax, manaspent, soul, town_id, posx, posy, posz, conditions, cap, sex, lastlogin, lastip, skull, skulltime, save, rank_id, guildnick, lastlogout, blessings, online) VALUES (NULL, " .. db.escapeString(character.name[cid]) .. ", " .. getConfigValue("worldId") .. ", 1, " .. getAccountIdByAccount(account.name[cid]) .. ", " .. config.newPlayerLevel .. ", " .. character.voc[cid] .. ", " .. getVocationInfo(character.voc[cid]).healthGain * config.newPlayerLevel .. ", " .. getVocationInfo(character.voc[cid]).healthGain * config.newPlayerLevel .. ", " .. (config.newPlayerLevel < 2 and 0 or getExperienceForLevel(config.newPlayerLevel)) .. ", 68, 76, 78, 39, " .. (character.sex[cid] == 1 and 136 or 128) .. ", 0, " .. config.newPlayerMagicLevel .. ", 0, 0, 0, 100, " .. config.newPlayerTownId .. ", " .. config.newPlayerSpawnPosX .. ", " .. config.newPlayerSpawnPosY .. ", " .. config.newPlayerSpawnPosZ .. ", 0, " .. capMax + getVocationInfo(character.voc[cid]).capacity * config.newPlayerLevel .. ", " .. character.sex[cid] .. ", 0, 0, 0, 0, 1, 0, '', 0, 0, 0);")
  280.         if query then
  281.             npcHandler:say("Your character has been created.", cid)
  282.             talkState[talkUser] = 0
  283.         else
  284.             npcHandler:say("Your character couldn't be created, please try again.", cid)
  285.             talkState[talkUser] = 5
  286.         end
  287.     end
  288.     return true
  289. end
  290.  
  291. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  292. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement