Ir para conteúdo
  • Cadastre-se

(Resolvido)Ajuda Script de Ban


Ir para solução Resolvido por Yan Liima,

Posts Recomendados

Bom dia, eu achei um script de ban feito pelo Omega que atende aos meus requisitos. Porem ele da um erro ao tentar usar no sv. Uso tfs 0.4, 8.60

Parece q foi testado em sqlite, eu uso mysql

Erro:

[9/3/2019 4:53:59] [Error - TalkAction Interface] 
[9/3/2019 4:53:59] data/talkactions/scripts/banunban.lua:onSay
[9/3/2019 4:53:59] Description: 
[9/3/2019 4:53:59] data/lib/004-database.lua:100: [Result:free] Result not set!
[9/3/2019 4:53:59] stack traceback:
[9/3/2019 4:53:59] 	[C]: in function 'error'
[9/3/2019 4:53:59] 	data/lib/004-database.lua:100: in function 'free'
[9/3/2019 4:53:59] 	data/talkactions/scripts/banunban.lua:12: in function 'isBanned'
[9/3/2019 4:53:59] 	data/talkactions/scripts/banunban.lua:38: in function <data/talkactions/scripts/banunban.lua:16>

Script:

Spoiler

local reasons = {[1] = 2, [2] = 5, [3] = 12, [4] = 19}

function isBanned(GUID)
	local query = db.getResult("SELECT active FROM bans WHERE param = "..GUID)
	if query:getID() > -1 then
		repeat
			if query:getDataInt("active") == 1 then
				return true
			end
		until not query:next()
	end
	query:free()
	return false
end

function onSay(cid, words, param)
	if param:lower() == "reasons" then
		return doPlayerSendTextMessage(cid, 27, "1 - unsuitable name, 2 - spamming, 3 - use of unnoficial software, 4 - destructive behaviour.")
	end
	local param = string.explode(param, ',')	
	if words == "!ban" then		
		local adminid = getPlayerGUID(cid)
		local player_name = param[1]
		local days = type(tonumber(param[2])) == 'number' and tonumber(param[2]) * 24 * 3600 or false
		local comment = param[3]
		local reason = reasons[tonumber(param[4])] or 19
		if not param[1] then
			doPlayerSendTextMessage(cid, 27, "Command requires parameters: name, days, comment, reason.")
		elseif not getPlayerGUIDByName(player_name) then
			doPlayerSendTextMessage(cid, 27, "Invalid player.")
		elseif not days then
			doPlayerSendTextMessage(cid, 27, "Invalid number of days.")
		else
			if not comment then
				comment = "No comment was added"
			end
			local player_to_ban = getPlayerGUIDByName(player_name)
			if isBanned(player_to_ban) then
				return doPlayerSendTextMessage(cid, 27, "This player is already banned.")
			end
			local func = db.query or db.executeQuery
			if func('INSERT INTO bans (type, value, param, active, expires, added, admin_id, comment, reason, action) VALUES (3, 8, '..player_to_ban..', 1, '..os.time() + days..', '..os.time()..', '..adminid..', "'..comment..'", '..reason..', 2)') then
				doPlayerSendTextMessage(cid, 27, "Player "..player_name.." has been banned.")
				local kick = getCreatureByName(player_name)
				if kick then
					doRemoveCreature(kick)
				end
			else
				doPlayerSendTextMessage(cid, 27, "Error while banning.")
			end
		end
	elseif words == "!unban" then
		local player_name = param[1]
		local unban_player = getPlayerGUIDByName(player_name)
		if unban_player then
			local func = db.query or db.executeQuery
			if not isBanned(unban_player) then
				return doPlayerSendTextMessage(cid, 27, "Player is currently not banned.")
			end
			if func("UPDATE bans SET active = 0 WHERE param = "..unban_player) then
				doPlayerSendTextMessage(cid, 27, "Player "..player_name.." has been successfully unbanned.")
			else
				doPlayerSendTextMessage(cid, 27, "Error while unbanning.")
			end
		else
			doPlayerSendTextMessage(cid, 27, "Invalid player name specified.")
		end
	end
	return true
