Ir para conteúdo
  • Cadastre-se

(Resolvido)[NPC] Function Error (HELP!)


Ir para solução Resolvido por zipter98,

Posts Recomendados

Boa tarde galera,
 
Recentemente atualizei meu servidor do TFS 1.0 para o TFS 1.2, até agora estou conseguindo adaptar os scripts, porém estou tendo sérios problemas com meu sistema de tasks. Queria ajuda pra ver se estou deixando alguma coisa passar:
 
ERRO NO CONSOLE:
 
aoBayk8by.jpg
 
NPC/SCRIPTS/TASK.LUA:

local choose = {}

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_PRIVATE and 0 or cid
if isInArray({"task", "tasks"}, msg:lower()) then
selfSay("Here.", cid)
taskNPCuid = getNpcCid()
if player:getStorageValue(cid, 32150) < 0 then player:setStorageValue(cid, 32150, 0) end
return taskWindow:sendToPlayer(cid)
end
return true
end

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

LIBS/TASK_LIB.LUA

player:getStorageValue = player:getStorageValue
player:setStorageValue = player:setStorageValue

rankStorage = 32150

THESNAPPER = {80000, 1}
DEMODRAS = {80001, 1}
HIDE = {80002, 1}
THEBLOODTUSK = {80003, 1}
SHARDHEAD = {80004, 1}
THUL = {80005, 1}
ESMERALDA = {80006, 1}
THEOLDWIDOW = {80007, 1}
THEMANY = {80008, 1}
LEVIATHAN = {80009, 1}
STONECRACKER = {80010, 1}
THENOXIUSSPAWN = {80011, 1}
MERIKHTHESLAUGHTERER = {80012, 1}
FAHIMTHEWISE = {80013, 1}
RANDOMPIRATEBOSS = {80014, 1}
THEHORNEDFOX = {80015, 1}
NECROPHARUS = {80016, 1}

