- local config = {
- newNameLength = {4, 20},
- itemid = 8189
- }
- local allowed = {
- "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"," "
- }
- --[[
- local array = {
- "-","1","2","3","4","5","6","7","8","9","0",
- "<",">","/","|","~","!","@","#","$","%","^",
- "&","*","(",")","_","=",",",".","gm","[","]",
- "admin","adm","owner","cm"
- }
- ]]
- function setPlayerName(cid, currentName, newName)
- if not isPlayer(cid) then return false end
- doRemoveCreature(cid)
- db.executeQuery(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)
- checkExhausted(cid, 1000, 5) -- zawed el line da ta7t kol function onSay
- 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
- for j = 1, #param do
- if inArray(allowed, param:sub(j,j):lower()) == false then
- doPlayerSendCancel(cid, "The name contains invalid words or characters.")
- return true
- end
- 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
- function inArray(array, item)
- for i = 1, #array do
- if array[i] == item then
- return true
- end
- end
- return false
- end