Action Hermes' powerful quest system, LUA. Tutorial included.

Discussion in 'Actions, MoveEvents & TalkActions' started by Hermes, Feb 10, 2010.

Thread Status:
Not open for further replies.
  1. Hermes

    Hermes dziwki kola gramy w lola

    Joined:
    Nov 17, 2007
    Messages:
    1,867
    Likes Received:
    13
    Best Answers:
    0
    thank you, I won't release anything again
     
    Last edited: Feb 21, 2010
  2. Ldrozd

    Ldrozd Piszę skrypty w zeszycie.

    Joined:
    Dec 13, 2008
    Messages:
    430
    Likes Received:
    2
    Best Answers:
    0
    awesome :w00t:
     
  3. Szakal

    Szakal Frank Jaeger

    Joined:
    Apr 16, 2008
    Messages:
    1,337
    Likes Received:
    7
    Best Answers:
    0
    Nice work Hermes , you own.

    :D
     
  4. zakius

    zakius Enter the Ninja!

    Joined:
    Apr 30, 2009
    Messages:
    2,635
    Likes Received:
    63
    Best Answers:
    0
    Actually for just one chest quests I preffer default system(less writing for me, mapper have to care about it:D)
    if you could integrate it with old one(like:if aid == 2000 use old system, else use new one, not hard but useful[no need of rewriting all existing chests, easy quest are 100% made by mapper etc and you still have power of the new system])
     
  5. Hermes

    Hermes dziwki kola gramy w lola

    Joined:
    Nov 17, 2007
    Messages:
    1,867
    Likes Received:
    13
    Best Answers:
    0
    Well, you can use just:
    Code (Text):
    1. [UID] = {itemReward = {id, 1}}
    It's better to have less scripts (chest scripts) for even advanced quests.
     
  6. zakius

    zakius Enter the Ninja!

    Joined:
    Apr 30, 2009
    Messages:
    2,635
    Likes Received:
    63
    Best Answers:
    0
    yeah, I know, you wanted suggestions right? ;d
    I like it for advanced quests, but writing all chests here can take some time(I don't have many of them on map, but some poeple can have a lot of)

    I mean sth like
    Code (Text):
    1. function onUse(cid, item, fromPosition, itemEx, toPosition)
    2.     if item.actionid == 2000 then
    3.         storage = item.uid
    4.         if(storage > 65535) then
    5.             return false
    6.         end
    7.         if(getPlayerStorageValue(cid, storage) > 0) then
    8.             doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
    9.             return true
    10.         end
    11.         local items = {}
    12.         local reward = 0
    13.         local size = isContainer(item.uid) and getContainerSize(item.uid) or 0
    14.         if(size == 0) then
    15.             reward = doCopyItem(item, false)
    16.         else
    17.             for i = 0, size do
    18.                 local tmp = getContainerItem(item.uid, i)
    19.                 if(tmp.itemid > 0) then
    20.                     table.insert(items, tmp)
    21.                 end
    22.             end
    23.         end
    24.         size = table.maxn(items)
    25.         if(size == 1) then
    26.             reward = doCopyItem(items[1], true)
    27.         end
    28.         local result = ""
    29.         if(reward ~= 0) then
    30.             local ret = getItemDescriptions(reward.uid)
    31.             if(reward.type > 0 and isItemRune(reward.itemid)) then
    32.                 result = reward.type .. " charges " .. ret.name
    33.             elseif(reward.type > 0 and isItemStackable(reward.itemid)) then
    34.                 result = reward.type .. " " .. ret.plural
    35.             else
    36.                 result = ret.article .. " " .. ret.name
    37.             end
    38.         else
    39.             if(size > 20) then
    40.                 reward = doCopyItem(item, false)
    41.             elseif(size > 8) then
    42.                 reward = getThing(doCreateItemEx(1988, 1))
    43.             else
    44.                 reward = getThing(doCreateItemEx(1987, 1))
    45.             end
    46.             for i = 1, size do
    47.                 local tmp = doCopyItem(items[i], true)
    48.                 if(doAddContainerItemEx(reward.uid, tmp.uid) ~= RETURNVALUE_NOERROR) then
    49.                     print("[Warning] QuestSystem:", "Could not add quest reward")
    50.                 else
    51.                     local ret = ", "
    52.                     if(i == 2) then
    53.                         ret = " and "
    54.                     elseif(i == 1) then
    55.                         ret = ""
    56.                     end
    57.                     result = result .. ret
    58.                     ret = getItemDescriptions(tmp.uid)
    59.                     if(tmp.type > 0 and isItemRune(tmp.itemid)) then
    60.                         result = result .. tmp.type .. " charges " .. ret.name
    61.                     elseif(tmp.type > 0 and isItemStackable(tmp.itemid)) then
    62.                         result = result .. tmp.type .. " " .. ret.plural
    63.                     else
    64.                         result = result .. ret.article .. " " .. ret.name
    65.                     end
    66.                 end
    67.             end
    68.         end
    69.         if(doPlayerAddItemEx(cid, reward.uid, false) ~= RETURNVALUE_NOERROR) then
    70.             result = "You have found a reward weighing " .. getItemWeight(reward.uid) .. " oz. It is too heavy or you have not enough space."
    71.         else
    72.             result = "You have found " .. result .. "."
    73.             setPlayerStorageValue(cid, storage, 1)
    74.             if(questsExperience[storage] ~= nil) then
    75.                 doPlayerAddExp(cid, questsExperience[storage])
    76.                 doSendAnimatedText(getCreaturePosition(cid), questsExperience[storage], TEXTCOLOR_WHITE)
    77.             end
    78.         end
    79.         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, result)
    80.     else
    81.  
    82.         --CREDITS: HERMES :* :* :*
    83.         --TODO: Check space in player backpack before giving reward.
    84.         --              "customMessage" parameter, ability to set own message like "You've got access to X."
    85.         --              support for multiple containers, to handle more than 20 slots
    86.         --              support for stackable items, it's concerned with this /\
    87.         --BTW. DO NOT mess with the script unless you know what you're doing.
    88.        
    89.         local QUESTSYSTEM_LIST = {
    90.         --[UNIQUE_ID] = {itemReward = {ITEM1, ITEM1_COUNT, ITEM2, ITEM2_COUNT...}, containerId = CUSTOM_CONTAINER_ID, experience = EXPERIENCE, neededLevel = LEVEL_TO_OPEN_CHEST, neededStorage = {STORAGE_TO_OPEN, VALUE}, setStorage = {SET_CUSTOM_STORAGE, VALUE}}
    91.                 --let's fill one table using all parameters we can
    92.                 [12345] = {itemReward = {2160, 10, 2195, 2}, containerId = 1990, experience = 2000, neededLevel = 10, neededStorage = {12345, 5}, setStorage = {12345, 6}},
    93.                 --this one will work too
    94.                 [12346] = {experience = 1000},
    95.                 --same as this
    96.                 [12347] = {itemReward = {2160, 2}, setStorage = {12345, 5}, neededStorage = {12345, -1}}
    97.         }
    98.  
    99.         local QS_ALLOW_GM, QS_TOTAL_WEIGHT, QS_CONTAINER, QUEST = true, 0, 1988, QUESTSYSTEM_LIST[item.uid]
    100.         local QS_MSG = {TOO_HEAVY = {"You have found something weighing ", " oz, it's too heavy."}, LEVEL_TOO_LOW = {"You need to have ", " level in order to open this chest."}, IT_IS_EMPTY = "It is empty."}
    101.         local message = function (cid, m)
    102.                 return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, m)
    103.         end
    104.         if not QUEST or item.uid == 0 or (getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES) and not QS_ALLOW_GM) then
    105.                 return false
    106.         end
    107.         if(QUEST.neededStorage and type(QUEST.neededStorage) == "table" and #QUEST.neededStorage == 2 and getPlayerStorageValue(cid, QUEST.neededStorage[1]) ~= QUEST.neededStorage[2]) or getPlayerStorageValue(cid, QUEST.uniqueId) == 1 then
    108.                 message(cid, QS_MSG.IT_IS_EMPTY)
    109.                 return true
    110.         end
    111.         if QUEST.neededLevel and getPlayerLevel(cid) < QUEST.neededLevel then
    112.                 message(cid, QS_MSG.LEVEL_TOO_LOW[1] .. QUEST.neededLevel .. QS_MSG.LEVEL_TOO_LOW[2])
    113.                 return true
    114.         end
    115.         if QUEST.containerId then
    116.                 QS_CONTAINER = QUEST.containerId
    117.         end
    118.         if QUEST.itemReward and type(QUEST.itemReward) == "table" and #QUEST.itemReward % 2 == 0 and #QUEST.itemReward < 40 then
    119.                 if #QUEST.itemReward == 2 then
    120.                         QS_TOTAL_WEIGHT = getItemWeightById(QUEST.itemReward[1], QUEST.itemReward[2], false)
    121.                         if getPlayerFreeCap(cid) < QS_TOTAL_WEIGHT then
    122.                                 message(cid, QS_MSG.TOO_HEAVY[1] .. QS_TOTAL_WEIGHT .. QS_MSG.TOO_HEAVY[2])
    123.                         else
    124.                                 doPlayerAddItem(cid, QUEST.itemReward[1], QUEST.itemReward[2])
    125.                                 message(cid, "You have found " .. QUEST.itemReward[2] .. " " .. getItemNameById(QUEST.itemReward[1]) .. ".")
    126.                         end
    127.                 elseif #QUEST.itemReward > 2 then
    128.                         tmp = 1
    129.                         while tmp < #QUEST.itemReward do
    130.                                 QS_TOTAL_WEIGHT = QS_TOTAL_WEIGHT + getItemWeightById(QUEST.itemReward[tmp], QUEST.itemReward[tmp+1], false)
    131.                                 tmp = tmp + 2
    132.                         end
    133.                         if getPlayerFreeCap(cid) < QS_TOTAL_WEIGHT + getItemWeightById(QS_CONTAINER) then
    134.                                 message(cid, QS_MSG.TOO_HEAVY[1] .. QS_TOTAL_WEIGHT .. QS_MSG.TOO_HEAVY[2])
    135.                         else
    136.                                 local bp = doPlayerAddItem(cid, QS_CONTAINER, 1)
    137.                                 tmp = 1
    138.                                 while tmp + 1 <= #QUEST.itemReward do
    139.                                         doAddContainerItem(bp, QUEST.itemReward[tmp], QUEST.itemReward[tmp+1])
    140.                                         tmp = tmp + 2
    141.                                 end
    142.                                 message(cid, "You have found " .. getItemArticleById(QS_CONTAINER) .. " " .. getItemNameById(QS_CONTAINER) .. ".")
    143.                         end
    144.                 end
    145.         elseif QUEST.experience and QUEST.experience > 0 then
    146.                 doPlayerAddExp(cid, QUEST.experience)
    147.                 doSendAnimatedText(fromPosition, QUEST.experience, 215)
    148.         elseif QUEST.setStorage and type(QUEST.setStorage) == "table" and #QUEST.setStorage == 2 then
    149.                 setPlayerStorageValue(cid, QUEST.setStorage[1], QUEST.setStorage[2])
    150.         elseif not QUEST.setStorage then
    151.                 setPlayerStorageValue(cid, QUEST.uniqueId, 1)
    152.         end
    153.         end
    154.         return true
    155. end
    not tested, but should work


    hmm, your way(parameter onMap) will still need adding quest to script right?
    its the thing that I want to exclude from my serv

    But go ahead, its your script so do it how you like :D
     
    Last edited: Feb 11, 2010
  7. Hermes

    Hermes dziwki kola gramy w lola

    Joined:
    Nov 17, 2007
    Messages:
    1,867
    Likes Received:
    13
    Best Answers:
    0
    Oh, I will consider merging questsystems so you can use only parameter onMap = {true, type = uniqueIdReward/copyItem}. But it's a bit difficult :p
     
  8. Zlorek

    Zlorek New Member

    Joined:
    Apr 14, 2008
    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Hermes Nup <Blain Here> ;>>
     
  9. Colandus

    Colandus Well-Known Member

    Joined:
    Jun 6, 2007
    Messages:
    2,424
    Likes Received:
    162
    Best Answers:
    18
    "great", "cool", "awesome", "OMG ROX"

    but unfortunately nobody will use 'em :( yes it's pleasant to read those comments, to know that people respect your work... i've lived that life, but in fact it's pretty damn pointless because none uses it !!

    now im not saying ur system is bad, it's good... but none will use it!!
     
  10. Snow

    Snow Member

    Joined:
    Jan 16, 2008
    Messages:
    381
    Likes Received:
    0
    Best Answers:
    0
    looks nice, too bad I don't know who to really make it useful :(
     
  11. Hermes

    Hermes dziwki kola gramy w lola

    Joined:
    Nov 17, 2007
    Messages:
    1,867
    Likes Received:
    13
    Best Answers:
    0
    Okay, from now I won't release anything. Thank you for your appreciation... -.-
     
Thread Status:
Not open for further replies.

Share This Page

Loading...