• 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 Talkstate?

LucasFerraz

Systems Analyst
Joined
Jun 10, 2010
Messages
2,857
Reaction score
96
Location
Brazil
Hello, I'm using this script http://otland.net/f82/creatureevent-npc-killing-name-now-player-can-choose-task-107936/

I've edited it today (Player can choose task by name and report by task name.)

There is something wrong, when I try to report it do not work. Can some1 help?
I've already tried to use talkstate and do not work.

When I say 'report' it will show all current tasks i'm doing and when i say task name(example 'trolls' if i'm doing it) npc understand that i'm starting this task
LUA:
local tasks =
{
	[1] = {questStarted = 1510, questStorage = 65000, killsRequired = 100, raceName = "Trolls", rewards = {{enable = true, type = "exp", values = 200}, {enable = true, type = "exp", values = 200}}},
 
	[2] = {questStarted = 1511, questStorage = 65001, killsRequired = 150, raceName = "Goblins", rewards = {{enable = true, type = "exp", values = 300}, {enable = true, type = "exp", values = 250}}},
 
	[3] = {questStarted = 1512, questStorage = 65002, killsRequired = 300, raceName = "Rotworms", rewards = {{enable = true, type = "exp", values = 1000}, {enable = true, type = "exp", values = 400}}},
 
	[4] = {questStarted = 1513, questStorage = 65003, killsRequired = 500, raceName = "Cyclops", rewards = {{enable = true, type = "exp", values = 3000}, {enable = true, type = "exp", values = 800}}},
 
	[5] = {questStarted = 1514, questStorage = 65004, killsRequired = 500, raceName = "Green Djinn", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "exp", values = 5000}}},
 
	[6] = {questStarted = 1515, questStorage = 65005, killsRequired = 500, raceName = "Blue Djinn", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "exp", values = 5000}}},
 
	[7] = {questStarted = 1516, questStorage = 65006, killsRequired = 3000, raceName = "Pirates", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "exp", values = 5000}}},
 
	[8] = {questStarted = 1517, questStorage = 65007, killsRequired = 3000, raceName = "Pirates 2", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "exp", values = 5000}}},
 
	[9] = {questStarted = 1518, questStorage = 65008, killsRequired = 5000, raceName = "Minotaurs", rewards = {{enable = false, type = "exp", values = 1}}},
 
	[10] = {questStarted = 1519, questStorage = 65009, killsRequired = 4000, raceName = "Necromanders", rewards = {{enable = false, type = "exp", values = 1}}},
 
	[11] = {questStarted = 1520, questStorage = 65010, killsRequired = 1000, raceName = "Necromanders 2", rewards = {{enable = true, type = "exp", values = 40000}}},
 
	[12] = {questStarted = 1521, questStorage = 65011, killsRequired = 300, raceName = "Crocodiles", rewards = {{enable = true, type = "exp", values = 800}, {enable = true, type = "points", values = 1}}},
 
	[13] = {questStarted = 1522, questStorage = 65012, killsRequired = 300, raceName = "Badgers", rewards = {{enable = true, type = "exp", values = 500}, {enable = true, type = "points", values = 1}}},
 
	[14] = {questStarted = 1523, questStorage = 65013, killsRequired = 300, raceName = "Tarantulas", rewards = {{enable = true, type = "exp", values = 1500}, {enable = true, type = "points", values = 2}}},
 
	[15] = {questStarted = 1524, questStorage = 65014, killsRequired = 150, raceName = "Carniphilas", rewards = {{enable = true, type = "exp", values = 2500}, {enable = true, type = "points", values = 3}}},
 
	[16] = {questStarted = 1525, questStorage = 65015, killsRequired = 200, raceName = "Stone Golems", rewards = {{enable = true, type = "exp", values = 2000}, {enable = true, type = "points", values = 3}}},
 
	[17] = {questStarted = 1526, questStorage = 65016, killsRequired = 300, raceName = "Mammoths", rewards = {{enable = true, type = "exp", values = 4000}, {enable = true, type = "points", values = 3}}},
 
	[18] = {questStarted = 1527, questStorage = 65017, killsRequired = 300, raceName = "Gnarlhounds", rewards = {{enable = true, type = "exp", values = 1000}, {enable = true, type = "points", values = 2}}},
 
	[19] = {questStarted = 1528, questStorage = 65018, killsRequired = 300, raceName = "Terramites", rewards = {{enable = true, type = "exp", values = 2500}, {enable = true, type = "points", values = 2}}},
 
	[20] = {questStarted = 1529, questStorage = 65019, killsRequired = 300, raceName = "Apes", rewards = {{enable = true, type = "exp", values = 1000}, {enable = true, type = "points", values = 2}}},
 
	[21] = {questStarted = 1530, questStorage = 65020, killsRequired = 300, raceName = "Thornback Tortoises", rewards = {{enable = true, type = "exp", values = 1500}, {enable = true, type = "points", values = 2}}},
 
	[22] = {questStarted = 1531, questStorage = 65021, killsRequired = 200, raceName = "Gargoyles", rewards = {{enable = true, type = "exp", values = 1500}, {enable = true, type = "points", values = 2}}},
 
	[23] = {questStarted = 1532, questStorage = 65022, killsRequired = 300, raceName = "Ice Golems", rewards = {{enable = true, type = "exp", values = 12000}, {enable = true, type = "points", values = 2}}},
 
	[24] = {questStarted = 1533, questStorage = 65023, killsRequired = 400, raceName = "Quara Scouts", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "points", values = 2}}},
 
	[25] = {questStarted = 1534, questStorage = 65024, killsRequired = 400, raceName = "Mutated Rats", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "points", values = 2}}},
 
	[26] = {questStarted = 1535, questStorage = 65025, killsRequired = 250, raceName = "Ancient Scarabs", rewards = {{enable = true, type = "exp", values = 15000}, {enable = true, type = "points", values = 2}}},
 
	[27] = {questStarted = 1536, questStorage = 65026, killsRequired = 300, raceName = "Wyverns", rewards = {{enable = true, type = "exp", values = 12000}, {enable = true, type = "points", values = 2}}},
 
	[28] = {questStarted = 1537, questStorage = 65027, killsRequired = 300, raceName = "Lancer Beetles", rewards = {{enable = true, type = "exp", values = 8000}, {enable = true, type = "points", values = 2}}},
 
	[29] = {questStarted = 1538, questStorage = 65028, killsRequired = 400, raceName = "Wailing Widows", rewards = {{enable = true, type = "exp", values = 12000}, {enable = true, type = "points", values = 3}}},
 
	[30] = {questStarted = 1539, questStorage = 65029, killsRequired = 250, raceName = "Killer Caimans", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "points", values = 2}}},
 
	[31] = {questStarted = 1540, questStorage = 65030, killsRequired = 300, raceName = "Bonebeasts", rewards = {{enable = true, type = "exp", values = 12000}, {enable = true, type = "points", values = 2}}},
 
	[32] = {questStarted = 1541, questStorage = 65031, killsRequired = 300, raceName = "Crystal Spiders", rewards = {{enable = true, type = "exp", values = 15000}, {enable = true, type = "points", values = 3}}},
 
	[33] = {questStarted = 1542, questStorage = 65032, killsRequired = 250, raceName = "Mutated Tigers", rewards = {{enable = true, type = "exp", values = 12000}, {enable = true, type = "points", values = 3}}},
 
	[34] = {questStarted = 1543, questStorage = 65033, killsRequired = 600, raceName = "Underwater Quaras", rewards = {{enable = true, type = "exp", values = 15000}, {enable = true, type = "points", values = 3}}},
 
	[35] = {questStarted = 1544, questStorage = 65034, killsRequired = 500, raceName = "Giant Spiders", rewards = {{enable = true, type = "exp", values = 20000}, {enable = true, type = "points", values = 3}}},
 
	[36] = {questStarted = 1545, questStorage = 65035, killsRequired = 300, raceName = "Werewolves", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 4}}},
 
	[37] = {questStarted = 1546, questStorage = 65036, killsRequired = 400, raceName = "Nightmares", rewards = {{enable = true, type = "exp", values = 25000}, {enable = true, type = "points", values = 3}}},
 
	[38] = {questStarted = 1547, questStorage = 65037, killsRequired = 600, raceName = "Hellspawns", rewards = {{enable = true, type = "exp", values = 25000}, {enable = true, type = "points", values = 4}}},
 
	[39] = {questStarted = 1548, questStorage = 65038, killsRequired = 800, raceName = "High Class Lizards", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 3}}},
 
	[40] = {questStarted = 1549, questStorage = 65039, killsRequired = 600, raceName = "Brimstone Bugs", rewards = {{enable = true, type = "exp", values = 15000}, {enable = true, type = "points", values = 3}}},
 
	[41] = {questStarted = 1550, questStorage = 65040, killsRequired = 400, raceName = "Mutated Bats", rewards = {{enable = true, type = "exp", values = 20000}, {enable = true, type = "points", values = 2}}},
 
	[42] = {questStarted = 1551, questStorage = 65041, killsRequired = 650, raceName = "Hydras", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 3}}},
 
	[43] = {questStarted = 1552, questStorage = 65042, killsRequired = 800, raceName = "Serpent Spawns", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 4}}},
 
	[44] = {questStarted = 1553, questStorage = 65043, killsRequired = 500, raceName = "Medusas", rewards = {{enable = true, type = "exp", values = 40000}, {enable = true, type = "points", values = 5}}},
 
	[45] = {questStarted = 1554, questStorage = 65044, killsRequired = 700, raceName = "Behemoths", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 4}}},
 
	[46] = {questStarted = 1555, questStorage = 65045, killsRequired = 900, raceName = "Sea Serpents", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 4}}},
 
	[47] = {questStarted = 1556, questStorage = 65046, killsRequired = 250, raceName = "Hellhounds", rewards = {{enable = true, type = "exp", values = 40000}, {enable = true, type = "points", values = 5}}},
 
	[48] = {questStarted = 1557, questStorage = 65047, killsRequired = 500, raceName = "Ghastly Dragons", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 5}}},
 
	[49] = {questStarted = 1558, questStorage = 65048, killsRequired = 900, raceName = "Drakens", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 3}}},
 
	[50] = {questStarted = 1559, questStorage = 65049, killsRequired = 650, raceName = "Destroyers", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 4}}},
 
	[51] = {questStarted = 1560, questStorage = 65050, killsRequired = 400, raceName = "Undead Dragons", rewards = {{enable = true, type = "exp", values = 50000}, {enable = true, type = "points", values = 6}}},
 
	[52] = {questStarted = 1561, questStorage = 65051, killsRequired = 1, raceName = "Tiquandas Revenge", rewards = {{enable = false, type = "storage", values = {65535, 1}}}},
 
	[53] = {questStarted = 1562, questStorage = 65052, killsRequired = 1, raceName = "Demodras", rewards = {{enable = false, type = "storage", values = {65535, 1}}}},
 
	[54] = {questStarted = 1563, questStorage = 65053, killsRequired = 6666, raceName = "Demons", rewards = {{enable = false, type = "storage", values = {65535, 1}}}}
 
 
 
}
 
 
local rankStorage = 32150
local questLogStorage = 33150
local chatStorage = 34150
local choose = {}
 
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local voc = {}
 
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
 
local function getTasksStarted(cid)
	local tmp = {}
	for k, v in pairs(tasks) do
		if getCreatureStorage(cid, v.questStarted) == 1 then
			table.insert(tmp, k)
		end
	end
	return tmp
end
 
local function getTaskByName(name)
	for k, v in pairs(tasks) do
		if v.raceName:lower() == name:lower() then
			return k
		end
	end
	return false
end
 
function creatureSayCallback(cid, type, msg)
 
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
	if msgcontains(msg, "task") then
		doCreatureSetStorage(cid, questLogStorage, 1)
		selfSay("All right, what would you like to hunt?", cid)
		local text = ""
		for i = 1, table.maxn(tasks) do
			text = text .. "\n" .. tasks[i].raceName .. (getCreatureStorage(cid, tasks[i].questStarted) == 2 and " [Done]" or "")
		end
		doShowTextDialog(cid, 5956, text)
 
	elseif getTaskByName(msg) then
		msg = getTaskByName(msg)
		if getCreatureStorage(cid, tasks[msg].questStarted) == 1 then
			selfSay("You are already making this task.", cid)
			talkState[talkUser] = 0
			return true
		end
		if getCreatureStorage(cid, tasks[msg].questStarted) == 2 then
			selfSay("You already finished this task.", cid)
			talkState[talkUser] = 0
			return true
		end
		if tasks[msg].level and getPlayerLevel(cid) < tasks[msg].level then
			selfSay("You need level " .. tasks[msg].level .. " or higher to start this task.", cid)
			talkState[talkUser] = 0
			return true
		end
		--for k, v in pairs(tasks) do
			--if getCreatureStorage(cid, v.questStarted) == 1 and tasks[msg] ~= k then
				--selfSay("You are already making a task.", cid)
				--talkState[talkUser] = 0
				--return true
			--end
		--end
		selfSay("In this task you have to defeat " .. tasks[msg].killsRequired .. " " .. tasks[msg].raceName .. ". Interested?", cid)
		choose[cid] = msg
		talkState[talkUser] = 1
	elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
		doCreatureSetStorage(cid, tasks[choose[cid]].questStarted, 1)
		selfSay("Happy hunting, friend! Come back to me when you are done hunting.", cid)
		talkState[talkUser] = 0
 
	elseif msgcontains(msg, "report") then
		for k, v in pairs(tasks) do
			if getCreatureStorage(cid, v.questStarted) == 1 then
				if getCreatureStorage(cid, v.questStorage) < 0 then
					doCreatureSetStorage(cid, v.questStorage, 0)
				end
				local t = getTasksStarted(cid)
				local response = "You are currently making " .. (#t > 1 and "these" or "this") .. " task" .. (#t > 1 and "s" or "") .. ":\n"
				if table.maxn(t) > 0 then
					for _, tsk in ipairs(t) do
						if getCreatureStorage(cid, tasks[tsk].questStorage) < 0 then doCreatureSetStorage(cid, tasks[tsk].questStorage, 0) end
							response = response .. "     Name: " .. tasks[tsk].raceName .. "     Kills: " .. getCreatureStorage(cid, tasks[tsk].questStorage) .. " - " .. tasks[tsk].killsRequired .. ".\n"
					end
					response = response .. "Please tell me the name of the task that do you want to report."
					selfSay(response, cid)
				else
					selfSay("You need to start at least one task first.", cid)
				end
			end
		end
 
	elseif string.sub(msg:lower(), 0, 6) == "report" then
		local t = getTaskByName(string.sub(msg, 8, string.len(msg)))
		if not t then
			selfSay("That task does not exists.", cid)
		end
 
		if getCreatureStorage(cid, tasks[t].questStarted) < 1 then
			selfSay("You don't have started this task.", cid)
		end
 
		for k, v in pairs(tasks) do
			if getCreatureStorage(cid, v.questStarted) == 1 then
				if getCreatureStorage(cid, v.questStorage) >= v.killsRequired then
					for i = 1, table.maxn(v.rewards) do
						if(v.rewards[i].enable) then
							if isInArray({"boss", "teleport", 1}, v.rewards[i].type) then
								doTeleportThing(cid, v.rewards[i].values)
							elseif isInArray({"exp", "experience", 2}, v.rewards[i].type) then
								doPlayerAddExperience(cid, v.rewards[i].values)
							elseif isInArray({"item", 3}, v.rewards[i].type) then
								doPlayerAddItem(cid, v.rewards[i].values[1], v.rewards[i].values[2])
							elseif isInArray({"money", 4}, v.rewards[i].type) then
								doPlayerAddMoney(cid, v.rewards[i].values)
							elseif isInArray({"storage", "stor", 5}, v.rewards[i].type) then
								doCreatureSetStorage(cid, v.rewards[i].values[1], v.rewards[i].values[2])
							elseif isInArray({"points", "rank", 2}, v.rewards[i].type) then
								doAddTaskPoints(cid, v.rewards[i].values)
							else
								print("[Warning - Error::Killing in the name of::Tasks config] Bad reward type: " .. v.rewards[i].type .. ", reward could not be loaded.")
							end
						end
					end
					local rank = getTaskPoints(cid)
					selfSay("Ahh, thank you, my friend! What would we do without you?", cid)
					doCreatureSetStorage(cid, v.questStarted, 2)
					if getTaskPoints(cid) >= 10 and < 20 then
						doCreatureSetStorage(cid, 32150, 1)
					elseif getTaskPoints(cid) >= 20 and < 40 then
						doCreatureSetStorage(cid, 32150, 2)
					elseif getTaskPoints(cid) >= 40 and < 70 then
						doCreatureSetStorage(cid, 32150, 3)
					elseif getTaskPoints(cid) >= 70 and < 100 then
						doCreatureSetStorage(cid, 32150, 4)
					elseif getTaskPoints(cid) >= 100 then
						doCreatureSetStorage(cid, 32150, 5)
					end
					break
				else
					selfSay("Current " .. getCreatureStorage(cid, tasks[t].questStorage) .. " " .. tasks[t].raceName .. " killed, you need to kill " .. tasks[t].killsRequired .. ".", cid)
				end
			end
		end
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
LUA:
local tasks =
{
	[1] = {questStarted = 1510, questStorage = 65000, killsRequired = 100, raceName = "Trolls", rewards = {{enable = true, type = "exp", values = 200}, {enable = true, type = "exp", values = 200}}},
 
	[2] = {questStarted = 1511, questStorage = 65001, killsRequired = 150, raceName = "Goblins", rewards = {{enable = true, type = "exp", values = 300}, {enable = true, type = "exp", values = 250}}},
 
	[3] = {questStarted = 1512, questStorage = 65002, killsRequired = 300, raceName = "Rotworms", rewards = {{enable = true, type = "exp", values = 1000}, {enable = true, type = "exp", values = 400}}},
 
	[4] = {questStarted = 1513, questStorage = 65003, killsRequired = 500, raceName = "Cyclops", rewards = {{enable = true, type = "exp", values = 3000}, {enable = true, type = "exp", values = 800}}},
 
	[5] = {questStarted = 1514, questStorage = 65004, killsRequired = 500, raceName = "Green Djinn", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "exp", values = 5000}}},
 
	[6] = {questStarted = 1515, questStorage = 65005, killsRequired = 500, raceName = "Blue Djinn", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "exp", values = 5000}}},
 
	[7] = {questStarted = 1516, questStorage = 65006, killsRequired = 3000, raceName = "Pirates", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "exp", values = 5000}}},
 
	[8] = {questStarted = 1517, questStorage = 65007, killsRequired = 3000, raceName = "Pirates 2", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "exp", values = 5000}}},
 
	[9] = {questStarted = 1518, questStorage = 65008, killsRequired = 5000, raceName = "Minotaurs", rewards = {{enable = false, type = "exp", values = 1}}},
 
	[10] = {questStarted = 1519, questStorage = 65009, killsRequired = 4000, raceName = "Necromanders", rewards = {{enable = false, type = "exp", values = 1}}},
 
	[11] = {questStarted = 1520, questStorage = 65010, killsRequired = 1000, raceName = "Necromanders 2", rewards = {{enable = true, type = "exp", values = 40000}}},
 
	[12] = {questStarted = 1521, questStorage = 65011, killsRequired = 300, raceName = "Crocodiles", rewards = {{enable = true, type = "exp", values = 800}, {enable = true, type = "points", values = 1}}},
 
	[13] = {questStarted = 1522, questStorage = 65012, killsRequired = 300, raceName = "Badgers", rewards = {{enable = true, type = "exp", values = 500}, {enable = true, type = "points", values = 1}}},
 
	[14] = {questStarted = 1523, questStorage = 65013, killsRequired = 300, raceName = "Tarantulas", rewards = {{enable = true, type = "exp", values = 1500}, {enable = true, type = "points", values = 2}}},
 
	[15] = {questStarted = 1524, questStorage = 65014, killsRequired = 150, raceName = "Carniphilas", rewards = {{enable = true, type = "exp", values = 2500}, {enable = true, type = "points", values = 3}}},
 
	[16] = {questStarted = 1525, questStorage = 65015, killsRequired = 200, raceName = "Stone Golems", rewards = {{enable = true, type = "exp", values = 2000}, {enable = true, type = "points", values = 3}}},
 
	[17] = {questStarted = 1526, questStorage = 65016, killsRequired = 300, raceName = "Mammoths", rewards = {{enable = true, type = "exp", values = 4000}, {enable = true, type = "points", values = 3}}},
 
	[18] = {questStarted = 1527, questStorage = 65017, killsRequired = 300, raceName = "Gnarlhounds", rewards = {{enable = true, type = "exp", values = 1000}, {enable = true, type = "points", values = 2}}},
 
	[19] = {questStarted = 1528, questStorage = 65018, killsRequired = 300, raceName = "Terramites", rewards = {{enable = true, type = "exp", values = 2500}, {enable = true, type = "points", values = 2}}},
 
	[20] = {questStarted = 1529, questStorage = 65019, killsRequired = 300, raceName = "Apes", rewards = {{enable = true, type = "exp", values = 1000}, {enable = true, type = "points", values = 2}}},
 
	[21] = {questStarted = 1530, questStorage = 65020, killsRequired = 300, raceName = "Thornback Tortoises", rewards = {{enable = true, type = "exp", values = 1500}, {enable = true, type = "points", values = 2}}},
 
	[22] = {questStarted = 1531, questStorage = 65021, killsRequired = 200, raceName = "Gargoyles", rewards = {{enable = true, type = "exp", values = 1500}, {enable = true, type = "points", values = 2}}},
 
	[23] = {questStarted = 1532, questStorage = 65022, killsRequired = 300, raceName = "Ice Golems", rewards = {{enable = true, type = "exp", values = 12000}, {enable = true, type = "points", values = 2}}},
 
	[24] = {questStarted = 1533, questStorage = 65023, killsRequired = 400, raceName = "Quara Scouts", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "points", values = 2}}},
 
	[25] = {questStarted = 1534, questStorage = 65024, killsRequired = 400, raceName = "Mutated Rats", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "points", values = 2}}},
 
	[26] = {questStarted = 1535, questStorage = 65025, killsRequired = 250, raceName = "Ancient Scarabs", rewards = {{enable = true, type = "exp", values = 15000}, {enable = true, type = "points", values = 2}}},
 
	[27] = {questStarted = 1536, questStorage = 65026, killsRequired = 300, raceName = "Wyverns", rewards = {{enable = true, type = "exp", values = 12000}, {enable = true, type = "points", values = 2}}},
 
	[28] = {questStarted = 1537, questStorage = 65027, killsRequired = 300, raceName = "Lancer Beetles", rewards = {{enable = true, type = "exp", values = 8000}, {enable = true, type = "points", values = 2}}},
 
	[29] = {questStarted = 1538, questStorage = 65028, killsRequired = 400, raceName = "Wailing Widows", rewards = {{enable = true, type = "exp", values = 12000}, {enable = true, type = "points", values = 3}}},
 
	[30] = {questStarted = 1539, questStorage = 65029, killsRequired = 250, raceName = "Killer Caimans", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "points", values = 2}}},
 
	[31] = {questStarted = 1540, questStorage = 65030, killsRequired = 300, raceName = "Bonebeasts", rewards = {{enable = true, type = "exp", values = 12000}, {enable = true, type = "points", values = 2}}},
 
	[32] = {questStarted = 1541, questStorage = 65031, killsRequired = 300, raceName = "Crystal Spiders", rewards = {{enable = true, type = "exp", values = 15000}, {enable = true, type = "points", values = 3}}},
 
	[33] = {questStarted = 1542, questStorage = 65032, killsRequired = 250, raceName = "Mutated Tigers", rewards = {{enable = true, type = "exp", values = 12000}, {enable = true, type = "points", values = 3}}},
 
	[34] = {questStarted = 1543, questStorage = 65033, killsRequired = 600, raceName = "Underwater Quaras", rewards = {{enable = true, type = "exp", values = 15000}, {enable = true, type = "points", values = 3}}},
 
	[35] = {questStarted = 1544, questStorage = 65034, killsRequired = 500, raceName = "Giant Spiders", rewards = {{enable = true, type = "exp", values = 20000}, {enable = true, type = "points", values = 3}}},
 
	[36] = {questStarted = 1545, questStorage = 65035, killsRequired = 300, raceName = "Werewolves", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 4}}},
 
	[37] = {questStarted = 1546, questStorage = 65036, killsRequired = 400, raceName = "Nightmares", rewards = {{enable = true, type = "exp", values = 25000}, {enable = true, type = "points", values = 3}}},
 
	[38] = {questStarted = 1547, questStorage = 65037, killsRequired = 600, raceName = "Hellspawns", rewards = {{enable = true, type = "exp", values = 25000}, {enable = true, type = "points", values = 4}}},
 
	[39] = {questStarted = 1548, questStorage = 65038, killsRequired = 800, raceName = "High Class Lizards", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 3}}},
 
	[40] = {questStarted = 1549, questStorage = 65039, killsRequired = 600, raceName = "Brimstone Bugs", rewards = {{enable = true, type = "exp", values = 15000}, {enable = true, type = "points", values = 3}}},
 
	[41] = {questStarted = 1550, questStorage = 65040, killsRequired = 400, raceName = "Mutated Bats", rewards = {{enable = true, type = "exp", values = 20000}, {enable = true, type = "points", values = 2}}},
 
	[42] = {questStarted = 1551, questStorage = 65041, killsRequired = 650, raceName = "Hydras", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 3}}},
 
	[43] = {questStarted = 1552, questStorage = 65042, killsRequired = 800, raceName = "Serpent Spawns", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 4}}},
 
	[44] = {questStarted = 1553, questStorage = 65043, killsRequired = 500, raceName = "Medusas", rewards = {{enable = true, type = "exp", values = 40000}, {enable = true, type = "points", values = 5}}},
 
	[45] = {questStarted = 1554, questStorage = 65044, killsRequired = 700, raceName = "Behemoths", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 4}}},
 
	[46] = {questStarted = 1555, questStorage = 65045, killsRequired = 900, raceName = "Sea Serpents", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 4}}},
 
	[47] = {questStarted = 1556, questStorage = 65046, killsRequired = 250, raceName = "Hellhounds", rewards = {{enable = true, type = "exp", values = 40000}, {enable = true, type = "points", values = 5}}},
 
	[48] = {questStarted = 1557, questStorage = 65047, killsRequired = 500, raceName = "Ghastly Dragons", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 5}}},
 
	[49] = {questStarted = 1558, questStorage = 65048, killsRequired = 900, raceName = "Drakens", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 3}}},
 
	[50] = {questStarted = 1559, questStorage = 65049, killsRequired = 650, raceName = "Destroyers", rewards = {{enable = true, type = "exp", values = 30000}, {enable = true, type = "points", values = 4}}},
 
	[51] = {questStarted = 1560, questStorage = 65050, killsRequired = 400, raceName = "Undead Dragons", rewards = {{enable = true, type = "exp", values = 50000}, {enable = true, type = "points", values = 6}}},
 
	[52] = {questStarted = 1561, questStorage = 65051, killsRequired = 1, raceName = "Tiquandas Revenge", rewards = {{enable = false, type = "storage", values = {65535, 1}}}},
 
	[53] = {questStarted = 1562, questStorage = 65052, killsRequired = 1, raceName = "Demodras", rewards = {{enable = false, type = "storage", values = {65535, 1}}}},
 
	[54] = {questStarted = 1563, questStorage = 65053, killsRequired = 6666, raceName = "Demons", rewards = {{enable = false, type = "storage", values = {65535, 1}}}}
 
 
 
}
 
 
local rankStorage = 32150
local questLogStorage = 33150
local chatStorage = 34150
local choose = {}
 
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local voc = {}
 
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
 
local function getTasksStarted(cid)
	local tmp = {}
	for k, v in pairs(tasks) do
		if getCreatureStorage(cid, v.questStarted) == 1 then
			table.insert(tmp, k)
		end
	end
	return tmp
end
 
local function getTaskByName(name)
	for k, v in pairs(tasks) do
		if v.raceName:lower() == name:lower() then
			return k
		end
	end
	return false
end
 
function creatureSayCallback(cid, type, msg)
 
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
	if msgcontains(msg, "task") then
		doCreatureSetStorage(cid, questLogStorage, 1)
		selfSay("All right, what would you like to hunt?", cid)
		local text = ""
		for i = 1, table.maxn(tasks) do
			text = text .. "\n" .. tasks[i].raceName .. (getCreatureStorage(cid, tasks[i].questStarted) == 2 and " [Done]" or "")
		end
		doShowTextDialog(cid, 5956, text)
 
	elseif getTaskByName(msg) then
		msg = getTaskByName(msg)
    local t = msg
    
		if getCreatureStorage(cid, tasks[msg].questStarted) == 1 then
      local v = tasks[msg]
			if getCreatureStorage(cid, v.questStarted) == 1 then
				if getCreatureStorage(cid, v.questStorage) >= v.killsRequired then
          for i = 1, table.maxn(v.rewards) do
						if(v.rewards[i].enable) then
							if isInArray({"boss", "teleport", 1}, v.rewards[i].type) then
								doTeleportThing(cid, v.rewards[i].values)
							elseif isInArray({"exp", "experience", 2}, v.rewards[i].type) then
								doPlayerAddExperience(cid, v.rewards[i].values)
							elseif isInArray({"item", 3}, v.rewards[i].type) then
								doPlayerAddItem(cid, v.rewards[i].values[1], v.rewards[i].values[2])
							elseif isInArray({"money", 4}, v.rewards[i].type) then
								doPlayerAddMoney(cid, v.rewards[i].values)
							elseif isInArray({"storage", "stor", 5}, v.rewards[i].type) then
								doCreatureSetStorage(cid, v.rewards[i].values[1], v.rewards[i].values[2])
							elseif isInArray({"points", "rank", 2}, v.rewards[i].type) then
								doAddTaskPoints(cid, v.rewards[i].values)
							else
								print("[Warning - Error::Killing in the name of::Tasks config] Bad reward type: " .. v.rewards[i].type .. ", reward could not be loaded.")
							end
						end
					end
					local rank = getTaskPoints(cid)
					selfSay("Ahh, thank you, my friend! What would we do without you?", cid)
					doCreatureSetStorage(cid, v.questStarted, 2)
					if getTaskPoints(cid) >= 10 and < 20 then
						doCreatureSetStorage(cid, 32150, 1)
					elseif getTaskPoints(cid) >= 20 and < 40 then
						doCreatureSetStorage(cid, 32150, 2)
					elseif getTaskPoints(cid) >= 40 and < 70 then
						doCreatureSetStorage(cid, 32150, 3)
					elseif getTaskPoints(cid) >= 70 and < 100 then
						doCreatureSetStorage(cid, 32150, 4)
					elseif getTaskPoints(cid) >= 100 then
						doCreatureSetStorage(cid, 32150, 5)
					end
				else
					selfSay("Current " .. getCreatureStorage(cid, tasks[t].questStorage) .. " " .. tasks[t].raceName .. " killed, you need to kill " .. tasks[t].killsRequired .. ".", cid)
				end
			end
			talkState[talkUser] = 0
			return true
		end
		if getCreatureStorage(cid, tasks[msg].questStarted) == 2 then
			selfSay("You already finished this task.", cid)
			talkState[talkUser] = 0
			return true
		end
		if tasks[msg].level and getPlayerLevel(cid) < tasks[msg].level then
			selfSay("You need level " .. tasks[msg].level .. " or higher to start this task.", cid)
			talkState[talkUser] = 0
			return true
		end
		--for k, v in pairs(tasks) do
			--if getCreatureStorage(cid, v.questStarted) == 1 and tasks[msg] ~= k then
				--selfSay("You are already making a task.", cid)
				--talkState[talkUser] = 0
				--return true
			--end
		--end
		selfSay("In this task you have to defeat " .. tasks[msg].killsRequired .. " " .. tasks[msg].raceName .. ". Interested?", cid)
		choose[cid] = msg
		talkState[talkUser] = 1
	elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
		doCreatureSetStorage(cid, tasks[choose[cid]].questStarted, 1)
		selfSay("Happy hunting, friend! Come back to me when you are done hunting.", cid)
		talkState[talkUser] = 0
 
	elseif msgcontains(msg, "report") then
		for k, v in pairs(tasks) do
			if getCreatureStorage(cid, v.questStarted) == 1 then
				if getCreatureStorage(cid, v.questStorage) < 0 then
					doCreatureSetStorage(cid, v.questStorage, 0)
				end
				local t = getTasksStarted(cid)
				local response = "You are currently making " .. (#t > 1 and "these" or "this") .. " task" .. (#t > 1 and "s" or "") .. ":\n"
				if table.maxn(t) > 0 then
					for _, tsk in ipairs(t) do
						if getCreatureStorage(cid, tasks[tsk].questStorage) < 0 then doCreatureSetStorage(cid, tasks[tsk].questStorage, 0) end
							response = response .. "     Name: " .. tasks[tsk].raceName .. "     Kills: " .. getCreatureStorage(cid, tasks[tsk].questStorage) .. " - " .. tasks[tsk].killsRequired .. ".\n"
					end
					response = response .. "Please tell me the name of the task that do you want to report."
					selfSay(response, cid)
				else
					selfSay("You need to start at least one task first.", cid)
				end
			end
		end
 
	elseif string.sub(msg:lower(), 0, 6) == "report" then
		local t = getTaskByName(string.sub(msg, 8, string.len(msg)))
		if not t then
			selfSay("That task does not exists.", cid)
		end
 
		if getCreatureStorage(cid, tasks[t].questStarted) < 1 then
			selfSay("You don't have started this task.", cid)
		end
 
		for k, v in pairs(tasks) do
			if getCreatureStorage(cid, v.questStarted) == 1 then
				if getCreatureStorage(cid, v.questStorage) >= v.killsRequired then
          for i = 1, table.maxn(v.rewards) do
						if(v.rewards[i].enable) then
							if isInArray({"boss", "teleport", 1}, v.rewards[i].type) then
								doTeleportThing(cid, v.rewards[i].values)
							elseif isInArray({"exp", "experience", 2}, v.rewards[i].type) then
								doPlayerAddExperience(cid, v.rewards[i].values)
							elseif isInArray({"item", 3}, v.rewards[i].type) then
								doPlayerAddItem(cid, v.rewards[i].values[1], v.rewards[i].values[2])
							elseif isInArray({"money", 4}, v.rewards[i].type) then
								doPlayerAddMoney(cid, v.rewards[i].values)
							elseif isInArray({"storage", "stor", 5}, v.rewards[i].type) then
								doCreatureSetStorage(cid, v.rewards[i].values[1], v.rewards[i].values[2])
							elseif isInArray({"points", "rank", 2}, v.rewards[i].type) then
								doAddTaskPoints(cid, v.rewards[i].values)
							else
								print("[Warning - Error::Killing in the name of::Tasks config] Bad reward type: " .. v.rewards[i].type .. ", reward could not be loaded.")
							end
						end
					end
					local rank = getTaskPoints(cid)
					selfSay("Ahh, thank you, my friend! What would we do without you?", cid)
					doCreatureSetStorage(cid, v.questStarted, 2)
					if getTaskPoints(cid) >= 10 and < 20 then
						doCreatureSetStorage(cid, 32150, 1)
					elseif getTaskPoints(cid) >= 20 and < 40 then
						doCreatureSetStorage(cid, 32150, 2)
					elseif getTaskPoints(cid) >= 40 and < 70 then
						doCreatureSetStorage(cid, 32150, 3)
					elseif getTaskPoints(cid) >= 70 and < 100 then
						doCreatureSetStorage(cid, 32150, 4)
					elseif getTaskPoints(cid) >= 100 then
						doCreatureSetStorage(cid, 32150, 5)
					end
					break
				else
					selfSay("Current " .. getCreatureStorage(cid, tasks[t].questStorage) .. " " .. tasks[t].raceName .. " killed, you need to kill " .. tasks[t].killsRequired .. ".", cid)
				end
			end
		end
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Try this.
 
Back
Top