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

TalkAction Changename in-game

Lua:
local config = {
	text = "You will be kicked in 2 seconds.",
	continue = true, -- Do not change this
	item = {
		Id = 1111,
		count = 1
	},
	maxTextLenght = 15,
	blacklistParam = {"god", "cm", "gm", "tutor", "tester"},
	newMethod = false,
	delay = 2 * 1000
}
 
function onSay(cid, words, param, channel)
	if(param == '') then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
		return true
	end

	local paramTemp, oldName = '', getCreatureName(cid)
	for word in string.gmatch(param, "%a+") do
		paramTemp = "" .. paramTemp .. " " .. word .. ""
	end

	string.gsub(paramTemp, "%s*", "", 1)
	param, text, continue, item = paramTemp, config.text, config.continue, config.item
	if(getPlayerGUIDByName(param) ~= nil) then
		text, continue = "That name is already in use.", false
	elseif(getPlayerItemCount(cid, item.Id) < item.count) then
		text, continue = "You do not have enough premium points.", false
	elseif(not getTilePzInfo(getCreaturePosition(cid))) then
		text, continue = "You must be inside a protection zone to use this command.", false
	elseif(not tostring(param)) then
		text, continue = "Invalid parameter.", false
	elseif(string.len(tostring(param)) > config.maxTextLenght) then
		text, continue = "You can use a maximum of " .. config.maxTextLenght .. " characters.", false
	elseif(string.find(param:lower(), "[^%l%s]") ~= nil) then
		text, continue = "You can not use symbols.", false
	else
		for blacklist = 1, table.maxn(config.blacklistParam) do
			if(string.find(param:lower(), config.blacklistParam[blacklist]) ~= nil) then
				text, continue = "Invalid name entry.", false
				break
			end
		end
	end

	if(continue == false) then
		doPlayerSendCancel(cid, text)
		return true
	end

	doPlayerRemoveItem(cid, item.Id, item.count)
	doPlayerSendTextMessage(cid, 25, text)

	local guid = getPlayerGUID(cid)
	if(config.newMethod == true) then
		doPlayerChangeName(guid, oldName, param) -- for 0.3.7+ (is it necessary to kick the player when using this?)
	else
		db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(param) .. " WHERE `id` = " .. guid .. ";")
		addEvent(function(cid, forceLogout)
			if(isPlayer(cid)) then
				doRemoveCreature(cid, forceLogout)
			end
		end, config.delay, cid, false)
	end

	return true
end
 
What error?
Lua:
local config = {
	text = "Your name has been changed succesfully.",
	continue = true, -- Do not change this
	item = {
		Id = 1111,
		count = 1
	},
	maxTextLenght = 15,
	blacklistParam = {"god", "cm", "gm", "tutor", "tester"},
	newMethod = false,
	delay = 2
}
 
function onSay(cid, words, param, channel)
	if(param == '') then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
		return true
	end

	local paramTemp, oldName = '', getCreatureName(cid)
	for word in string.gmatch(param, "%a+") do
		paramTemp = "" .. paramTemp .. " " .. word .. ""
	end

	string.gsub(paramTemp, "%s*", "", 1)
	param, text, continue = paramTemp, config.text, config.continue
	if(getPlayerGUIDByName(param) ~= nil) then
		text, continue = "That name is already in use.", false
	elseif(getPlayerItemCount(cid, config.item.Id) < config.item.count) then
		text, continue = "You do not have enough premium points.", false
	elseif(not getTilePzInfo(getCreaturePosition(cid))) then
		text, continue = "You must be inside a protection zone to use this command.", false
	elseif(not tostring(param)) then
		text, continue = "Invalid parameter.", false
	elseif(string.len(tostring(param)) > config.maxTextLenght) then
		text, continue = "You can use a maximum of " .. config.maxTextLenght .. " characters.", false
	elseif(string.find(param:lower(), "[^%l%s]") ~= nil) then
		text, continue = "You can not use symbols.", false
	else
		for blacklist = 1, table.maxn(config.blacklistParam) do
			if(string.find(param:lower(), config.blacklistParam[blacklist]) ~= nil) then
				text, continue = "Invalid name entry.", false
				break
			end
		end
	end

	if(continue == false) then
		doPlayerSendCancel(cid, text)
		return true
	end

	local guid = getPlayerGUID(cid)
	doPlayerRemoveItem(cid, config.item.Id, config.item.count)
	if(config.newMethod == true) then
		doPlayerChangeName(guid, oldName, param) -- for 0.3.7+ (is it necessary to kick the player when using this?)
	else
		db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(param) .. " WHERE `id` = " .. guid .. ";")
		text = "" .. text .. " You will be kicked in " .. config.delay .. " seconds."
	end

	doPlayerSendTextMessage(cid, 25, "" .. text .. "")
	if(config.newMethod == false) then
		addEvent(function(cid, forceLogout)
			if(isPlayer(cid)) then
				doRemoveCreature(cid, forceLogout)
			end
		end, config.delay * 1000, cid, false)
	end

	return true
