Jump to content

[Aporte] Boss Kill Coins


Zart

Mensajes recomendados

Una persona del foro hizo una pregunta sobre la posibilidad de una quest, me aburría en el proceso, así que se la hice, la dejo aquí por si a alguien le es de utilidad, sin embargo no es nada nuevo, pueden modificar para que cumpla otras funciones si lo desean.

 

-- //Jayden//
quest give_coins_by_boss begin
	state start begin
		-- Quest functions
		function set_unique_boss()
			local boss = {  -- Si eliges la versión de boss por coins unico, coloca aqui en el mismo formato los boss que quieras: [ID_MOB] = CANTIDAD_DE_COINS,
				[101] = 100,
				[102] = 200,
				[103] = 300,
				[104] = 400
			}
			return boss[npc.get_race()]
		end
		function check_race_exist(x)
			local race = {101,102,103,104} -- Si eliges la versión de boss global, coloca aqui en el mismo formato los boss que quieras: {ID_MOB, ID_MOB, ID_MOB}
			for index, value in ipairs(race) do
				if value == x then
					return true
				end
			end
			return false
		end
		function settings()
			return
			{
				["coins"] = 100, -- Introduce aquí la cantidad de Coins en caso de ser la versión global que quieras que de a todos los boss dentro de la lista.
				["player"] = pc.get_account_id()
			}
		end
		function set_config(val)
			if val == 1 then
				return true
			else
				return false
			end
		end
		-- ./Quest functions

		-- Quest body
		when kill with not npc.is_pc() begin
			local settings,boss_setting = give_coins_by_boss.settings(), give_coins_by_boss.set_unique_boss()
			if give_coins_by_boss.set_config(1) then -- Cambia este valor por 0 para activar el modo unico, dejalo en 1 para activar el modo global.
				if give_coins_by_boss.check_race_exist(npc.get_race()) then
					mysql_query(string.format("UPDATE account.account SET coins=coins+%d WHERE id = %d",settings.coins,settings.player))
				end
			else
				mysql_query(string.format("UPDATE account.account SET coins=coins+%d WHERE id = %d",boss_setting,settings.player))				
			end
		end
	end
end
-- //Jayden//

Tiene dos formas de entregar los coins: Global y Único (No se me ocurrió otro nombre.)

En el modo Global, todos los Jefes/Mobs/etc que ingreses en la lista, darán la misma cantidad de coins.

En el modo Único, puedes establecer cuantos coins dará cada Jefe/Mob/etc.

 

Como se configura?

MODO ÚNICO

Si eliges el modo Único para que tu elijas la cantidad de Coins que quieres que otorgue cada Boss, tienes que agregarlos a este Array, en este formato

[ID_DEL_BOSS] = CANTIDAD_DE_COINS, (El ultimo nunca debe llevar una coma "," al final). Esto lo miras en la quest:

local boss = {
     ID ->   [101] = 100, <-- Cantidad de coins
                [102] = 200,
                [103] = 300,
                [104] = 400 <--- El último no lleva coma ","
            }

 

MODO GLOBAL

Si eliges el modo Global para que todos los boss den la misma cantidad de Coins, tienes que añadirlos a este otro Array simple, en este formato:

{ID_DEL_BOSS, ID_DEL_BOSS, ID_DEL_BOSS} (El último de aquí tampoco lleva coma "," al final). Esto también lo miras en la quest:

local race = {101,102,103,104} <------ El ultimo no lleva coma

Para establecer la cantidad de coins global de este, lo cambias aquí:

{
                ["coins"] = 100, <---------------------------
                ["player"] = pc.get_account_id()
            }

 

¿COMO PUEDO SELECCIONAR LA VERSION ÚNICA O GLOBAL?

Con cambiar un numero lo harás:

if give_coins_by_boss.set_config(1) then -- Cambia este valor por 0 para activar el modo Único, déjalo en 1 para activar el modo Global.

FIN DEL TUTORIAL

 

Saludos, felices fiestas, feliz cumpleaños, feliz día de algo.

Enlace para comentar
Compartir en otros sitios

hace 6 minutos, VegaS™ dijo:

I'm not a fan of Lua and isn't my domain, but your quest style is not ok.
You can do it a multi-table to define the boss, this is how should looks.

Debes iniciar sesión para ver el contenido del enlace en esta publicación.
Ocultar contenido


quest MainQuestCollect begin
    state start begin  
		function GetCoinsByRace(bRace)
			local data = {
				[1] = {
					["id"] = {8024, 8025, 8026, 8027}, 
					["value"] = 100}, 
				[2] = {
					["id"] = {101}, 
					["value"] = 25}
			};
			
			-- Lua 5.1+ for smaller version use: table.getn({...})
			for i = 1, #data do
				for j = 1, #data[i]["id"] do
					if (bRace == data[i]["id"][j]) then
						return data[i]["value"];
				end
			end
			return 0;
		end

        when kill with not npc.is_pc() begin
			bCoins = MainQuestCollect.GetCoinsByRace(npc.get_race())
			if bCoins > 0 then
				pc.charge_cash(bCoins, "MAIN_QUEST_COLLECT")
				syschat(string.format("You get %d coins from %s.", bCoins, mob_name(npc.get_race())))
			end
		end
	end  
end

 

Also ymir already did the function for lua to charge the coins via pc.charge_cash, but not all people was used because name of row is called: "cash" and they are used on website/itemshop etc row "coins", but can change it.
You don't need to use other mysql query command for that, when you already have that on source.


//@../src/db/ClientManager.cpp
//Search for:
	sprintf(szQuery, "update account set `cash` = `cash` + %d where id = %d limit 1", packet->dwAmount, packet->dwAID);
//Replace `cash` = `cash` with `coins` = `coins`.

 

I like your style as practice and formal development, but I did it this way just because I was getting bored, so to be honest, I did not follow any syntax or structure in this case, so yes, you are absolutely right.

Most people use the column "coins" instead of "cash" with the function or without it, I could do it the way you say, but by generally I did not.

So, at this point, thanks for answering this thread, it's good to know that other developers read new (or not too new) content from others!

Enlace para comentar
Compartir en otros sitios

Unirse a la conversación

Puedes publicar ahora y registrarte más tarde. Si tienes una cuenta, regístrate para publicar con su cuenta.

Guest
Responder a este tema...

×   Has pegado contenido con formato .   Eliminar formato

  Only 75 emoji are allowed.

×   Tu enlace se ha incorporado automáticamente.   Mostrar un enlace en su lugar

×   Se ha restaurado el contenido anterior. .   Borrar editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recientemente navegando por este tema   0 miembros

    • No hay usuarios registrados visitando esta página.
×
×
  • Crear nuevo...