tasks =
{
[1] = {questStarted = 65000, questStorage = 65100, killsRequired = 100, raceName = "Trolls", repeatable = false, rewards = {{enable = true, type = "exp", values = 40000}, {enable = true, type = "money", values = 40000}}},
[2] = {questStarted = 65001, questStorage = 65101, killsRequired = 150, raceName = "Goblins", repeatable = false, rewards = {{enable = true, type = "exp", values = 70000}, {enable = true, type = "money", values = 50000}}},
[3] = {questStarted = 65002, questStorage = 65102, killsRequired = 300, raceName = "Rotworms", repeatable = false, rewards = {{enable = true, type = "exp", values = 100000}, {enable = true, type = "money", values = 60000}}},
[4] = {questStarted = 65003, questStorage = 65103, killsRequired = 500, raceName = "Cyclops", repeatable = false, rewards = {{enable = true, type = "exp", values = 150000}, {enable = true, type = "money", values = 80000}}},
[5] = {questStarted = 14007, questStorage = 14107, killsRequired = 300, raceName = "Crocodiles", repeatable = true, rewards = {{enable = true, type = "exp", values = 100000}, {enable = true, type = "storage", values = THESNAPPER}, {enable = true, type = "points", values = 2}}},
[6] = {questStarted = 14008, questStorage = 14108, killsRequired = 300, raceName = "Tarantulas", repeatable = true, rewards = {{enable = true, type = "exp", values = 150000}, {enable = true, type = "storage", values = HIDE}, {enable = true, type = "points", values = 2}}},
[7] = {questStarted = 14009, questStorage = 14109, killsRequired = 150, raceName = "Carniphilas", repeatable = false, rewards = {{enable = true, type = "exp", values = 250000}, {enable = true, type = "money", values = 150000}}},
[8] = {questStarted = 14010, questStorage = 14110, killsRequired = 200, raceName = "Stone Golems", repeatable = false, rewards = {{enable = true, type = "exp", values = 200000}, {enable = true, type = "money", values = 150000}}},
[9] = {questStarted = 14011, questStorage = 14111, killsRequired = 300, raceName = "Mammoths", repeatable = true, rewards = {{enable = true, type = "exp", values = 150000}, {enable = true, type = "storage", values = THEBLOODTUSK}, {enable = true, type = "points", values = 2}}},
[10] = {questStarted = 14012, questStorage = 14112, killsRequired = 300, raceName = "Ice Golems", repeatable = true, rewards = {{enable = true, type = "exp", values = 150000}, {enable = true, type = "storage", values = SHARDHEAD}, {enable = true, type = "points", values = 2}}},
[11] = {questStarted = 14013, questStorage = 14113, killsRequired = 300, raceName = "Quaras Scout", repeatable = true, rewards = {{enable = true, type = "exp", values = 250000}, {enable = true, type = "money", values = 250000}}},
[12] = {questStarted = 14014, questStorage = 14114, killsRequired = 300, raceName = "Quaras", repeatable = true, rewards = {{enable = true, type = "exp", values = 300000}, {enable = true, type = "storage", values = THUL}, {enable = true, type = "points", values = 2}}},
[13] = {questStarted = 14015, questStorage = 14115, killsRequired = 70, raceName = "Water Elementals", repeatable = false, rewards = {{enable = true, type = "exp", values = 200000}, {enable = true, type = "money", values = 200000}}},
[14] = {questStarted = 14016, questStorage = 14116, killsRequired = 70, raceName = "Earth Elementals", repeatable = false, rewards = {{enable = true, type = "exp", values = 200000}, {enable = true, type = "money", values = 200000}}},
[15] = {questStarted = 14017, questStorage = 14117, killsRequired = 70, raceName = "Energy Elementals", repeatable = false, rewards = {{enable = true, type = "exp", values = 200000}, {enable = true, type = "money", values = 200000}}},
[16] = {questStarted = 14018, questStorage = 14118, killsRequired = 70, raceName = "Fire Elementals", repeatable = false, rewards = {{enable = true, type = "exp", values = 200000}, {enable = true, type = "money", values = 200000}}},
[17] = {questStarted = 14019, questStorage = 14119, killsRequired = 200, raceName = "Mutated Rats", repeatable = true, rewards = {{enable = true, type = "exp", values = 150000}, {enable = true, type = "storage", values = ESMERALDA}, {enable = true, type = "points", values = 2}}},
[18] = {questStarted = 14020, questStorage = 14120, killsRequired = 500, raceName = "Giant Spiders", repeatable = true, rewards = {{enable = true, type = "exp", values = 250000}, {enable = true, type = "storage", values = THEOLDWIDOW}, {enable = true, type = "points", values = 2}}},
[19] = {questStarted = 14021, questStorage = 14121, killsRequired = 500, raceName = "Hydras", repeatable = true, rewards = {{enable = true, type = "storage", values = THEMANY}, {enable = true, type = "points", values = 4}}},
[20] = {questStarted = 14001, questStorage = 14101, killsRequired = 500, raceName = "Sea Serpents", repeatable = true, rewards = {{enable = true, type = "storage", values = LEVIATHAN}, {enable = true, type = "points", values = 4}}},
[21] = {questStarted = 14022, questStorage = 14122, killsRequired = 500, raceName = "Behemoths", repeatable = true, rewards = {{enable = true, type = "storage", values = STONECRACKER}, {enable = true, type = "points", values = 4}}},
[22] = {questStarted = 14002, questStorage = 14102, killsRequired = 375, raceName = "Serpents Spawn", repeatable = true, rewards = {{enable = true, type = "storage", values = THENOXIOUSSPAWN}, {enable = true, type = "points", values = 4}}},
[23] = {questStarted = 65022, questStorage = 65122, killsRequired = 125, raceName = "Green Djinns", repeatable = true, rewards = {{enable = true, type = "exp", values = 230000}, {enable = true, type = "money", values = 5000}, {enable = true, type = "storage", values = MERIKHTHESLAUGHTERER}}},
[24] = {questStarted = 65023, questStorage = 65123, killsRequired = 125, raceName = "Blue Djinns", repeatable = true, rewards = {{enable = true, type = "exp", values = 230000}, {enable = true, type = "money", values = 5000}, {enable = true, type = "storage", values = FAHIMTHEWISE}}},
[25] = {questStarted = 65024, questStorage = 65124, killsRequired = 300, raceName = "Pirates", repeatable = false, rewards = {{enable = true, type = "exp", values = 300000}, {enable = true, type = "money", values = 400000}, {enable = true, type = "storage", values = RANDOMPIRATEBOSS}}},
[26] = {questStarted = 14004, questStorage = 14104, killsRequired = 500, raceName = "Minotaurs", repeatable = false, rewards = {{enable = true, type = "storage", values = THEHORNEDFOX}}},
[27] = {questStarted = 14003, questStorage = 14103, killsRequired = 1000, raceName = "Magicians", repeatable = false, rewards = {{enable = true, type = "storage", values = NECROPHARUS}}},
[28] = {questStarted = 65030, questStorage = 65130, killsRequired = 500, raceName = "Dragons", repeatable = true, rewards = {{enable = true, type = "storage", values = DEMODRAS}, {enable = true, type = "exp", values = 400000}}},
[29] = {questStarted = 14023, questStorage = 14123, killsRequired = 6666, raceName = "Demons", repeatable = false, rewards = {{enable = true, type = "exp", values = 1000000}, {enable = true, type = "item", values = {10305,1}}}}}

