Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for i,v in ipairs(plantables) do
- AddPrefabPostInit(v.plant, function(inst)
- local function test_turf(inst, tiletype)
- if v.validTurf then
- for i,turf in ipairs(v.validTurf) do
- if tiletype == turf then
- return true
- end
- end
- return false
- end
- if v.invalidTurf then
- for i,turf in ipairs(v.invalidTurf) do
- if tiletype == turf then
- return false
- end
- end
- return true
- end
- return true
- end
- local function test_ground(inst, pt)
- if v.turfExtras then
- if not v.turfExtras() then
- return false
- end
- end
- local tiletype = GetGroundTypeAtPosition(pt)
- local ground_OK = test_turf(inst, tiletype) and tiletype < GROUND.UNDERGROUND
- if ground_OK then
- local notags = {'NOBLOCK', 'player', 'FX'}
- local ents = TheSim:FindEntities(pt.x,pt.y,pt.z, 4, nil, notags) -- or we could include a flag to the search?
- local min_spacing = inst.components.deployable.min_spacing or 2
- for k, v in pairs(ents) do
- if v ~= inst and v.entity:IsValid() and v.entity:IsVisible() and not v.components.placer and v.parent == nil then
- if distsq( Vector3(v.Transform:GetWorldPosition()), pt) < min_spacing*min_spacing then
- return false
- end
- end
- end
- return true
- end
- return false
- end
- local function CanDeploy(inst) return true end
- local function OnDeploy(inst, pt, deployer)
- local flower = SpawnPrefab(v.spawn or v.altSpawn())
- if flower then
- flower.Transform:SetPosition(pt.x, pt.y, pt.z)
- inst.components.stackable:Get():Remove()
- if v.deployExtras then
- v.deployExtras(inst, pt, deployer, flower)
- end
- if v.sounds then
- if not flower.SoundEmitter then
- flower.entity:AddSoundEmitter()
- end
- for i,sound in ipairs(v.sounds) do
- flower.SoundEmitter:PlaySound(sound)
- end
- end
- end
- end
- inst:AddComponent("deployable")
- inst.components.deployable.ondeploy = OnDeploy
- inst.components.deployable.test = test_ground
- if v.spacing then
- inst.components.deployable.min_spacing = v.spacing
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement