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,134
    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
    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:
    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,134
    If i use elseif then it wont give more solutions when he finds first value and overall it seems buggy:
    Code:
        if msgcontains(msg:lower(), 'task') then
            if L >= tasks["deer"].minL and L <= tasks["deer"].maxL then
                if getPlayerStorageValue(cid, 10100) < 1 then
                    selfSay ("Say {deer} for task ", cid)
                end
           
            elseif L >= tasks["wolf"].minL and L <= tasks["wolf"].maxL then
                if getPlayerStorageValue(cid, 10101) < 1 then
                    selfSay ("Say {wolf} for task", cid)
                end
    
            elseif L >= tasks["boar"].minL and L <= tasks["boar"].maxL then
                if getPlayerStorageValue(cid, 10102) < 1 then
                    selfSay ("Say {boar} for task", cid)
                end
           
            elseif L >= tasks["bear"].minL and L <= tasks["bear"].maxL then
                if getPlayerStorageValue(cid, 10103) < 1 then
                    selfSay ("Say {bear} for task", cid)
                end
            else selfSay ("no moar tasks", cid)
            end
    already tried this: Had no effect
    Code:
    if msgcontains(msg:lower(), 'task') then
    npcHandler.topic[cid] = 0
    if L >= tasks["deer"].minL and L <= tasks["deer"].maxL then
    if getPlayerStorageValue(cid, 10100) < 1 then
    selfSay ("Say {deer} for task ", cid)
    npcHandler.topic[cid] = 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)
    npcHandler.topic[cid] = 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)
    npcHandler.topic[cid] = 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)
    npcHandler.topic[cid] = 1
    end
    if npcHandler.topic[cid] == 0 then
    selfSay ("NO MOAR TASKS!!", cid)
    else npcHandler.topic[cid] = 0
    end
    end
    
     
  4. tarantonio

    tarantonio Old School Player

    Joined:
    Jun 21, 2009
    Messages:
    456
    @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,134
    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
    You can also use the same monster storage for all orcs.
     
  7. tarantonio

    tarantonio Old School Player

    Joined:
    Jun 21, 2009
    Messages:
    456
    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
    Code:
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..getCreatureName(target)..'s killed.')
    
    If you want to make that Orcs for example, you can add name = "Orc" to the table and in the textmessage like this.
    Code:
    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
    I never stop learning with you. Thanks
     
  10. tanii

    tanii Empire-war.com

    Joined:
    Jan 16, 2015
    Messages:
    334
    @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
  12. tanii

    tanii Empire-war.com

    Joined:
    Jan 16, 2015
    Messages:
    334
  13. RosOT

    RosOT Who am i?

    Joined:
    Feb 12, 2013
    Messages:
    715
    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:
    local keywordHandler = KeywordHandler:new()
    local npcHandler = NpcHandler:new(keywordHandler)
    NpcSystem.parseParameters(npcHandler)
    local talkState = {}
    
    function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
    function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
    function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
    function onThink() npcHandler:eek:nThink() 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
    local config = {
    npcstorage = 18687,
    killstorage = 19001,
    amountkills = 50,
    rewardpoints = 50,
    rewardexp = 12000
    }
    
    if(msgcontains(msg, 'mission')) then
    if getPlayerStorageValue(cid, config.npcstorage) == -1 then
    selfSay('So you want to do the mission? I want you to kill 50 players, do you accept?', cid)
    talkState[talkUser] = 1
    elseif getPlayerStorageValue(cid, config.npcstorage) == 1 then
    selfSay('Did you kill 50 players?', cid)
    talkState[talkUser] = 1
    else
    selfSay('You already did your mission.', cid)
    end
    elseif(msgcontains(msg, 'yes')) and talkState[talkUser] == 1 then
    if getPlayerStorageValue(cid, config.npcstorage) == -1 then
    selfSay('Lets see if you can make it!', cid)
    doPlayerSetStorageValue(cid, config.npcstorage, 1)
    talkState[talkUser] = 0
    return true
    end
    if getPlayerStorageValue(cid, config.npcstorage) == 1 and getPlayerStorageValue(cid, config.killstorage) >= config.amountkills then
    selfSay('Well, didn\'t expected it, but well done, here is your reward.', cid)
    db.executeQuery('UPDATE accounts SET premium_points=premium_points+'..config.rewardpoints..' WHERE id=' .. getPlayerAccountId(cid))
    doPlayerAddExp(cid, config.rewardexp)
    doPlayerSetStorageValue(cid, config.npcstorage, 2)
    talkState[talkUser] = 0
    else
    selfSay('You killed '..(getPlayerStorageValue(cid, config.killstorage) +1)..' players, you need to kill '..config.amountkills..'!', cid)
    talkState[talkUser] = 0
    end
    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
    talkState[talkUser] = 0
    selfSay('I knew you were not strong enough!', cid)
    end
    return true
    end
    
    npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
    npcHandler:addModule(FocusModule:new())
    
     
    Tarek1337 likes this.
  14. tanii

    tanii Empire-war.com

    Joined:
    Jan 16, 2015
    Messages:
    334
    [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
    You will have this with every NPC that is posted without code tags, it's because
    Code:
    :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:
    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
    
     
  16. kostas136

    kostas136 Banned User

    Joined:
    Apr 1, 2009
    Messages:
    215
    @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:
    305
    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:
        <event type="onKill" name="troll_mission" event="script" value="trollmission.lua"/>
    
    and the creaturescrips/scripts/trollmission.lua
    Code:
    local config = {
         ['troll'] = {amount = 25, storage = 19000, startstorage = 5002, startvalue = 1},
         ['troll champion'] = {amount = 10, storage = 19001, startstorage = 5002, startvalue = 1}
    }
    function onKill(cid, target)
         local monster = config[getCreatureName(target):lower()]
         if isPlayer(target) or not monster or isSummon(target) then
             return true
         end
    
         if (getPlayerStorageValue(cid, monster.storage)+1) < monster.amount and getPlayerStorageValue(cid, monster.startstorage) >= monster.startvalue then
             setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
             doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..getCreatureName(target)..'s killed.')
         end
         if (getPlayerStorageValue(cid, monster.storage)+1) == monster.amount then
             doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Congratulations, you have killed '..(getPlayerStorageValue(cid, monster.storage)+1)..' '..getCreatureName(target)..'s and completed the '..getCreatureName(target)..'s mission.')
             setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
         end
         return true
    end
    
    
     
    Last edited: Oct 15, 2015
  18. Xikini

    Xikini Titan Kingdoms Premium User

    Joined:
    Nov 17, 2010
    Messages:
    2,626
    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:
    <event type="onKill" name="troll_mission" event="script" value="trollmission.lua"/> -- incorrect
    <event type="kill" name="troll_mission" event="script" value="trollmission.lua"/> -- correct
    Code:
    types of creaturescripts that I can think of off-hand..
       advance
       cast
       channeljoin
       combat
       death
       kill
       login
       look
       mailreceive
       preparedeath
       reportbug
       statschange
       thankyou
       think
       throw
     
    Codex NG likes this.
  19. Andréew

    Andréew Well-Known Member

    Joined:
    Apr 14, 2015
    Messages:
    305
    It does not work for me :/ i think i added everything right.

    in the creaturescripts xml
    Code:
        <event type="kill" name="troll_mission" event="script" value="trollmission.lua"/>
    
    and the creaturescrips/scripts/trollmission.lua
    Code:
    local config = {
         ['troll'] = {amount = 25, storage = 19000, startstorage = 5002, startvalue = 1},
         ['troll champion'] = {amount = 10, storage = 19001, startstorage = 5002, startvalue = 1}
    }
    function onKill(cid, target)
         local monster = config[getCreatureName(target):lower()]
         if isPlayer(target) or not monster or isSummon(target) then
             return true
         end
    
         if (getPlayerStorageValue(cid, monster.storage)+1) < monster.amount and getPlayerStorageValue(cid, monster.startstorage) >= monster.startvalue then
             setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
             doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..getCreatureName(target)..'s killed.')
         end
         if (getPlayerStorageValue(cid, monster.storage)+1) == monster.amount then
             doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Congratulations, you have killed '..(getPlayerStorageValue(cid, monster.storage)+1)..' '..getCreatureName(target)..'s and completed the '..getCreatureName(target)..'s mission.')
             setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
         end
         return true
    end
    
    
    then i also added this to the data/lib/050-function.lua
    Code:
    function isSummon(cid)
    return (isCreature(cid) == TRUE and (getCreatureMaster(cid) ~= cid)) and TRUE or FALSE
    end
    
    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:
    <?xml version="1.0" encoding="UTF-8"?>
    <npc name="Tomas" script="Tomas.lua" speed="100" walkinterval="2000" floorchange="0">
       <health now="100" max="100"/>
       <look type="129" head="78" body="20" legs="116" feet="38" addons="1"/>
       <parameters>
         <parameter key="message_greet" value="Hello |PLAYERNAME|, can you do me a {favor}?"/>
       </parameters>
    </npc>
    
    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 storage = 5002
    
    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 msgcontains(msg, "favor") then
             if getPlayerStorageValue(cid, storage) == -1 then
                 selfSay("I have a mission for you, to kill 25 trolls and 10 troll champions, do you accept?", cid)
                 talkState[talkUser] = 1
             elseif getPlayerStorageValue(cid, storage) == 1 then
                 selfSay("Did you kill 25 trolls and 10 troll champions?", cid)
                 talkState[talkUser] = 1
             else
                 selfSay("You already did the mission.", cid)
             end
         elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
             if getPlayerStorageValue(cid, storage) == -1 then
                 selfSay("Thank you, the trolls has been harassing this village for to long", cid)
                 setPlayerStorageValue(cid, storage, 1)
             else
                 if getPlayerStorageValue(cid, 19000) == 5 and getPlayerStorageValue(cid, 19001) == 3 then
                     selfSay("Good job, here is your reward. go to the anvil at Darnells shop and use this.", cid)
                     doPlayerAddItem(cid, 2225, 1)
                     setPlayerStorageValue(cid, storage, 2)
                 else
                     selfSay("You didn't kill them all.", cid)
                 end
             end
             talkState[talkUser] = 0
         elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
             selfSay("Ok then.", cid)
             talkState[talkUser] = 0
         end
         return true
    end
    
    npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
    npcHandler:addModule(FocusModule:new())
    
     
  20. God Mythera

    God Mythera Well-Known Member

    Joined:
    Aug 11, 2012
    Messages:
    1,870
    I am using this for my server, thanks for making this ^^
     

Share This Page