end

 

 

Alguem pode ajudar? Rep+

@Vodkart @WooX 

Editado por Jhonny Bravo (veja o histórico de edições)
Link para o post
Compartilhar em outros sites

Sem você postar o script fica complicado.

 

 

 

Nós somos aquilo que fazemos repetidamente. Excelência, não é um modo de agir, mas um hábito.

                                                                                                                                                                                                                                        Aristóteles 

Link para o post
Compartilhar em outros sites
4 horas atrás, WooX disse:

Sem você postar o script fica complicado.

 

Mas eu postei ta em spoiler

Parece q o erro parou mas quando tento dar ban fala q deu mais n kicka bem bane o perso. Creio q é pelo fato de estar pra sqlite

Editado por Jhonny Bravo (veja o histórico de edições)
Link para o post
Compartilhar em outros sites
3 horas atrás, Jhonny Bravo disse:

Mas eu postei ta em spoiler

Parece q o erro parou mas quando tento dar ban fala q deu mais n kicka bem bane o perso. Creio q é pelo fato de estar pra sqlite

 

Não tinha visto. Porque ao invés de usar o script você não utiliza a função que já vem na source?

 

 

 

Nós somos aquilo que fazemos repetidamente. Excelência, não é um modo de agir, mas um hábito.

                                                                                                                                                                                                                                        Aristóteles 

Link para o post
Compartilhar em outros sites
Em 19/03/2019 em 01:54, WooX disse:

Não tinha visto. Porque ao invés de usar o script você não utiliza a função que já vem na source?

 

acho BAN por comando algo bem util. Tenho algumas ideias otimas para isso, so q precisava da script funcionando

Link para o post
Compartilhar em outros sites

tente trocar essa função:

 

function isBanned(GUID)
	local query = db.getResult("SELECT active FROM bans WHERE param = "..GUID)
	if query:getID() > -1 then
		repeat
			if query:getDataInt("active") == 1 then
				return true
			end
		until not query:next()
	end
	query:free()
	return false
end

 

por essa que eu refiz:

 

 

function isBanned(guid)
	local qry = db.getResult("SELECT `value` FROM `bans` WHERE `param` = " .. guid .. " AND `active` = 1;")
	if (qry:getID() ~= -1) then
			return true
	end
	return false
end

 

vodkart_logo.png

[*Ninguém será digno do sucesso se não usar suas derrotas para conquistá-lo.*]

 

DISCORDvodkart#6090

 

Link para o post
Compartilhar em outros sites
Em 25/03/2019 em 09:57, Vodkart disse:

tente trocar essa função:

 


function isBanned(GUID)
	local query = db.getResult("SELECT active FROM bans WHERE param = "..GUID)
	if query:getID() > -1 then
		repeat
			if query:getDataInt("active") == 1 then
				return true
			end
		until not query:next()
	end
	query:free()
	return false
end

 

por essa que eu refiz:

 

 


function isBanned(guid)
	local qry = db.getResult("SELECT `value` FROM `bans` WHERE `param` = " .. guid .. " AND `active` = 1;")
	if (qry:getID() ~= -1) then
			return true
	end
	return false
end

 

 

N funcionou. N da nenhum erro, o comando funciona, da o retorno da mensagem dizendo que o jogador foi banido. Mas ele n é kikado e nem é banido

Link para o post
Compartilhar em outros sites

query:free() somente se a consulta for um sucesso amiguinhos, segue abaixo a correção :

function isBanned(GUID)
	local query = db.getResult("SELECT active FROM bans WHERE param = "..GUID)
	if query:getID() > -1 then
		repeat
			if query:getDataInt("active") == 1 then
				return true
			end
		until not query:next()

		query:free() -- somente se query:getID() for maior que -1
	end
	
	return false