function getTasksStarted(cid)
local tmp = {}
for k, v in pairs(tasks) do
if player:getStorageValue(cid, v.questStarted) == 1 then
table.insert(tmp, k)
end
end
return tmp
end

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 taskWindow:sendToPlayer(cid)
taskWindow = ModalWindow(1900, "Mission Management", "Select a task:")
local task_status = {}

if taskWindow:getId() == 1900 then
    taskWindow:addButton(1, "Select")
    taskWindow:addButton(2, "Cancel")
	for i = 1, #tasks do
		if player:getStorageValue(cid, tasks[i].questStarted) == 2 then
			task_status[i] = "[completed]"
		else
			if player:getStorageValue(cid, tasks[i].questStarted) == 1 then
				task_status[i] = "[" .. player:getStorageValue(cid, tasks[i].questStorage) .. "/" .. tasks[i].killsRequired .. "]"
			else
				if player:getStorageValue(cid, tasks[i].questStarted) < 1 then
					task_status[i] = tasks[i].killsRequired
				else
					task_status[i] = tasks[i].killsRequired .. " [unknown]"
				end
			end
		end
		
		if player:getStorageValue(cid, tasks[i].questStarted) == 1 and player:getStorageValue(cid, tasks[i].questStorage) >= tasks[i].killsRequired then
			taskWindow:addChoice(i, tasks[i].raceName .. " [click for reward]")
		else
			taskWindow:addChoice(i, tasks[i].raceName .. ", " .. task_status[i])
		end
	end
end
taskWindow:sendToPlayer(cid)
return true
end

CREATURESCRIPTS/SCRIPTS/TASK_WINDOW.LUA

function onModalWindow(cid, modalWindowId, buttonId, choiceId)
	local rank = player:getStorageValue(cid, rankStorage)
	if rank < 0 then
		player:SetStorageValue(cid, rankStorage, 0)
	end
					
	local r_string = function() if tasks[choiceId].repeatable then return "repeatable" end return "not repeatable" end
	local r_article_string = function (id, amount)
		task_item_word = ""
		if amount > 1 then
			task_item_word = task_item_word .. amount .. "x " .. getItemName(id)
		else
			if ItemType(itemId):getArticle() == "" then
				task_item_word = task_item_word .. getItemName(id)
			else
				task_item_word = task_item_word .. ItemType(itemId):getArticle() .. " " .. getItemName(id)
			end
		end
	return task_item_word
	end
	local storage_string = {[80000] = "The Snapper",
[80001] = "Demodras",
[80002] = "The Hide",
[80003] = "The Bloodtusk",
[80004] = "The Shardhead",
[80005] = "Thul",
[80006] = "Esmeralda",
[80007] = "The Old Widow",
[80008] = "The Many",
[80009] = "The Leviathan",
[80010] = "The Stonecracker",
[80011] = "The Noxious Spawn",
[80012] = "Merikh The Slaughterer",
[80013] = "Fahim The Wise",
[80014] = "pirate leader",
[80015] = "The Horned Fox",
[80016] = "Necropharus"
	}
	if (not modalWindowId == 1900) then return false end

	if buttonId == 1 then -- confirm task
		if player:getStorageValue(cid, tasks[choiceId].questStarted) < 1 then
			player:setStorageValue(cid, tasks[choiceId].questStarted, 1)
			player:setStorageValue(cid, tasks[choiceId].questStorage, 0)
			creature:say(taskNPCuid, "In this mission you have to hunt " .. tasks[choiceId].killsRequired .. " " .. tasks[choiceId].raceName .. " down. Good luck!", TALKTYPE_PRIVATE_NP, false, cid, getThingPos(taskNPCuid))
		else
			if player:getStorageValue(cid, tasks[choiceId].questStarted) == 1 then
				if tasks[choiceId].killsRequired > player:getStorageValue(cid, tasks[choiceId].questStorage) then
					doPlayerPopupFYI(cid,"Status: Active\nKills: " .. player:getStorageValue(cid, tasks[choiceId].questStorage) .. "/" .. tasks[choiceId].killsRequired .. " (" .. tasks[choiceId].killsRequired - player:getStorageValue(cid, tasks[choiceId].questStorage) .. " left)\n\nThis mission is " .. r_string() .. ".")
					TaskWindow:sendToPlayer(cid)
				else
					player:setStorageValue(cid, tasks[choiceId].questStarted, 2)
					task_reward_str = "Reward(s):\n"
					for i = 1, table.maxn(tasks[choiceId].rewards) do
						if(tasks[choiceId].rewards[i].enable) then
							if isInArray({"boss", "teleport", 1}, tasks[choiceId].rewards[i].type) then
								doTeleportThing(cid, tasks[choiceId].rewards[i].values)
								task_reward_str = task_reward_str .. "You have been teleported.\n"
							elseif isInArray({"exp", "experience", 2}, tasks[choiceId].rewards[i].type) then
								doPlayerAddExperience(cid, tasks[choiceId].rewards[i].values)
								task_reward_str = task_reward_str .. "+ " .. tasks[choiceId].rewards[i].values .. " exp\n"
							elseif isInArray({"item", 3}, tasks[choiceId].rewards[i].type) then
								doPlayerAddItem(cid, tasks[choiceId].rewards[i].values[1], tasks[choiceId].rewards[i].values[2])
								task_reward_str = task_reward_str .. r_article_string(tasks[choiceId].rewards[i].values[1], tasks[choiceId].rewards[i].values[2]) .. "\n"
							elseif isInArray({"money", 4}, tasks[choiceId].rewards[i].type) then
								doPlayerAddMoney(cid, tasks[choiceId].rewards[i].values)
								task_reward_str = task_reward_str .. "+ " .. tasks[choiceId].rewards[i].values .. " gp\n"
							elseif isInArray({"storage", "stor", 5}, tasks[choiceId].rewards[i].type) then
								player:setStorageValue(cid, tasks[choiceId].rewards[i].values[1], tasks[choiceId].rewards[i].values[2])
								task_reward_str = task_reward_str .. "Chance to duel " .. storage_string[tasks[choiceId].rewards[i].values[1]] .. ".\n"
							elseif isInArray({"points", "rank", 2}, tasks[choiceId].rewards[i].type) then
								player:setStorageValue(cid, rankStorage, player:getStorageValue(cid, rankStorage) + tasks[choiceId].rewards[i].values)
								task_reward_str = task_reward_str .. "+ " .. tasks[choiceId].rewards[i].values .. " rank points.\n"
							else
								print("[Warning - Npc::KillingInTheNameOf] Wrong reward type: " .. (tasks[choiceId].rewards[i].type or "nil") .. ", reward could not be loaded.")
							end
						end
					end
					if task_reward_str == "Reward(s):\n" then
						doPlayerPopupFYI(cid,task_reward_str .. "none")
					else
						doPlayerPopupFYI(cid,task_reward_str)
					end
					creature:say(taskNPCuid, "Great job" .. (((rank > 4 and rank < 10) and (", Huntsman") or (rank > 9 and rank < 20) and (", Ranger") or (rank > 19 and rank < 30) and (", Big Game Hunter") or (rank > 29 and rank < 50) and (", Trophy Hunter") or (rank > 49) and (", Elite Hunter")) or ", my Beginner") .. "! Here is your reward. Keep hunting and good luck!", TALKTYPE_PRIVATE_NP, false, cid, getThingPos(taskNPCuid))
				end
			else
				if tasks[choiceId].repeatable then
					for i = 1, table.maxn(tasks[choiceId].rewards) do
						if isInArray({"storage", "stor", 5}, tasks[choiceId].rewards[i].type) then
							doPlayerPopupFYI(cid,"To repeat this mission again, fight with " .. storage_string[tasks[choiceId].rewards[i].values[1]] .. " first.")
							break
						end
						if i == table.maxn(tasks[choiceId].rewards) then
							doPlayerPopupFYI(cid,"You can't repeat this mission.")
						end
					end
				else
					doPlayerPopupFYI(cid,"You can't repeat this mission.")
				end
				TaskWindow:sendToPlayer(cid)
			end
		end
	elseif buttonId == 255 then
		doPlayerPopupFYI(cid,"Please use a button.")
		TaskWindow:sendToPlayer(cid)
	end
	
return true
end

29161_4.png

 

 

2d168ur.png

 

Link para o post
Compartilhar em outros sites
  • Solução

No código do NPC, você está usando como objeto dos metamétodos getStorageValuesetStorageValue uma variável inexistente (player).

Confesso não programar nas novas versões do TFS, mas tente:

local choose = {}
 
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)
    local player = Player(cid)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
    if isInArray({"task", "tasks"}, msg:lower()) then
        selfSay("Here.", cid)
        taskNPCuid = getNpcCid()
        if player:getStorageValue(cid, 32150) < 0 then player:setStorageValue(cid, 32150, 0) end
        return taskWindow:sendToPlayer(cid)
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Editado por zipter98 (veja o histórico de edições)

não respondo pms solicitando suporte em programação/scripting

Link para o post
Compartilhar em outros sites

valeu zipter, essa correção completou esse código. Agora ta dando erro no task_window.lua, tava faltando a mesma variável, coloquei ela como no task.lua, mas agora recebo esse erro:

 

PABAGHqzk.jpg

 

task_window.lua:

function onModalWindow(cid, modalWindowId, buttonId, choiceId)
	local player = Player(cid)
	local rank = player:getStorageValue(cid, rankStorage)
	if rank < 0 then
		player:SetStorageValue(cid, rankStorage, 0)
	end
					
	local r_string = function() if tasks[choiceId].repeatable then return "repeatable" end return "not repeatable" end
	local r_article_string = function (id, amount)
		task_item_word = ""
		if amount > 1 then
			task_item_word = task_item_word .. amount .. "x " .. getItemName(id)
		else
			if ItemType(itemId):getArticle() == "" then
				task_item_word = task_item_word .. getItemName(id)
			else
				task_item_word = task_item_word .. ItemType(itemId):getArticle() .. " " .. getItemName(id)
			end
		end
	return task_item_word
	end

29161_4.png

 

 

2d168ur.png

 

Link para o post
Compartilhar em outros sites

Como Lua é case-sensitive, letras maiúsculas e minúsculas fazem diferença no nome de uma função.

Troque:

player:SetStorageValue(cid, rankStorage, 0)

por:

player:setStorageValue(cid, rankStorage, 0)
Editado por zipter98 (veja o histórico de edições)

não respondo pms solicitando suporte em programação/scripting

Link para o post
Compartilhar em outros sites

Cara, não sabia que era case sensitive  :facepalm:  Ainda tem algumas coisas pra adaptar no código todo, a ModalWindow ta ficando "em branco" vou tentar arrumar o resto aqui kkkk obrigado por ajudar!

29161_4.png

 

 

2d168ur.png

 

Link para o post
Compartilhar em outros sites

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo