Jump to content

Recommended Posts

I'm trying to make placers for things that already exist. I really don't get what I'm doing wrong. They always work great when I put them directly into the prefab file but I think that shouldn't even be an option.

This:

local function gravestoneplacer(inst)return Prefab( "common/objects/gravestone", fn, assets, prefabs ),GLOBAL.MakePlacer( "common/gravestone_placer", "gravestone", "gravestones", "grave1")endAddPrefabPostInit("gravestone", gravestoneplacer)
Results in the error: playercontroller.lua:126: attempt to index field 'placer'(a nil value)

Putting this at the end of modmain.lua:

return Prefab( "common/objects/gravestone", fn, assets, prefabs ) ,GLOBAL.MakePlacer( "common/gravestone_placer", "gravestone", "gravestones", "grave1")
Results in the error: Variable 'MakePlacer' is not declared

Like I said they work great when they're in the prefab file but trying to pass them from modmain.lua to the prefab is giving me trouble. When I try to dissect other mods that use custom placers, they seem to overwrite the prefab lua file so they're no help. What am I doing wrong?

Edited by mouse
Link to comment
https://forums.kleientertainment.com/forums/topic/27596-makeplacer-in-modmainlua/
Share on other sites

I'm trying to make placers for things that already exist. I really don't get what I'm doing wrong. They always work great when I put them directly into the prefab file but I think that shouldn't even be an option.

This:

local function gravestoneplacer(inst)return Prefab( "common/objects/gravestone", fn, assets, prefabs ),GLOBAL.MakePlacer( "common/gravestone_placer", "gravestone", "gravestones", "grave1")endAddPrefabPostInit("gravestone", gravestoneplacer)
Results in the error: playercontroller.lua:126: attempt to index field 'placer'(a nil value)

Putting this at the end of modmain.lua:

return Prefab( "common/objects/gravestone", fn, assets, prefabs ) ,GLOBAL.MakePlacer( "common/gravestone_placer", "gravestone", "gravestones", "grave1")
Results in the error: Variable 'MakePlacer' is not declared

Like I said they work great when they're in the prefab file but trying to pass them from modmain.lua to the prefab is giving me trouble. When I try to dissect other mods that use custom placers, they seem to overwrite the prefab lua file so they're no help. What am I doing wrong?

 

I very tired and half (or mre than hlaf ) drunk right now but I'm pretty sure you shou;dn't return anything from your postinit function , especially not in the first line of code.

 

 

"return" will return what you set it to return and will not go through any subsequent lines of code in your function , so :

GLOBAL.MakePlacer( "common/gravestone_placer", "gravestone", "gravestones", "grave1")

will never even be executed.

.

Edited by RCatta

Well it looks like my own personal mental retardation as subsided enough to allow me to figure it out.

For anyone who's looking for a similar solution:

First you need to create a new lua file in: <your root mod directory>/scripts/prefabs/

Make sure it doesn't share the same name as anything in <don't starve root directory>/data/scripts/prefabs/

For example: intergratedredditmod/scripts/prefabs/idiotwrangler.lua

In my case: graverobbers delight/scripts/prefabs/gravestoneplacer.lua

That file is where you'll put your placer. At the top, be sure to include:

require "prefabutil"
In my case:

require "prefabutil"return MakePlacer( "common/gravestone_placer", "gravestone", "gravestones", "grave2")

Next, in modmain.lua put the following:

PrefabFiles = {"your file name here",}
In my case:

PrefabFiles = {"gravestoneplacer",}
And that's it! It's so depressingly simple looking at it now.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...