Ir para conteúdo

Featured Replies

Postado
  • Solução
local scrollId = 1234

function onSay(cid, words, param)
    if param == "" then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'To use the command: !changename "NEW_NAME')
        return false
    end
    if getPlayerItemCount(cid, scrollId) < 0 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You need a ' .. getItemNameById(scrollId))
        return false
    end
    if getTilePzInfo(getPlayerPosition(cid)) ~= true then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You can only use this command in a protected area.')
        return false
    end

    doPlayerRemoveItem(cid, scrollId, 1)
    local guid = getPlayerGUID(cid)
    doRemoveCreature(cid)
    db.executeQuery("UPDATE `players` SET `name` = '" .. param .. "' WHERE `id` = " .. guid .. ";")
    doRemoveCreature(guid)
    return true
end

 

Achei um script bem mais completo do que esse que criei:

local config = {
	item = {Id = 1111, count = 0},
	paramBlacklist = {"account manager", "god", "tutor", "tester"},
	kick = {enabled = true, delay = 2 * 1000},
	forceLogout = false,
	namelockCheck = true,
	vowelsCheck = true,
	maxTextLenght = 29,
	minWordLenght = 2,
	maxWordLenght = 14,
	maxWords = 3
}
 
config.kick.enabled = getBooleanFromString(config.kick.enabled)
config.forceLogout = getBooleanFromString(config.forceLogout)
config.namelockCheck = getBooleanFromString(config.namelockCheck)
config.vowelsCheck = getBooleanFromString(config.vowelsCheck)
 
function onSay(cid, words, param, channel)
	local t = string.explode(param, ",")
	local len, firstWord, wordCount, textCancel, limit = string.len(tostring(t[1])), true, 0, '', ";"
	if(getConfigValue('sqlType') == 'mysql') then
		limit = db.updateLimiter()
	end
 
	if(param == '') then
		return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
	elseif(getPlayerGUIDByName(t[1], true) ~= nil) then
		textCancel = "That name is already in use."
	elseif(getPlayerItemCount(cid, config.item.Id) < config.item.count) then
		textCancel = "You do not fulfill the requirements."
	elseif(not getTilePzInfo(getCreaturePosition(cid))) then
		textCancel = "You must be inside a protection zone to use this command."
	elseif(len > config.maxTextLenght) then
		textCancel = "A name must have at least " .. config.minWordLenght .. " but no more than " .. config.maxTextLenght .. " letters!"
	elseif(config.namelockCheck and db.getResult("SELECT * FROM `player_namelocks` WHERE `name` = " .. db.escapeString(t[1]) .. "" .. limit .. ""):getID() ~= 1) then
		textCancel = "That name is namelocked."
	elseif(string.find(t[1]:lower(), "[^%l%s]") ~= nil) then
		textCancel = "This name contains invalid letters. Please use only A-Z, a-z and space!"
	else
		paramTemp = ''
		for word in string.gmatch(t[1], "%a+") do
			len, wordCount = string.len(word), wordCount + 1
			if(isInArray(config.paramBlacklist, paramTemp:lower())) then
				textCancel = "Invalid name entry."
				break
			elseif(len < config.minWordLenght) then
				textCancel = "This name contains a word with only " .. len .. " letter" .. (len > 1 and "s" or '') .. ". Please use more than " .. len .. " letter" .. (len > 2 and "s" or '') .. " for each word!"
				break
			elseif(len > config.maxWordLenght) then
				textCancel = "This name contains a word that is too long. Please use no more than " .. config.maxWordLenght .. " letters for each word!"
				break
			elseif(wordCount > config.maxWords) then
				textCancel = "This name contains more than 3 words. Please choose another name!"
				break
			elseif(config.vowelsCheck and string.find(word:lower(), "[aeiouy]") == nil) then
				textCancel = "This name contains a word without vowels. Please choose another name!"
				break
			else
				wordTemp = ''
				for i = 1, len do
					letter = string.sub(word, i, i)
					if(i == 1) then
						if(getBooleanFromString(firstWord) and string.find(letter, "%l")) then
							letter = string.upper(letter)
						end
					else
						if(string.find(letter, "%u")) then
							letter = string.lower(letter)
						end
					end
 
					firstWord = false
					wordTemp = "" .. wordTemp .. "" .. letter .. ""
				end
			end
 
			paramTemp = "" .. paramTemp .. "" .. (paramTemp ~= '' and " " or '') .. "" .. wordTemp .. ""
		end
	end
 
	if(textCancel ~= '') then
		doPlayerSendCancel(cid, textCancel)
		return true
	end
 
	local oldName, guid = getCreatureName(cid), getPlayerGUID(cid)
	t[1] = paramTemp
	doPlayerRemoveItem(cid, config.item.Id, config.item.count)
	if(pcall(doPlayerChangeName, guid, oldName, t[1]) ~= true) then
		db.executeQuery("INSERT INTO `player_namelocks` (`player_id`, `name`, `new_name`, `date`) VALUES (" .. guid .. ", " .. db.escapeString(oldName) .. ", " .. db.escapeString(t[1]) .. ", " .. os.time() .. ");")
		db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(t[1]) .. " WHERE `id` = " .. guid .. "" .. limit .. "")
	end
 
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your name has been changed successfully." .. (config.kick.enabled and " You will be kicked in " .. config.kick.delay / 1000 .. " seconds." or " Re-enter the game to see the changes.") .. "")
	if(config.kick.enabled) then
		addEvent(function(cid, forceLogout)
			if(isPlayer(cid)) then
				doRemoveCreature(cid, forceLogout)
			end
		end, config.kick.delay, cid, config.forceLogout)
	end
 
	return true
end

 

A parte do .xml fica assim:

<talkaction log="yes" words="!changename;/changename;!namechange;/namechange" access="0" event="script" value="changename.lua"/>

 

 

Editado por Anderson Sacani
Estava oculto (veja o histórico de edições)

  • Respostas 10
  • Visualizações 662
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

  • Anderson Sacani
    Anderson Sacani

    local scrollId = 1234 function onSay(cid, words, param) if param == "" then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'To use the command: !changename "NEW_NAME')

Postado
  • Autor
Em 09/02/2023 em 14:45, Anderson Sacani disse:

local scrollId = 1234

function onSay(cid, words, param)
    if param == "" then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'To use the command: !changename "NEW_NAME')
        return false
    end
    if getPlayerItemCount(cid, scrollId) < 0 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You need a ' .. getItemNameById(scrollId))
        return false
    end
    if getTilePzInfo(getPlayerPosition(cid)) ~= true then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You can only use this command in a protected area.')
        return false
    end

    doPlayerRemoveItem(cid, scrollId, 1)
    local guid = getPlayerGUID(cid)
    doRemoveCreature(cid)
    db.executeQuery("UPDATE `players` SET `name` = '" .. param .. "' WHERE `id` = " .. guid .. ";")
    doRemoveCreature(guid)
    return true
end

 

Achei um script bem mais completo do que esse que criei:


local config = {
	item = {Id = 1111, count = 0},
	paramBlacklist = {"account manager", "god", "tutor", "tester"},
	kick = {enabled = true, delay = 2 * 1000},
	forceLogout = false,
	namelockCheck = true,
	vowelsCheck = true,
	maxTextLenght = 29,
	minWordLenght = 2,
	maxWordLenght = 14,
	maxWords = 3
}
 
config.kick.enabled = getBooleanFromString(config.kick.enabled)
config.forceLogout = getBooleanFromString(config.forceLogout)
config.namelockCheck = getBooleanFromString(config.namelockCheck)
config.vowelsCheck = getBooleanFromString(config.vowelsCheck)
 
function onSay(cid, words, param, channel)
	local t = string.explode(param, ",")
	local len, firstWord, wordCount, textCancel, limit = string.len(tostring(t[1])), true, 0, '', ";"
	if(getConfigValue('sqlType') == 'mysql') then
		limit = db.updateLimiter()
	end
 
	if(param == '') then
		return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
	elseif(getPlayerGUIDByName(t[1], true) ~= nil) then
		textCancel = "That name is already in use."
	elseif(getPlayerItemCount(cid, config.item.Id) < config.item.count) then
		textCancel = "You do not fulfill the requirements."
	elseif(not getTilePzInfo(getCreaturePosition(cid))) then
		textCancel = "You must be inside a protection zone to use this command."
	elseif(len > config.maxTextLenght) then
		textCancel = "A name must have at least " .. config.minWordLenght .. " but no more than " .. config.maxTextLenght .. " letters!"
	elseif(config.namelockCheck and db.getResult("SELECT * FROM `player_namelocks` WHERE `name` = " .. db.escapeString(t[1]) .. "" .. limit .. ""):getID() ~= 1) then
		textCancel = "That name is namelocked."
	elseif(string.find(t[1]:lower(), "[^%l%s]") ~= nil) then
		textCancel = "This name contains invalid letters. Please use only A-Z, a-z and space!"
	else
		paramTemp = ''
		for word in string.gmatch(t[1], "%a+") do
			len, wordCount = string.len(word), wordCount + 1
			if(isInArray(config.paramBlacklist, paramTemp:lower())) then
				textCancel = "Invalid name entry."
				break
			elseif(len < config.minWordLenght) then
				textCancel = "This name contains a word with only " .. len .. " letter" .. (len > 1 and "s" or '') .. ". Please use more than " .. len .. " letter" .. (len > 2 and "s" or '') .. " for each word!"
				break
			elseif(len > config.maxWordLenght) then
				textCancel = "This name contains a word that is too long. Please use no more than " .. config.maxWordLenght .. " letters for each word!"
				break
			elseif(wordCount > config.maxWords) then
				textCancel = "This name contains more than 3 words. Please choose another name!"
				break
			elseif(config.vowelsCheck and string.find(word:lower(), "[aeiouy]") == nil) then
				textCancel = "This name contains a word without vowels. Please choose another name!"
				break
			else
				wordTemp = ''
				for i = 1, len do
					letter = string.sub(word, i, i)
					if(i == 1) then
						if(getBooleanFromString(firstWord) and string.find(letter, "%l")) then
							letter = string.upper(letter)
						end
					else
						if(string.find(letter, "%u")) then
							letter = string.lower(letter)
						end
					end
 
					firstWord = false
					wordTemp = "" .. wordTemp .. "" .. letter .. ""
				end
			end
 
			paramTemp = "" .. paramTemp .. "" .. (paramTemp ~= '' and " " or '') .. "" .. wordTemp .. ""
		end
	end
 
	if(textCancel ~= '') then
		doPlayerSendCancel(cid, textCancel)
		return true
	end
 
	local oldName, guid = getCreatureName(cid), getPlayerGUID(cid)
	t[1] = paramTemp
	doPlayerRemoveItem(cid, config.item.Id, config.item.count)
	if(pcall(doPlayerChangeName, guid, oldName, t[1]) ~= true) then
		db.executeQuery("INSERT INTO `player_namelocks` (`player_id`, `name`, `new_name`, `date`) VALUES (" .. guid .. ", " .. db.escapeString(oldName) .. ", " .. db.escapeString(t[1]) .. ", " .. os.time() .. ");")
		db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(t[1]) .. " WHERE `id` = " .. guid .. "" .. limit .. "")
	end
 
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your name has been changed successfully." .. (config.kick.enabled and " You will be kicked in " .. config.kick.delay / 1000 .. " seconds." or " Re-enter the game to see the changes.") .. "")
	if(config.kick.enabled) then
		addEvent(function(cid, forceLogout)
			if(isPlayer(cid)) then
				doRemoveCreature(cid, forceLogout)
			end
		end, config.kick.delay, cid, config.forceLogout)
	end
 
	return true
end

 

A parte do .xml fica assim:


<talkaction log="yes" words="!changename;/changename;!namechange;/namechange" access="0" event="script" value="changename.lua"/>

 

 

Valeu mano, salvou! ?

  • 1 month later...
Postado
  • Diretor

O problema do seu script é que ele remove o jogador do jogo antes de atualizar o nome no banco de dados, o que causa o desaparecimento do personagem. Além disso, você precisa especificar o novo nome que o jogador deseja usar. Aqui está uma versão atualizada

 

function onUse(cid, item, frompos, item2, topos)
    if (getTilePzInfo(getPlayerPosition(cid)) == TRUE) then
        local playerName = getPlayerName(cid)
        local oldName, guid = getCreatureName(cid), getPlayerGUID(cid)
        db.executeQuery("INSERT INTO `player_namelocks` (`player_id`, `name`, `new_name`, `date`) VALUES (" .. guid .. ", " .. db.escapeString(oldName) .. ", " .. os.time() .. ");")
        doRemoveItem(item.uid, 1)
        doRemoveCreature(cid)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Your name has been changed successfully!")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You can only use this item inside protection zone!")
    end
end
 

Postado
Em 16/03/2023 em 08:16, L3K0T disse:

O problema do seu script é que ele remove o jogador do jogo antes de atualizar o nome no banco de dados, o que causa o desaparecimento do personagem. Além disso, você precisa especificar o novo nome que o jogador deseja usar. Aqui está uma versão atualizada

 

function onUse(cid, item, frompos, item2, topos)
    if (getTilePzInfo(getPlayerPosition(cid)) == TRUE) then
        local playerName = getPlayerName(cid)
        local oldName, guid = getCreatureName(cid), getPlayerGUID(cid)
        db.executeQuery("INSERT INTO `player_namelocks` (`player_id`, `name`, `new_name`, `date`) VALUES (" .. guid .. ", " .. db.escapeString(oldName) .. ", " .. os.time() .. ");")
        doRemoveItem(item.uid, 1)
        doRemoveCreature(cid)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Your name has been changed successfully!")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You can only use this item inside protection zone!")
    end
end
 

como ficaria o comando ? esse ja e o script inteiro ?

Postado
Em 16/03/2023 em 08:16, L3K0T disse:

O problema do seu script é que ele remove o jogador do jogo antes de atualizar o nome no banco de dados, o que causa o desaparecimento do personagem. Além disso, você precisa especificar o novo nome que o jogador deseja usar. Aqui está uma versão atualizada

 

function onUse(cid, item, frompos, item2, topos)
    if (getTilePzInfo(getPlayerPosition(cid)) == TRUE) then
        local playerName = getPlayerName(cid)
        local oldName, guid = getCreatureName(cid), getPlayerGUID(cid)
        db.executeQuery("INSERT INTO `player_namelocks` (`player_id`, `name`, `new_name`, `date`) VALUES (" .. guid .. ", " .. db.escapeString(oldName) .. ", " .. os.time() .. ");")
        doRemoveItem(item.uid, 1)
        doRemoveCreature(cid)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Your name has been changed successfully!")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You can only use this item inside protection zone!")
    end
end
 

Com toda certeza absoluta não irá funcionar.

Já falei que o ChatGPT é apenas pra auxiliar? Tu ta pedindo pra ele gerar um script, mas não funcionará. Sabe por que?

Porque tu ta mandando uma consulta pro banco de dados antes do personagem deslogar, então o nome dele é alterado no banco de dados, porém, o nome dele ainda é o antigo na memória do servidor, então, quando ele desloga, o nome antigo que está na memória do servidor sobrescreve o nome que já foi alterado no banco de dados, voltando a ser como era antes e o script não resultando em nada.

Provavelmente esse teu script não dará erro, mas com toda a certeza não funcionará.

 

O jogador tem que ser removido antes da consulta. O ChatGPT é muito ruim ainda!

 

Vou te explicar uma coisa:

O correto é:

Primeiro: Armazena o resultado do 'getPlayerGUID(cid)' dentro de uma variável, essa variável pode ter um nome 'guid';

Segundo: Remove o jogador;

Terceiro: Executa a consulta chamando a variável 'guid' para obter o id que foi armazenado na memória do servidor;

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.6k

Informação Importante

Confirmação de Termo