end
 
!changename Lucas
18:42 Lucas [80]: aa
There is a space before name

EDIT
another problem:
18:44 L u c a s [80]: <
 
Before or after the name?
There's nothing to do about the second error, unless you want me to put a mininum letter check for each word.
 
Try this:
Lua:
local config = {
	text = "Your name has been changed succesfully.",
	continue = true, -- Do not change this
	item = {
		Id = 1111,
		count = 1
	},
	maxTextLenght = 15,
	blacklistParam = {"god", "cm", "gm", "tutor", "tester"},
	newMethod = false,
	delay = 2
}
 
function onSay(cid, words, param, channel)
	if(param == '') then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
		return true
	end

	local paramTemp, oldName = '', getCreatureName(cid)
	for word in string.gmatch(param, "%a+") do
		paramTemp = "" .. paramTemp .. " " .. word .. ""
	end

	string.gsub(paramTemp, "%s+", "", 1)
	param, text, continue = paramTemp, config.text, config.continue
	if(getPlayerGUIDByName(param) ~= nil) then
		text, continue = "That name is already in use.", false
	elseif(getPlayerItemCount(cid, config.item.Id) < config.item.count) then
		text, continue = "You do not have enough premium points.", false
	elseif(not getTilePzInfo(getCreaturePosition(cid))) then
		text, continue = "You must be inside a protection zone to use this command.", false
	elseif(not tostring(param)) then
		text, continue = "Invalid parameter.", false
	elseif(string.len(tostring(param)) > config.maxTextLenght) then
		text, continue = "You can use a maximum of " .. config.maxTextLenght .. " characters.", false
	elseif(string.find(param:lower(), "[^%l%s]") ~= nil) then
		text, continue = "You can not use symbols.", false
	else
		for blacklist = 1, table.maxn(config.blacklistParam) do
			if(string.find(param:lower(), config.blacklistParam[blacklist]) ~= nil) then
				text, continue = "Invalid name entry.", false
				break
			end
		end
	end

	if(continue == false) then
		doPlayerSendCancel(cid, text)
		return true
	end

	local guid = getPlayerGUID(cid)
	doPlayerRemoveItem(cid, config.item.Id, config.item.count)
	if(config.newMethod == true) then
		doPlayerChangeName(guid, oldName, param) -- for 0.3.7+ (is it necessary to kick the player when using this?)
	else
		db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(param) .. " WHERE `id` = " .. guid .. ";")
		text = "" .. text .. " You will be kicked in " .. config.delay .. " seconds."
	end

	doPlayerSendTextMessage(cid, 25, "" .. text .. "")
	if(config.newMethod == false) then
		addEvent(function(cid, forceLogout)
			if(isPlayer(cid)) then
				doRemoveCreature(cid, forceLogout)
			end
		end, config.delay * 1000, cid, false)
	end

	return true
end
 
Lua:
local config = {
	text = "Your name has been changed succesfully.",
	continue = true, -- Do not change this
	item = {
		Id = 1111,
		count = 1
	},
	maxTextLenght = 15,
	blacklistParam = {"god", "cm", "gm", "tutor", "tester"},
	newMethod = false,
	delay = 2
}
 
function onSay(cid, words, param, channel)
	if(param == '') then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
		return true
	end

	local paramTemp, oldName = '', getCreatureName(cid)
	for word in string.gmatch(param, "%a+") do
		paramTemp = "" .. paramTemp .. " " .. word .. ""
	end

	string.gsub(paramTemp, "%s*", "", 2)
	param, text, continue = paramTemp, config.text, config.continue
	if(getPlayerGUIDByName(param) ~= nil) then
		text, continue = "That name is already in use.", false
	elseif(getPlayerItemCount(cid, config.item.Id) < config.item.count) then
		text, continue = "You do not have enough premium points.", false
	elseif(not getTilePzInfo(getCreaturePosition(cid))) then
		text, continue = "You must be inside a protection zone to use this command.", false
	elseif(not tostring(param)) then
		text, continue = "Invalid parameter.", false
	elseif(string.len(tostring(param)) > config.maxTextLenght) then
		text, continue = "You can use a maximum of " .. config.maxTextLenght .. " characters.", false
	elseif(string.find(param:lower(), "[^%l%s]") ~= nil) then
		text, continue = "You can not use symbols.", false
	else
		for blacklist = 1, table.maxn(config.blacklistParam) do
			if(string.find(param:lower(), config.blacklistParam[blacklist]) ~= nil) then
				text, continue = "Invalid name entry.", false
				break
			end
		end
	end

	if(continue == false) then
		doPlayerSendCancel(cid, text)
		return true
	end

	local guid = getPlayerGUID(cid)
	doPlayerRemoveItem(cid, config.item.Id, config.item.count)
	if(config.newMethod == true) then
		doPlayerChangeName(guid, oldName, param) -- for 0.3.7+ (is it necessary to kick the player when using this?)
	else
		db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(param) .. " WHERE `id` = " .. guid .. ";")
		text = "" .. text .. " You will be kicked in " .. config.delay .. " seconds."
	end

	doPlayerSendTextMessage(cid, 25, "" .. text .. "")
	if(config.newMethod == false) then
		addEvent(function(cid, forceLogout)
			if(isPlayer(cid)) then
				doRemoveCreature(cid, forceLogout)
			end
		end, config.delay * 1000, cid, false)
	end

	return true
end
 
Try this:
Lua:
local config = {
	text = "Your name has been changed succesfully.",
	continue = true, -- Do not change this
	item = {
		Id = 1111,
		count = 1
	},
	maxTextLenght = 15,
	blacklistParam = {"god", "cm", "gm", "tutor", "tester"},
	newMethod = false,
	delay = 2
}
 
function onSay(cid, words, param, channel)
	if(param == '') then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
		return true
	end

	local paramTemp, space, oldName = '', '', getCreatureName(cid)
	for word in string.gmatch(param, "%a+") do
		paramTemp = "" .. paramTemp .. "" .. space .. "" .. word .. ""
		if(space == '') then
			space = " "
		end
	end

	param, text, continue = paramTemp, config.text, config.continue
	if(getPlayerGUIDByName(param) ~= nil) then
		text, continue = "That name is already in use.", false
	elseif(getPlayerItemCount(cid, config.item.Id) < config.item.count) then
		text, continue = "You do not have enough premium points.", false
	elseif(not getTilePzInfo(getCreaturePosition(cid))) then
		text, continue = "You must be inside a protection zone to use this command.", false
	elseif(not tostring(param)) then
		text, continue = "Invalid parameter.", false
	elseif(string.len(tostring(param)) > config.maxTextLenght) then
		text, continue = "You can use a maximum of " .. config.maxTextLenght .. " characters.", false
	elseif(string.find(param:lower(), "[^%l%s]") ~= nil) then
		text, continue = "You can not use symbols.", false
	else
		for blacklist = 1, table.maxn(config.blacklistParam) do
			if(string.find(param:lower(), config.blacklistParam[blacklist]) ~= nil) then
				text, continue = "Invalid name entry.", false
				break
			end
		end
	end

	if(continue == false) then
		doPlayerSendCancel(cid, text)
		return true
	end

	local guid = getPlayerGUID(cid)
	doPlayerRemoveItem(cid, config.item.Id, config.item.count)
	if(config.newMethod == true) then
		doPlayerChangeName(guid, oldName, param) -- for 0.3.7+ (is it necessary to kick the player when using this?)
	else
		db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(param) .. " WHERE `id` = " .. guid .. ";")
		text = "" .. text .. " You will be kicked in " .. config.delay .. " seconds."
	end

	doPlayerSendTextMessage(cid, 25, "" .. text .. "")
	if(config.newMethod == false) then
		addEvent(function(cid, forceLogout)
			if(isPlayer(cid)) then
				doRemoveCreature(cid, forceLogout)
			end
		end, config.delay * 1000, cid, false)
	end

	return true
