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.