NPC Mission

Discussion in 'Programming & Scripting' started by Limos, Mar 10, 2014.

  1. whitevo

    whitevo Feeling good, thats what I do.

    Joined:
    Jan 2, 2015
    Messages:
    3,160
    Likes Received:
    539
    Best Answers:
    1
    if msgcontains(msg:lower(), 'task') then
    talkState[talkUser] = 0
    if L >= tasks["deer"].minL and L <= tasks["deer"].maxL then
    if getPlayerStorageValue(cid, 10100) < 1 then
    selfSay ("Say {deer} for task ", cid)
    talkState[talkUser] = 1
    end
    end
    if L >= tasks["wolf"].minL and L <= tasks["wolf"].maxL then
    if getPlayerStorageValue(cid, 10101) < 1 then
    selfSay ("Say {wolf} for task", cid)
    talkState[talkUser] = 1
    end
    end
    if L >= tasks["boar"].minL and L <= tasks["boar"].maxL then
    if getPlayerStorageValue(cid, 10102) < 1 then
    selfSay ("Say {boar} for task", cid)
    talkState[talkUser] = 1
    end
    end
    if L >= tasks["bear"].minL and L <= tasks["bear"].maxL then
    if getPlayerStorageValue(cid, 10103) < 1 then
    selfSay ("Say {bear} for task", cid)
    talkState[talkUser] = 1
    end
    if talkState[talkUser] == 0 then
    selfSay ("NO MOAR TASKS!!", cid)
    else talkState[talkUser] = 0
    end
    end

    talkState doesn't work here for TFS 1.0

    I want to to say "no moar tasks!!" if he doesn't bring out any previous answers
    i don't say it if he says any other answers before
     
  2. Limos

    Limos Premium User

    Joined:
    Jun 7, 2010
    Messages:
    10,017
    Likes Received:
    2,907
    Best Answers:
    4
    It's a table so it's not related to a TFS version, but for TFS 1.0 you can use this instead (it's added in the npcsystem, so you don't need to create a table at the top of the npc like with talkState).
    Code (Text):
    1. npcHandler.topic[cid]
    For the npc, use elseif and else, it will say the else part if all other statements above are not true.
     
  3. whitevo

    whitevo Feeling good, thats what I do.

    Joined:
    Jan 2, 2015
    Messages:
    3,160
    Likes Received:
    539
    Best Answers:
    1
    If i use elseif then it wont give more solutions when he finds first value and overall it seems buggy:
    Code (Text):
    1.     if msgcontains(msg:lower(), 'task') then
    2.         if L >= tasks["deer"].minL and L <= tasks["deer"].maxL then
    3.             if getPlayerStorageValue(cid, 10100) < 1 then
    4.                 selfSay ("Say {deer} for task ", cid)
    5.             end
    6.        
    7.         elseif L >= tasks["wolf"].minL and L <= tasks["wolf"].maxL then
    8.             if getPlayerStorageValue(cid, 10101) < 1 then
    9.                 selfSay ("Say {wolf} for task", cid)
    10.             end
    11.  
    12.         elseif L >= tasks["boar"].minL and L <= tasks["boar"].maxL then
    13.             if getPlayerStorageValue(cid, 10102) < 1 then
    14.                 selfSay ("Say {boar} for task", cid)
    15.             end
    16.        
    17.         elseif L >= tasks["bear"].minL and L <= tasks["bear"].maxL then
    18.             if getPlayerStorageValue(cid, 10103) < 1 then
    19.                 selfSay ("Say {bear} for task", cid)
    20.             end
    21.         else selfSay ("no moar tasks", cid)
    22.         end
    already tried this: Had no effect
    Code (Text):
    1.  
    2. if msgcontains(msg:lower(), 'task') then
    3. npcHandler.topic[cid] = 0
    4. if L >= tasks["deer"].minL and L <= tasks["deer"].maxL then
    5. if getPlayerStorageValue(cid, 10100) < 1 then
    6. selfSay ("Say {deer} for task ", cid)
    7. npcHandler.topic[cid] = 1
    8. end
    9. end
    10. if L >= tasks["wolf"].minL and L <= tasks["wolf"].maxL then
    11. if getPlayerStorageValue(cid, 10101) < 1 then
    12. selfSay ("Say {wolf} for task", cid)
    13. npcHandler.topic[cid] = 1
    14. end
    15. end
    16. if L >= tasks["boar"].minL and L <= tasks["boar"].maxL then
    17. if getPlayerStorageValue(cid, 10102) < 1 then
    18. selfSay ("Say {boar} for task", cid)
    19. npcHandler.topic[cid] = 1
    20. end
    21. end
    22. if L >= tasks["bear"].minL and L <= tasks["bear"].maxL then
    23. if getPlayerStorageValue(cid, 10103) < 1 then
    24. selfSay ("Say {bear} for task", cid)
    25. npcHandler.topic[cid] = 1
    26. end
    27. if npcHandler.topic[cid] == 0 then
    28. selfSay ("NO MOAR TASKS!!", cid)
    29. else npcHandler.topic[cid] = 0
    30. end
    31. end
    32.  
     
  4. tarantonio

    tarantonio Old School Player

    Joined:
    Jun 21, 2009
    Messages:
    456
    Likes Received:
    78
    Best Answers:
    0
    @Limos If I want to make a task with "races" instead of monsters, example: kill orcs (normal, spearman, berserker,...), how I change the lua?
     
  5. whitevo

    whitevo Feeling good, thats what I do.

    Joined:
    Jan 2, 2015
    Messages:
    3,160
    Likes Received:
    539
    Best Answers:
    1
    Make table named
    Orcs = {"orc", "orc spearman", "orc berserker"}
    And loop trough
    for tableValue=1, #Orcs do
    if orcs.[tableValue] == target:getName() then
    +1 to orc task :D
    end
    end
     
  6. Limos

    Limos Premium User

    Joined:
    Jun 7, 2010
    Messages:
    10,017
    Likes Received:
    2,907
    Best Answers:
    4
    You can also use the same monster storage for all orcs.
     
  7. tarantonio

    tarantonio Old School Player

    Joined:
    Jun 21, 2009
    Messages:
    456
    Likes Received:
    78
    Best Answers:
    0
    Nice and elegant!, but the problem is how to manage the creaturescripts part to show correct msg.
     
  8. Limos

    Limos Premium User

    Joined:
    Jun 7, 2010
    Messages:
    10,017
    Likes Received:
    2,907
    Best Answers:
    4
    Code (Text):
    1.  
    2. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..getCreatureName(target)..'s killed.')
    3.  
    If you want to make that Orcs for example, you can add name = "Orc" to the table and in the textmessage like this.
    Code (Text):
    1.  
    2. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..(monster.name or getCreatureName(target))..'s killed.')
     
    tarantonio likes this.
  9. tarantonio

    tarantonio Old School Player

    Joined:
    Jun 21, 2009
    Messages:
    456
    Likes Received:
    78
    Best Answers:
    0
    I never stop learning with you. Thanks
     
  10. tanii

    tanii Empire-war.com

    Joined:
    Jan 16, 2015
    Messages:
    334
    Likes Received:
    5
    Best Answers:
    0
    @Limos bro can u create mission like kill 100 people get 200 premium points and with options of frags 50,100,500,600,1000 example?
     
  11. Limos

    Limos Premium User

    Joined:
    Jun 7, 2010
    Messages:
    10,017
    Likes Received:
    2,907
    Best Answers:
    4
  12. tanii

    tanii Empire-war.com

    Joined:
    Jan 16, 2015
    Messages:
    334
    Likes Received:
    5
    Best Answers:
    0
  13. RosOT

    RosOT Who am i?

    Joined:
    Feb 12, 2013
    Messages:
    718
    Likes Received:
    134
    Best Answers:
    0
    Now stop bumping and double posting shit. post something once and wait for a reply :|

    This belongs to @Limos post i just changed the reward item to points~
    Code (Text):
    1.  
    2. local keywordHandler = KeywordHandler:new()
    3. local npcHandler = NpcHandler:new(keywordHandler)
    4. NpcSystem.parseParameters(npcHandler)
    5. local talkState = {}
    6.  
    7. function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
    8. function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
    9. function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
    10. function onThink() npcHandler:eek:nThink() end
    11.  
    12. function creatureSayCallback(cid, type, msg)
    13. if(not npcHandler:isFocused(cid)) then
    14. return false
    15. end
    16.  
    17. local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    18. local config = {
    19. npcstorage = 18687,
    20. killstorage = 19001,
    21. amountkills = 50,
    22. rewardpoints = 50,
    23. rewardexp = 12000
    24. }
    25.  
    26. if(msgcontains(msg, 'mission')) then
    27. if getPlayerStorageValue(cid, config.npcstorage) == -1 then
    28. selfSay('So you want to do the mission? I want you to kill 50 players, do you accept?', cid)
    29. talkState[talkUser] = 1
    30. elseif getPlayerStorageValue(cid, config.npcstorage) == 1 then
    31. selfSay('Did you kill 50 players?', cid)
    32. talkState[talkUser] = 1
    33. else
    34. selfSay('You already did your mission.', cid)
    35. end
    36. elseif(msgcontains(msg, 'yes')) and talkState[talkUser] == 1 then
    37. if getPlayerStorageValue(cid, config.npcstorage) == -1 then
    38. selfSay('Lets see if you can make it!', cid)
    39. doPlayerSetStorageValue(cid, config.npcstorage, 1)
    40. talkState[talkUser] = 0
    41. return true
    42. end
    43. if getPlayerStorageValue(cid, config.npcstorage) == 1 and getPlayerStorageValue(cid, config.killstorage) >= config.amountkills then
    44. selfSay('Well, didn\'t expected it, but well done, here is your reward.', cid)
    45. db.executeQuery('UPDATE accounts SET premium_points=premium_points+'..config.rewardpoints..' WHERE id=' .. getPlayerAccountId(cid))
    46. doPlayerAddExp(cid, config.rewardexp)
    47. doPlayerSetStorageValue(cid, config.npcstorage, 2)
    48. talkState[talkUser] = 0
    49. else
    50. selfSay('You killed '..(getPlayerStorageValue(cid, config.killstorage) +1)..' players, you need to kill '..config.amountkills..'!', cid)
    51. talkState[talkUser] = 0
    52. end
    53. elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
    54. talkState[talkUser] = 0
    55. selfSay('I knew you were not strong enough!', cid)
    56. end
    57. return true
    58. end
    59.  
    60. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
    61. npcHandler:addModule(FocusModule:new())
    62.  
     
    Tarek1337 likes this.
  14. tanii

    tanii Empire-war.com

    Joined:
    Jan 16, 2015
    Messages:
    334
    Likes Received:
    5
    Best Answers:
    0
    [07/06/2015 18:59:04] [Error - LuaScriptInterface::loadFile] data/npc/scripts/darkskull.lua:6: function arguments expected near ':'
    [07/06/2015 18:59:04] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/darkskull.lua
    [07/06/2015 18:59:04] data/npc/scripts/darkskull.lua:6: function arguments expected near ':'

    whats this error? and how to solv?
     
  15. Limos

    Limos Premium User

    Joined:
    Jun 7, 2010
    Messages:
    10,017
    Likes Received:
    2,907
    Best Answers:
    4
    You will have this with every NPC that is posted without code tags, it's because
    Code (Text):
    1. :o
    Will be changed to a :eek: smiley without code tags.
    So you can just change it back or copy paste those 4 lines from an other NPC Lua script.
    Code (Text):
    1.  
    2. function onCreatureAppear(cid)       npcHandler:onCreatureAppear(cid)       end
    3. function onCreatureDisappear(cid)     npcHandler:onCreatureDisappear(cid)       end
    4. function onCreatureSay(cid, type, msg)     npcHandler:onCreatureSay(cid, type, msg)     end
    5. function onThink()         npcHandler:onThink()           end
    6.  
     
  16. kostas136

    kostas136 Banned User

    Joined:
    Apr 1, 2009
    Messages:
    215
    Likes Received:
    30
    Best Answers:
    0
    @Limos Could you please contact me on skype, cant send u message, kostaspolo1
     
  17. Andréew

    Andréew Well-Known Member

    Joined:
    Apr 14, 2015
    Messages:
    322
    Likes Received:
    330
    Best Answers:
    0
    How do i put this in the quest log so you can see how many dragons or in my case Trolls i've killed?

    edit:
    I did apply it to the server and got this error
    [​IMG]

    in the creaturescripts xml
    Code (Text):
    1.  
    2.     <event type="onKill" name="troll_mission" event="script" value="trollmission.lua"/>
    3.  
    and the creaturescrips/scripts/trollmission.lua
    Code (Text):
    1.  
    2. local config = {
    3.      ['troll'] = {amount = 25, storage = 19000, startstorage = 5002, startvalue = 1},
    4.      ['troll champion'] = {amount = 10, storage = 19001, startstorage = 5002, startvalue = 1}
    5. }
    6. function onKill(cid, target)
    7.      local monster = config[getCreatureName(target):lower()]
    8.      if isPlayer(target) or not monster or isSummon(target) then
    9.          return true
    10.      end
    11.  
    12.      if (getPlayerStorageValue(cid, monster.storage)+1) < monster.amount and getPlayerStorageValue(cid, monster.startstorage) >= monster.startvalue then
    13.          setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
    14.          doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..getCreatureName(target)..'s killed.')
    15.      end
    16.      if (getPlayerStorageValue(cid, monster.storage)+1) == monster.amount then
    17.          doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Congratulations, you have killed '..(getPlayerStorageValue(cid, monster.storage)+1)..' '..getCreatureName(target)..'s and completed the '..getCreatureName(target)..'s mission.')
    18.          setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
    19.      end
    20.      return true
    21. end
    22.  
    23.  
     
    Last edited: Oct 15, 2015
  18. Xikini

    Xikini Titan Kingdoms Premium User

    Joined:
    Nov 17, 2010
    Messages:
    2,767
    Likes Received:
    1,443
    Best Answers:
    7
    Looked into it thoroughly.. and unfortunately there's no quick way that I can see.
    https://otland.net/threads/quest-log-killing-in-the-name-of-help-me.83155/
    (for TFS 0.3.7 and similar it's located "data/xml/quests")

    At your other problem..
    Code (Text):
    1. <event type="onKill" name="troll_mission" event="script" value="trollmission.lua"/> -- incorrect
    2. <event type="kill" name="troll_mission" event="script" value="trollmission.lua"/> -- correct
    Code (Text):
    1.  
    2. types of creaturescripts that I can think of off-hand..
    3.    advance
    4.    cast
    5.    channeljoin
    6.    combat
    7.    death
    8.    kill
    9.    login
    10.    look
    11.    mailreceive
    12.    preparedeath
    13.    reportbug
    14.    statschange
    15.    thankyou
    16.    think
    17.    throw
     
    Codex NG likes this.
  19. Andréew

    Andréew Well-Known Member

    Joined:
    Apr 14, 2015
    Messages:
    322
    Likes Received:
    330
    Best Answers:
    0
    It does not work for me :/ i think i added everything right.

    in the creaturescripts xml
    Code (Text):
    1.  
    2.     <event type="kill" name="troll_mission" event="script" value="trollmission.lua"/>
    3.  
    and the creaturescrips/scripts/trollmission.lua
    Code (Text):
    1.  
    2. local config = {
    3.      ['troll'] = {amount = 25, storage = 19000, startstorage = 5002, startvalue = 1},
    4.      ['troll champion'] = {amount = 10, storage = 19001, startstorage = 5002, startvalue = 1}
    5. }
    6. function onKill(cid, target)
    7.      local monster = config[getCreatureName(target):lower()]
    8.      if isPlayer(target) or not monster or isSummon(target) then
    9.          return true
    10.      end
    11.  
    12.      if (getPlayerStorageValue(cid, monster.storage)+1) < monster.amount and getPlayerStorageValue(cid, monster.startstorage) >= monster.startvalue then
    13.          setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
    14.          doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..getCreatureName(target)..'s killed.')
    15.      end
    16.      if (getPlayerStorageValue(cid, monster.storage)+1) == monster.amount then
    17.          doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Congratulations, you have killed '..(getPlayerStorageValue(cid, monster.storage)+1)..' '..getCreatureName(target)..'s and completed the '..getCreatureName(target)..'s mission.')
    18.          setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
    19.      end
    20.      return true
    21. end
    22.  
    23.  
    then i also added this to the data/lib/050-function.lua
    Code (Text):
    1.  
    2. function isSummon(cid)
    3. return (isCreature(cid) == TRUE and (getCreatureMaster(cid) ~= cid)) and TRUE or FALSE
    4. end
    5.  
    i can speak with the npc and i can accept the quest, but it does not count my kills and i dont get any massage that i've killed 1/25 trolls
    when i did kill enough to make the quest i go back to the npc and he says " You haven't killed them all.

    here is npc script
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="UTF-8"?>
    3. <npc name="Tomas" script="Tomas.lua" speed="100" walkinterval="2000" floorchange="0">
    4.    <health now="100" max="100"/>
    5.    <look type="129" head="78" body="20" legs="116" feet="38" addons="1"/>
    6.    <parameters>
    7.      <parameter key="message_greet" value="Hello |PLAYERNAME|, can you do me a {favor}?"/>
    8.    </parameters>
    9. </npc>
    10.  
    Code (Text):
    1.  
    2. local keywordHandler = KeywordHandler:new()
    3. local npcHandler = NpcHandler:new(keywordHandler)
    4. NpcSystem.parseParameters(npcHandler)
    5. local talkState = {}
    6.  
    7. function onCreatureAppear(cid)       npcHandler:onCreatureAppear(cid)       end
    8. function onCreatureDisappear(cid)     npcHandler:onCreatureDisappear(cid)       end
    9. function onCreatureSay(cid, type, msg)     npcHandler:onCreatureSay(cid, type, msg)     end
    10. function onThink()         npcHandler:onThink()           end
    11.  
    12. local storage = 5002
    13.  
    14. function creatureSayCallback(cid, type, msg)
    15.      if not npcHandler:isFocused(cid) then
    16.          return false
    17.      end
    18.      local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    19.  
    20.      if msgcontains(msg, "favor") then
    21.          if getPlayerStorageValue(cid, storage) == -1 then
    22.              selfSay("I have a mission for you, to kill 25 trolls and 10 troll champions, do you accept?", cid)
    23.              talkState[talkUser] = 1
    24.          elseif getPlayerStorageValue(cid, storage) == 1 then
    25.              selfSay("Did you kill 25 trolls and 10 troll champions?", cid)
    26.              talkState[talkUser] = 1
    27.          else
    28.              selfSay("You already did the mission.", cid)
    29.          end
    30.      elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
    31.          if getPlayerStorageValue(cid, storage) == -1 then
    32.              selfSay("Thank you, the trolls has been harassing this village for to long", cid)
    33.              setPlayerStorageValue(cid, storage, 1)
    34.          else
    35.              if getPlayerStorageValue(cid, 19000) == 5 and getPlayerStorageValue(cid, 19001) == 3 then
    36.                  selfSay("Good job, here is your reward. go to the anvil at Darnells shop and use this.", cid)
    37.                  doPlayerAddItem(cid, 2225, 1)
    38.                  setPlayerStorageValue(cid, storage, 2)
    39.              else
    40.                  selfSay("You didn't kill them all.", cid)
    41.              end
    42.          end
    43.          talkState[talkUser] = 0
    44.      elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
    45.          selfSay("Ok then.", cid)
    46.          talkState[talkUser] = 0
    47.      end
    48.      return true
    49. end
    50.  
    51. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
    52. npcHandler:addModule(FocusModule:new())
    53.  
     
  20. God Mythera

    God Mythera Well-Known Member

    Joined:
    Aug 11, 2012
    Messages:
    1,897
    Likes Received:
    207
    Best Answers:
    0
    I am using this for my server, thanks for making this ^^
     

Share This Page

Loading...