Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Name Changer
- Scripted by Grandelf
- ]]--
- NameNpc = {}
- NameNpc.NpcId = -- Put npc id here.
- 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"}
- function NameNpc.NameNpcOnGossipTalk(pUnit, Event, player)
- pUnit:GossipCreateMenu(1, player, 0)
- pUnit:GossipMenuAddItem(1, "Change my name.", 1, 1)
- pUnit:GossipMenuAddItem(1, "Nevermind.", 2, 0)
- pUnit:GossipSendMenu(player)
- end
- function NameNpc.NameNpcOnGossipSelect(pUnit, Event, player, id, intid, code, pMisc)
- if(intid == 1) then
- NameNpc[player:GetName()] = {}
- NameNpc[player:GetName()].tab = {}
- if (NameNpc.SymbolCheck(player, code) == true) then
- local StrL = string.len(""..code.."")
- if (StrL < 13) then
- local N = string.sub(""..code.."", 1, 1)
- local UN = string.upper(""..N.."")
- local N2 = string.sub(""..code.."", 2, StrL)
- local LN = string.lower(""..N2.."")
- local Name = UN:gsub(""..UN.."", ""..UN..""..LN.."")
- if (CharDBQuery("SELECT name FROM characters WHERE name = '"..Name.."'", 0) == false) then
- player:SendBroadcastMessage("You will be disconnected in 5 seconds. This is needed for changing your name.")
- local playername = player:GetName()
- RegisterTimedEvent("NameNpc.Disconnect", 5000, 1, player)
- RegisterTimedEvent("NameNpc.ChangeName", 8000, 1, playername, Name)
- player:GossipComplete()
- else
- player:SendBroadcastMessage("This name is already taken.")
- end
- else
- player:SendBroadcastMessage("The name is to long.")
- end
- else
- player:SendBroadcastMessage("These symbols aint allowed.")
- end
- end
- if(intid == 2) then
- player:GossipComplete()
- end
- end
- function NameNpc.SymbolCheck(player, str)
- if (t == nil) or (t == 0) then
- t = 1
- end
- local StrL = string.len(str)
- local StrC = StrL + 1
- while (t ~= StrC) do
- local N = string.sub(str, t, t)
- if (table.find(NameNpc.AllowedSymbols, N) == false) then
- t = 0
- return false
- else
- t = t + 1
- if (t == StrC) then
- t = 0
- return true
- end
- end
- end
- end
- function NameNpc.Disconnect(player)
- player:SoftDisconnect()
- end
- function NameNpc.ChangeName(playername, name)
- CharDBQuery("UPDATE characters SET name = '"..name.."' WHERE name = '"..playername.."'", 0)
- end
- function table.find(t, v)
- if type(t) == "table" and v then
- for k, val in pairs(t) do
- if v == val then
- return true
- end
- end
- end
- return false
- end
- RegisterUnitGossipEvent(NameNpc.NpcId, 1, "NameNpc.NameNpcOnGossipTalk")
- RegisterUnitGossipEvent(NameNpc.NpcId, 2, "NameNpc.NameNpcOnGossipSelect")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement