Ir para conteúdo

[AGS] Guild Task


Omega

Posts Recomendados

Aviso

Esse script precisa do Advanced Guild System instalado corretamente para funcionar.

 

Informações

Esse sistema de scripts funciona como uma task para toda a guild. Assim, qualquer membro da guilda pode aceitar uma task e cada monstro morto por qualquer membro irá contar para completar a task. Ao terminar a task, um membro deve falar com o NPC, que dará guild points e depositará o dinheiro na conta da guilda. Para melhor usufruto, use em conjunto com o Guild Banker.

 

Códigos

data/lib/guildtask_lib.lua

 

 

-- Storages
GT = {
	kills = 51,
	totalKills = 52,
	task = 53,
	time = 54,


-- Customization starts here

-- Monsters

	monsters = {
		{names = {"dragon"}, totalKills = 5, money = 5000, points = 3, minPoints = 0},
		{names = {"dragon lord"}, totalKills = 5, money = 15000, points = 5, minPoints = 1},
	},

-- Other variables

	waitTime = 1440, -- Tempo de espera para começar outra task após entregar uma
}

-- Customization ends here

function doResetGuildTask(guild_id, resetTime)
	for _, stgkey in ipairs({GT.kills, GT.totalKills, GT.task, GT.time}) do
		setGuildStorageValue(guild_id, stgkey, 0)
	end
	if resetTime then
		setGuildStorageValue(guild_id, GT.time, os.time() + GT.waitTime * 60)
	end
	return true
end

function doStartGuildTask(guild_id, task)
	local taskInfo = GT.monsters[task]
	setGuildStorageValue(guild_id, GT.totalKills, taskInfo.totalKills)
	setGuildStorageValue(guild_id, GT.task, task)
	setGuildStorageValue(guild_id, GT.kills, 0)
	return true
end

function getGuildTaskWaitTime(guild)
	local nextTime = getGuildStorageValue(guild, GT.time)
	if nextTime > os.time() then
		return nextTime - os.time()
	else
		return 0
	end
end

function doCompleteGuildTask(guild_id)
	local taskInfo = GT.monsters[getGuildStorageValue(guild_id, GT.task)]
	doGuildAddPoints(guild_id, taskInfo.points)
	doGuildAddBalance(guild_id, taskInfo.money)
	doResetGuildTask(guild_id, true)
	return true
end

 

 

 

data/creaturescripts/scripts/guild_onKill.lua

 

 

function onKill(cid, target)
	if not isPlayer(cid) or not isMonster(target) then
		return true
	end
	local guild = getPlayerGuildId(cid)
	if guild < 1 then
		return true
	end
	local task = getGuildStorageValue(guild, GT.task)
	local kills, total_kills = getGuildStorageValue(guild, GT.kills), getGuildStorageValue(guild, GT.totalKills)
	if task >= 1 and kills < total_kills then
		local monsterName = getCreatureName(target)		
		if isInArray(GT.monsters[task].names, monsterName:lower()) then			
			if kills + 1 == total_kills then
				setGuildStorageValue(guild, GT.kills, kills + 1)
				doFunctionOnGuildMembers(guild, function(cid)
					doPlayerSendTextMessage(cid, 25, "Congratulations, your guild has completed a guild task.")
				end)
			elseif kills <= -1 then
				setGuildStorageValue(guild, GT.kills, 1)
			else
				setGuildStorageValue(guild, GT.kills, kills + 1)
			end
		end
	end
	return true
end

 

 

 

data/npcs/scripts/guild_task_npc.lua

 

 

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid)			end
function onCreatureDisappear(cid)			npcHandler:onCreatureDisappear(cid)			end
function onCreatureSay(cid, type, msg)			npcHandler:onCreatureSay(cid, type, msg)		end
function onThink()					npcHandler:onThink()					end

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end

	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

	local guild = getPlayerGuildId(cid)
	if guild < 1 then
		selfSay("I can only offer tasks for guild members.")
		return true
	end
	if msgcontains(msg, "tasks") then
		selfSay("Do you want to {start} a task, {reset} a task, {finish} your task, check your guild's {progress} or {information} about guild tasks?", cid)
		talkState[talkUser] = 1
	elseif msgcontains(msg, "information") then
		selfSay("You can start a task here and all of your guild mates can help you kill those monsters. Just say {start}.", cid)
	elseif talkState[talkUser] == 1 then
		if msgcontains(msg, "start") then
			if getPlayerGuildLevel(cid) < 2 then
				selfSay("Only leaders or vice-leaders can start guild tasks.", cid)
				talkState[talkUser] = 0
			elseif getGuildTaskWaitTime(guild) > 0 then
				local waitTime = getGuildTaskWaitTime(guild)
				selfSay("Your guild must wait ".. math.ceil(waitTime / 60) .. " minutes before starting another guild task.", cid)
			elseif getGuildStorageValue(guild, GT.task) > 1 then
				selfSay("Your guild already has an active guild task.", cid)
			else
				local points = getGuildPoints(guild)
				local list = ""
				for taskId, info in pairs(GT.monsters) do
					if info.minPoints <= points then
						list = list .. info.names[1] .. ", "
					end
				end
				selfSay("I have the following tasks for your guild: " .. list:sub(1, list:len() - 2) .. ". Which one do you want?", cid)
				talkState[talkUser] = 2
			end
		elseif msgcontains(msg, "reset") then
			if getGuildStorageValue(guild, GT.task) < 1 then
				selfSay("Your guild doesn't have an active guild task.", cid)
			elseif getPlayerGuildLevel(cid) < 2 then
				selfSay("Only leaders or vice-leaders of your guild can cancel guild tasks.", cid)
			else
				doResetGuildTask(guild, false)
				selfSay("Done.", cid)
			end
		elseif msgcontains(msg, "progress") then
			local kills, totalKills = getGuildStorageValue(guild, GT.kills), getGuildStorageValue(guild, GT.totalKills)
			if totalKills > 0 then
				local taskId = getGuildStorageValue(guild, GT.task)
				local taskName = GT.monsters[taskId].names[1] .. "."
				selfSay("Your guild has killed " .. kills .. " out of " .. totalKills .. " " .. taskName, cid)
			else
				selfSay("Your guild doesn't have an active guild task.", cid)
			end
		elseif msgcontains(msg, "finish") then
			local kills, totalKills = getGuildStorageValue(guild, GT.kills), getGuildStorageValue(guild, GT.totalKills)
			if totalKills > 0 then				
				if kills >= totalKills then
					local taskId = getGuildStorageValue(guild, GT.task)
					local taskInfo = GT.monsters[taskId]
					doFunctionOnGuildMembers(guild, function(pid)
						doPlayerSendTextMessage(pid, 22, "Your guild has finished the " .. taskInfo.names[1] .. " task.")
					end)
					doCompleteGuildTask(guild)
					selfSay("Congratulations, your guild has now completed a guild task and a deposit has been made into your guild account.", cid)
					talkState[talkUser] = 1
				else
					selfSay("Your guild hasn't completed the guild task yet. Do you want to check on your {progress}?", cid)
				end
			else
				selfSay("Your guild doesn't have an active guild task.", cid)
			end
		end
	elseif talkState[talkUser] == 2 then
		local points = getGuildPoints(guild)
		for taskId, info in pairs(GT.monsters) do
			if info.minPoints <= points and string.find(info.names[1], msg) then
				doStartGuildTask(guild, taskId)
				local starterName = getCreatureName(cid)
				doFunctionOnGuildMembers(guild, function(cid)
					doPlayerSendTextMessage(cid, 27, starterName .. " has started the " .. info.names[1] .. " task for your guild.")
				end)
				selfSay("You have started a task for your guild. You now have to kill " .. info.totalKills .. " monsters to finish.", cid)
				talkState[talkUser] = 1
				return true
			end
		end
		selfSay("That wasn't a valid task for your guild.", cid)
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

 

 

data/lib/npc/Arthur.xml

 

 

<?xml version="1.0" encoding="UTF-8"?>
<npc name="Arthur" script="data/npc/scripts/guild_task_npc.lua" walkinterval="3000" floorchange="0">
	<health now="100" max="100"/>
	<look type="129" head="115" body="95" legs="113" feet="0" addons="3"/>
	<parameters>
  <parameter key="message_greet" value="|PLAYERNAME|, would you like to get some {tasks}?"/>
  <parameter key="message_farewell" value="May your adventures be sucessful, |PLAYERNAME|."/>
  <parameter key="message_walkaway" value="See ya..."/>
  </parameters>
</npc>

 

 

 

Configurações

  • Para acrescentar monstros:

Abra o arquivo guildtask_lib.lua e adicione

{names = {"nome da task", "nome do monstro(1)", "nome do monstro(2), etc...}, totalKills = numero de monstros para completar a task, money = recompensa(dinheiro), points = recompensa(pontos), minPoints = mínimo de pontos para habilitar a task},

Logo abaixo dos demais monstros. Por exemplo, para acrescentar uma task para matar vários tipos de dragons, ficaria assim (o primeiro nome é o nome do task):

-- Monsters

	monsters = {
		{names = {"dragon"}, totalKills = 5, money = 5000, points = 3, minPoints = 0},
		{names = {"dragon lord"}, totalKills = 5, money = 15000, points = 5, minPoints = 1},
		{names = {"dragon hunter task", "dragon lord", "dragon", "frost dragon", "undead dragon"}, totalKills = 500, money = 150000, points = 5, minPoints = 10},
              
	},
  • Para configurar o tempo entre uma task e outra, utilize a variável waitTime (guildtask_lib.lua):
-- Other variables

	waitTime = 1440, -- Tempo de espera para começar outra task após entregar uma
}

Para que não haja tempo de espera, coloque o valor 0. Esse tempo é em minutos.

Editado por Omega
Link para o comentário
Compartilhar em outros sites

E se um membro for invitado na guild no meio da task? Tipo, um leader mata 800/1000 bichos e invita um membro novo, esse novo membro também vai ganhar a recompensa?

Link para o comentário
Compartilhar em outros sites

nunca tinha pensado nisso, boa ideia cara!

parabéns mesmo, acho que a task fica mais competitiva quando é por guild xD

 

rep+

 

Ideia muito criativa, realmente algo que vale a pena - e muito - colocar em um servidor, meus sinceros parabéns :)

 

Obrigado pela força, pessoal!

 

 

E se um membro for invitado na guild no meio da task? Tipo, um leader mata 800/1000 bichos e invita um membro novo, esse novo membro também vai ganhar a recompensa?

A recompensa não é por membro, e sim para a guild. Quando uma task é entregue, a guilda recebe a recompensa em dinheiro em sua conta. Por isso eu recomendo usar em conjunto com o Guild Banker.

Além disso, a guilda também recebe points. Por enquanto, o que fazer com esses points fica a cargo de cada um, mas em breve desenvolvo algo relacionado a isso também.

Link para o comentário
Compartilhar em outros sites

  • 3 weeks later...
  • 4 years later...

Quando eu tento pegar uma task:

10:45 Arthur: Strikker, would you like to get some tasks?
10:45 Strikker [20]: tasks
10:45 Arthur: Do you want to start a task, reset a task, finish your task, check your guild's progress or information about guild tasks?
10:46 Strikker [20]: start
10:46 Arthur: I have the following tasks for your guild: . Which one do you want?

 


guildtask_lib.lua


