• 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!

Name Change Item (TFS 1.0)

God Mythera

Veteran OT User
Joined
Aug 11, 2012
Messages
2,048
Solutions
2
Reaction score
256
Location
United States
Credit to GOD Wille for giving me the script for 0.4 but i have made it work for 1.0 ^^ Enjoy.

Code:
    <talkaction words="!rename" script="rename.lua"/>

Code:
local config = {
    newNameLength = {4, 20},
    itemid = 8189
}

local array = {"-","1","2","3","4","5","6","7","8","9","0","<",">","/","|","~","!","@","#","$","%","^","&","*","(",")","_","=",",","."}

function setPlayerName(cid, currentName, newName)
  if not isPlayer(cid) then return false end
  doRemoveCreature(cid)
  db.query(string.format('UPDATE `players` SET `name` = %s WHERE name = %s;', db.escapeString(newName), db.escapeString(currentName)))
  return true
end

function onSay(cid, words, param, channel)
  if (param == '') then
    doPlayerSendCancel(cid, 'Command requires param')
    return true
  end
  if getPlayerItemCount(cid,8189) < 1 then
        doPlayerSendCancel(cid,"You Dont Have Change Name Item")
        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
        return true
    end

  if not param then
    doPlayerSendCancel(cid, string.format('Use: %s  <newname>', words))
    return true
  end
    if string.find(param,"1") or string.find(param,"2") or string.find(param,"1") or string.find(param,"3") or string.find(param,"4") or string.find(param,"5") or
        string.find(param,"6") or string.find(param,"7") or string.find(param,"8") or string.find(param,"9") or string.find(param,"0") or string.find(param,"-") or
        string.find(param,"=") or string.find(param,"<") or string.find(param,">") or string.find(param,"/") or string.find(param,"&") or string.find(param,"@") then
        doPlayerSendCancel(cid, "This Name Is Invalid")
        return true
    end
  local length = string.len(param)
  if math.min(math.max(length, config.newNameLength[1]), config.newNameLength[2]) ~= length then
    doPlayerSendCancel(cid, string.format('New name has to be between %i and %i characters long.', config.newNameLength[1], config.newNameLength[2]))
    return true
  end
  doPlayerRemoveItem(cid,8189,1)
  setPlayerName(cid, getPlayerName(cid),param)
  return true
end

TFS 1.0
Code:
db.query(string.format('UPDATE `players` SET `name` = %s WHERE name = %s;', db.escapeString(newName), db.escapeString(currentName)))

TFS 0.4
Code:
db.executeQuery(string.format('UPDATE `players` SET `name` = %s WHERE name = %s;', db.escapeString(newName), db.escapeString(currentName)))
 
Last edited:
Why are you bumping this?
 
Code:
if string.find(param,"1") or string.find(param,"2") or string.find(param,"1") or string.find(param,"3") or string.find(param,"4") or string.find(param,"5") or
string.find(param,"6") or string.find(param,"7") or string.find(param,"8") or string.find(param,"9") or string.find(param,"0") or string.find(param,"-") or
string.find(param,"=") or string.find(param,"<") or string.find(param,">") or string.find(param,"/") or string.find(param,"&") or string.find(param,"@") then
creating a table with all these in it, then doing it, mfw
 
This should work for 1.0, 1.1, 1.2
Code:
local x = {
    length = {['min'] = 4, ['max'] = 20},
    itemid = 8189
}

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 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 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)
    return true
end
Edited: See @MatheusMkalo post.
 
Last edited:
This should work for 1.0, 1.1, 1.2
Code:
local x = {
    length = {['min'] = 4, ['max'] = 20},
    itemid = 8189
}

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` = '.. name ..' WHERE name = '.. newName ..';')
end

function correctNameLength(str)
    local value = str:len()
    return x.length['min'] >= value and x.length['max'] <= value
end
--[[
    change cid to player in onSay and remove or comment out the line just below onSay
    local player = Player(cid) to make it work for 1.1, 1.2
]]
function onSay(cid, words, param, channel)
    local player = 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 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)
    return true
end
local player = type(cid) == "userdata" and cid or Player(cid)
 
That's my code for TFS 0.4
Not sure if it can cause any problems, use on your own risk.
Cykotitan made it once for me. (Like 1 year ago)
Code:
local itemId = 5542 -- scroll id

function onTextEdit(cid, item, text)
    if item.itemid == itemId then
       if getTilePzInfo(getPlayerPosition(cid)) ~= TRUE then
           doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You can only use this item inside protection zone!")
           return false
       end

       local checkPlayer = findPlayer(text)
       if (checkPlayer) then
           doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Character name ' .. text .. ' is already in use.')
       else
           text = text:trim()
           text = text:gsub("(%a)([%w_']*)", function(first, rest) return first:upper()..rest:lower() end)
           local low = text:lower()
           if text:len() < 4 then
               doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Name must be atleast 4 letters long.')
           elseif text:len() > 15 then
               doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Name must be less than 15 letters long.')
           elseif text:find('[^A-Za-z%s]') then
               doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Name may only contain letters and spaces.')
           elseif text:find('  ') then
               doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Name may not contain double spaces.')
           elseif low:sub(1, 4) == 'god ' or low:sub(1, 3) == 'cm ' or low:sub(1, 3) == 'gm ' or low:find('admin') then
               doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Name is invalid.')
           elseif doPlayerRemoveItem(cid, itemId, 1) then
               local id = getPlayerGUID(cid)
               local saveName = text:gsub(text, "n", "")
               doRemoveCreature(cid)
               db.executeQuery("UPDATE players SET name = '" .. saveName .. "' WHERE id = " .. id)
           else
               doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'You need to have a namelock scroll.')
           end
       end
       return false
    end
    return true
end
 
hi, its not working for me on tfs 1.2, i changed function onSay(cid, words, param, channel) to function onSay(player, words, param, channel) and removed line below, but it alwasy appear message of incorrect name lenght
 
Back
Top