end
Link para o post
Compartilhar em outros sites
7 horas atrás, Lyu disse:

query:free() somente se a consulta for um sucesso amiguinhos, segue abaixo a correção :


function isBanned(GUID)
	local query = db.getResult("SELECT active FROM bans WHERE param = "..GUID)
	if query:getID() > -1 then
		repeat
			if query:getDataInt("active") == 1 then
				return true
			end
		until not query:next()

		query:free() -- somente se query:getID() for maior que -1
	end
	
	return false
end

 

Boa kkkkk funcionou, kikou o jogador e adicionou na tabela de bans. Porem ainda da pra logar, mas se eu usar o comando tentando banir dnv diz que esta banido.IMG-20190326-WA0022.thumb.jpg.f6eeada5e206f87b392059a351aaf304.jpg

 

Link para o post
Compartilhar em outros sites
  • Solução

@Lyu god <3

Segue a correção meninas, e vê se funciona:

local reasons = {[1] = 2, [2] = 5, [3] = 12, [4] = 19}

function isBanned(GUID)
	local query = db.getResult("SELECT active FROM bans WHERE param = "..GUID)
	if query:getID() > -1 then
		repeat
			if query:getDataInt("active") == 1 then
				return true
			end
		until not query:next()

		query:free() -- somente se query:getID() for maior que -1
	end
	
	return false
end

function onSay(cid, words, param)
	if param:lower() == "reasons" then
		return doPlayerSendTextMessage(cid, 27, "1 - unsuitable name, 2 - spamming, 3 - use of unnoficial software, 4 - destructive behaviour.")
	end
	local param = string.explode(param, ',')	
	if words == "!ban" then		
		local adminid = getPlayerGUID(cid)
		local player_name = param[1]
		local days = type(tonumber(param[2])) == 'number' and tonumber(param[2]) * 24 * 3600 or false
		local comment = param[3]
		local reason = reasons[tonumber(param[4])] or 19
		if not param[1] then
			doPlayerSendTextMessage(cid, 27, "Command requires parameters: name, days, comment, reason.")
		elseif not getPlayerGUIDByName(player_name) then
			doPlayerSendTextMessage(cid, 27, "Invalid player.")
		elseif not days then
			doPlayerSendTextMessage(cid, 27, "Invalid number of days.")
		else
			if not comment then
				comment = "No comment was added"
			end
			local player_to_ban = getPlayerGUIDByName(player_name)
			if isBanned(player_to_ban) then
				return doPlayerSendTextMessage(cid, 27, "This player is already banned.")
			end
			local func = db.query or db.executeQuery
			if func('INSERT INTO bans (type, value, param, active, expires, added, admin_id, comment, reason, action) VALUES (3, 3, '..player_to_ban..', 1, '..os.time() + days..', '..os.time()..', '..adminid..', "'..comment..'", '..reason..', 2)') then
				doPlayerSendTextMessage(cid, 27, "Player "..player_name.." has been banned.")
				local kick = getCreatureByName(player_name)
				if kick then
					doRemoveCreature(kick)
				end
			else
				doPlayerSendTextMessage(cid, 27, "Error while banning.")
			end
		end
	elseif words == "!unban" then
		local player_name = param[1]
		local unban_player = getPlayerGUIDByName(player_name)
		if unban_player then
			local func = db.query or db.executeQuery
			if not isBanned(unban_player) then
				return doPlayerSendTextMessage(cid, 27, "Player is currently not banned.")
			end
			if func("UPDATE bans SET active = 0 WHERE param = "..unban_player) then
				doPlayerSendTextMessage(cid, 27, "Player "..player_name.." has been successfully unbanned.")
			else
				doPlayerSendTextMessage(cid, 27, "Error while unbanning.")
			end
		else
			doPlayerSendTextMessage(cid, 27, "Invalid player name specified.")
		end
	end
	return true
end

 

