Jump to content

quest kill count in database


Go to solution Solved by Tasho,

Recommended Posts

hi guys :)

 

I'm trying to count the amount of kill in the database

 

mysql_direct_query("INSERT INTO `kill_system` (`id`,  `quantidade`) VALUES ('"..pc.get_player_id().."', '"..total_players.."');")

mysql_direct_query("UPDATE `kill_system` SET `quantidade`='"..total_players.."' WHERE id='"..pc.get_player_id().."';")

 

Ps: ID = id player | quantidade = count kill

No sucess =/ 

 

My database

GoWA3JYOS2_lBKSu1tbRjg.png

My quest clean

quest contador_kill begin
        state start begin
                when login begin
                        set_state(contador_kills)
                end
        end
        state contador_kills begin
                when kill with npc.is_pc() begin
                        pc.setqf("total_players", pc.getqf("total_players") +1)
                        if npc.get_empire == 1 then
                                pc.setqf("players_shinsoo", pc.getqf("players_shinsoo") +1)
                        elseif npc.get_empire == 2 then
                                pc.setqf("players_chunjo", pc.getqf("players_chunjo") +1)
                        elseif npc.get_empire == 3 then
                                pc.setqf("players_jinno", pc.getqf("players_jinno") +1)
                        end
                end
                when 11000.chat or 11002.chat or 11004.chat."Contador de Kills" with button or info begin
                say_title("Contador de Kills:")
                say("")
                say("Aqui podes ver todas as")
                say("tuas mortes feitas desde que começaste a jogar.")
                say("Podes ver quantos Jogadores e")
                say("Quantos Moobs ja mataste.")
				say("")
                say_reward("Escolhe uma opcao!")
				say("")
                        local a = select ("Quantos Players Matei", "Sair")
                        if a == 2 then
                                return
                        elseif a == 1 then
                                say_title("Contador de Kills:")
                                say("Queres ver Por Reinos, ou o Total?")
								say("")
                                        local b = select ("Por Reinos", "Total", "Sair")
                                        if b == 3 then
                                                return
                                        elseif b == 2 then
                                                say_title("Contador de Kills:")
												say("")
                                                say_reward("No total, mataste "..pc.getqf("total_players").." Players.")
                                                say("")
                                        elseif b == 1 then
                                                say_title("Contador de Kills:")
                                                say("De que Reino?")
												say("")
                                                local c = select ("Shinsoo", "Chunjo", "Jinno", "Sair")
                                                if c == 4 then
                                                        return
                                                elseif c == 1 then
                                                        say_title("Contador de Kills:")
														say("")
                                                        say_reward("Mataste "..pc.getqf("players_shinsoo").." Players do Reino de Shinsoo.")
                                                        say("")
                                                elseif c == 2 then
                                                        say_title("Contador de Kills:")
														say("")
                                                        say_reward("Mataste "..pc.getqf("players_chunjo").." Players do Reino de Chunjo.")
                                                        say("")
                                                elseif c == 3 then
                                                        say_title("Contador de Kills:")
														say("")
                                                        say_reward("Mataste "..pc.getqf("players_jinno").." Players do Reino de Jinno.")
                                                        say("")
                                                end
                                        end
                        end
                end
        end
end

 

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
https://metin2.dev/topic/18064-quest-kill-count-in-database/
Share on other sites

  • Honorable Member

in what database is the kill_system table located?

That's how you do it correctly:

quest contador_kill begin
	state start begin
		function GetEmpireNames()
			local data = {
				[1] = "shinsoo",
				[2] = "chunjo",
				[3] = "jinno"
			};
			
			return data;
		end -- function
		
		when kill with npc.is_pc() begin
			local qf_name = string.format("players_%s", contador_kill.GetEmpireNames()[npc.get_empire()]);

			pc.setqf("total_players", pc.getqf("total_players")+1);
			pc.setqf(qf_name, pc.getqf(qf_name)+1);
			
			-- Insert value in MySQL or Update it if already existing.
			mysql_direct_query(string.format("INSERT INTO player.kill_system (id, quantidade) VALUES(%d, 1) ON DUPLICATE KEY UPDATE quantidade = %d;", pc.get_player_id(), pc.getqf("total_players")));
		end -- when

		when 11000.chat."Contador de Kills" or
			11002.chat."Contador de Kills" or
			11004.chat."Contador de Kills" begin

			say_title("Contador de Kills:[ENTER]")
			say_reward(string.format("You killed a total of %d players.[ENTER]", pc.getqf("total_players")))
			say("Of which:[ENTER]")
			for _, empire_name in ipairs(contador_kill.GetEmpireNames()) do
				local qf_name = string.format("players_%s", empire_name);
				say_reward(string.format("- %d from %s;", pc.getqf(qf_name), empire_name))
			end -- for
		end -- when
	end -- state
end -- quest

 

you see the query includes the database and not just the table name?

Substitute DATABASE. with the database where the table is located and you're done.

  • Love 1

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

1 hour ago, Syreldar said:

in what database is the kill_system table located?

That's how you do it correctly:


quest contador_kill begin
	state start begin
		function GetEmpireNames()
			local data = {
				[1] = "shinsoo",
				[2] = "chunjo",
				[3] = "jinno"
			};
			
			return data;
		end -- function
		
		when kill with npc.is_pc() begin
			local qf_name = string.format("players_%s", contador_kill.GetEmpireNames()[npc.get_empire()]);

			pc.setqf("total_players", pc.getqf("total_players")+1);
			pc.setqf(qf_name, pc.getqf(qf_name)+1);
			
			-- Insert value in MySQL.
			mysql_direct_query(string.format("UPDATE DATABASE.kill_system SET quantidade = %d WHERE id = %d;", pc.getqf("total_players"), pc.get_player_id()));
		end -- when

		when 11000.chat."Contador de Kills" or
			11002.chat."Contador de Kills" or
			11004.chat."Contador de Kills" begin

			say_title("Contador de Kills:[ENTER]")
			say_reward(string.format("You killed a total of %d players.[ENTER]", pc.getqf("total_players")))
			say("Of which:[ENTER]")
			for _, empire_name in ipairs(contador_kill.GetEmpireNames()) do
				local qf_name = string.format("players_%s", empire_name);
				say_reward(string.format("- %d from %s;", pc.getqf(qf_name), empire_name))
			end -- for
		end -- when
	end -- state
end -- quest

 

you see the query includes the database and not just the table name?

Substitute DATABASE. with the database where the table is located and you're done.

no insert database count =/

database player

GoWA3JYOS2_lBKSu1tbRjg.png

 

quest contador_kill begin
	state start begin
		when login begin
			set_state(contador_kills)
		end
	end
	state contador_kills begin
		function GetEmpireNames()
			local data = {
				[1] = "shinsoo",
				[2] = "chunjo",
				[3] = "jinno"
			};
			
			return data;
		end -- function
		
		when kill with npc.is_pc() begin
			local qf_name = string.format("players_%s", contador_kill.GetEmpireNames()[npc.get_empire()]);

			pc.setqf("total_players", pc.getqf("total_players")+1);
			pc.setqf(qf_name, pc.getqf(qf_name)+1);
			
			-- Insert value in MySQL.
			mysql_direct_query(string.format("UPDATE player.kill_system SET quantidade = %d WHERE id = %d;", pc.getqf("total_players"), pc.get_player_id()));
		end -- when

		when 11000.chat."Contador de Kills" or 
			11002.chat."Contador de Kills" or 
			11004.chat."Contador de Kills" begin

			say_title("Contador de Kills:[ENTER]")
			say_reward(string.format("Você matou um total de %d players.[ENTER]", pc.getqf("total_players")))
			say("Dos reinos:[ENTER]")
			for _, empire_name in ipairs(contador_kill.GetEmpireNames()) do
				local qf_name = string.format("players_%s", empire_name);
				say_reward(string.format("- %d reino %s;", pc.getqf(qf_name), empire_name))
			end -- for
		end -- when
	end
end

 

Edited by Metin2 Dev
Core X - External 2 Internal
  • Solution

.

  • UPDATE = The UPDATE statement is used to modify the existing records in a table.
  • INSERT = The INSERT INTO statement is used to insert new records in a table.
50 minutes ago, amosth said:
  • mysql_direct_query(string.format("UPDATE player.kill_system SET quantidade = %d WHERE id = %d;", pc.getqf("total_players"),

 

  • You trying to update field id <which doesn't exist>
  • First one you need to do INSERT and after that UPDATE, there are many solutions for that, but i would like that one: INSERT ... ON DUPLICATE KEY UPDATE
local quantidade = pc.getqf("total_players")
mysql_direct_query(string.format("INSERT INTO player.kill_system (id, quantidade) VALUES(%d, %d) ON DUPLICATE KEY UPDATE quantidade = quantidade + %d;", pc.get_player_id(), quantidade, quantidade));

If you specify an ON DUPLICATE KEY UPDATE clause and a row to be inserted would cause a duplicate value in a UNIQUE index or PRIMARY KEY, an UPDATE of the old row occurs.

  • Love 1
14 minutes ago, Tasho said:

.

  • UPDATE = The UPDATE statement is used to modify the existing records in a table.
  • INSERT = The INSERT INTO statement is used to insert new records in a table.

 

  • You trying to update field id <which doesn't exist>
  • First one you need to do INSERT and after that UPDATE, there are many solutions for that, but i would like that one: INSERT ... ON DUPLICATE KEY UPDATE

local quantidade = pc.getqf("total_players")
mysql_direct_query(string.format("INSERT INTO player.kill_system (id, quantidade) VALUES(%d, %d) ON DUPLICATE KEY UPDATE quantidade = quantidade + %d;", pc.get_player_id(), quantidade, quantidade));

If you specify an ON DUPLICATE KEY UPDATE clause and a row to be inserted would cause a duplicate value in a UNIQUE index or PRIMARY KEY, an UPDATE of the old row occurs.

woool!!

Very nice guy, perfect work :)

  • Honorable Member
21 hours ago, amosth said:

no insert database count =/

database player

 

well, next time maybe learn to read properly at least..

  • Love 1

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.