-- Storages
GT = {
    kills = 51,
    totalKills = 52,
    task = 53,
    time = 54,


-- Customization starts here

-- Monsters

    monsters = {
        {names = {"Troll"}, totalKills = 2000, money = 600000, points = 1, minPoints = 0},
        {names = {"Rotworm"}, totalKills = 2000, money = 600000, points = 1, minPoints = 1},
        {names = {"Goblin"}, totalKills = 2000, money = 600000, points = 1, minPoints = 2},
        {names = {"Dwarf"}, totalKills = 2000, money = 600000, points = 1, minPoints = 3},
        {names = {"Amazon"}, totalKills = 2000, money = 600000, points = 1, minPoints = 4},
        {names = {"Carrion Worm"}, totalKills = 2000, money = 600000, points = 1, minPoints = 5},
        {names = {"Valkyrie"}, totalKills = 2000, money = 600000, points = 1, minPoints = 6},
        {names = {"Skeleton"}, totalKills = 2000, money = 600000, points = 1, minPoints = 7},
        {names = {"Minotaur"}, totalKills = 2000, money = 600000, points = 1, minPoints = 8},
        {names = {"Ghoul"}, totalKills = 2000, money = 600000, points = 1, minPoints = 9},
        {names = {"Elf"}, totalKills = 2000, money = 600000, points = 1, minPoints = 10},
        {names = {"Dwarf Soldier"}, totalKills = 2000, money = 600000, points = 1, minPoints = 11},
        {names = {"Tarantula"}, totalKills = 2000, money = 600000, points = 1, minPoints = 12},
        {names = {"Cyclops"}, totalKills = 2000, money = 600000, points = 1, minPoints = 13},

        {names = {"Larva"}, totalKills = 2000, money = 600000, points = 1, minPoints = 14},
        {names = {"Nomad"}, totalKills = 2000, money = 600000, points = 1, minPoints = 15},
        {names = {"Tortoise"}, totalKills = 2000, money = 600000, points = 1, minPoints = 16},
        {names = {"Terramite"}, totalKills = 2000, money = 600000, points = 1, minPoints = 17},
        {names = {"Crocodile"}, totalKills = 2000, money = 600000, points = 1, minPoints = 18},

            

            
        {names = {"Scarab"}, totalKills = 40000, money = 800000, points = 1, minPoints = 19},
        {names = {"Kongra"}, totalKills = 40000, money = 800000, points = 1, minPoints = 20},
        {names = {"Sibang"}, totalKills = 40000, money = 800000, points = 1, minPoints = 21},
        {names = {"Mammoth"}, totalKills = 40000, money = 800000, points = 1, minPoints = 22},
        {names = {"Cyclops Drone"}, totalKills = 40000, money = 800000, points = 1, minPoints = 23},
        {names = {"Cyclops Smith"}, totalKills = 40000, money = 800000, points = 1, minPoints = 24},
        {names = {"Demon Skeleton"}, totalKills = 40000, money = 800000, points = 1, minPoints = 25},
        {names = {"Wyvern"}, totalKills = 40000, money = 800000, points = 1, minPoints = 26},
        {names = {"Vampire"}, totalKills = 40000, money = 800000, points = 1, minPoints = 27},
        {names = {"Zombie"}, totalKills = 40000, money = 800000, points = 1, minPoints = 28},
        {names = {"Mutated Rat"}, totalKills = 40000, money = 30000, points = 1, minPoints = 29},
        {names = {"Dwarf Guard"}, totalKills = 40000, money = 800000, points = 1, minPoints = 30},
        {names = {"Dragon"}, totalKills = 40000, money = 800000, points = 1, minPoints = 31},
        {names = {"Ice Witch"}, totalKills = 40000, money = 800000, points = 1, minPoints = 32},
        {names = {"Frost Giantess"}, totalKills = 40000, money = 800000, points = 1, minPoints = 33},
        {names = {"Ice Golem"}, totalKills = 40000, money = 800000, points = 1, minPoints = 34},
        {names = {"Stone Golem"}, totalKills = 40000, money = 800000, points = 1, minPoints = 35},
            
            


        {names = {"Giant Spider"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 36},
        {names = {"Dragon Lord"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 37},
        {names = {"Frost Dragon"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 38},
        {names = {"Wyrm"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 39},
        {names = {"Hydra"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 40},
        {names = {"Warlock"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 41},
        {names = {"Slick Water Elemental"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 42},
        {names = {"Water Elemental"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 43},
        {names = {"Earth Elemental"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 44},
        {names = {"Crystal Spider"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 45},
        {names = {"Black Knight"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 46},
        {names = {"Hero"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 47},
        {names = {"Demon"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 48},
        {names = {"Serpent Spawn"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 49},
        {names = {"Werewolf"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 50},
        {names = {"Destroyer"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 51},
        {names = {"Mutated Tiger"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 52},
        {names = {"Grim Reaper"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 53},
        {names = {"Juggernaut"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 54},
        {names = {"Hand of Cursed Fate"}, totalKills = 60000, money = 1200000, points = 1, minPoints = 55}
    },

-- Other variables

    waitTime = 1440, -- Tempo de espera para começar outra task após entregar uma
}

-- Customization ends here

function doResetGuildTask(guild_id, resetTime)
    for _, stgkey in ipairs({GT.kills, GT.totalKills, GT.task, GT.time}) do
        setGuildStorageValue(guild_id, stgkey, 0)
    end
    if resetTime then
        setGuildStorageValue(guild_id, GT.time, os.time() + GT.waitTime * 60)
    end
    return true
end

function doStartGuildTask(guild_id, task)
    local taskInfo = GT.monsters[task]
    setGuildStorageValue(guild_id, GT.totalKills, taskInfo.totalKills)
    setGuildStorageValue(guild_id, GT.task, task)
    setGuildStorageValue(guild_id, GT.kills, 0)
    return true
end

function getGuildTaskWaitTime(guild)
    local nextTime = getGuildStorageValue(guild, GT.time)
    if nextTime > os.time() then
        return nextTime - os.time()
    else
        return 0
    end
end

function doCompleteGuildTask(guild_id)
    local taskInfo = GT.monsters[getGuildStorageValue(guild_id, GT.task)]
    doGuildAddPoints(guild_id, taskInfo.points)
    doGuildAddBalance(guild_id, taskInfo.money)
    doResetGuildTask(guild_id, true)
    return true
end

 

Editado por gmstrikker
Link para o comentário
Compartilhar em outros sites

  • 2 weeks later...
×
×
  • Criar Novo...