════ҳ̸Ҳ̸ҳஜ۩۞۩ஜҳ̸Ҳ̸ҳ═══╗

Te Ajudei? Rep + e ficamos Quits

166420979_logoyanliimaornight.png.33f822b8970081a5b3646e85dbfd5934.png

Precisando de ajuda?

discord.png.1ecd188791d0141f74d99db371a2e0a4.png.890d5a38d7bcde75543c72b624a65de1.pngDiscord: Yan Liima #3702

Programador Júnior de LUA, PHP e JavaScript

Juntos somos lendas, separados somos Mitos!

╚══════════════════════════ҳ̸Ҳ̸ҳஜ۩۞۩ஜҳ̸Ҳ̸ҳ═════════════════════════════╝

Link para o post
Compartilhar em outros sites
30 minutos atrás, Yan Liima disse:

@Lyu god <3

Segue a correção meninas, e vê se funciona:


local reasons = {[1] = 2, [2] = 5, [3] = 12, [4] = 19}

function isBanned(GUID)
	local query = db.getResult("SELECT active FROM bans WHERE param = "..GUID)
	if query:getID() > -1 then
		repeat
			if query:getDataInt("active") == 1 then
				return true
			end
		until not query:next()

		query:free() -- somente se query:getID() for maior que -1
	end
	
	return false
end

function onSay(cid, words, param)
	if param:lower() == "reasons" then
		return doPlayerSendTextMessage(cid, 27, "1 - unsuitable name, 2 - spamming, 3 - use of unnoficial software, 4 - destructive behaviour.")
	end
	local param = string.explode(param, ',')	
	if words == "!ban" then		
		local adminid = getPlayerGUID(cid)
		local player_name = param[1]
		local days = type(tonumber(param[2])) == 'number' and tonumber(param[2]) * 24 * 3600 or false
		local comment = param[3]
		local reason = reasons[tonumber(param[4])] or 19
		if not param[1] then
			doPlayerSendTextMessage(cid, 27, "Command requires parameters: name, days, comment, reason.")
		elseif not getPlayerGUIDByName(player_name) then
			doPlayerSendTextMessage(cid, 27, "Invalid player.")
		elseif not days then
			doPlayerSendTextMessage(cid, 27, "Invalid number of days.")
		else
			if not comment then
				comment = "No comment was added"
			end
			local player_to_ban = getPlayerGUIDByName(player_name)
			if isBanned(player_to_ban) then
				return doPlayerSendTextMessage(cid, 27, "This player is already banned.")
			end
			local func = db.query or db.executeQuery
			if func('INSERT INTO bans (type, value, param, active, expires, added, admin_id, comment, reason, action) VALUES (3, 3, '..player_to_ban..', 1, '..os.time() + days..', '..os.time()..', '..adminid..', "'..comment..'", '..reason..', 2)') then
				doPlayerSendTextMessage(cid, 27, "Player "..player_name.." has been banned.")
				local kick = getCreatureByName(player_name)
				if kick then
					doRemoveCreature(kick)
				end
			else
				doPlayerSendTextMessage(cid, 27, "Error while banning.")
			end
		end
	elseif words == "!unban" then
		local player_name = param[1]
		local unban_player = getPlayerGUIDByName(player_name)
		if unban_player then
			local func = db.query or db.executeQuery
			if not isBanned(unban_player) then
				return doPlayerSendTextMessage(cid, 27, "Player is currently not banned.")
			end
			if func("UPDATE bans SET active = 0 WHERE param = "..unban_player) then
				doPlayerSendTextMessage(cid, 27, "Player "..player_name.." has been successfully unbanned.")
			else
				doPlayerSendTextMessage(cid, 27, "Error while unbanning.")
			end
		else
			doPlayerSendTextMessage(cid, 27, "Invalid player name specified.")
		end
	end
	return true
end

 

 

Funcionou obbbgg

Unico script de ban pft

Link para o post
Compartilhar em outros sites

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

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo