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

NPC Rename NPC

Lua:
local function validName(name)
	if getPlayerGUIDByName(name) ~= nil then
		return RET_EXISTS
	end
 
	local notAllowed = {"god", "gm", "cm"}
	for _, naw in pairs(notAllowed) do
		if (name:lower():find(naw .. " ") or name:lower() == naw or name:lower():find("admin")) then
			return RET_INVALID
		end
	end
 
	for i = 1, name:len() do
		if not(isInArray(chars, name:sub(i,i))) then
			return RET_INVALID
		end
	end
	return RET_VALID
end
 
Last edited:
04:00 Renamer: What should be your new name?
04:00 Admin [30933: adminlol
04:00 Renamer: So you want 'Adminlol' to be your new name for 20 scarab coins?
04:00 Admin [30933: gm
04:00 Renamer: Maybe later.
04:00 Admin [30933: hi
04:00 Admin [30933: name
04:01 Admin [30933: bye
04:01 Renamer: Bye.
04:01 Admin [30933: hi
04:01 Renamer: Hello Admin. Do you want a new name.
04:01 Admin [30933: name
04:01 Renamer: What should be your new name?
04:01 Admin [30933: GM
04:01 Renamer: So you want 'Gm' to be your new name for 20 scarab coins?


i can rename names gm admin cm
 
Last edited:
Updated again, should work better now.
 
i put this line
if (name:lower():find(naw .. " ") or name:lower() == naw or name:lower():find("admin") or >>>>>> this line >>>>>> name:lower():find("gm") or name:lower():find("cm")) then

and work good ty alot
 
I didnt do that because players wont be able to name themselves like Ogmo, as it contains gm in the middle.
GM usually is in the begining of the name and seperated with a space.
 
When I change a name, the player just gets kicked, but it's name still the same, help please >_>
 
When u paste this NPC into notepad it says :eek: at :eek:nCreature so it looks like :eek:nCreature. Damn forum change xD hehe
Code:
:eek:nCreature
^the example lol
EDIT: apparently I cant get away from it lol
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Renamer" script="renamer.lua" walkinterval="0" floorchange="0">
<health now="150" max="150"/>
<look type="129" head="114" body="119" legs="114" feet="114" corpse="2212"/>
<parameters>
<parameter key="message_greet" value="Hello |PLAYERNAME|. Do you want a new {name}."/>
</parameters>
</npc>

Npc/scripts/renamer.lua:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talk = {}
local name = {}

function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function onPlayerEndTrade(cid) npcHandler:onPlayerEndTrade(cid) end
function onPlayerCloseChannel(cid) npcHandler:onPlayerCloseChannel(cid) end

function creatureGreetCallback(cid)
talk[cid] = 0
name[cid] = ''
return true
end

local chars = {' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}

RET_VALID = 1
RET_EXISTS = 2
RET_INVALID = 3

local function validName(name)
if getPlayerGUIDByName(name) ~= nil then
return RET_EXISTS
end

local notAllowed = {"god", "gm", "cm"}
for _, naw in pairs(notAllowed) do
if (name:lower():find(naw .. " ") or name:lower() == naw or name:lower():find("admin")) then
return RET_INVALID
end
end

for i = 1, name:len() do
if not(isInArray(chars, name:sub(i,i))) then
return RET_INVALID
end
end
return RET_VALID
end

local function getValid(name, opt)
local function tchelper(first, rest)
return first:upper()..rest:lower()
end

return opt and name:gsub("(%a)([%w_']*)", tchelper) or name:gsub("^%l", string.upper)
end

local config = {
type = 'money', -- or 'item'
money = 10000, -- = 1cc
item = {2159, 20}, -- itemid, itemcount
everyFirstLetterCapital = true
}

function messageDefaultCallback(cid, type, msg)
if not(npcHandler:isFocused(cid)) then
return false
end

if msgcontains(msg, "name") and talk[cid] == 0 then
selfSay("What should be your new name?", cid)
talk[cid] = 1
elseif talk[cid] == 1 then
local v = getValid(msg:lower(), config.everyFirstLetterCapital)
local ret = validName(v)
if ret == RET_VALID then
selfSay("So you want '" .. v .. "' to be your new name for " .. (config.type == "money" and (config.money .. " gold") or (config.item[2] .. ' ' .. (config.item[2] > 1 and getItemPluralNameById(config.item[1]) or getItemNameById(config.item[1])))) .. "?", cid)
talk[cid], name[cid] = 2, v
else
if ret == RET_INVALID then
selfSay(msg .. " is not a valid name. What should be your new name?", cid)
elseif ret == RET_EXISTS then
selfSay(msg .. " already exists. What should be your new name?", cid)
end
end
elseif talk[cid] == 2 then
if msgcontains(msg, "yes") then
if (config.type == 'money' and doPlayerRemoveMoney(cid, config.money)) or (config.type ~= 'money' and doPlayerRemoveItem(cid, config.item[1], config.item[2])) then
local curName = getPlayerName(cid)
doRemoveCreature(cid)
db.query("UPDATE players SET name = '"..name[cid].."' WHERE name = '"..curName.."';")
else
selfSay("You don't have " .. (config.type == "money" and (config.money .. " gold") or (config.item[2] .. ' ' .. (config.item[2] > 1 and getItemPluralNameById(config.item[1]) or getItemNameById(config.item[1])))) .. "!", cid)
talk[cid] = 0
end
else
selfSay("Maybe later.", cid)
talk[cid] = 0
end
end


return true
end

npcHandler:setMessage(MESSAGE_FAREWELL, "Bye.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "How rude!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, messageDefaultCallback)
npcHandler:setCallback(CALLBACK_FAREWELL, creatureFarewell)
npcHandler:setCallback(CALLBACK_CREATURE_DISAPPEAR, creatureFarewell)
npcHandler:setCallback(CALLBACK_GREET, creatureGreetCallback)
npcHandler:addModule(FocusModule:new())
 
I have problem. All time I have this: "Renamer: NAME already exists. What should be your new name?" all names exists, whatever I write xD and no matter what letters I use - big, small etc. I use TFS1.4
Please help :)
 
Back
Top