Advertisement
1x_Gacha

NPC Dialogue | Local

Aug 16th, 2020 (edited)
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.01 KB | None | 0 0
  1. local localPlayer = game.Players.LocalPlayer
  2.  
  3. local parent = script.Parent
  4.  
  5. local storage = game:GetService('ReplicatedStorage')
  6. local remote = storage.Remotes.Dialogue
  7. local tollremote = storage.Remotes.PayToll
  8. local eventremote = storage.Remotes.EventTrigger
  9. local marketremote = storage:WaitForChild('Remotes'):WaitForChild('BlackMarket')
  10.  
  11. local m = require(storage.Resources.Dialogue)
  12. local deb = false
  13. local deb2 = false
  14. local inchat = false
  15.  
  16. local playerHolder = parent.PT
  17. local npcHolder = parent.NPCT
  18. local sample = script.Sample
  19.  
  20. --local InEvent = localPlayer:WaitForChild('Bools'):WaitForChild('InEvent')
  21.  
  22. local function animate(phrase)
  23.     local text = phrase
  24.     for i = 1, #text do
  25.         npcHolder.RES.Text = string.sub(text, 1, i)
  26.         wait(.1)
  27.     end
  28. end
  29.  
  30. local function clearChat()
  31.     for i,v in pairs(playerHolder:GetChildren())do
  32.         if v:IsA('ImageLabel')then
  33.             v:Destroy()
  34.         end
  35.     end
  36.     npcHolder.RES.Text = " "
  37. end
  38.  
  39. local function ELOOP(event)
  40.     parent.Visible = true
  41.     local FIRE = m.dialogue[event]
  42.     animate(FIRE['Dialog1']['NPCRES']['INITIAL'])
  43.     wait(2)
  44.     for i,v in pairs(FIRE['Dialog1']['PRES'])do
  45.         local clone = sample:Clone()
  46.         clone.Name = i
  47.         clone.RES.Text = v
  48.         clone.Parent = playerHolder
  49.         clone.RES.MouseButton1Click:Connect(function()
  50.             if deb2 then return end
  51.             deb2 = true
  52.             clearChat()
  53.             animate(FIRE['Dialog1']['NPCRES'][clone.Name])
  54.             wait(2)
  55.             if FIRE['Dialog2'] and not clone.Name == 'EXIT'then
  56.                 print('MORE')
  57.                 deb2 = false
  58.             else
  59.                 clearChat()
  60.                 parent.Visible = false
  61.                 inchat = false
  62.                 deb2 = false
  63.             end
  64.         end)
  65.     end
  66. end
  67.  
  68.  
  69.  
  70. local function EEVENT(event)
  71.     parent.Visible = true
  72.     local FIRE = m.dialogue[event]
  73.     local InEvent = localPlayer:FindFirstChild('Bools'):FindFirstChild('InEvent')
  74.     local completed = localPlayer:FindFirstChild('Bools'):FindFirstChild('IsComplete')
  75.    
  76.     if InEvent.Value == true then
  77.        
  78.         eventremote:FireServer('CHECK', m.dialogue[event]['EVENT'])
  79.         wait(1)
  80.         print(completed.Value)
  81.        
  82.         if completed.Value == true then
  83.             print('CHECK TRUE IS COMPLETE')
  84.             animate(m.dialogue[event]['COMPLETE']['NPCRES']['INITIAL'])
  85.             wait(2)
  86.             for i,v in pairs(m.dialogue[event]['COMPLETE']['PRES'])do
  87.                 local clone = sample:Clone()
  88.                 clone.Name = i
  89.                 clone.RES.Text = v
  90.                 clone.Parent = playerHolder
  91.                 clone.RES.MouseButton1Click:Connect(function()
  92.                     if deb2 then return end
  93.                     deb2 = true
  94.                     if clone.Name == 'EXIT'then
  95.                         clearChat()
  96.                         parent.Visible = false
  97.                         inchat = false
  98.                         deb2 = false
  99.                     end
  100.                 end)
  101.             end
  102.         else
  103.             print('CHECK FALSE NOT COMPLETE')
  104.             animate(m.dialogue[event]['ACTIVE']['NPCRES']['INITIAL'])
  105.             wait(2)
  106.             for i,v in pairs(m.dialogue[event]['ACTIVE']['PRES'])do
  107.                 local clone = sample:Clone()
  108.                 clone.Name = i
  109.                 clone.RES.Text = v
  110.                 clone.Parent = playerHolder
  111.                 clone.RES.MouseButton1Click:Connect(function()
  112.                     if deb2 then return end
  113.                     deb2 = true
  114.                     if clone.Name == 'EXIT'then
  115.                         clearChat()
  116.                         parent.Visible = false
  117.                         inchat = false
  118.                         deb2 = false
  119.                     end
  120.                 end)
  121.             end
  122.         end
  123.     else
  124.         animate(m.dialogue[event]['Dialog1']['NPCRES']['INITIAL'])
  125.         wait(2)
  126.         for i,v in pairs(m.dialogue[event]['Dialog1']['PRES'])do
  127.             local clone = sample:Clone()
  128.             clone.Name = i
  129.             clone.RES.Text = v
  130.             clone.Parent = playerHolder
  131.             clone.RES.MouseButton1Click:Connect(function()
  132.                 if deb2 then return end
  133.                 deb2 = true
  134.                 if clone.Name == 'EXIT'then
  135.                     clearChat()
  136.                     animate(m.dialogue[event]['Dialog1']['NPCRES']['EXIT'])
  137.                     wait(2)
  138.                     parent.Visible = false
  139.                     inchat = false
  140.                     deb2 = false
  141.                 elseif clone.Name == 'RES1' then
  142.                     clearChat()
  143.                     animate(m.dialogue[event]['Dialog1']['NPCRES']['RES1'])
  144.                     wait(2)
  145.                     eventremote:FireServer('REGISTER', m.dialogue[event]['EVENT'])     
  146.                     clearChat()
  147.                     parent.Visible = false
  148.                     inchat = false
  149.                     deb2 = false   
  150.                 end
  151.             end)
  152.         end
  153.     end
  154. end
  155.  
  156. local function ESMALL(event)
  157.     parent.Visible = true
  158.     local FIRE = m.dialogue[event]
  159.     animate(FIRE['NPCRES']['INITIAL'])
  160.     wait(2)
  161.     clearChat()
  162.     parent.Visible = false
  163.     inchat = false
  164. end
  165.  
  166. local function ETELEPORT(event, city)
  167.     parent.Visible = true
  168.     local FIRE = m.dialogue[event]
  169.     animate(FIRE['NPCRES']['INITIAL'])
  170.     wait(2)
  171.     for i,v in pairs(FIRE['PRES'])do
  172.         local clone = sample:Clone()
  173.         clone.Name = i
  174.         clone.RES.Text = v
  175.         clone.Parent = playerHolder
  176.         clone.RES.MouseButton1Click:Connect(function()
  177.             if deb2 then return end
  178.             deb2 = true
  179.             clearChat()
  180.             animate(FIRE['NPCRES'][clone.Name])
  181.             wait(2)
  182.             if clone.Name == 'EXIT'then
  183.                 deb2 = false
  184.                 clearChat()
  185.                 parent.Visible = false
  186.                 inchat = false
  187.             else
  188.                 deb2 = false
  189.                 clearChat()
  190.                 parent.Visible = false
  191.                 inchat = false
  192.                 tollremote:FireServer(city)
  193.             end
  194.         end)
  195.     end
  196. end
  197.  
  198. local function ESTORE(event)
  199.     parent.Visible = true
  200.     local FIRE = m.dialogue[event]
  201.     animate(FIRE['Dialog1']['NPCRES']['INITIAL'])
  202.     wait(2)
  203.     for i,v in pairs(FIRE['Dialog1']['PRES'])do
  204.         local clone = sample:Clone()
  205.         clone.Name = i
  206.         clone.RES.Text = v
  207.         clone.Parent = playerHolder
  208.         clone.RES.MouseButton1Click:Connect(function()
  209.             if deb2 then return end
  210.             deb2 = true
  211.             clearChat()
  212.             animate(FIRE['Dialog1']['NPCRES'][clone.Name])
  213.             wait(2)
  214.             if clone.Name == 'EXIT' then
  215.                 deb2 = false
  216.                 clearChat()
  217.                 parent.Visible = false
  218.                 inchat = false
  219.             else
  220.                 deb2 = false
  221.                 clearChat()
  222.                 parent.Visible = false
  223.                 inchat = false
  224.                 marketremote:FireServer('OPEN')
  225.             end
  226.         end)
  227.     end
  228. end
  229.  
  230.  
  231. remote.OnClientEvent:Connect(function(event, city)
  232.     if deb then return end
  233.     deb = true
  234.     if inchat then wait(1) deb = false return end
  235.     inchat = true
  236.     deb = false
  237.     local FIRE = m.dialogue[event]['TYPE']
  238.     if FIRE == 'LOOP' then
  239.         ELOOP(event)
  240.     elseif
  241.         FIRE == "EVENT" then
  242.         EEVENT(event)
  243.     elseif
  244.         FIRE == "SMALL" then
  245.         ESMALL(event)
  246.     elseif
  247.         FIRE == "TELEPORT" then
  248.         ETELEPORT(event, city)
  249.     elseif
  250.         FIRE == 'STORE' then
  251.         ESTORE(event)
  252.     end
  253. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement