_Q_ Posted October 21, 2014 Share Posted October 21, 2014 I'm making custom items that let you plant 10x10 pinecones and other plants just with one item.Now I would like to spawn placer for every point the pinecone will be placed.local assets ={Asset("ANIM", "anim/acorn.zip")}local notags = {'NOBLOCK', 'player', 'FX'}local function test_ground(inst, pt) local spawn_points = {} local pos = pt for i = 1, 10 do table.insert(spawn_points, {x = pos.x, y = pos.y, z = pos.z}) pos.x = pos.x + 2 pos.z = pos.z + 2 end local num = 0 for k,v in pairs(spawn_points) do pos = Vector3(v.x, v.y, v.z) local tiletype = GetGroundTypeAtPosition(pos) local ground_OK = tiletype ~= GROUND.ROCKY and tiletype ~= GROUND.ROAD and tiletype ~= GROUND.IMPASSABLE and tiletype ~= GROUND.UNDERROCK and tiletype ~= GROUND.WOODFLOOR and tiletype ~= GROUND.CARPET and tiletype ~= GROUND.CHECKER and tiletype < GROUND.UNDERGROUND if ground_OK then local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, 4, nil, notags) 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()), pos) < min_spacing*min_spacing then num = num -1 end end end num = num +1 end end if num == 10 then pt.x = pt.x - 20 pt.z = pt.z -20 return true else pt.x = pt.x - 20 pt.z = pt.z -20 return false endendlocal function growtree(inst) print ("GROWTREE") inst.growtask = nil inst.growtime = nil local tree = SpawnPrefab("deciduoustree") if tree then tree.Transform:SetPosition(inst.Transform:GetWorldPosition() ) tree:growfromseed()--PushEvent("growfromseed") inst:Remove() endendlocal function plant_many(inst, growtime) inst:RemoveComponent("inventoryitem") RemovePhysicsColliders(inst) inst.AnimState:PlayAnimation("idle_planted") inst.SoundEmitter:PlaySound("dontstarve/wilson/plant_tree") inst.growtime = GetTime() + growtime if inst.components.edible then inst:RemoveComponent("edible") end print ("PLANT", growtime) inst.growtask = inst:DoTaskInTime(growtime, growtree)endlocal function ondeploy (inst, pt) local starting_point = pt local pos = pt local spacing = 2 for i = 1, 10 do for j = 1, 10 do local acorn = SpawnPrefab("acorn") if acorn then acorn.Transform:SetPosition(pos.x,pos.y,pos.z) acorn:RemoveComponent("perishable") local timeToGrow = GetRandomWithVariance(TUNING.ACORN_GROWTIME.base, TUNING.ACORN_GROWTIME.random) plant_many(acorn, timeToGrow) pos = Point(acorn.Transform:GetWorldPosition()) end pos.x = pos.x + spacing pos.z = pos.z + spacing end pos = starting_point pos.x = pos.x + spacing pos.z = pos.z - spacing end inst.components.stackable:Get():Remove() endlocal function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() MakeInventoryPhysics(inst) inst.AnimState:SetBank("acorn") inst.AnimState:SetBuild("acorn") inst.AnimState:PlayAnimation("idle") inst:AddComponent("stackable") inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM inst:AddComponent("inventoryitem") inst:AddComponent("deployable") inst.components.deployable.test = test_ground inst.components.deployable.ondeploy = ondeploy return instendreturn Prefab( "common/inventory/acorn_2x2", fn, assets, prefabs), MakePlacer( "common/acorn_2x2_placer", "acorn", "acorn", "idle_planted" ) Link to comment Share on other sites More sharing options...
chromiumboy Posted October 21, 2014 Share Posted October 21, 2014 I think you'd need to modify playercontroller.lua, in the functions used to build or deploy something. Link to comment Share on other sites More sharing options...
Cyde042 Posted October 21, 2014 Share Posted October 21, 2014 I'm not the best person to get advice from on this matter but, the only thing I could imagine is either doing it dirty and making a custom animation, or maybe you could use the matrix algorithm with make placer (if it's even possible to bind multiple placers to the same prefab)? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.