TFS 0.X Grizzly Adams (Killing in the name of)

Discussion in 'Support' started by clario, Sep 13, 2018.

  1. clario

    clario OTS based on Heroes III Might and Magic

    Joined:
    Feb 4, 2018
    Messages:
    97
    Likes Received:
    3
    Best Answers:
    0
    Hey there PPL , i got a bug witch dont count monster killed :
    Code (Text):
    1. Grizzly Adams: Current -1 troll killed, you need to kill 2.

    login.lua:
    Code (Text):
    1. registerCreatureEvent(cid, "killinginthenameof")
    creature scripts.lua
    Code (Text):
    1.  
    2. local questCreatures =
    3. {
    4.     ["troll"] = {questStarted = 1510, questStorage = 65000, creatureStorage = 15000, killsRequired = 1, raceName = "troll"},
    5.     ["frost troll"] = {questStarted = 1510, questStorage = 65000, creatureStorage = 15001, killsRequired = 100, raceName = "Trolls"},
    6.     ["furious troll"] = {questStarted = 1510, questStorage = 65000, creatureStorage = 15002, killsRequired = 100, raceName = "Trolls"},
    7.     ["island troll"] = {questStarted = 1510, questStorage = 65000, creatureStorage = 15003, killsRequired = 100, raceName = "Trolls"},
    8.     ["swamp troll"] = {questStarted = 1510, questStorage = 65000, creatureStorage = 15004, killsRequired = 100, raceName = "Trolls"},
    9.     ["troll champion"] = {questStarted = 1510, questStorage = 65000, creatureStorage = 15005, killsRequired = 100, raceName = "Trolls"},
    10.     ["troll legionnaire"] = {questStarted = 1510, questStorage = 65000, creatureStorage = 15006, killsRequired = 100, raceName = "Trolls"}
    11. }
    12. local msgType = MESSAGE_STATUS_CONSOLE_ORANGE
    13.  
    14. function onKill(cid, target, lastHit)
    15.  
    16. local creature = questCreatures[getCreatureName(target):lower()]
    17.  
    18.     if creature then
    19.         if isPlayer(target) or isSummon(target) then return true end
    20.  
    21.         if getCreatureStorage(cid, creature.questStarted) > 0 then
    22.             if getCreatureStorage(cid, creature.questStorage) < creature.killsRequired then
    23.                 if getCreatureStorage(cid, creature.questStorage) < 0 then
    24.                     doCreatureSetStorage(cid, creature.questStorage, 0)
    25.                 end
    26.  
    27.                 if getCreatureStorage(cid, creature.creatureStorage) < 0 then
    28.                     doCreatureSetStorage(cid, creature.creatureStorage, 0)
    29.                 end
    30.                 doCreatureSetStorage(cid, creature.questStorage, getCreatureStorage(cid, creature.questStorage) + 1)
    31.                 doCreatureSetStorage(cid, creature.creatureStorage, getCreatureStorage(cid, creature.creatureStorage) + 1)
    32.                 doPlayerSendTextMessage(cid, msgType, getCreatureStorage(cid, creature.creatureStorage) .. " " .. getCreatureName(target) .. " defeated. Total [" .. getCreatureStorage(cid, creature.questStorage) .. "/" .. creature.killsRequired .. "] " .. creature.raceName .. ".")
    33.             end
    34.         end
    35.     end
    36.     return true
    37. end
    38.  
    npc script.lua
    Code (Text):
    1.  
    2. local THESNAPPER_POSITION = {x = 100, y = 100, z = 7}
    3. local HIDE_POSITION = {x = 100, y = 100, z = 7}
    4. local THEBLOODTUSK_POSITION = {x = 100, y = 100, z = 7}
    5. local SHARDHEAD_POSITION = {x = 100, y = 100, z = 7}
    6. local THUL_POSITION = {x = 100, y = 100, z = 7}
    7. local ESMERALDA_POSITION = {x = 100, y = 100, z = 7}
    8. local THEOLDWIDOW_POSITION = {x = 100, y = 100, z = 7}
    9. local THEMANY_POSITION = {x = 100, y = 100, z = 7}
    10. local LEVIATHAN_POSITION = {x = 100, y = 100, z = 7}
    11. local STONECRACKER_POSITION = {x = 100, y = 100, z = 7}
    12. local THENOXIUSSPAWN_POSITION = {x = 100, y = 100, z = 7}
    13. local MERIKHTHESLAUGHTERER_POSITION = {x = 100, y = 100, z = 7}
    14. local FAHIMTHEWISE_POSITION = {x = 100, y = 100, z = 7}
    15. local RANDOMPIRATEBOSS_POSITION = {x = 100, y = 100, z = 7}
    16. local THEHORNEDFOX_POSITION = {x = 100, y = 100, z = 7}
    17. local NECROPHARUS_POSITION = {x = 100, y = 100, z = 7}
    18.  
    19.  
    20. local tasks =
    21. {
    22.     [1] = {questStarted = 1510, questStorage = 65000, killsRequired = 2, raceName = "troll", rewards = {{enable = true, type = "exp", values = 200}, {enable = true, type = "money", values = 200}}}
    23. }
    24.  
    25. local rankStorage = 32150
    26. local choose = {}
    27.  
    28. local keywordHandler = KeywordHandler:new()
    29. local npcHandler = NpcHandler:new(keywordHandler)
    30. NpcSystem.parseParameters(npcHandler)
    31. local talkState = {}
    32.  
    33. function onCreatureAppear(cid)                          npcHandler:eek:nCreatureAppear(cid) end
    34. function onCreatureDisappear(cid)                       npcHandler:eek:nCreatureDisappear(cid) end
    35. function onCreatureSay(cid, type, msg)                  npcHandler:eek:nCreatureSay(cid, type, msg) end
    36. function onThink()                                      npcHandler:eek:nThink() end
    37.  
    38. function getTasksStarted(cid)
    39.     local tmp = {}
    40.     for k, v in pairs(tasks) do
    41.         if getCreatureStorage(cid, v.questStarted) == 1 then
    42.             table.insert(tmp, k)
    43.         end
    44.     end
    45.     return tmp
    46. end
    47.  
    48. function getTaskByName(name)
    49.     for k, v in pairs(tasks) do
    50.         if v.raceName:lower() == name:lower() then
    51.             return k
    52.         end
    53.     end
    54.     return false
    55. end
    56.  
    57. function creatureSayCallback(cid, type, msg)
    58.  
    59.     if(not npcHandler:isFocused(cid)) then
    60.         return false
    61.     end
    62.     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
    63.     if isInArray({"task", "tasks"}, msg:lower()) then
    64.         selfSay("There you can see the following tasks, please tell me the number of the task that you want to do.", cid)
    65.         local text = ""
    66.         for i = 1, table.maxn(tasks) do
    67.             text = text .. (text == "" and "" or "\n") .. i .. "  -  " .. tasks.raceName .. (getCreatureStorage(cid, tasks.questStarted) == 1 and " [...]" or getCreatureStorage(cid, tasks.questStarted) == 2 and " [x]" or "")
    68.         end
    69.         return doShowTextDialog(cid, 5956, text)
    70.  
    71.     elseif getTaskByName(msg) or tasks[tonumber(msg)] then
    72.         msg = (getTaskByName(msg) or tonumber(msg))
    73.         if getCreatureStorage(cid, tasks[msg].questStarted) == 1 then
    74.             selfSay("You already started this task.", cid)
    75.             talkState[talkUser] = 0
    76.             return true
    77.         end
    78.         if getCreatureStorage(cid, tasks[msg].questStarted) == 2 then
    79.             selfSay("You already finished this task.", cid)
    80.             talkState[talkUser] = 0
    81.             return true
    82.         end
    83.         if tasks[msg].level and getPlayerLevel(cid) < tasks[msg].level then
    84.             selfSay("You need level " .. tasks[msg].level .. " or higher to make this task.", cid)
    85.             talkState[talkUser] = 0
    86.             return true
    87.         end
    88.         selfSay("Are you sure that do you want to start the task number " .. msg .. "? In this task you will need to defeat " .. tasks[msg].killsRequired .. " " .. tasks[msg].raceName .. ".", cid)
    89.         choose[cid] = msg
    90.         talkState[talkUser] = 1
    91.     elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
    92.         doCreatureSetStorage(cid, tasks[choose[cid]].questStarted, 1)
    93.         selfSay("You have started the task number " .. choose[cid] .. ", remember... in this task you will need to defeat " .. tasks[choose[cid]].killsRequired .. " " .. tasks[choose[cid]].raceName .. ". Good luck!", cid)
    94.         talkState[talkUser] = 0
    95.         return true
    96.  
    97.     elseif msg:lower() == "report" then
    98.         local t = getTasksStarted(cid)
    99.         local response = "You are currently making " .. (#t > 1 and "these" or "this") .. " task" .. (#t > 1 and "s" or "") .. ":\n"
    100.         if table.maxn(t) > 0 then
    101.             for _, tsk in ipairs(t) do
    102.                 if getCreatureStorage(cid, tasks[tsk].questStorage) < 0 then doCreatureSetStorage(cid, tasks[tsk].questStorage, 0) end
    103.                 response = response .. "     Name: " .. tasks[tsk].raceName .. "     Kills: " .. getCreatureStorage(cid, tasks[tsk].questStorage) .. " - " .. tasks[tsk].killsRequired .. ".\n"
    104.             end
    105.             response = response .. "Please say report and the name of the task that do you want to report, example: 'Report Trolls'."
    106.             return selfSay(response, cid)
    107.         else
    108.             return selfSay("You need to start at least one task first.", cid)
    109.         end
    110.     elseif string.sub(msg:lower(), 0, 6) == "report" then
    111.         local t = getTaskByName(string.sub(msg, 8, string.len(msg)))
    112.         if not t then
    113.             return selfSay("That task does not exists.", cid)
    114.         end
    115.  
    116.         if getCreatureStorage(cid, tasks[t].questStarted) == 2 then
    117.             return selfSay("You already finished this task.", cid)
    118.         end
    119.  
    120.         if getCreatureStorage(cid, tasks[t].questStarted) < 1 then
    121.             return selfSay("You don't have started this task.", cid)
    122.         end
    123.  
    124.         if tasks[t].killsRequired > getCreatureStorage(cid, tasks[t].questStorage) then
    125.             return selfSay("Current " .. getCreatureStorage(cid, tasks[t].questStorage) .. " " .. tasks[t].raceName .. " killed, you need to kill " .. tasks[t].killsRequired .. ".", cid)
    126.         end
    127.  
    128.         for i = 1, table.maxn(tasks[t].rewards) do
    129.             if(tasks[t].rewards.enable) then
    130.                 if isInArray({"boss", "teleport", 1}, tasks[t].rewards.type) then
    131.                     doTeleportThing(cid, tasks[t].rewards.values)
    132.                 elseif isInArray({"exp", "experience", 2}, tasks[t].rewards.type) then
    133.                     doPlayerAddExperience(cid, tasks[t].rewards.values)
    134.                 elseif isInArray({"item", 3}, tasks[t].rewards.type) then
    135.                     doPlayerAddItem(cid, v.rewards.values[1], tasks[t].rewards.values[2])
    136.                 elseif isInArray({"money", 4}, tasks[t].rewards.type) then
    137.                     doPlayerAddMoney(cid, tasks[t].rewards.values)
    138.                 elseif isInArray({"storage", "stor", 5}, tasks[t].rewards.type) then
    139.                     doCreatureSetStorage(cid, tasks[t].rewards.values[1], tasks[t].rewards.values[2])
    140.                 elseif isInArray({"points", "rank", 2}, tasks[t].rewards.type) then
    141.                     doCreatureSetStorage(cid, rankStorage, getCreatureStorage(cid, rankStorage) + tasks[t].rewards.values)
    142.                 else
    143.                     print("[Warning - Npc::KillingInTheNameOf] Wrong reward type: " .. (tasks[t].rewards.type or "nil") .. ", reward could not be loaded.")
    144.                 end
    145.             end
    146.         end
    147.         local rank = getCreatureStorage(cid, rankStorage)
    148.         selfSay("Great!... you have finished the task number " .. t .. "" .. (rank > 4 and ", you are a " or "") .. "" .. (((rank > 4 and rank < 10) and ("Huntsman") or (rank > 9 and rank < 20) and ("Ranger") or (rank > 19 and rank < 30) and ("Big Game Hunter") or (rank > 29 and rank < 50) and ("Trophy Hunter") or (rank > 49) and ("Elite Hunter")) or "") .. ". Good job.", cid)
    149.         return doCreatureSetStorage(cid, tasks[t].questStarted, 2)
    150.     end
    151.     return true
    152. end
    153.  
    154. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
    155. npcHandler:addModule(FocusModule:new())
    156.  
    [B]npc.xml
    [/B]
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="UTF-8"?>
    3.  
    4. <npc name="Grizzly Adams" script="data/npc/scripts/killinginthenameof.lua" access="3" walkinterval="2000" lookdir="2">
    5.     <mana now="800" max="800"/>
    6.     <health now="200" max="200"/>
    7. <look type="144" head="97" body="97" legs="94" feet="97" addons="3"/>
    8. </npc>
    9.  
    Beging for help?
     
    Last edited by a moderator: Sep 14, 2018
  2. gudan garam

    gudan garam Active Member

    Joined:
    Feb 13, 2011
    Messages:
    238
    Likes Received:
    60
    Best Answers:
    8
    Have you registered the creaturescripts in your creaturescripts.xml?
     
  3. clario

    clario OTS based on Heroes III Might and Magic

    Joined:
    Feb 4, 2018
    Messages:
    97
    Likes Received:
    3
    Best Answers:
    0
    Yeah as kill event
     
  4. villelagui

    villelagui C++ Programmer

    Joined:
    May 16, 2009
    Messages:
    25
    Likes Received:
    2
    Best Answers:
    0
    Any errors in console ?
     
  5. clario

    clario OTS based on Heroes III Might and Magic

    Joined:
    Feb 4, 2018
    Messages:
    97
    Likes Received:
    3
    Best Answers:
    0
    nope
     
  6. villelagui

    villelagui C++ Programmer

    Joined:
    May 16, 2009
    Messages:
    25
    Likes Received:
    2
    Best Answers:
    0
    Add me on discord I can help you fix it ...
    Villela#3397
     
  7. clario

    clario OTS based on Heroes III Might and Magic

    Joined:
    Feb 4, 2018
    Messages:
    97
    Likes Received:
    3
    Best Answers:
    0
    Whhen i can iwil do it)):)
     

Share This Page

Loading...