Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.71 KB | None | 0 0
  1. --[[
  2.     Date:       20.10.2017
  3.     Quest Name: LockPicking.lua
  4.     Author:     Dominik Michalski
  5.     Version:    1.0.0
  6. ]]--
  7.  
  8. quest lockpicking begin
  9.     -- send target and talk about this system with npc
  10.     state start begin
  11.         when login or levelup or enter with pc.level >= 90 begin
  12.             set_state (box_inform)
  13.         end
  14.     end
  15.     state box_inform begin
  16.         when letter begin
  17.             send_letter("Spróchniałe Skrzynie")
  18.             local v = find_npc_by_vnum (20131)
  19.             if v != 0 then
  20.                 target.vid ("__TARGET__",v,"Idź do Poszukiwacza")
  21.             end
  22.         end
  23.         when button or info begin
  24.             say_cegla("  Oferta:")
  25.             say("")
  26.             say("Poszukiwacz z Twojej wioski ma dla Ciebie ofertę.")
  27.             say("Udaj się do niego, aby dowiedzieć się więcej.")
  28.             say("")
  29.         end
  30.        
  31.         when __TARGET__.target.click or 20131.chat."Spróchniałe Skrzynie" begin
  32.             target.delete("__TARGET__")
  33.             say_title(mob_name(20131))
  34.             say("")
  35.             say("Witaj Poszukiwaczu Przygód!")
  36.             say("Ja też jestem Poszukiwaczem! Szukam skarbów ")
  37.             say("ukrytych w zakamarkach starych skrzyń.")
  38.             say("")
  39.             say("Chcesz dowiedzieć się coś o Spróchniałych Skrzyniach? ")
  40.             say("Na nowo odkrytych mapach widzieliśmy dużo tych skrzyń.")
  41.             say("Wyglądem przypominają szkatułki Władców, lecz skrywają ")
  42.             say("cenniejsze nagrody.")
  43.             say("")
  44.             say("Możesz użyć specjalnego Klucza, aby zapewnić sobie ")
  45.             say("100% pewności przy otwieraniu zamków.")
  46.             say("Jeśli nie posiadasz klucza, wystarczy,")
  47.             say("że klikniesz na szkatułkę.")
  48.             say_item_vnum(51040, "Magiczny Klucz", "Dzięki temu przedmiotowi możesz otworzyć każdą napotkaną szkatułkę.")
  49.             say("")
  50.             pc.give_item2(51040,1)
  51.             pc.set_skill_level(lockpicking.settings()['skillVnum'], lockpicking.getSkillLevel()+1)
  52.             clear_letter()
  53.             set_state(main_part)
  54.         end
  55.     end
  56.    
  57.     -- main part of this system
  58.     state main_part begin
  59.    
  60.         function settings()
  61.             return {
  62.                 ['skillVnum'] = 133,
  63.                 ['maxLevel'] = 40,
  64.                 ['readDelay'] = 2, -- in hours
  65.                
  66.                 ['boxNPCVnum'] = 20130,
  67.                 ['missionNPCVnum'] = 20131,
  68.                 ['skillBookVnum'] = 51033,
  69.                 ['specialItemVnum'] = 51040,
  70.                
  71.                 ['bookReadChance'] = 40, -- percentage
  72.                 ['defaultChance'] = 20, -- percentage
  73.                 ['defaultCount'] = 1,
  74.                 ['keyAllowUse'] = 10,
  75.                
  76.                 -- choose lang for texts in mission
  77.                 ['choosenLang'] = "pl",
  78.                 ['translation'] = {
  79.                     ['pl'] = {
  80.                         ['chat_skill_max_level'] = "Posiadasz już maksymalny poziom tej umiejętności.",
  81.                         ['chat_dont_have_item'] = "Nie posiadasz odpowiedniej księgi, aby rozwinąć tę umiejętność.",
  82.                         ['chat_training_success'] = "Pomyślnie zakończyłeś trening!",
  83.                         ['chat_upgraded_to_master'] = "Rozwinąłeś umiejętność na poziom Mistrzowski.",
  84.                         ['chat_training_failed'] = "Trening zakończony niepowodzeniem. Spróbuj ponownie później.",
  85.                         ['chat_cant_read_by_time'] = "Nie możesz jeszcze czytać tej książki. Spróbuj ponownie za %d minut.",
  86.                         ['chat_opening_success'] = "Brawo! Udało Ci się otworzyć skrzynię!",
  87.                         ['chat_opening_failed'] = "Nie udało Ci się otworzyć tej skrzyni.",
  88.                         ['chat_cannot_open_box'] = "Nie możesz otworzyć tej skrzyni, odbierz pierwsze misje od poszukiwacza.",
  89.                         ['chat_inform_about_count_of_opened'] = "Do tej pory napotkałeś %d skrzyń.",
  90.                     },
  91.                    
  92.                     ['eng'] = {
  93.                         ['chat_skill_max_level'] = "You have maxium level of this skill.",
  94.                         ['chat_dont_have_item'] = "You don't have proper book to upgrade this skill.",
  95.                         ['chat_training_success'] = "You have successfully finished training!",
  96.                         ['chat_upgraded_to_master'] = "You have upgraded skill to the Master level.",
  97.                         ['chat_training_failed'] = "Training failed. Please try again later.",
  98.                         ['chat_cant_read_by_time'] = "You can't read this book now. Try again in %d minutes.",
  99.                         ['chat_opening_success'] = "Congratulations! You was able to open this box!",
  100.                         ['chat_opening_failed'] = "You didn't be able to open this box.",
  101.                         ['chat_cannot_open_box'] = "You can't open this box, go to Researcher and get mission before you do it again.",
  102.                         ['chat_inform_about_count_of_opened'] = "You already fount the %d boxes!",
  103.                     },
  104.                 },
  105.             }
  106.         end
  107.    
  108.         function getSkillLevel()
  109.             return tonumber(pc.get_skill_level(lockpicking.settings()['skillVnum']))
  110.         end
  111.    
  112.         function learnByBook()
  113.             -- check if player have item(just for sure)
  114.             if pc.count_item(lockpicking.settings()['skillBookVnum']) < 1 then
  115.                 chat(lockpicking.settings()['translation'][lockpicking.settings()['choosenLang']]['chat_dont_have_item'])
  116.                 return
  117.             end
  118.             -- check if player can read the book(time limit)
  119.             if pc.getqf("nextRead") >= get_time() and not pc.is_skill_book_no_delay() then
  120.                 chat(string.format(lockpicking.settings()['translation'][lockpicking.settings()['choosenLang']]['chat_cant_read_by_time'], math.floor((pc.getqf("nextRead") - get_time())/60) ))
  121.                 return
  122.             end
  123.             -- check if player have max level of skillVnum
  124.             if lockpicking.getSkillLevel() >= lockpicking.settings()['maxLevel'] then
  125.                 chat(lockpicking.settings()['translation'][lockpicking.settings()['choosenLang']]['chat_skill_max_level'])
  126.                 return
  127.             end
  128.            
  129.             local readChance
  130.             if pc.is_skill_book_always_read() then
  131.                 readChance = 0
  132.             else
  133.                 readChance = number(1, 100)
  134.             end
  135.            
  136.             pc.remove_item(lockpicking.settings()['skillBookVnum'], 1)
  137.             if pc.getqf("nextRead") >= get_time() then
  138.                 pc.remove_skill_book_no_delay()
  139.             end
  140.  
  141.             pc.remove_skill_book_always_read()
  142.             pc.setqf("nextRead", get_time() + ( (lockpicking.settings()['readDelay']) * 3600 ))
  143.            
  144.             if readChance <= lockpicking.settings()['bookReadChance'] then
  145.                 pc.set_skill_level(lockpicking.settings()['skillVnum'], lockpicking.getSkillLevel()+1)
  146.                
  147.                 -- other info when player advances to the max level
  148.                 if lockpicking.getSkillLevel() == lockpicking.settings()['maxLevel'] then
  149.                     chat(lockpicking.settings()['translation'][lockpicking.settings()['choosenLang']]['chat_training_success'])
  150.                     chat(lockpicking.settings()['translation'][lockpicking.settings()['choosenLang']]['chat_upgraded_to_master'])
  151.                 else
  152.                     chat(lockpicking.settings()['translation'][lockpicking.settings()['choosenLang']]['chat_training_success'])
  153.                 end
  154.             else
  155.                 chat(lockpicking.settings()['translation'][lockpicking.settings()['choosenLang']]['chat_training_failed'])
  156.             end
  157.         end
  158.    
  159.         function getCount(level)
  160.             if level >= 1 and level < 10 then
  161.                 return tonumber(lockpicking.settings()['defaultCount'])
  162.             elseif level >= 10 and level < 20 then
  163.                 return tonumber(lockpicking.settings()['defaultCount'] + number(0, 2))
  164.             elseif level >= 20 and level < 30 then
  165.                 return tonumber(lockpicking.settings()['defaultCount'] + number(1, 3))
  166.             elseif level >= 30 and level < 40 then
  167.                 return tonumber(lockpicking.settings()['defaultCount'] + number(1, 4))
  168.             elseif level >= lockpicking.settings()['maxLevel'] then
  169.                 return tonumber(lockpicking.settings()['defaultCount'] + number(2, 4))
  170.             else
  171.                 return 0
  172.             end
  173.         end
  174.    
  175.         function getChance(level)
  176.             if level == 1 then
  177.                 return tonumber(lockpicking.settings()['defaultChance'])
  178.             elseif level > 1 then
  179.                 return tonumber(lockpicking.settings()['defaultChance'] + level)
  180.             else
  181.                 return -1
  182.             end
  183.         end
  184.        
  185.         function get_reward_from_box()
  186.             local reward_table = {
  187.                 {['vnum'] = 30096, ['count'] = 3, ['chance'] = 100}, -- one of these records must have value 100
  188.                 {['vnum'] = 71001, ['count'] = 1, ['chance'] = 20},
  189.                 {['vnum'] = 71094, ['count'] = 1, ['chance'] = 20},
  190.                 {['vnum'] = 71084, ['count'] = 15, ['chance'] = 70},
  191.                 {['vnum'] = 71085, ['count'] = 15, ['chance'] = 60},
  192.                 {['vnum'] = 71084, ['count'] = 20, ['chance'] = 50},
  193.                 {['vnum'] = 71085, ['count'] = 20, ['chance'] = 50},
  194.                 {['vnum'] = 71084, ['count'] = 10, ['chance'] = 90},
  195.                 {['vnum'] = 71085, ['count'] = 10, ['chance'] = 90},
  196.                 {['vnum'] = 71107, ['count'] = 1, ['chance'] = 45},
  197.                 {['vnum'] = 71153, ['count'] = 1, ['chance'] = 5},
  198.                 {['vnum'] = 71044, ['count'] = 3, ['chance'] = 45},
  199.                 {['vnum'] = 71045, ['count'] = 3, ['chance'] = 45},
  200.                 {['vnum'] = 71027, ['count'] = 2, ['chance'] = 35},
  201.                 {['vnum'] = 71028, ['count'] = 2, ['chance'] = 35},
  202.                 {['vnum'] = 71029, ['count'] = 2, ['chance'] = 50},
  203.                 {['vnum'] = 71030, ['count'] = 2, ['chance'] = 50},
  204.                 {['vnum'] = 71032, ['count'] = 1, ['chance'] = 35},
  205.                 {['vnum'] = 71034, ['count'] = 3, ['chance'] = 60},
  206.                 {['vnum'] = 71080, ['count'] = 1, ['chance'] = 40},
  207.                 {['vnum'] = 71081, ['count'] = 1, ['chance'] = 30},
  208.                 {['vnum'] = 71082, ['count'] = 1, ['chance'] = 20},
  209.                 {['vnum'] = 70004, ['count'] = 1, ['chance'] = 15},
  210.                 {['vnum'] = 30096, ['count'] = 5, ['chance'] = 75},
  211.                 {['vnum'] = 70102, ['count'] = 3, ['chance'] = 60},
  212.                 {['vnum'] = 25040, ['count'] = 1, ['chance'] = 45},
  213.                 {['vnum'] = 50002, ['count'] = 1, ['chance'] = 75},
  214.                 {['vnum'] = 50006, ['count'] = 1, ['chance'] = 60},
  215.                 {['vnum'] = 50007, ['count'] = 1, ['chance'] = 70},
  216.                 {['vnum'] = 50008, ['count'] = 1, ['chance'] = 40},
  217.                 {['vnum'] = 50009, ['count'] = 1, ['chance'] = 50},
  218.                 {['vnum'] = 50012, ['count'] = 1, ['chance'] = 40},
  219.                 {['vnum'] = 50013, ['count'] = 1, ['chance'] = 45},
  220.                 {['vnum'] = 50034, ['count'] = 3, ['chance'] = 60},
  221.                 {['vnum'] = 50216, ['count'] = 1, ['chance'] = 60},
  222.                 {['vnum'] = 71210, ['count'] = 2, ['chance'] = 90},
  223.                 {['vnum'] = 51503, ['count'] = 3, ['chance'] = 70},
  224.                 {['vnum'] = 51504, ['count'] = 1, ['chance'] = 50},
  225.                 {['vnum'] = 71016, ['count'] = 1, ['chance'] = 45},
  226.                 {['vnum'] = 71018, ['count'] = 5, ['chance'] = 60},
  227.                 {['vnum'] = 71019, ['count'] = 5, ['chance'] = 60},
  228.                 {['vnum'] = 71019, ['count'] = 5, ['chance'] = 60},
  229.                 {['vnum'] = 71020, ['count'] = 5, ['chance'] = 60},
  230.                 {['vnum'] = 50157, ['count'] = 1, ['chance'] = 45},
  231.                 {['vnum'] = 77004, ['count'] = 1, ['chance'] = 65},
  232.                 {['vnum'] = 77005, ['count'] = 1, ['chance'] = 40},
  233.                 {['vnum'] = 80022, ['count'] = 1, ['chance'] = 30},
  234.                 {['vnum'] = 80021, ['count'] = 1, ['chance'] = 25},
  235.                 {['vnum'] = 30500, ['count'] = 5, ['chance'] = 60},
  236.                 {['vnum'] = 30501, ['count'] = 4, ['chance'] = 60},
  237.                 {['vnum'] = 30502, ['count'] = 3, ['chance'] = 60},
  238.                 {['vnum'] = 30503, ['count'] = 2, ['chance'] = 60},
  239.                 {['vnum'] = 30504, ['count'] = 1, ['chance'] = 60},
  240.                 {['vnum'] = 80010, ['count'] = 1, ['chance'] = 100},
  241.                 {['vnum'] = 80011, ['count'] = 1, ['chance'] = 50},
  242.                 {['vnum'] = 80012, ['count'] = 1, ['chance'] = 40},
  243.                 {['vnum'] = 80013, ['count'] = 1, ['chance'] = 30},
  244.                 {['vnum'] = 80018, ['count'] = 1, ['chance'] = 20},
  245.                 {['vnum'] = 80017, ['count'] = 1, ['chance'] = 15},
  246.                 {['vnum'] = 80014, ['count'] = 1, ['chance'] = 15},
  247.                 {['vnum'] = 72725, ['count'] = 1, ['chance'] = 40},
  248.                 {['vnum'] = 72729, ['count'] = 1, ['chance'] = 40},
  249.                 {['vnum'] = 72726, ['count'] = 1, ['chance'] = 25},
  250.                 {['vnum'] = 72730, ['count'] = 1, ['chance'] = 25},
  251.                 {['vnum'] = 72703, ['count'] = 1, ['chance'] = 5},
  252.                 {['vnum'] = 72704, ['count'] = 1, ['chance'] = 5},
  253.                 {['vnum'] = 72705, ['count'] = 1, ['chance'] = 5},
  254.                 {['vnum'] = 72706, ['count'] = 1, ['chance'] = 5},
  255.                 {['vnum'] = 71050, ['count'] = 1, ['chance'] = 50},
  256.                 {['vnum'] = 50107, ['count'] = 5, ['chance'] = 50}
  257.             }
  258.             local itemChance = number(1, 100)
  259.             local itemVnum = 0
  260.             local itemCount = 0
  261.             repeat
  262.                 local idx = number(1, table.getn(reward_table))
  263.                 if itemChance <= reward_table[idx]['chance'] then
  264.                     itemVnum = reward_table[idx]['vnum']
  265.                     itemCount = reward_table[idx]['count']
  266.                 end
  267.             until (itemVnum != 0 and itemCount != 0)
  268.             return {itemVnum, itemCount}
  269.         end
  270.    
  271.         function openBox(byKey)
  272.             local chance
  273.             if byKey == true then
  274.                 chance = 100
  275.             else
  276.                 chance = lockpicking.getChance(lockpicking.getSkillLevel())
  277.             end
  278.            
  279.             if chance == -1 then
  280.                 chat(lockpicking.settings()['translation'][lockpicking.settings()['choosenLang']]['chat_cannot_open_box'])
  281.                 return
  282.             end
  283.             npc.purge() -- remove NPC from map
  284.            
  285.             if number(1, 100) <= chance then
  286.                 chat(lockpicking.settings()['translation'][lockpicking.settings()['choosenLang']]['chat_opening_success'])
  287.                 for i = 1, lockpicking.getCount(lockpicking.getSkillLevel()) do
  288.                     local rewardTable = lockpicking.get_reward_from_box()
  289.                     pc.give_item2(rewardTable[1], rewardTable[2])
  290.                 end
  291.             else
  292.                 chat(lockpicking.settings()['translation'][lockpicking.settings()['choosenLang']]['chat_opening_failed'])
  293.             end
  294.         end
  295.        
  296.         function increaseOpenedCount()
  297.             if lockpicking.getSkillLevel() < 1 then
  298.                 return
  299.             end
  300.             local opened = pc.getqf("openedBoxes")
  301.             pc.setqf("openedBoxes", opened + 1)
  302.             chat(string.format(lockpicking.settings()['translation'][lockpicking.settings()['choosenLang']]['chat_inform_about_count_of_opened'], opened+1))
  303.         end
  304.        
  305.         when 51033.use begin
  306.             lockpicking.learnByBook()
  307.         end
  308.    
  309.         -- click on box npc
  310.         when 20130.click begin
  311.             lockpicking.increaseOpenedCount()
  312.             lockpicking.openBox(false)
  313.         end
  314.        
  315.         -- user Special Item to open Box
  316.         when 20130.take with item.vnum == 51040 begin
  317.         lockpicking.increaseOpenedCount()
  318.             if lockpicking.getSkillLevel() < 1 then
  319.                 chat(lockpicking.settings()['translation'][lockpicking.settings()['choosenLang']]['chat_cannot_open_box'])
  320.                 return
  321.             end
  322.        
  323.              -- set flag, that item was first used
  324.             if item.get_socket(1) != 1 then
  325.                 item.set_socket(1, 1)
  326.                 item.set_socket(0, lockpicking.settings()['keyAllowUse']) -- set the count for using key
  327.             end
  328.            
  329.             if item.get_socket(0) > 0 then
  330.                 item.set_socket(0, item.get_socket(0) - 1)
  331.                 if item.get_socket(0) == 0 then
  332.                     item.remove()
  333.                 end
  334.                
  335.                 lockpicking.openBox(true)
  336.             end
  337.         end
  338.        
  339.         -- talk with quest NPC
  340.         when 20131.chat."Kim jesteś?" begin
  341.             say_title(mob_name(20131))
  342.             say("")
  343.             say("Witaj Poszukiwaczu Przygód!")
  344.             say("Ja też jestem Poszukiwaczem! Szukam skarbów ")
  345.             say("ukrytych w zakamarkach starych skrzyń.")
  346.             say("")
  347.             say("Po osiągnięciu 90 poziomu będę potrzebował ")
  348.             say("Twojej pomocy. Na nowo odkrytych mapach ")
  349.             say("widzieliśmy wiele starych, drogocennych skrzyń!")
  350.             say("")
  351.         end
  352.        
  353.         when 20131.chat."Spróchniałe Skrzynie" begin
  354.             say_title(mob_name(20131))
  355.             say("")
  356.             say("Witaj Poszukiwaczu Przygód!")
  357.             say("Chcesz dowiedzieć się coś o Spróchniałych Skrzyniach? ")
  358.             say("Na nowo odkrytych mapach widzieliśmy dużo tych skrzyń.")
  359.             say("Wyglądem przypominają szkatułki Władców, lecz skrywają ")
  360.             say("cenniejsze nagrody.")
  361.             say("")
  362.             say("Po osiągnięciu 90 poziomu będę potrzebował ")
  363.             say("Twojej pomocy. Na nowo odkrytych mapach ")
  364.             say("widzieliśmy wiele starych, drogocennych skrzyń!")
  365.             say("")
  366.         end
  367.        
  368.     end
  369. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement