local scrollId = 1234
function onSay(cid, words, param)
if param == "" then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'To use the command: !changename "NEW_NAME')
return false
end
if getPlayerItemCount(cid, scrollId) < 0 then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You need a ' .. getItemNameById(scrollId))
return false
end
if getTilePzInfo(getPlayerPosition(cid)) ~= true then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You can only use this command in a protected area.')
return false
end
doPlayerRemoveItem(cid, scrollId, 1)
local guid = getPlayerGUID(cid)
doRemoveCreature(cid)
db.executeQuery("UPDATE `players` SET `name` = '" .. param .. "' WHERE `id` = " .. guid .. ";")
doRemoveCreature(guid)
return true
end
Achei um script bem mais completo do que esse que criei:
local config = {
item = {Id = 1111, count = 0},
paramBlacklist = {"account manager", "god", "tutor", "tester"},
kick = {enabled = true, delay = 2 * 1000},
forceLogout = false,
namelockCheck = true,
vowelsCheck = true,
maxTextLenght = 29,
minWordLenght = 2,
maxWordLenght = 14,
maxWords = 3
}
config.kick.enabled = getBooleanFromString(config.kick.enabled)
config.forceLogout = getBooleanFromString(config.forceLogout)
config.namelockCheck = getBooleanFromString(config.namelockCheck)
config.vowelsCheck = getBooleanFromString(config.vowelsCheck)
function onSay(cid, words, param, channel)
local t = string.explode(param, ",")
local len, firstWord, wordCount, textCancel, limit = string.len(tostring(t[1])), true, 0, '', ";"
if(getConfigValue('sqlType') == 'mysql') then
limit = db.updateLimiter()
end
if(param == '') then
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
elseif(getPlayerGUIDByName(t[1], true) ~= nil) then
textCancel = "That name is already in use."
elseif(getPlayerItemCount(cid, config.item.Id) < config.item.count) then
textCancel = "You do not fulfill the requirements."
elseif(not getTilePzInfo(getCreaturePosition(cid))) then
textCancel = "You must be inside a protection zone to use this command."
elseif(len > config.maxTextLenght) then
textCancel = "A name must have at least " .. config.minWordLenght .. " but no more than " .. config.maxTextLenght .. " letters!"
elseif(config.namelockCheck and db.getResult("SELECT * FROM `player_namelocks` WHERE `name` = " .. db.escapeString(t[1]) .. "" .. limit .. ""):getID() ~= 1) then
textCancel = "That name is namelocked."
elseif(string.find(t[1]:lower(), "[^%l%s]") ~= nil) then
textCancel = "This name contains invalid letters. Please use only A-Z, a-z and space!"
else
paramTemp = ''
for word in string.gmatch(t[1], "%a+") do
len, wordCount = string.len(word), wordCount + 1
if(isInArray(config.paramBlacklist, paramTemp:lower())) then
textCancel = "Invalid name entry."
break
elseif(len < config.minWordLenght) then
textCancel = "This name contains a word with only " .. len .. " letter" .. (len > 1 and "s" or '') .. ". Please use more than " .. len .. " letter" .. (len > 2 and "s" or '') .. " for each word!"
break
elseif(len > config.maxWordLenght) then
textCancel = "This name contains a word that is too long. Please use no more than " .. config.maxWordLenght .. " letters for each word!"
break
elseif(wordCount > config.maxWords) then
textCancel = "This name contains more than 3 words. Please choose another name!"
break
elseif(config.vowelsCheck and string.find(word:lower(), "[aeiouy]") == nil) then
textCancel = "This name contains a word without vowels. Please choose another name!"
break
else
wordTemp = ''
for i = 1, len do
letter = string.sub(word, i, i)
if(i == 1) then
if(getBooleanFromString(firstWord) and string.find(letter, "%l")) then
letter = string.upper(letter)
end
else
if(string.find(letter, "%u")) then
letter = string.lower(letter)
end
end
firstWord = false
wordTemp = "" .. wordTemp .. "" .. letter .. ""
end
end
paramTemp = "" .. paramTemp .. "" .. (paramTemp ~= '' and " " or '') .. "" .. wordTemp .. ""
end
end
if(textCancel ~= '') then
doPlayerSendCancel(cid, textCancel)
return true
end
local oldName, guid = getCreatureName(cid), getPlayerGUID(cid)
t[1] = paramTemp
doPlayerRemoveItem(cid, config.item.Id, config.item.count)
if(pcall(doPlayerChangeName, guid, oldName, t[1]) ~= true) then
db.executeQuery("INSERT INTO `player_namelocks` (`player_id`, `name`, `new_name`, `date`) VALUES (" .. guid .. ", " .. db.escapeString(oldName) .. ", " .. db.escapeString(t[1]) .. ", " .. os.time() .. ");")
db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(t[1]) .. " WHERE `id` = " .. guid .. "" .. limit .. "")
end
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your name has been changed successfully." .. (config.kick.enabled and " You will be kicked in " .. config.kick.delay / 1000 .. " seconds." or " Re-enter the game to see the changes.") .. "")
if(config.kick.enabled) then
addEvent(function(cid, forceLogout)
if(isPlayer(cid)) then
doRemoveCreature(cid, forceLogout)
end
end, config.kick.delay, cid, config.forceLogout)
end
return true
end
A parte do .xml fica assim:
<talkaction log="yes" words="!changename;/changename;!namechange;/namechange" access="0" event="script" value="changename.lua"/>