goldfish911 Posted February 10, 2015 Share Posted February 10, 2015 So I have a prefab for a custom buildable set up, and it uses prefabutil.lua to create a placeable for it.However, I cannot seem to figure out how placers work. By placer I mean the green outline you get when building something like a science machine. Adding a recipe to modmain that crafts "custombuilding_placer" (the name of the placer) results in a single framed custom building spawning at the player's location. So how can I go about making the placer thing work?Any help would be greatly appreciated! Link to comment https://forums.kleientertainment.com/forums/topic/50798-how-do-i-build-a-custom-buildable-using-a-placer/ Share on other sites More sharing options...
Corrosive Posted February 10, 2015 Share Posted February 10, 2015 It's hard to give specifics without seeing your prefab code so far, but technically your recipe should be crafting "custombuilding" and also pass the name of the placer. Your prefab file should return both a Prefab(...) and a MakePlacer(...). I assume this is what you're doing already. Take a look at recipe.lua for the parameter list of its constructor function:Recipe = Class(function(self, name, ingredients, tab, level, placer, min_spacing, nounlock, numtogive)The min_spacing parameter defines how big of an area placement requires. it defaults to 3.2 if you don't pass this argument. Your building recipe will look something like:Recipe("custombuilding", {Ingredient("boards", 3)}, RECIPETABS.TOWN, TECH.SCIENCE_ONE, "custombuilding_placer", 4)----- Your placer will push an "onbuilt" event, so you need your prefab to listen for this if you want an animation when it gets built. Assuming you have called inst.entity:AddAnimState() in your prefab's initialization function with something like local anim = inst.entity:AddAnimState(), and also set the build and bank name, you can do that like this:inst:ListenForEvent( "onbuilt", function() anim:PlayAnimation("place") anim:PushAnimation("idle",false) -- chains the idle animation onto the end of the place animation inst.SoundEmitter:PlaySound("path/to/yoursound") -- You have to have added a SoundEmitter prior, naturallyend)You should take a peek into the placer.lua component to see what's going on behind the scenes. Link to comment https://forums.kleientertainment.com/forums/topic/50798-how-do-i-build-a-custom-buildable-using-a-placer/#findComment-611602 Share on other sites More sharing options...
goldfish911 Posted February 10, 2015 Author Share Posted February 10, 2015 It's hard to give specifics without seeing your prefab code so far, but technically your recipe should be crafting "custombuilding" and also pass the name of the placer. Your prefab file should return both a Prefab(...) and a MakePlacer(...). I assume this is what you're doing already. Take a look at recipe.lua for the parameter list of its constructor function:Recipe = Class(function(self, name, ingredients, tab, level, placer, min_spacing, nounlock, numtogive)The min_spacing parameter defines how big of an area placement requires. it defaults to 3.2 if you don't pass this argument. Your building recipe will look something like:Recipe("custombuilding", {Ingredient("boards", 3)}, RECIPETABS.TOWN, TECH.SCIENCE_ONE, "custombuilding_placer", 4)----- Your placer will push an "onbuilt" event, so you need your prefab to listen for this if you want an animation when it gets built. Assuming you have called inst.entity:AddAnimState() in your prefab's initialization function with something like local anim = inst.entity:AddAnimState(), and also set the build and bank name, you can do that like this:inst:ListenForEvent( "onbuilt", function() anim:PlayAnimation("place") anim:PushAnimation("idle",false) -- chains the idle animation onto the end of the place animation inst.SoundEmitter:PlaySound("path/to/yoursound") -- You have to have added a SoundEmitter prior, naturallyend)You should take a peek into the placer.lua component to see what's going on behind the scenes.Wow. You are a lifesaver. Your assumptions were both correct, a prefab was made, along with a placer(as that's what I was mistakenly building) I understand that the "onbuilt" event is called, I just don't understand what triggers it. Is the recipe.lua responsible? Link to comment https://forums.kleientertainment.com/forums/topic/50798-how-do-i-build-a-custom-buildable-using-a-placer/#findComment-611606 Share on other sites More sharing options...
Corrosive Posted February 10, 2015 Share Posted February 10, 2015 I understand that the "onbuilt" event is called, I just don't understand what triggers it. Is the recipe.lua responsible? This one is a bit of a rabbit hole, but essentially the event gets pushed by builder.lua, which defines the builder component that is attached to the player in player_common.lua. That's what handles recipes. You'll notice that it pushes two events since not everything gets every event:self.inst:PushEvent("buildstructure", {item=prod, recipe = recipe})prod:PushEvent("onbuilt") Link to comment https://forums.kleientertainment.com/forums/topic/50798-how-do-i-build-a-custom-buildable-using-a-placer/#findComment-611645 Share on other sites More sharing options...
goldfish911 Posted February 10, 2015 Author Share Posted February 10, 2015 This one is a bit of a rabbit hole, but essentially the event gets pushed by builder.lua, which defines the builder component that is attached to the player in player_common.lua. That's what handles recipes. You'll notice that it pushes two events since not everything gets every event:self.inst:PushEvent("buildstructure", {item=prod, recipe = recipe})prod:PushEvent("onbuilt") Alright, thanks! Link to comment https://forums.kleientertainment.com/forums/topic/50798-how-do-i-build-a-custom-buildable-using-a-placer/#findComment-611658 Share on other sites More sharing options...
Foxrai Posted February 10, 2015 Share Posted February 10, 2015 (edited) Alright, thanks! Acctually I think I made it little easier way: From scratch - create custom item http://forums.kleientertainment.com/topic/29427-tutorial-creating-a-handslot-equippable-item-from-scratch/ - POINT 3 for you from this tutorial above- need only "ground item" image any size you need, and of course inventoryimage 64x64pixels. In your character.lua: local youritem_recipe = Recipe("youritem", {Ingredient("rocks", 2)}, RECIPETABS.TOWN, TECH.NONE, "youritem_placer" )youritem_recipe.sortkey = 2youritem_recipe.atlas = resolvefilepath("images/inventoryimages/youritem.xml")STRINGS.RECIPE_DESC.YOURITEM = "it's my item!!!"part in the red adds the "green shadow" you use to place your items on the ground. Without that character will build item just under his feet. in youritem.lua: inst.AnimState:SetBank("youritem") inst.AnimState:SetBuild("youritem") inst.AnimState:PlayAnimation("idle") <<< animation you made in Spriter Don't really need the "ONBUILT" from what i noticed. I don't have it - and all works fine. Edited February 10, 2015 by Foxrai Link to comment https://forums.kleientertainment.com/forums/topic/50798-how-do-i-build-a-custom-buildable-using-a-placer/#findComment-611820 Share on other sites More sharing options...
goldfish911 Posted February 11, 2015 Author Share Posted February 11, 2015 Acctually I think I made it little easier way: From scratch - create custom item http://forums.kleientertainment.com/topic/29427-tutorial-creating-a-handslot-equippable-item-from-scratch/ - POINT 3 for you from this tutorial above- need only "ground item" image any size you need, and of course inventoryimage 64x64pixels. In your character.lua: local youritem_recipe = Recipe("youritem", {Ingredient("rocks", 2)}, RECIPETABS.TOWN, TECH.NONE, "youritem_placer" )youritem_recipe.sortkey = 2youritem_recipe.atlas = resolvefilepath("images/inventoryimages/youritem.xml")STRINGS.RECIPE_DESC.YOURITEM = "it's my item!!!"part in the red adds the "green shadow" you use to place your items on the ground. Without that character will build item just under his feet. in youritem.lua: inst.AnimState:SetBank("youritem") inst.AnimState:SetBuild("youritem") inst.AnimState:PlayAnimation("idle") <<< animation you made in Spriter Don't really need the "ONBUILT" from what i noticed. I don't have it - and all works fine. The other guy already explained it, I just couldn't figure out how to add the placer at first because I didn't know the placer could be used as an argument. I know "ONBUILT" isn't necessary, but it's convenient to know how things work before I use them later. Link to comment https://forums.kleientertainment.com/forums/topic/50798-how-do-i-build-a-custom-buildable-using-a-placer/#findComment-611954 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now