Advertisement
Guest User

Grandelf

a guest
Dec 31st, 2009
673
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.78 KB | None | 0 0
  1. --[[
  2.  
  3.     Name Changer
  4.     Scripted by Grandelf
  5.  
  6. ]]--
  7.  
  8. NameNpc = {}
  9. NameNpc.NpcId =                 -- Put npc id here.
  10.  
  11. NameNpc.AllowedSymbols = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
  12.  
  13. function NameNpc.NameNpcOnGossipTalk(pUnit, Event, player)
  14.     pUnit:GossipCreateMenu(1, player, 0)
  15.     pUnit:GossipMenuAddItem(1, "Change my name.", 1, 1)
  16.     pUnit:GossipMenuAddItem(1, "Nevermind.", 2, 0)
  17.     pUnit:GossipSendMenu(player)
  18. end
  19.  
  20. function NameNpc.NameNpcOnGossipSelect(pUnit, Event, player, id, intid, code, pMisc)
  21.     if(intid == 1) then
  22.         NameNpc[player:GetName()] = {}
  23.         NameNpc[player:GetName()].tab = {}
  24.         if (NameNpc.SymbolCheck(player, code) == true) then
  25.             local StrL = string.len(""..code.."")
  26.             if (StrL < 13) then
  27.                 local N = string.sub(""..code.."", 1, 1)
  28.                 local UN = string.upper(""..N.."")
  29.                 local N2 = string.sub(""..code.."", 2, StrL)
  30.                 local LN = string.lower(""..N2.."")
  31.                 local Name = UN:gsub(""..UN.."", ""..UN..""..LN.."")
  32.                 if (CharDBQuery("SELECT name FROM characters WHERE name = '"..Name.."'", 0) == false) then
  33.                     player:SendBroadcastMessage("You will be disconnected in 5 seconds. This is needed for changing your name.")
  34.                     local playername = player:GetName()
  35.                     RegisterTimedEvent("NameNpc.Disconnect", 5000, 1, player)
  36.                     RegisterTimedEvent("NameNpc.ChangeName", 8000, 1, playername, Name)
  37.                     player:GossipComplete()
  38.                 else
  39.                     player:SendBroadcastMessage("This name is already taken.")
  40.                 end
  41.             else
  42.                 player:SendBroadcastMessage("The name is to long.")
  43.             end
  44.         else
  45.             player:SendBroadcastMessage("These symbols aint allowed.")
  46.         end
  47.     end
  48.     if(intid == 2) then
  49.         player:GossipComplete()
  50.     end
  51. end
  52.  
  53. function NameNpc.SymbolCheck(player, str)
  54.     if (t == nil) or (t == 0) then
  55.         t = 1
  56.     end
  57.     local StrL = string.len(str)
  58.     local StrC = StrL + 1
  59.     while (t ~= StrC) do
  60.         local N = string.sub(str, t, t)
  61.         if (table.find(NameNpc.AllowedSymbols, N) == false) then
  62.             t = 0
  63.             return false
  64.         else
  65.             t = t + 1
  66.             if (t == StrC) then
  67.                 t = 0
  68.                 return true
  69.             end
  70.         end    
  71.     end
  72. end
  73.  
  74. function NameNpc.Disconnect(player)
  75.     player:SoftDisconnect()  
  76. end
  77.  
  78. function NameNpc.ChangeName(playername, name)
  79.     CharDBQuery("UPDATE characters SET name = '"..name.."' WHERE name = '"..playername.."'", 0)
  80. end
  81.  
  82. function table.find(t, v)
  83.     if type(t) == "table" and v then
  84.         for k, val in pairs(t) do
  85.             if v == val then
  86.                 return true
  87.             end
  88.         end
  89.     end
  90.     return false
  91. end
  92.  
  93. RegisterUnitGossipEvent(NameNpc.NpcId, 1, "NameNpc.NameNpcOnGossipTalk")
  94. RegisterUnitGossipEvent(NameNpc.NpcId, 2, "NameNpc.NameNpcOnGossipSelect")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement