Advertisement
Starly124

Untitled

Feb 11th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. for i,v in ipairs(plantables) do
  2. AddPrefabPostInit(v.plant, function(inst)
  3. local function test_turf(inst, tiletype)
  4. if v.validTurf then
  5. for i,turf in ipairs(v.validTurf) do
  6. if tiletype == turf then
  7. return true
  8. end
  9. end
  10. return false
  11. end
  12. if v.invalidTurf then
  13. for i,turf in ipairs(v.invalidTurf) do
  14. if tiletype == turf then
  15. return false
  16. end
  17. end
  18. return true
  19. end
  20. return true
  21. end
  22.  
  23. local function test_ground(inst, pt)
  24. if v.turfExtras then
  25. if not v.turfExtras() then
  26. return false
  27. end
  28. end
  29.  
  30. local tiletype = GetGroundTypeAtPosition(pt)
  31. local ground_OK = test_turf(inst, tiletype) and tiletype < GROUND.UNDERGROUND
  32.  
  33. if ground_OK then
  34. local notags = {'NOBLOCK', 'player', 'FX'}
  35. local ents = TheSim:FindEntities(pt.x,pt.y,pt.z, 4, nil, notags) -- or we could include a flag to the search?
  36. local min_spacing = inst.components.deployable.min_spacing or 2
  37.  
  38. for k, v in pairs(ents) do
  39. if v ~= inst and v.entity:IsValid() and v.entity:IsVisible() and not v.components.placer and v.parent == nil then
  40. if distsq( Vector3(v.Transform:GetWorldPosition()), pt) < min_spacing*min_spacing then
  41. return false
  42. end
  43. end
  44. end
  45.  
  46. return true
  47.  
  48. end
  49. return false
  50. end
  51.  
  52. local function CanDeploy(inst) return true end
  53. local function OnDeploy(inst, pt, deployer)
  54. local flower = SpawnPrefab(v.spawn or v.altSpawn())
  55. if flower then
  56. flower.Transform:SetPosition(pt.x, pt.y, pt.z)
  57. inst.components.stackable:Get():Remove()
  58. if v.deployExtras then
  59. v.deployExtras(inst, pt, deployer, flower)
  60. end
  61. if v.sounds then
  62. if not flower.SoundEmitter then
  63. flower.entity:AddSoundEmitter()
  64. end
  65. for i,sound in ipairs(v.sounds) do
  66. flower.SoundEmitter:PlaySound(sound)
  67. end
  68. end
  69. end
  70. end
  71.  
  72. inst:AddComponent("deployable")
  73. inst.components.deployable.ondeploy = OnDeploy
  74. inst.components.deployable.test = test_ground
  75. if v.spacing then
  76. inst.components.deployable.min_spacing = v.spacing
  77. end
  78. end)
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement