omigaaad
Banned User
- Joined
- Jun 29, 2010
- Messages
- 35
- Reaction score
- 8
Code:
<talkaction log="yes" words="!changename;/changename;!namechange;/namechange" access="0" event="script" value="changename.lua"/>
Lua:
local config = {
text = "Your name has been changed successfully.",
item = {
Id = 8189,
count = 1
},
maxTextLenght = 15,
blacklistParam = {"account manager", "god", "cm", "gm", "tutor", "tester"},
minWordLenght = 3,
newMethod = false,
delay = 2
}
function onSay(cid, words, param, channel)
local textCancel = config.text
if(param == '') then
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
elseif(getPlayerGUIDByName(param) ~= nil) then
textCancel = "That name is already in use."
elseif(getPlayerItemCount(cid, config.item.Id) < config.item.count) then
textCancel = "You do not have Change name scroll."
elseif(not getTilePzInfo(getCreaturePosition(cid))) then
textCancel = "You must be inside a protection zone to use this command."
elseif(string.len(tostring(param)) >= config.maxTextLenght) then
textCancel = "You can only use a maximum of " .. config.maxTextLenght .. " characters."
elseif(string.find(param:lower(), "[^%l%s]") ~= nil) then
textCancel = "You cannot use symbols."
else
for blacklist = 1, table.maxn(config.blacklistParam) do
if(string.find(param:lower(), config.blacklistParam[blacklist]) ~= nil) then
textCancel = "Invalid name entry."
break
end
end
end
if(config.text ~= textCancel) then
doPlayerSendCancel(cid, textCancel)
return true
end
local paramTemp, space, oldName = '', '', getCreatureName(cid)
for word in string.gmatch(param, "%a+") do
if(string.len(word) < config.minWordLenght) then
doPlayerSendCancel(cid, "Each word must have a minimum of " .. config.minWordLenght .. " characters.")
return true
end
paramTemp = "" .. paramTemp .. "" .. space .. "" .. word .. ""
if(space == '') then
space = " "
end
end
local guid = getPlayerGUID(cid)
param = paramTemp
doPlayerRemoveItem(cid, config.item.Id, config.item.count)
if(config.newMethod == true) then
doPlayerChangeName(guid, oldName, param)
else
db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(param) .. " WHERE `id` = " .. guid .. ";")
end
doPlayerSendTextMessage(cid, 25, "" .. config.text .. " You will be kicked in " .. config.delay .. " seconds.")
addEvent(function(cid, forceLogout)
if(isPlayer(cid)) then
doRemoveCreature(cid, forceLogout)
end
end, config.delay * 1000, cid, false)
return true
end