Advertisement
Starly124

Untitled

Feb 11th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. --Milkable
  2. --How long the Countdown lasts.
  3. local beefalo_Countdown = 60
  4.  
  5.  
  6.  
  7. local function omm_trade_test(inst, item)
  8. if inst.components.sleeper:IsAsleep() then
  9. return false
  10. elseif item.components.tradable and item:HasTag("MILKBUCKET") and inst.components.Countdown:IsReady() then
  11. return true
  12. else
  13. return false
  14. end
  15. end
  16.  
  17. local function omm_trade_fn(inst, giver, item)
  18. if GLOBAL.GetPlayer() and GLOBAL.GetPlayer().components.inventory then
  19. local red_cap = SpawnPrefab("red_cap")
  20. GLOBAL.GetPlayer().components.inventory:GiveItem(red_cap)
  21. local blue_cap = SpawnPrefab("blue_cap")
  22. GLOBAL.GetPlayer().components.inventory:GiveItem(blue_cap)
  23.  
  24. --Reset the Countdown.
  25. inst.components.Countdown:SetCountdown(beefalo_Countdown)
  26. end
  27. end
  28.  
  29.  
  30.  
  31. local function make_milkable(inst)
  32. inst:AddComponent("trader")
  33. inst.components.trader:SetAcceptTest(omm_trade_test)
  34. inst.components.trader.onaccept = omm_trade_fn
  35. inst.components.trader:Enable()
  36.  
  37. inst:AddComponent("Countdown")
  38. inst.components.Countdown.countdown_max = beefalo_Countdown
  39. inst.components.Countdown:StartCountdown()
  40. end
  41. AddPrefabPostInit("beefalo", make_milkable)
  42.  
  43.  
  44. local milk_items = {"cutgrass","twigs",}
  45.  
  46. local function milktag(inst)
  47. inst:AddTag("MILKBUCKET")
  48. if not inst.components.tradable then
  49. inst:AddComponent("tradable")
  50. end
  51. end
  52. for key,prefab in pairs(milk_items) do
  53. AddPrefabPostInit(prefab, milktag)
  54. end
  55. --Milkable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement