• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Change name - error space

Wilku93

Member
Joined
Jul 7, 2024
Messages
36
Reaction score
9
GitHub
Wilku93
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?



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 :D I thought that was it "space". Problem is with "Enter"
 

Attachments

Last edited:
Have you seen this topic? I made it for revScript. I don’t know what TFS version you’re using... take a look here then

 
Have you seen this topic? I made it for revScript. I don’t know what TFS version you’re using... take a look here then

That's where I got it from :D And there's the error I wrote about. "Enter" causes "Enter" to also appear in the nickname and looks like in the screenshot
 

Similar threads

Back
Top