Facebook
From Lousy Horse, 2 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 24
  1. local config = {
  2.     newNameLength = {4, 20},
  3.         itemid = 8189
  4. }
  5.  
  6. local allowed = {
  7.         "a","b","c","d","e","f","g","h","i",
  8.         "j","k","l","m","n","o","p","q","r",
  9.         "s","t","u","v","w","x","y","z"," "
  10. }
  11.  
  12. --[[
  13. local array = {
  14.         "-","1","2","3","4","5","6","7","8","9","0",
  15.         "<",">","/","|","~","!","@","#","$","%","^",
  16.         "&","*","(",")","_","=",",",".","gm","[","]",
  17.         "admin","adm","owner","cm"
  18. }
  19. ]]
  20.  
  21. function setPlayerName(cid, currentName, newName)
  22.   if not isPlayer(cid) then return false end
  23.   doRemoveCreature(cid)
  24.   db.executeQuery(string.format('UPDATE `players` SET `name` = %s WHERE name = %s;', db.escapeString(newName), db.escapeString(currentName)))
  25.   return true
  26. end
  27.  
  28. function onSay(cid, words, param, channel)
  29. checkExhausted(cid, 1000, 5) -- zawed el line da ta7t kol function onSay
  30.   if (param == '') then
  31.     doPlayerSendCancel(cid, 'Command requires param')
  32.     return true
  33.   end
  34.  
  35.   if getPlayerItemCount(cid,8189) < 1 then
  36.                 doPlayerSendCancel(cid,"You Dont Have Change Name Item")
  37.                 doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
  38.                 return true
  39.         end
  40.  
  41.   if not param then
  42.     doPlayerSendCancel(cid, string.format('Use: %s  <newname>', words))
  43.     return true
  44.   end
  45.  
  46.         for j = 1, #param do
  47.                 if inArray(allowed, param:sub(j,j):lower()) == false then
  48.                         doPlayerSendCancel(cid, "The name contains invalid words or characters.")
  49.                         return true
  50.                 end
  51.         end
  52.  
  53. --[[
  54.         if string.find(param,"1") or string.find(param,"2") or string.find(param,"1") or string.find(param,"3") or string.find(param,"4") or string.find(param,"5") or
  55.                 string.find(param,"6") or string.find(param,"7") or string.find(param,"8") or string.find(param,"9") or string.find(param,"0") or string.find(param,"-") or
  56.                 string.find(param,"=") or string.find(param,"<") or string.find(param,">") or string.find(param,"/") or string.find(param,"&") or string.find(param,"@") then
  57.                 doPlayerSendCancel(cid, "This Name Is Invalid")
  58.                 return true
  59.         end
  60. ]]
  61.  
  62.   local length = string.len(param)
  63.   if math.min(math.max(length, config.newNameLength[1]), config.newNameLength[2]) ~= length then
  64.     doPlayerSendCancel(cid, string.format('New name has to be between %i and %i characters long.', config.newNameLength[1], config.newNameLength[2]))
  65.     return true
  66.   end
  67.  
  68.   doPlayerRemoveItem(cid,8189,1)
  69.   setPlayerName(cid, getPlayerName(cid),param)
  70.   return true
  71. end
  72.  
  73. function inArray(array, item)
  74.         for i = 1, #array do
  75.                 if array[i] == item then
  76.                         return true
  77.                 end
  78.         end
  79.         return false
  80. end