• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Npc Task System (HELP)

julhinhuu

New Member
Joined
Jul 16, 2011
Messages
35
Reaction score
0
Someone could make a onKill function for this task system? I would greatly appreciate it .

TFS : 1.2
V10.90

Code:
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 qntdade = 600
local stoTime = 96586
local stoKill = 96587
local premio = 100000 --em exp!
local msg = string.lower(msg)
local left = math.ceil((getPlayerStorageValue(cid, stoTime) - os.time())/(24 * 60 * 60)) --nao mexe!


if (msgcontains(msg, 'tarefa') or msgcontains(msg, 'missao')) then
if getPlayerStorageValue(cid, stoTime) ~= -1 and left > 0 and getPlayerStorageValue(cid, stoKill) > 0 then
local faltaMatar = getPlayerStorageValue(cid, stoKill)
local jaMatou = math.abs(getPlayerStorageValue(cid, stoKill)-qntdade)
local prazo = os.date("%d/%m/%y %X", getPlayerStorageValue(cid, stoTime))
selfSay("Você ainda não matou os "..qntdade.." multis, atualmente você matou ".. (jaMatou)..", resta "..faltaMatar..". Seu prazo é de até "..prazo..".", cid)
talkState[talkUser] = 0
return true
elseif getPlayerStorageValue(cid, stoTime) ~= -1 and left <= 0 and getPlayerStorageValue(cid, stoKill) ~= -1 then
selfSay("Infelismente você não matou as "..qntdade.." multis a tempo. Se você quiser, você pode tentar fazer denovo a missao.", cid)
setPlayerStorageValue(cid, stoTime, -1)
setPlayerStorageValue(cid, stoKill, -1)
talkState[talkUser] = 0
return true
elseif getPlayerStorageValue(cid, stoTime) ~= -1 and left > 0 and getPlayerStorageValue(cid, stoKill) == -1 then
local prazo = os.date("%d/%m/%y %X", getPlayerStorageValue(cid, stoTime))
selfSay("Você tem que esperar pelo menos 1 semana para poder pegar essa tarefa denovo. O prazo de acaba dia ".. prazo..".", cid)
talkState[talkUser] = 0
return true
elseif getPlayerStorageValue(cid, stoTime) ~= -1 and left > 0 and getPlayerStorageValue(cid, stoKill) == 0 then
selfSay("Obrigado! você matou os "..qntdade.." multis em menos de 1 semana. Aqui esta sua recompensa! Lembre-se que você pode fazer esta task quantas vezes quiser,desde que tenha concluído 1 semana contado a partir do dia de inicio.", cid)
doPlayerAddExp(cid, premio) --premio
setPlayerStorageValue(cid, stoKill, -1)
talkState[talkUser] = 0
return true
else
if getPlayerStorageValue(cid, stoTime) ~= -1 and getPlayerStorageValue(cid, stoKill) == -1 then
setPlayerStorageValue(cid, stoTime, -1) --soh pra evitar problemas...
end
selfSay("Você quer me ajudar a acabar com poderosas gosmas chamadas Multi?", cid)
talkState[talkUser] = 1
end

elseif (msgcontains(msg, 'yes') or msgcontains(msg, 'sim')) and talkState[talkUser] == 1 then
selfSay("Ótimo! Você precisa matar pelo menos "..qntdade.." Multis em um prazo de 1 semana para eu te dar a recompensa. Aceita?", cid)
talkState[talkUser] = 2

elseif (msgcontains(msg, 'yes') or msgcontains(msg, 'sim')) and talkState[talkUser] == 2 then
local semana = 7 * 24 * 60 * 60
setPlayerStorageValue(cid, stoTime, os.time()+semana)
setPlayerStorageValue(cid, stoKill, qntdade)
local sto = getPlayerStorageValue(cid, stoTime)
selfSay("Você já pode começar a matar os multis, mas cuidado! É uma criatura muito forte. Volte aqui quando matar "..qntdade.." multis para ser recompensado. O prazo é até ".. os.date("%d/%m/%y %X", sto) ..".", cid)

end

return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Take a look at the tutorial section, you will easily find what you're looking for here:
https://otland.net/threads/npc-mission.211063/#post-2022378

Edit this storage, amount, startstorage and value to fit your script.
Creaturescript:
Code:
local config = {
  ['monster name'] = {amount = 5, storage = 19000, startstorage = 5002, startvalue = 1}
}
function onKill(cid, target)
  local monster = config[getCreatureName(target):lower()]
  if isPlayer(target) or not monster or isSummon(target) then
  return true
  end

  if (getPlayerStorageValue(cid, monster.storage)+1) < monster.amount and getPlayerStorageValue(cid, monster.startstorage) >= monster.startvalue then
  setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
  doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..getCreatureName(target)..'s killed.')
  end
  if (getPlayerStorageValue(cid, monster.storage)+1) == monster.amount then
  doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Congratulations, you have killed '..(getPlayerStorageValue(cid, monster.storage)+1)..' '..getCreatureName(target)..'s and completed the '..getCreatureName(target)..'s mission.')
  setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
  end
  return true
end
The startstorage is the storage from the NPC with value 1, so this means the script will start counting after accepting the mission.
The other storage, named storage, is to count the monsters.
 
Back
Top