end
And C++ shouldn't be needed really.
 
Last edited:
!changename Lucas = It's ok now.
!changename L u c a s = Too many spaces
!changename ? = Character without name

Try this:
Lua:
local config = {
	text = "Your name has been changed succesfully.",
	continue = true, -- Do not change this
	item = {
		Id = 1111,
		count = 1
	},
	maxTextLenght = 15,
	blacklistParam = {"account manager", "god", "cm", "gm", "tutor", "tester"},
	newMethod = false,
	delay = 2
}
 
function onSay(cid, words, param, channel)
	if(param == '') then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
		return true
	end

	local paramTemp, space, oldName = '', '', getCreatureName(cid)
	for word in string.gmatch(param, "%a+") do
		paramTemp = "" .. paramTemp .. "" .. space .. "" .. word .. ""
		if(space == '') then
			space = " "
		end
	end

	param, text, continue = paramTemp, config.text, config.continue
	if(getPlayerGUIDByName(param) ~= nil) then
		text, continue = "That name is already in use.", false
	elseif(getPlayerItemCount(cid, config.item.Id) < config.item.count) then
		text, continue = "You do not have enough premium points.", false
	elseif(not getTilePzInfo(getCreaturePosition(cid))) then
		text, continue = "You must be inside a protection zone to use this command.", false
	elseif(not tostring(param)) then
		text, continue = "Invalid parameter.", false
	elseif(string.len(tostring(param)) > config.maxTextLenght) then
		text, continue = "You can use a maximum of " .. config.maxTextLenght .. " characters.", false
	elseif(string.find(param:lower(), "[^%l%s]") ~= nil) then
		text, continue = "You can not use symbols.", false
	else
		for blacklist = 1, table.maxn(config.blacklistParam) do
			if(string.find(param:lower(), config.blacklistParam[blacklist]) ~= nil) then
				text, continue = "Invalid name entry.", false
				break
			end
		end
	end

	if(continue == false) then
		doPlayerSendCancel(cid, text)
		return true
	end

	local guid = getPlayerGUID(cid)
	doPlayerRemoveItem(cid, config.item.Id, config.item.count)
	if(config.newMethod == true) then
		doPlayerChangeName(guid, oldName, param) -- for 0.3.7+ (is it necessary to kick the player when using this?)
	else
		db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(param) .. " WHERE `id` = " .. guid .. ";")
		text = "" .. text .. " You will be kicked in " .. config.delay .. " seconds."
	end

	doPlayerSendTextMessage(cid, 25, "" .. text .. "")
	if(config.newMethod == false) then
		addEvent(function(cid, forceLogout)
			if(isPlayer(cid)) then
				doRemoveCreature(cid, forceLogout)
			end
		end, config.delay * 1000, cid, false)
	end

	return true
end
And C++ shouldn't be needed really.

- - - Updated - - -

Added Account manager to blacklist
blacklistParam = {"account manager", "god", "cm", "gm", "tutor", "tester"},

- - - Updated - - -

Changed
Lua:
elseif(string.find(param:lower(), "[^%l%s]") ~= nil) then
to
Lua:
elseif(string.find(param:lower(), "?[^%l%s]") ~= nil) then

If I use !changename Pêdro = Character name "P dro"
and If I use !changename L?uquinhas = Character name "L uquinhas"
 
Last edited:
ê, ?, (and Ñ too I think) are considered symbols too. If you want to add them you'll have to create a whitelist table and manually add each symbol you want.

I added the config value "minWordLenght" to avoid those 1 lettered words.
Lua:
local config = {
	text = "Your name has been changed successfully.",
	item = {
		Id = 1111,
		count = 1
	},
	maxTextLenght = 15,
	blacklistParam = {"account manager", "god", "cm", "gm", "tutor", "tester"},
	minWordLenght = 3,
	newMethod = false,
	delay = 2
}

function onSay(cid, words, param, channel)
	local textCancel = config.text
	if(param == '') then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
	elseif(getPlayerGUIDByName(param) ~= nil) then
		textCancel = "That name is already in use."
	elseif(getPlayerItemCount(cid, config.item.Id) < config.item.count) then
		textCancel = "You do not have enough premium points."
	elseif(not getTilePzInfo(getCreaturePosition(cid))) then
		textCancel = "You must be inside a protection zone to use this command."
	elseif(string.len(tostring(param)) >= config.maxTextLenght) then
		textCancel = "You can only use a maximum of " .. config.maxTextLenght .. " characters."
	elseif(string.find(param, "[%a]") ~= nil) then
		textCancel = "Invalid parameter."
	elseif(string.find(param:lower(), "[^%l%s]") ~= nil) then
		textCancel = "You can not use symbols."
	else
		for blacklist = 1, table.maxn(config.blacklistParam) do
			if(string.find(param:lower(), config.blacklistParam[blacklist]) ~= nil) then
				textCancel = "Invalid name entry."
				break
			end
		end
	end

	if(config.text ~= textCancel) then
		doPlayerSendCancel(cid, textCancel)
		return true
	end

	local paramTemp, space, oldName = '', '', getCreatureName(cid)
	for word in string.gmatch(param, "%a+") do
		if(string.len(word) < config.minWordLenght) then
			doPlayerSendCancel(cid, "Each word must have a minimum of " .. config.minWordLenght .. " characters.")
			return true
		end

		paramTemp = "" .. paramTemp .. "" .. space .. "" .. word .. ""
		if(space == '') then
			space = " "
		end
	end

	local guid = getPlayerGUID(cid)
	param = paramTemp
	doPlayerRemoveItem(cid, config.item.Id, config.item.count)
	if(config.newMethod == true) then
		doPlayerChangeName(guid, oldName, param) -- for 0.3.7+ (is it necessary to kick the player when using this?)
	else
		db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(param) .. " WHERE `id` = " .. guid .. ";")
		config.text = "" .. config.text .. " You will be kicked in " .. config.delay .. " seconds."
	end

	doPlayerSendTextMessage(cid, 25, config.text)
	if(config.newMethod == false) then
		addEvent(function(cid, forceLogout)
			if(isPlayer(cid)) then
				doRemoveCreature(cid, forceLogout)
			end
		end, config.delay * 1000, cid, false)
	end

	return true
end
 
Last edited:
Invalid parameter, why?
!changename Mynewname

- Do not accepting any symbol. OK

- Accepting space as name.
Example: "!changename ".
 
Last edited:
It should be the other way. My bad.
Lua:
local config = {
	text = "Your name has been changed successfully.",
	item = {
		Id = 1111,
		count = 1
	},
	maxTextLenght = 15,
	blacklistParam = {"account manager", "god", "cm", "gm", "tutor", "tester"},
	minWordLenght = 3,
	newMethod = false,
	delay = 2
}

