• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua How to make npc check if item has an action ID

ziggy46802

Active Member
Joined
Aug 19, 2012
Messages
418
Reaction score
27
How do I make it so the npc has the requirement of like

first.item is already set as ID 2320 by the way

Code:
If (first.item).aid == 2504 and (doPlayerRemoveItem(cid,first.item,first.item_count)) then

I tried this and am getting this error

Code:
data/npc/scripts/sewerquest.lua:82: attempt to index field 'item' (a number value)
[25/09/2012 17:28:10] stack traceback:
[25/09/2012 17:28:10] 	data/npc/scripts/sewerquest.lua:82: in function 'callback'
 
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
 
 
 
 
--------------------------------
------- NPC MISSION  2.0 --------
------ by Acubens - Otland.net -
--------------------------------
 
 
local first = {
-- Place true if you want to use the system of experience as a reward, false if you want to use items as a reward
useExpReward = true,
-- The experience that will get the player at the end of the mission
experience = 1000,
-- Id of the item that will be asking for the NPC to complete the mission
item = 2320, 
-- Count of the item required
item_count = 1,  
-- id of the gift that going to obtain the player at finish the mission 
reward = 2152,
-- count of the gift item
reward_count = 5, 
-- storage
storage = 1004, 
-- name of the quest
questname = "Sewer Worker"
}
 
local npc_message ={
 
-- Proceed - message
"So did they overwhelm him and end up, err, killing... him?",
-- if you dont have items - message
"I need proof of what happened to my sewer worker.", 
-- thanks - message
"Well, that is unfortunately bad news, but thank you for telling me what happened and at least you did his original job for me by exterminating the rats.  Here is some cash, go buy some better gear and go exploring!",
-- already done - message
"Well we already know that the sewer worker is dead.  You can hone your skills more before you leave town by killing more rats down there though if you would like to.",
-- ready to go - message
"I sent him down into the sewer to get rid of the rats, but who knows, maybe they {overwhelmed} him and, well, killed him.",
-- congratulations - message
"Congratulations, you have finished the quest: Sewer Worker"
 
}
 
 
if(msgcontains(msg, 'sewer')) then
selfSay(npc_message[5], cid)
end

if(msgcontains(msg, 'key')) and getPlayerStorageValue(cid, 1005) == 1 then
setPlayerStorageValue(cid, 1005, 2)
doItemSetAttribute(doPlayerAddItem(cid, 2089, 1), "aid", 2004)
elseif (msgcontains(msg, 'key')) and getPlayerStorageValue(cid, 1005) == 2 then
	selfSay("I already gave you the key", cid)
end
 
if(msgcontains(msg, 'overwhelmed')) then
	selfSay(npc_message[1], cid)
	talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
	if (getPlayerStorageValue(cid,first.storage) == 3) then
		selfSay(npc_message[4], cid)
	else
		if (first.item).itemaid == 2504 and (doPlayerRemoveItem(cid,first.item,first.item_count)) then
			setPlayerStorageValue(cid,first.storage,3)
			if(useExpReward) then
				doPlayerAddExperience(cid,first.experience)
				doPlayerAddItem(cid, 2152, 5)
			else
				doPlayerAddItem(cid,first.reward,first.reward_count)
				doPlayerAddExp(cid, 4000)
			end
			selfSay(npc_message[3], cid)
			doSendMagicEffect(getCreaturePosition(cid), 10)
			doCreatureSay(cid, npc_message[6], TALKTYPE_ORANGE_1)
		else
			selfSay(npc_message[2], cid)
		end
	end
return true
end
 
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

I take no credit for the "system" of quest that is being used by the npc, somebody else here on OTLand made this system up and it works wonders, but not for checking if the item to take from the player has an action id.
 
LUA:
local key = getPlayerItemById(cid, true, first.item)
if key.actionid == 2504 and doRemoveItem(key.uid) then
won't work if player has 2 keys of same id and the first one found has wrong actionid :p
 
It would not work, I even tried a simpler form using this code

Code:
local key = getPlayerItemById(cid, true, first.item)
				if key.actionid == 2504 and doRemoveItem(cid, first.item, 1) then

but he still throws the "else" at you like you dont have the skull with the AID 2504

- - - Updated - - -

Thank you Cykotitan, I kept messing around with it until I eventually got it to work.
 
Back
Top