• 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!

Solved getCreatureOutfit not working inside of my npc

Xikini

I whore myself out for likes
Senator
Joined
Nov 17, 2010
Messages
6,818
Solutions
586
Reaction score
5,387
Code:
The Forgotten Server, version 0.3.7_SVN (Crying Damson)

Made this script, which access's a monster file, to change my looktype to 209.
Had trouble using '209' by itself to change my looktype. (if you know how to fix this, please tell!)
Code:
local time = 5 -- minutes
function onUse(cid, item, fromPosition, itemEx, toPosition)
   doRemoveItem(item.uid, 1)
   doSetMonsterOutfit(cid, "necromancer costume", time * 1000 * 60)
   doPlayerSendTextMessage(cid, 20, "Five minutes until your disguise breaks!")
   return true
end
And I have created this much of my npc so far, however whether my disguise is active, or inactive, or if I change into a necromancer using /newtype 209, it still says the first line. 'Only necromancers are permitted inside the sanctum!'
I want it to only say that line if the player does not have the looktype of a necromancer.
The second part checks if the player has completed the quest already so that they will not have to have the 'disguise' to talk to the npc any longer.

Thanks in advance for any help! It's all very much appreciated!
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


local function greetCallback(cid)   
     -- If player is not a necromancer                If player has not finished the quest
   if getCreatureOutfit(cid).lookType ~= 209 or (getPlayerStorageValue(cid,45023) ~= 2) then
     selfSay("Only necromancers are permitted inside the sanctum!", cid)
     return false
   elseif (getPlayerStorageValue(cid,45023) == 2) then -- when quest is complete
     npcHandler:setMessage(MESSAGE_GREET, "Welcome new master.", cid)
   elseif getCreatureOutfit(cid).lookType == 209 then -- when you are a necromancer
     npcHandler:setMessage(MESSAGE_GREET, "Welcome good master.", cid)
   end
   return true
end

local function creatureSayCallback(cid, type, msg)
   if not npcHandler:isFocused(cid) then
     return false
   end
   
   if msgcontains(msg, "reset") then
   selfSay("reset complete.", cid)
     setPlayerStorageValue(cid,45023,-1)
   end
   
   return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
I think its because of this code

Code:
if getCreatureOutfit(cid).lookType ~= 209 or (getPlayerStorageValue(cid,45023) ~= 2) then
     selfSay("Only necromancers are permitted inside the sanctum!", cid)
     return false

Meaning that as long as your player doesn't look that way it will prompt this dialog. And irregardless outfit or not if your player hasn't completed the quest it will prompt this dialog.
 
I think its because of this code

Code:
if getCreatureOutfit(cid).lookType ~= 209 or (getPlayerStorageValue(cid,45023) ~= 2) then
     selfSay("Only necromancers are permitted inside the sanctum!", cid)
     return false

Meaning that as long as your player doesn't look that way it will prompt this dialog. And irregardless outfit or not if your player hasn't completed the quest it will prompt this dialog.
Why does it do that though? I thought 'or' would make it so that if this is true/untrue.. and this is true/untrue, then.. elseif

As a work-around after readin your reply I have done this.. but for future reference how would I properly use the 'or' statement to achieve my goal?
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


local function greetCallback(cid)   

   if (getPlayerStorageValue(cid,45023) == 1) then -- when quest is complete
     npcHandler:setMessage(MESSAGE_GREET, "Welcome new master.", cid)
   elseif getCreatureOutfit(cid).lookType ~= 209 then
     selfSay("Only necromancers are permitted inside the sanctum!", cid)
     return false
   elseif getCreatureOutfit(cid).lookType == 209 then -- when you are a necromancer
     npcHandler:setMessage(MESSAGE_GREET, "Welcome good master.", cid)
   end
   return true
end

local function creatureSayCallback(cid, type, msg)
   if not npcHandler:isFocused(cid) then
     return false
   end
   
   if msgcontains(msg, "reset") then
   selfSay("reset complete.", cid)
     setPlayerStorageValue(cid,45023,-1)
   end
   
   if msgcontains(msg, "complete") then
   selfSay("reset complete.", cid)
     setPlayerStorageValue(cid,45023,1)
   end
   
   return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
You can use and instead of or, because if 1 of them is not true, then they aren't both true, with using and they should be both true.
 
You can use and instead of or, because if 1 of them is not true, then they aren't both true, with using and they should be both true.
I was trying to make it so if one was true, then say message, if both were not true, then skip to elseif. :(
 
If you use and then someone it means someone needs to have not that outfit and not that storage for the if statement to be true.
So if someone has the outfit or the storage, then they aren't both true but only one of them which makes it not true in total for the if statement.
 
Back
Top