function onSay(cid, words, param, channel)
	local textCancel = config.text
	if(param == '') then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
	elseif(getPlayerGUIDByName(param) ~= nil) then
		textCancel = "That name is already in use."
	elseif(getPlayerItemCount(cid, config.item.Id) < config.item.count) then
		textCancel = "You do not have enough premium points."
	elseif(not getTilePzInfo(getCreaturePosition(cid))) then
		textCancel = "You must be inside a protection zone to use this command."
	elseif(string.len(tostring(param)) >= config.maxTextLenght) then
		textCancel = "You can only use a maximum of " .. config.maxTextLenght .. " characters."
	elseif(string.find(param, "%a") ~= nil) then
		textCancel = "Invalid parameter."
	elseif(string.find(param:lower(), "[^%l%s]") ~= nil) then
		textCancel = "You can not use symbols."
	else
		for blacklist = 1, table.maxn(config.blacklistParam) do
			if(string.find(param:lower(), config.blacklistParam[blacklist]) ~= nil) then
				textCancel = "Invalid name entry."
				break
			end
		end
	end

	if(config.text ~= textCancel) then
		doPlayerSendCancel(cid, textCancel)
		return true
	end

	local paramTemp, space, oldName = '', '', getCreatureName(cid)
	for word in string.gmatch(param, "%a+") do
		if(string.len(word) < config.minWordLenght) then
			doPlayerSendCancel(cid, "Each word must have a minimum of " .. config.minWordLenght .. " characters.")
			return true
		end
 
		paramTemp = "" .. paramTemp .. "" .. space .. "" .. word .. ""
		if(space == '') then
			space = " "
		end
	end

	local guid = getPlayerGUID(cid)
	param = paramTemp
	doPlayerRemoveItem(cid, config.item.Id, config.item.count)
	if(config.newMethod == true) then
		doPlayerChangeName(guid, oldName, param) -- for 0.3.7+ (is it necessary to kick the player when using this?)
	else
		db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(param) .. " WHERE `id` = " .. guid .. ";")
		config.text = "" .. config.text .. " You will be kicked in " .. config.delay .. " seconds."
	end

	doPlayerSendTextMessage(cid, 25, config.text)
	if(config.newMethod == false) then
		addEvent(function(cid, forceLogout)
			if(isPlayer(cid)) then
				doRemoveCreature(cid, forceLogout)
			end
		end, config.delay * 1000, cid, false)
	end

	return true
end
 
Last edited:
Here.
Lua:
local config = {
	text = "Your name has been changed successfully.",
	item = {
		Id = 1111,
		count = 1
	},
	maxTextLenght = 15,
	blacklistParam = {"account manager", "god", "cm", "gm", "tutor", "tester"},
	minWordLenght = 3,
	newMethod = false,
	delay = 2
}

function onSay(cid, words, param, channel)
	local textCancel = config.text
	if(param == '') then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
	elseif(getPlayerGUIDByName(param) ~= nil) then
		textCancel = "That name is already in use."
	elseif(getPlayerItemCount(cid, config.item.Id) < config.item.count) then
		textCancel = "You do not have enough premium points."
	elseif(not getTilePzInfo(getCreaturePosition(cid))) then
		textCancel = "You must be inside a protection zone to use this command."
	elseif(string.len(tostring(param)) >= config.maxTextLenght) then
		textCancel = "You can only use a maximum of " .. config.maxTextLenght .. " characters."
	elseif(string.find(param, "[%a]") == nil) then
		textCancel = "Invalid parameter."
	elseif(string.find(param:lower(), "[^%l%s]") ~= nil) then
		textCancel = "You can not use symbols."
	else
		for blacklist = 1, table.maxn(config.blacklistParam) do
			if(string.find(param:lower(), config.blacklistParam[blacklist]) ~= nil) then
				textCancel = "Invalid name entry."
				break
			end
		end
	end

	if(config.text ~= textCancel) then
		doPlayerSendCancel(cid, textCancel)
		return true
	end

	local paramTemp, space, oldName = '', '', getCreatureName(cid)
	for word in string.gmatch(param, "%a+") do
		if(string.len(word) < config.minWordLenght) then
			doPlayerSendCancel(cid, "Each word must have a minimum of " .. config.minWordLenght .. " characters.")
			return true
		end
 
		paramTemp = "" .. paramTemp .. "" .. space .. "" .. word .. ""
		if(space == '') then
			space = " "
		end
	end

	local guid = getPlayerGUID(cid)
	param = paramTemp
	doPlayerRemoveItem(cid, config.item.Id, config.item.count)
	if(config.newMethod == true) then
		doPlayerChangeName(guid, oldName, param) -- for 0.3.7+ (is it necessary to kick the player when using this?)
	else
		db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(param) .. " WHERE `id` = " .. guid .. ";")
		config.text = "" .. config.text .. " You will be kicked in " .. config.delay .. " seconds."
	end

	doPlayerSendTextMessage(cid, 25, config.text)
	if(config.newMethod == false) then
		addEvent(function(cid, forceLogout)
			if(isPlayer(cid)) then
				doRemoveCreature(cid, forceLogout)
			end
		end, config.delay * 1000, cid, false)
	end
 
	return true
end
 
- !changename Mynewname OK

- Do not accepting any symbol. OK

- Accepting space as name.
Example: "!changename ". miss
 
Lua:
local config = {
	text = "Your name has been changed successfully.",
	item = {
		Id = 1111,
		count = 1
	},
	maxTextLenght = 15,
	blacklistParam = {"account manager", "god", "cm", "gm", "tutor", "tester"},
	minWordLenght = 3,
	newMethod = false,
	delay = 2
}

function onSay(cid, words, param, channel)
	local textCancel = config.text
	if(param == '') then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
	elseif(getPlayerGUIDByName(param) ~= nil) then
		textCancel = "That name is already in use."
	elseif(getPlayerItemCount(cid, config.item.Id) < config.item.count) then
		textCancel = "You do not have enough premium points."
	elseif(not getTilePzInfo(getCreaturePosition(cid))) then
		textCancel = "You must be inside a protection zone to use this command."
	elseif(string.len(tostring(param)) >= config.maxTextLenght) then
		textCancel = "You can only use a maximum of " .. config.maxTextLenght .. " characters."
	elseif(string.find(param, "[^%s]") == nil) then
		textCancel = "Invalid parameter."
	elseif(string.find(param:lower(), "[^%l%s]") ~= nil) then
		textCancel = "You can not use symbols."
	else
		for blacklist = 1, table.maxn(config.blacklistParam) do
			if(string.find(param:lower(), config.blacklistParam[blacklist]) ~= nil) then
				textCancel = "Invalid name entry."
				break
			end
		end
	end

	if(config.text ~= textCancel) then
		doPlayerSendCancel(cid, textCancel)
		return true
	end

	local paramTemp, space, oldName = '', '', getCreatureName(cid)
	for word in string.gmatch(param, "%a+") do
		if(string.len(word) < config.minWordLenght) then
			doPlayerSendCancel(cid, "Each word must have a minimum of " .. config.minWordLenght .. " characters.")
			return true
		end
 
		paramTemp = "" .. paramTemp .. "" .. space .. "" .. word .. ""
		if(space == '') then
			space = " "
		end
	end

	local guid = getPlayerGUID(cid)
	param = paramTemp
	doPlayerRemoveItem(cid, config.item.Id, config.item.count)
	if(config.newMethod == true) then
		doPlayerChangeName(guid, oldName, param) -- for 0.3.7+ (is it necessary to kick the player when using this?)
	else
		db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(param) .. " WHERE `id` = " .. guid .. ";")
		config.text = "" .. config.text .. " You will be kicked in " .. config.delay .. " seconds."
	end

	doPlayerSendTextMessage(cid, 25, config.text)
	if(config.newMethod == false) then
		addEvent(function(cid, forceLogout)
			if(isPlayer(cid)) then
				doRemoveCreature(cid, forceLogout)
			end
		end, config.delay * 1000, cid, false)
	end

	return true
end
 
Back
Top