Solved all bugs (i think)
- A name with only spaces it's not valid.
- A name with symbols or numbers it's not valid.
- A name with too many spaces it's not valid. The number of spaces can be set at variable "maxspaces"
btw nice scriptLua:local itemId, count, maxTextLenght, delay = 2160, 1, 15, 2 * 1000 local blacklistParam = {"god", "cm", "gm", "tutor", "tester"} local maxspaces = 2 function getSpaces(word) _, count = string.gsub(word, " ", " ") return count end function onSay(cid, words, param, channel) local text, continue = "You will be kicked in 2 seconds.", true if (not param or param:find("%a") == nil) then text, continue = "You must put a correct name.", false elseif(db.getResult("SELECT `name` FROM `players` WHERE `name` = " .. db.escapeString(param) .. ";"):getID() ~= -1) then text, continue = "That name is already in use.", false elseif(getPlayerItemCount(cid, itemId) < 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(getSpaces(param) > maxspaces) then text, continue = "Parameter contains too much spaces.", false elseif(string.len(tostring(param)) > maxTextLenght) then text, continue = "You can use a maximum of " .. maxTextLenght .. " characters.", false elseif(string.find(param:lower(), "[%p%d]") ~= nil) then text, continue = "You can not use symbols.", false else for blacklist = 1, table.maxn(blacklistParam) do if(string.find(param:lower(), blacklistParam[blacklist]) ~= nil) then text, continue = "Invalid name entry.", false break end end end if(continue == false) then doPlayerSendCancel(cid, text) return true end db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(param) .. " WHERE `id` = " .. getPlayerGUID(cid) .. ";") doPlayerRemoveItem(cid, itemId, count) doPlayerSendTextMessage(cid, 25, text) addEvent(function(cid, forceLogout) if(isPlayer(cid)) then doRemoveCreature(cid, forceLogout) end end, delay, cid, false) return true end
local itemId, count, maxTextLenght, delay = 1111, 1, 15, 2 * 1000
local blacklistParam = {"god", "cm", "gm", "tutor", "tester"}
function onSay(cid, words, param, channel)
local text, continue = "You will be kicked in 2 seconds.", true
local spaceStart, spaceEnd = string.find(param, "%s*")
if(db.getResult("SELECT `name` FROM `players` WHERE `name` = " .. db.escapeString(param) .. ";"):getID() ~= -1) then
text, continue = "That name is already in use.", false
elseif(getPlayerItemCount(cid, itemId) < 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(spaceStart == 1 or spaceEnd == string.len(tostring(param))) then
text, continue = "The first or last characters cannot be spaces.", false
elseif(string.find(param, "%a%s+") ~= nil) then
text, continue = "Parameter contains too many spaces in between letters.", false
elseif(string.len(tostring(param)) > maxTextLenght) then
text, continue = "You can use a maximum of " .. 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(blacklistParam) do
if(string.find(param:lower(), blacklistParam[blacklist]) ~= nil) then
text, continue = "Invalid name entry.", false
break
end
end
end
if(continue == false) then
doPlayerSendCancel(cid, text)
return true
end
db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(param) .. " WHERE `id` = " .. getPlayerGUID(cid) .. ";")
doPlayerRemoveItem(cid, itemId, count)
doPlayerSendTextMessage(cid, 25, text)
addEvent(function(cid, forceLogout)
if(isPlayer(cid)) then
doRemoveCreature(cid, forceLogout)
end
end, delay, cid, false)
return true
end
This should do it:
Lua:local itemId, count, maxTextLenght, delay = 1111, 1, 15, 2 * 1000 local blacklistParam = {"god", "cm", "gm", "tutor", "tester"} function onSay(cid, words, param, channel) local text, continue = "You will be kicked in 2 seconds.", true local spaceStart, spaceEnd = string.find(param, "%s*") if(db.getResult("SELECT `name` FROM `players` WHERE `name` = " .. db.escapeString(param) .. ";"):getID() ~= -1) then text, continue = "That name is already in use.", false elseif(getPlayerItemCount(cid, itemId) < 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(spaceStart == 1 or spaceEnd == string.len(tostring(param))) then text, continue = "The first or last characters cannot be spaces.", false elseif(string.find(param, "%a%s+") ~= nil) then text, continue = "Parameter contains too many spaces in between letters.", false elseif(string.len(tostring(param)) > maxTextLenght) then text, continue = "You can use a maximum of " .. 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(blacklistParam) do if(string.find(param:lower(), blacklistParam[blacklist]) ~= nil) then text, continue = "Invalid name entry.", false break end end end if(continue == false) then doPlayerSendCancel(cid, text) return true end db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(param) .. " WHERE `id` = " .. getPlayerGUID(cid) .. ";") doPlayerRemoveItem(cid, itemId, count) doPlayerSendTextMessage(cid, 25, text) addEvent(function(cid, forceLogout) if(isPlayer(cid)) then doRemoveCreature(cid, forceLogout) end end, delay, cid, false) return true end
local itemId, count, maxTextLenght, delay, newMethod = 1111, 1, 15, 2 * 1000, true
local blacklistParam = {"god", "cm", "gm", "tutor", "tester"}
function onSay(cid, words, param, channel)
local oldName, guid, text, continue = getCreatureName(cid), getPlayerGUIDByName(oldName), "You will be kicked in 2 seconds.", true
local spaceStart, spaceEnd = string.find(param, "%s*")
if(getPlayerGUIDByName(param) ~= nil) then
text, continue = "That name is already in use.", false
elseif(getPlayerItemCount(cid, itemId) < 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(spaceStart == 1 or spaceEnd == string.len(tostring(param))) then
text, continue = "The first or last characters cannot be spaces.", false
elseif(string.find(param, "%a%s+") ~= nil) then
text, continue = "Parameter contains too many spaces in between letters.", false
elseif(string.len(tostring(param)) > maxTextLenght) then
text, continue = "You can use a maximum of " .. 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(blacklistParam) do
if(string.find(param:lower(), blacklistParam[blacklist]) ~= nil) then
text, continue = "Invalid name entry.", false
break
end
end
end
if(continue == false) then
doPlayerSendCancel(cid, text)
return true
end
if(getBooleanFromString(newMethod)) 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, delay, cid, false)
end
doPlayerRemoveItem(cid, itemId, count)
doPlayerSendTextMessage(cid, 25, text)
return true
end
local itemId, count, maxTextLenght, delay, newMethod = 1111, 1, 15, 2 * 1000, false
local blacklistParam = {"god", "cm", "gm", "tutor", "tester"}
function onSay(cid, words, param, channel)
local oldName, guid, text, continue = getCreatureName(cid), getPlayerGUIDByName(oldName), "You will be kicked in 2 seconds.", true
local spaceStart, spaceEnd = string.find(param, "%s*")
if(getPlayerGUIDByName(param) ~= nil) then
text, continue = "That name is already in use.", false
elseif(getPlayerItemCount(cid, itemId) < 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(spaceStart == 1 or spaceEnd == string.len(tostring(param))) then
text, continue = "The first or last characters cannot be spaces.", false
elseif(string.find(param, "%a%s+") ~= nil) then
text, continue = "Parameter contains too many spaces in between letters.", false
elseif(string.len(tostring(param)) > maxTextLenght) then
text, continue = "You can use a maximum of " .. 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(blacklistParam) do
if(string.find(param:lower(), blacklistParam[blacklist]) ~= nil) then
text, continue = "Invalid name entry.", false
break
end
end
end
if(continue == false) then
doPlayerSendCancel(cid, text)
return true
end
if(getBooleanFromString(newMethod)) 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, delay, cid, false)
end
doPlayerRemoveItem(cid, itemId, count)
doPlayerSendTextMessage(cid, 25, text)
return true
end
have u tested my fix? it works good in all what u said xd. Yes string.gsub it will return all spaces what has the sentence, of course, the limit of spaces can be set at variable "maxspaces"(?). Don't worry bro, i'm trying to help to make ur script work at 100%, just that.Nice but, try this with that script: "/changename [space]blabla"; "/changename blabla[space]" or "/changename [space]"
EDIT: Wait...that string.gsub(word, " ", " ") is searching for every space on the param...so if you do "/changename About Twenty Percent Cooler" it'll return 3 and so it won't work.
local itemId, count, maxTextLenght, delay, newMethod = 1111, 1, 15, 2 * 1000, false
local blacklistParam = {"god", "cm", "gm", "tutor", "tester"}
function onSay(cid, words, param, channel)
local oldName, guid, text, continue = getCreatureName(cid), getPlayerGUIDByName(oldName), "You will be kicked in 2 seconds.", true
local spaceStart, spaceEnd = string.find(param, "%s*")
if(getPlayerGUIDByName(param) ~= nil) then
text, continue = "That name is already in use.", false
elseif(getPlayerItemCount(cid, itemId) < 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(spaceStart == 1 or spaceEnd == string.len(tostring(param))) then
text, continue = "The first or last characters cannot be spaces.", false
elseif(string.find(param, "%a%s+") ~= nil) then
text, continue = "Parameter contains too many spaces in between letters.", false
elseif(string.len(tostring(param)) > maxTextLenght) then
text, continue = "You can use a maximum of " .. 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(blacklistParam) do
if(string.find(param:lower(), 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, itemId, count)
doPlayerSendTextMessage(cid, 25, text)
if(getBooleanFromString(newMethod)) 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, delay, cid, false)
end
return true
end
If you say so But still your script needs to check if the param contains spaces and the beginning or at the end of it.
EDIT:
Small fix for the position of the last functions.
Lua:local itemId, count, maxTextLenght, delay, newMethod = 1111, 1, 15, 2 * 1000, false local blacklistParam = {"god", "cm", "gm", "tutor", "tester"} function onSay(cid, words, param, channel) local oldName, guid, text, continue = getCreatureName(cid), getPlayerGUIDByName(oldName), "You will be kicked in 2 seconds.", true local spaceStart, spaceEnd = string.find(param, "%s*") if(getPlayerGUIDByName(param) ~= nil) then text, continue = "That name is already in use.", false elseif(getPlayerItemCount(cid, itemId) < 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(spaceStart == 1 or spaceEnd == string.len(tostring(param))) then text, continue = "The first or last characters cannot be spaces.", false elseif(string.find(param, "%a%s+") ~= nil) then text, continue = "Parameter contains too many spaces in between letters.", false elseif(string.len(tostring(param)) > maxTextLenght) then text, continue = "You can use a maximum of " .. 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(blacklistParam) do if(string.find(param:lower(), 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, itemId, count) doPlayerSendTextMessage(cid, 25, text) if(getBooleanFromString(newMethod)) 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, delay, cid, false) end return true end
local itemId, count, maxTextLenght, delay, newMethod = 1111, 1, 15, 2 * 1000, false
local blacklistParam = {"god", "cm", "gm", "tutor", "tester"}
function onSay(cid, words, param, channel)
local paramTemp, oldName, guid, text, continue = "", getCreatureName(cid), getPlayerGUIDByName(oldName), "You will be kicked in 2 seconds.", true
for word in string.gmatch(param, "%a+") do
paramTemp = "" .. paramTemp .. "" .. word .. " "
end
param = string.reverse(string.gsub(string.reverse(paramTemp), "%s*", "", 1))
if(getPlayerGUIDByName(param) ~= nil) then
text, continue = "That name is already in use.", false
elseif(getPlayerItemCount(cid, itemId) < 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)) > maxTextLenght) then
text, continue = "You can use a maximum of " .. 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(blacklistParam) do
if(string.find(param:lower(), 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, itemId, count)
doPlayerSendTextMessage(cid, 25, text)
if(getBooleanFromString(newMethod)) 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, delay, cid, false)
end
return true
end
11:03 Boga Rula [80]: /changename - error in console
11:04 Boga Rula [80]: /changename Luquinhas - error in console
11:04 Boga Rula [80]: /changename"Luquinhas" - no error, nothing happens
11:04 Boga Rula [80]: /changename "Luquinhas" - error in console
11:04 Boga Rula [80]: /changename, Luquinhas - no error, nothing happens
local itemId, count, maxTextLenght, delay, newMethod = 1111, 1, 15, 2 * 1000, false
local blacklistParam = {"god", "cm", "gm", "tutor", "tester"}
function onSay(cid, words, param, channel)
if(param == '') then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
return true
end
local paramTemp = ''
for word in string.gmatch(param, "%a+") do
paramTemp = "" .. paramTemp .. " " .. word .. ""
end
string.gsub(paramTemp, "%s*", "", 1)
param = paramTemp
local oldName, guid, text, continue = getCreatureName(cid), getPlayerGUIDByName(oldName), "You will be kicked in 2 seconds.", true
if(getPlayerGUIDByName(param) ~= nil) then
text, continue = "That name is already in use.", false
elseif(getPlayerItemCount(cid, itemId) < 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)) > maxTextLenght) then
text, continue = "You can use a maximum of " .. 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(blacklistParam) do
if(string.find(param:lower(), 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, itemId, count)
doPlayerSendTextMessage(cid, 25, text)
if(getBooleanFromString(newMethod)) 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, delay, cid, false)
end
return true
end
local itemId, count, maxTextLenght, delay, newMethod = 1111, 1, 15, 2 * 1000, false
local blacklistParam = {"god", "cm", "gm", "tutor", "tester"}
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 = paramTemp
local guid, text, continue = getPlayerGUIDByName(oldName), "You will be kicked in 2 seconds.", true
if(getPlayerGUIDByName(param) ~= nil) then
text, continue = "That name is already in use.", false
elseif(getPlayerItemCount(cid, itemId) < 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)) > maxTextLenght) then
text, continue = "You can use a maximum of " .. 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(blacklistParam) do
if(string.find(param:lower(), 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, itemId, count)
doPlayerSendTextMessage(cid, 25, text)
if(getBooleanFromString(newMethod)) 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, delay, cid, false)
end
return true
end
17:45 Boga Rula [80]: /changename"Lucas"
17:46 Boga Rula [80]: /changename, Lucas
17:46 Boga Rula [80]: /changename Lucas
17:46 Boga Rula [80]: /changename
17:46 Boga Rula [80]: !changename