Ir para conteúdo
  • 0

Ajuda Random NPC


deglorio

Pergunta

O @Bodak Reborn fez um NPC Daily. Ele funciona perfeitamente, ai fiz uma cópia de outros 3 NPC mudando os pokemons random e as storages. Até ai beleza, porém quando eu falo com primeiro NPC hi, task, ai ele manda um random X. Ai vou no outro NPC  e falo hi, task, ele manda outro random. Beleza até ai, mas se eu voltar no primeiro npc, ele manda o random do NPC 2. 

 

Segue o npc dele.

 

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

local tasks = {
[1] = {name = "Blastoise", qnt = 20, npc = "Junko"},
[2] = {name = "Electabuzz", qnt = 15, npc = "Junko"},
[3] = {name = "Venusaur", qnt = 18, npc = "Junko"},
[4] = {name = "Charizard", qnt = 27, npc = "Junko"},
}

local function getRandomTaskMonster1 ()
	local randomTask = math.random(#tasks)
	local taskPokemon = tasks[randomTask].name
return taskPokemon
end

local function getRandomTaskMonster2 ()
	local randomTask2 = math.random(#tasks)
	local taskPokemon2 = tasks[randomTask2].name
return taskPokemon2
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 msg = msg:lower()
	
	if msgcontains(msg, "task") then
		qntLeft = 84956
		gotDaily = 84957
		fixedPokemon = 84958
		daily = 5619846
		check = 84959
		done = 84960
		
		if getPlayerStorageValue (cid, gotDaily) == 1 then
			if getPlayerStorageValue (cid, done) == 1 then
				selfSay ("Thank you! Was incredible!", cid)
				talkState[talkUser] = 0
			return true
			elseif getPlayerStorageValue (cid, qntLeft) == 0 then
				selfSay ("Did you kill all of them?", cid)
				setPlayerStorageValue (cid, check, 1)
				talkState[talkUser] = 2
			return true
			elseif getPlayerStorageValue(cid, 25588) > os.time() then
				selfSay("You have to wait 24h to do my task again!", cid)
				talkState[talkUser] = 0
			return true
			elseif getPlayerStorageValue (cid, daily) ~= 0 and getPlayerStorageValue (cid, daily) ~= -1 then
				if getPlayerStorageValue (cid, qntLeft) >= 0 then				
					local n = string.explode(getPlayerStorageValue (cid, daily), " ")
					local str = string.sub(getPlayerStorageValue (cid, daily), 1, 1)
					local sta = string.sub(getPlayerStorageValue (cid, daily), 2, string.len(getPlayerStorageValue (cid, daily)))
					name = ""..string.upper(str)..""..string.lower(sta)..""
		
					selfSay("What are you waiting for? Go kill the remaining "..getPlayerStorageValue (cid, qntLeft).." "..name.."!", cid)
					talkState[talkUser] = 2
				return true
				end
			end
		end
		
		
		if getPlayerStorageValue (cid, fixedPokemon) ~= 1 then
			randomName1 = getRandomTaskMonster1 ()
			randomName2 = getRandomTaskMonster2 ()
			
			while randomName1 == randomName2 do
				randomName1 = getRandomTaskMonster1 ()
				randomName2 = getRandomTaskMonster2 ()
			end
			
			for i = 1, #tasks do
				if tasks[i].name == randomName1 then
					qnt1 = tasks[i].qnt
				end
				
				if tasks[i].name == randomName2 then
					qnt2 = tasks[i].qnt
				end
			end
			setPlayerStorageValue (cid, fixedPokemon, 1)
		end
		
		selfSay("Which you prefer? "..qnt1.." "..randomName1.." or "..qnt2.." "..randomName2.."?", cid)
		talkState[talkUser] = 1
	return true
	elseif (msg == randomName1:lower() or msg == randomName2:lower()) and talkState[talkUser] == 1 then
		decide = msg
		selfSay("Are you sure?", cid)
		talkState[talkUser] = 2
	return true
	elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then		
		if getPlayerStorageValue (cid, check) == 1 then
			selfSay ("Thank you! That was incredible, i can't believe you kill all of them!", cid)
			setPlayerStorageValue(cid, sto, -1)
			doPlayerAddExperience(cid, 1500000)
			doPlayerAddItem(cid, 2160, 25)
		 
			local sto = 5646132
			setPlayerStorageValue(cid, sto, -1)
			setPlayerStorageValue(cid, 25566, os.time() + 24*60*60)
			setPlayerStorageValue(cid, 181601, 1)
			setPlayerStorageValue(cid, 181602, 1)
			setPlayerStorageValue(cid, qntLeft, -1)
			setPlayerStorageValue(cid, done, 1)
			talkState[talkUser] = 0		
		end
		
		if getPlayerStorageValue (cid, gotDaily) == 1 then return true end
		
		setPlayerStorageValue (cid, daily, decide)
		setPlayerStorageValue (cid, gotDaily, 1)
		
		for i = 1, #tasks do
			if tasks[i].name:lower() == getPlayerStorageValue (cid, daily) then
				qnt = tasks[i].qnt
			end
		end
		
		setPlayerStorageValue (cid, qntLeft, qnt)
		
		local sto = getFreeTaskStorage(cid)
		if sto == -1 then
			selfSay("You can't catch more tasks! You are already with the maximum of "..(maxTasks).." tasks!", cid)
			talkState[talkUser] = 0
		return true
		end

		local n = string.explode(getPlayerStorageValue (cid, daily), " ")
		local str = string.sub(getPlayerStorageValue (cid, daily), 1, 1)
		local sta = string.sub(getPlayerStorageValue (cid, daily), 2, string.len(getPlayerStorageValue (cid, daily)))
		name = ""..string.upper(str)..""..string.lower(sta)..""
		
		local storage = 154721
		setPlayerStorageValue (cid, storage, name.."/"..qnt)
		selfSay("OK kill all, good luck!", cid)
		talkState[talkUser] = 0
	return true
	end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Se alguém puder me ajudar nessa parte.

Link para o comentário
Compartilhar em outros sites

6 respostass a esta questão

Posts Recomendados

  • 0

O modo que eu fiz, grava o nome dos pokémon em uma storage, então se tu colocar a mesma storage em todos os NPCs, cada vez que tu falar com um tu vai substituir a antiga storage, entende? Se não me engano, a storage que tu tem que manter é a "done".

Link para o comentário
Compartilhar em outros sites

  • 0

@Bodak Reborn

Perfeitamente.

 

Tem como fazer algo tipo.

 

Seu o player for < 30 ele da rondom em tais pokes

Seu o player for  < 60 ele da rondom em tais pokes

Seu o player for  < 100 ele da rondom em tais pokes

Seu o player for  < 200 ele da rondom em tais pokes

 

Seria Possíel em um unico NPC?

 

Link para o comentário
Compartilhar em outros sites

  • 0

Tenta assim:

troca

local tasks = {[1] = {name = "Blastoise", qnt = 20, npc = "Junko"},[2] = {name = "Electabuzz", qnt = 15, npc = "Junko"},[3] = {name = "Venusaur", qnt = 18, npc = "Junko"},[4] = {name = "Charizard", qnt = 27, npc = "Junko"},}

 

por

local tasks = {}if getPlayerLevel (cid) < 30 then	tasks = {	[1] = {name = "Weedle", qnt = 20},	[2] = {name = "Rattata", qnt = 15},	[3] = {name = "Charmander", qnt = 18},	[4] = {name = "Poliwag", qnt = 27},	}}elseif getPlayerLevel (cid) >= 30 and getPlayerLevel (cid) < 60 then	tasks = {	[1] = {name = "Ivysaur", qnt = 20},	[2] = {name = "Poliwhirl", qnt = 15},	[3] = {name = "Seadra", qnt = 18},	[4] = {name = "Weepinbell", qnt = 27},	}elseif getPlayerLevel (cid) >= 60 and getPlayerLevel (cid) < 100 then	tasks = {	[1] = {name = "Marowak", qnt = 20},	[2] = {name = "Machoke", qnt = 15},	[3] = {name = "Haunter", qnt = 18},	[4] = {name = "Hypno", qnt = 27},	}elseif getPlayerLevel (cid) >= 100 then	tasks = {	[1] = {name = "Blastoise", qnt = 20},	[2] = {name = "Electabuzz", qnt = 15},	[3] = {name = "Venusaur", qnt = 18},	[4] = {name = "Charizard", qnt = 27},	}end

 

Link para o comentário
Compartilhar em outros sites

  • 0
Citar

tasks = { [1] = {name = "Weedle", qnt = 20}, [2] = {name = "Rattata", qnt = 15}, [3] = {name = "Charmander", qnt = 18}, [4] = {name = "Poliwag", qnt = 27}, }

} << remova 

 

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...