• 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 Problem with my mission NPC.

Diemorko

New Member
Joined
Jan 31, 2011
Messages
64
Reaction score
0
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

if(getPlayerStorageValue(cid, 10100, 1) == -1 or getPlayerStorageValue(cid, 10101, 1) == -1) then
   if(msgcontains(msg, 'help') or msgcontains(msg, 'mission')) then
     npcHandler:say("I\'m looking for {sniper gloves}, I can give you a nice addon if you bring it to me. Will you help me with this gloves?.", cid)
     talkState[talkUser] = 1
   elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
     if(getPlayerStorageValue(cid, 10100, 1) == -1)  then
         npcHandler:say("Come back when you get the legendary {sniper gloves}, I think sometime you can kill some hunters in hunter tower.", cid)
       setPlayerStorageValue(cid, 10100, 1)
     else
         npcHandler:say("Then dont lose my time.", cid)
     end
   elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
     npcHandler:say("Come back if you got that gloves.", cid)
     end
     return true
     end
end

if(getPlayerStorageValue(cid, 10100, 1) == 1) then
   if(msgcontains(msg, 'help') or msgcontains(msg, 'mission') or msgcontains(msg, 'sniper gloves')) then
     npcHandler:say("Did you get a {sniper gloves} for me?", cid)
     talkState[talkUser] = 1
   elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
     if(doPlayerRemoveItem(cid, 5875, 1)) then
         npcHandler:say("Thank you, there is your reward. And from now you can {trade} with me.", cid)
     doSendMagicEffect(getCreaturePosition(cid), 13)
   if getPlayerSex(cid) == 1 then
       setPlayerStorageValue(cid,10103,1)
       doPlayerAddOutfit(cid, 129, 2)
  elseif getPlayerSex(cid) == 0 then
       setPlayerStorageValue(cid,10103,1)
  doPlayerAddOutfit(cid, 137, 2)
  end
       setPlayerStorageValue(cid, 10101, 1)
       setPlayerStorageValue(cid, 10100, 0)
     else
         npcHandler:say("Come back when you get {sniper gloves} for me!.", cid)
     end
   elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
     npcHandler:say("Come back if you got that gloves.", cid)
     end
     return true
     end
end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

And here is the error:
10i86r9.jpg


TFS 1.0

Anyone could fix for me this script? :p I know i wrote it like nób :< but i just started with lua :-/
 
Last edited by a moderator:
It seems like you have more "end"s that you need, use this

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

if(getPlayerStorageValue(cid, 10100, 1) == -1 or getPlayerStorageValue(cid, 10101, 1) == -1) then
   if(msgcontains(msg, 'help') or msgcontains(msg, 'mission')) then
     npcHandler:say("I\'m looking for {sniper gloves}, I can give you a nice addon if you bring it to me. Will you help me with this gloves?.", cid)
     talkState[talkUser] = 1
   elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
     if(getPlayerStorageValue(cid, 10100, 1) == -1)  then
         npcHandler:say("Come back when you get the legendary {sniper gloves}, I think sometime you can kill some hunters in hunter tower.", cid)
       setPlayerStorageValue(cid, 10100, 1)
     else
         npcHandler:say("Then dont lose my time.", cid)
     end
   elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
     npcHandler:say("Come back if you got that gloves.", cid)
     end
     return true
     end
end

if(getPlayerStorageValue(cid, 10100, 1) == 1) then
   if(msgcontains(msg, 'help') or msgcontains(msg, 'mission') or msgcontains(msg, 'sniper gloves')) then
     npcHandler:say("Did you get a {sniper gloves} for me?", cid)
     talkState[talkUser] = 1
   elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
     if(doPlayerRemoveItem(cid, 5875, 1)) then
         npcHandler:say("Thank you, there is your reward. And from now you can {trade} with me.", cid)
     doSendMagicEffect(getCreaturePosition(cid), 13)
   if getPlayerSex(cid) == 1 then
       setPlayerStorageValue(cid,10103,1)
       doPlayerAddOutfit(cid, 129, 2)
  elseif getPlayerSex(cid) == 0 then
       setPlayerStorageValue(cid,10103,1)
  doPlayerAddOutfit(cid, 137, 2)
  end
       setPlayerStorageValue(cid, 10101, 1)
       setPlayerStorageValue(cid, 10100, 0)
     else
         npcHandler:say("Come back when you get {sniper gloves} for me!.", cid)
     end
   elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
     npcHandler:say("Come back if you got that gloves.", cid)
     end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
There are some other things wrong aswell.
Code:
getPlayerStorageValue(cid, 10100, 1) == -1
Should be
Code:
getPlayerStorageValue(cid, 10100) == -1
And the function was ended to early, so a part was outside the function.
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

     if(getPlayerStorageValue(cid, 10100) == -1 and getPlayerStorageValue(cid, 10101) == -1) then
         if(msgcontains(msg, 'help') or msgcontains(msg, 'mission')) then
             npcHandler:say("I\'m looking for {sniper gloves}, I can give you a nice addon if you bring it to me. Will you help me with this gloves?", cid)
             talkState[talkUser] = 1
         elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
             if(getPlayerStorageValue(cid, 10100) == -1)  then
                 npcHandler:say("Come back when you get the legendary {sniper gloves}, I think sometime you can kill some hunters in hunter tower.", cid)
                 setPlayerStorageValue(cid, 10100, 1)
             else
                 npcHandler:say("Then dont lose my time.", cid)
             end
         elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
             npcHandler:say("Come back if you got that gloves.", cid)
         end
     elseif(getPlayerStorageValue(cid, 10100) == 1) then
         if(msgcontains(msg, 'help') or msgcontains(msg, 'mission') or msgcontains(msg, 'sniper gloves')) then
             npcHandler:say("Did you get a {sniper gloves} for me?", cid)
             talkState[talkUser] = 1
         elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
             if(doPlayerRemoveItem(cid, 5875, 1)) then
                 npcHandler:say("Thank you, there is your reward. And from now you can {trade} with me.", cid)
                 doSendMagicEffect(getPlayerPosition(cid), 13)
                 if getPlayerSex(cid) == 1 then
                     setPlayerStorageValue(cid,10103,1)
                     doPlayerAddOutfit(cid, 129, 2)
                 elseif getPlayerSex(cid) == 0 then
                     setPlayerStorageValue(cid,10103,1)
                     doPlayerAddOutfit(cid, 137, 2)
                 end
                 setPlayerStorageValue(cid, 10101, 1)
                 setPlayerStorageValue(cid, 10100, 0)
             else
                 npcHandler:say("Come back when you get {sniper gloves} for me!", cid)
             end
         elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
             npcHandler:say("Come back if you got that gloves.", cid)
         end
     end
     return true
end

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

It is not needed to check more times for the same message btw, you can just do 1x: "elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then" and under that check for storage, same goes for help/mission and no.
 
Work great! thank you.
Now next problem :-/
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 shopModule = ShopModule:new()
npcHandler:addModule(shopModule)
if(getPlayerStorageValue(cid, 10101) == 1) then
shopModule:addBuyableItem({'royal spear'}, 7378, 25, 1, 'royal spear')
else
shopModule:addBuyableItem({'spear'}, 2389, 8, 1, 'spear')
end

  local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

  if(getPlayerStorageValue(cid, 10100) == -1 and getPlayerStorageValue(cid, 10101) == -1) then
  if(msgcontains(msg, 'help') or msgcontains(msg, 'mission')) then
  npcHandler:say("I\'m looking for {sniper gloves}, I can give you a nice addon if you bring it to me. Will you help me with this gloves?", cid)
  talkState[talkUser] = 1
  elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
  if(getPlayerStorageValue(cid, 10100) == -1)  then
  npcHandler:say("Come back when you get the legendary {sniper gloves}, I think sometime you can kill some hunters in hunter tower.", cid)
  setPlayerStorageValue(cid, 10100, 1)
  else
  npcHandler:say("Then dont lose my time.", cid)
  end
  elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
  npcHandler:say("Come back if you got that gloves.", cid)
  end
  elseif(getPlayerStorageValue(cid, 10100) == 1) then
  if(msgcontains(msg, 'help') or msgcontains(msg, 'mission') or msgcontains(msg, 'sniper gloves')) then
  npcHandler:say("Did you get a {sniper gloves} for me?", cid)
  talkState[talkUser] = 1
  elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
  if(doPlayerRemoveItem(cid, 5875, 1)) then
  npcHandler:say("Thank you, there is your reward. And from now you can {trade} with me.", cid)
  doSendMagicEffect(getPlayerPosition(cid), 13)
  if getPlayerSex(cid) == 1 then
  setPlayerStorageValue(cid,10103,1)
  doPlayerAddOutfit(cid, 129, 2)
  elseif getPlayerSex(cid) == 0 then
  setPlayerStorageValue(cid,10103,1)
  doPlayerAddOutfit(cid, 137, 2)
  end
  setPlayerStorageValue(cid, 10101, 1)
  setPlayerStorageValue(cid, 10100, 0)
  else
  npcHandler:say("Come back when you get {sniper gloves} for me!", cid)
  end
  elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
  npcHandler:say("Come back if you got that gloves.", cid)
  end
  end
  return true
end

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

Why every one can buy royal spears?!
ANd how I can remove storage id? :p
 
Also got problem with my Addon npc :-/
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local shortsword = 2406 -- TUTAJ WPISZ ID SHORT SWORDA
local book1 = 1955 -- TUTAJ WPISZ ID KSIĄŻKI1
local book2 = 12497 -- TUTAJ WPISZ ID KSIĄŻKI2
local book3 = 12406 -- TUTAJ WPISZ ID KSIĄŻKI3
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

-- Storage IDs --

fdruid        = 22043
sdruid        = 22044

newaddon    = 'Just in time! Your backpack is finished. Here you go, I hope you like it.'
noitems        = 'Sorry, but that\'s not enough leather to make one of these backpacks.'
noitems2    = 'Sorry, but that\'s not enough leather to make one of these backpacks.'
already        = 'It seems you already have this addon, don\'t you try to mock me son!'


function citizenfirst(cid, message, keywords, parameters, node)

    if(not npcHandler:isFocused(cid)) then
        return false
    end

    if isPremium(cid) then
    addon = getPlayerStorageValue(cid,fdruid)
    if addon == -1 then
        if getPlayerItemCount(cid,5878)>= 100 then
        if doPlayerRemoveItem(cid,5878,100) and getPlayerSex(cid) == 1 then
            doCreatureSay('Just in time! Your backpack is finished. Here you go, I hope you like it.')           
            doSendMagicEffect(getCreaturePosition(cid), 13)
            setPlayerStorageValue(cid,fdruid,1)
            doPlayerAddOutfit(cid, 128, 1)
        elseif doPlayerRemoveItem(cid,5878,100) and getPlayerSex(cid) == 0 then
            doCreatureSay('Just in time! Your backpack is finished. Here you go, I hope you like it.')           
            doSendMagicEffect(getCreaturePosition(cid), 13)
            setPlayerStorageValue(cid,fdruid,1)
            doPlayerAddOutfit(cid, 136, 1)
        end   
        else
            selfSay(noitems)
        end
    else
        selfSay(already)
    end
    end

end




node1 = keywordHandler:addKeyword({'minotaur leather'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Ah, right, almost forgot about the backpack! Have you brought me 100 pieces of minotaur leather as requested?'})
node1:addChildKeyword({'yes'}, citizenfirst, {})
node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I know, it\'s quite some work... don\'t lose heart, just keep killing minotaurs and you\'ll eventually get lucky.', reset = true})

node2 = keywordHandler:addKeyword({'minotaur leathers'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Ah, right, almost forgot about the backpack! Have you brought me 100 pieces of minotaur leather as requested?'})
node2:addChildKeyword({'yes'}, citizenfirst, {})
node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I know, it\'s quite some work... don\'t lose heart, just keep killing minotaurs and you\'ll eventually get lucky.', reset = true})


    if(msgcontains(msg, 'help')) then
        npcHandler:say("I lost my book\'s somewhere, if you bring me one of them then i will reward you. Do you have my book?.", cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
            if(doPlayerRemoveItem(cid, book1, 1) or doPlayerRemoveItem(cid, book2, 1) or doPlayerRemoveItem(cid, book3, 1))  then
                doPlayerAddItem(cid, shortsword, 1)
            setPlayerStorageValue(cid, 10001, 1)
                npcHandler:say("Thank you stranger! Please, this is your reward. Go back if you find another one.", cid)
            else
                npcHandler:say("You don\'t have a book! Bring it to me and then we will talk..", cid)
        end
    elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then 
        npcHandler:say("Come back if you got that book.", cid)
        end
        return true
        end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top