Advertisement
Guest User

command change name

a guest
Aug 16th, 2019
1,682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.20 KB | None | 0 0
  1. local function characterNameAlreadyExists(characterName)
  2.     local resultId = db.storeQuery('SELECT * FROM `players` WHERE `name` = ' .. db.escapeString(characterName))
  3.     if not resultId then
  4.         return false
  5.     end
  6.     result.free(resultId)
  7.     return true
  8. end
  9.  
  10. local function isCharacterNameCorrect(characterName)
  11.     local reason
  12.     local words = { "owner", "gamemaster", "hoster", "admin", "staff",
  13.     "tibia", "account", "god", "anal", "ass", "fuck",
  14.     "sex", "hitler", "pussy", "dick", "rape", "cm", "gm",
  15.     "tutor", "counsellor", "maldito" }
  16.     for index, word in pairs(words) do
  17.         if string.find(characterName:lower(), word) then
  18.             reason = string.format("The name contains the word %s and is prohibited.", word)
  19.             break
  20.         end
  21.     end
  22.     for index, word in pairs(characterName:split(" ")) do
  23.         if #word < 4 then
  24.             reason = "The name is very long, you must use a shorter one."
  25.             break
  26.         end
  27.     end
  28.     if not reason then
  29.         if MonsterType(characterName) then
  30.             reason = string.format("The name %s can't be a monster's name.", characterName)
  31.         elseif Npc(characterName) then
  32.             reason = string.format("The name %s can't be a npc's name.", characterName)
  33.         elseif string.match(characterName, "%a+%s%a+%s%a+") or string.match(characterName, "%s+%a-%s+") then
  34.             reason = "The name contains many spaces separations."
  35.         elseif string.match(characterName, "%d+") or string.match(characterName, "%p+") then
  36.             reason = "The name cannot contain numbers or symbols."
  37.         elseif #characterName > 18 then
  38.             reason = "The name is very long, you must use a shorter one."
  39.         elseif #characterName < 4 then
  40.             reason = "The name is very short, you must use a longer one."
  41.         end
  42.     end
  43.     return reason
  44. end
  45.  
  46. local function changeName(player, name)
  47.     return db.query(('UPDATE `players` SET `name` = "%s" WHERE `id` = %u'):format(name, player:getGuid()))
  48. end
  49.  
  50. function onSay(player, words, param)
  51.     if param == '' then
  52.         return not player:sendCancelMessage("Insufficient parameters.")
  53.     end
  54.     if player:getItemCount(2112) < 1 then
  55.         player:getPosition():sendMagicEffect(CONST_ME_POFF)
  56.         return not player:sendCancelMessage("You dont have change name item.")
  57.     end
  58.     local newname = param:lower():gsub("(%l)(%w*)", function(a, b) return string.upper(a) .. b end):trim()
  59.     local reason = isCharacterNameCorrect(newname)
  60.     if reason then
  61.         player:sendCancelMessage(reason)
  62.     elseif characterNameAlreadyExists(newname) then
  63.         player:sendCancelMessage("A player with that name already exists, please choose another name.")
  64.     elseif player:removeItem(2112, 1) and changeName(player, newname) then
  65.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The name has been changed successfully.")
  66.         addEvent(function(cid)
  67.             local player = Player(cid)
  68.             if player then
  69.                 player:remove()
  70.             end
  71.         end, 1400, player.uid)
  72.     else
  73.         player:sendCancelMessage("An error occurred while changing the name.")
  74.     end
  75.     return false
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement