Hello. I use the item to change my nickname and everything works fine except for one thing. When changing the nickname, if someone confirms with "Enter" instead of clicking "Okey", an error appears after changing the nickname, as in the chat and photo. Can this be done somehow so that "Enter" does not cause such an error?
Btw. This "space" has nothing to do with the script
I thought that was it "space". Problem is with "Enter"
LUA:
local x = {
length = {['min'] = 4, ['max'] = 20},
itemid = 26394
}
-- List of forbidden names
local forbiddenNames = {
"GM",
"Tutor",
"Admin",
"Owner",
"Developer",
"Support",
"Moderator",
"Game Master",
"GOD",
"GoD",
}
function setPlayerName(cid, newName)
local player = Player(cid)
local name = db.escapeString(player:getName())
newName = db.escapeString(newName)
player:remove()
db.query('UPDATE players SET name = '.. newName ..' WHERE name = '.. name ..';')
end
function correctNameLength(str)
local value = str:len()
return x.length['min'] <= value and x.length['max'] >= value
end
function isNameForbidden(name)
for _, forbiddenName in ipairs(forbiddenNames) do
if name:lower() == forbiddenName:lower() then
return true
end
end
return false
end
function onSay(cid, words, param, channel)
local player = type(cid) == "userdata" and cid or Player(cid)
if not param or param == '' then
player:sendCancelMessage('Use: '.. words ..' <newname>')
return true
end
local position, item = player:getPosition(), ItemType(x.itemid)
if player:getItemCount(x.itemid) < 1 then
player:sendCancelMessage("You do not have enough ".. item:getName()..".")
position:sendMagicEffect(CONST_ME_POFF)
return true
end
if param:find("[^%a%s]") then
player:sendCancelMessage("This name ".. param .." is invalid")
return true
end
if isNameForbidden(param) then
player:sendCancelMessage("This name is not allowed.")
return true
end
if not correctNameLength(param) then
player:sendCancelMessage("The new name has to be between " .. x.length['min'] .. " and " .. x.length['max'] .. " characters.")
return true
end
item:remove()
setPlayerName(player:getId(), param)
player:sendTextMessage(MESSAGE_INFO_DESCR, "Your name has been changed to " .. param .. ".")
return true
end
Post automatically merged:
Btw. This "space" has nothing to do with the script

Attachments
-
acc.webp223.2 KB · Views: 13 · VirusTotal
-
acc1.webp246.2 KB · Views: 13 · VirusTotal
Last edited: