Jump to content

Making a structure portable [Solved][Example File]


Recommended Posts

I want to make a portable version of the salt lick. I honestly got farther than I thought I would, but I have hit a snag and will probably hit more.

First I got the item to spawn and work just like salt lick in the world. Once I tried to make it deployable (referencing portablecookpot) I was able to get the item into inventory but when placed it does not work as a salt lick would. I understand that portable items have two prefabs (1 for placed 1 for inventory), this is where I think I got lost. EDIT: I was able to fix this myself surprisingly  Only issue I have with this is the place structure cannot be picked back up...

Without more in game testing I'm not sure if it will be a problem or not but, I'm worried that the durability sate of the salt lick will be "reset" when picked up. Can someone look at my code thus far and let me know what they think about this?

 

Attached files below if anyone could take a look and tell what I did wrong/need to do.

 

 

 

 

Edited by its zea
Link to comment
Share on other sites

Using the original saltlick code I would have removed the OnBuilt functions and the MakePlacer and then added the inventory item component with a function for when its dropped.

inst.components.inventoryitem:SetOnDroppedFn(OnDropped)

So for that OnDropped function I would add back some of the things the OnBuilt function had like play idle and alert critters.

Also I don't think a seperate prefab is used for the inventory, just a different image is set. Keeping the same prefab would help in this case because it saves the information about how much it was used. Which then displays the correct saltlick animation too. Having to remove prefab and spawn a new one each time like your code seems to be doing doesn't save that data. I'm sure it can be possible to save that information but in this case it isn't needed to use a new prefab entirely. So I would set the inventory images you have on the same prefab.

Link to comment
Share on other sites

11 hours ago, maliblues said:

Using the original saltlick code I would have removed the OnBuilt functions and the MakePlacer and then added the inventory item component with a function for when its dropped.


inst.components.inventoryitem:SetOnDroppedFn(OnDropped)

So for that OnDropped function I would add back some of the things the OnBuilt function had like play idle and alert critters.

Also I don't think a seperate prefab is used for the inventory, just a different image is set. Keeping the same prefab would help in this case because it saves the information about how much it was used. Which then displays the correct saltlick animation too. Having to remove prefab and spawn a new one each time like your code seems to be doing doesn't save that data. I'm sure it can be possible to save that information but in this case it isn't needed to use a new prefab entirely. So I would set the inventory images you have on the same prefab.

I removed the onbuild function and added the components to ondeploy. I want the structure to still be placed not dropped. Looking at every example in the game files i.e. portable cookpot seasoning station and grinder they all use the prefab and prefab_item system. At this point I have the salt lick working I just cannot deconstruct it for some reason.

Edited by its zea
Link to comment
Share on other sites

Without editing my code I launched DST and my mod does not allow me to "place" my item anymore (although it did work last test...). I am completely confused and have no idea where to go next....

Edited by its zea
Link to comment
Share on other sites

7 hours ago, its zea said:

I removed the onbuild function and added the components to ondeploy. I want the structure to still be placed not dropped. Looking at every example in the game files i.e. portable cookpot seasoning station and grinder they all use the prefab and prefab_item system. At this point I have the salt lick working I just cannot deconstruct it for some reason.

That's useful to know! I wanted to try testing it for myself and try to figure it out. It would help to have the custom portablelick component and your modmain file (and if there's any other relevant one)

Edit: by deconstruct do you mean the dismantle function? If your custom component that sets your OnDismantle function is a copy of the portablecookware component then that wouldn't be enough. I haven't seen your mod fille so I don't know if you're aware of this but by searching through the files I see that ACTIONS.DISMANTLE is the component action portablecookware uses (actions.lua) it runs further checks so seems like this action only works for that component. Also further checks in componentactions.lua. So I would have thought a custom component action is needed unless you've done this and something else is the cause. I can only really guess without seeing the files.

Edited by maliblues
Link to comment
Share on other sites

16 hours ago, maliblues said:

That's useful to know! I wanted to try testing it for myself and try to figure it out. It would help to have the custom portablelick component and your modmain file (and if there's any other relevant one)

Edit: by deconstruct do you mean the dismantle function? If your custom component that sets your OnDismantle function is a copy of the portablecookware component then that wouldn't be enough. I haven't seen your mod fille so I don't know if you're aware of this but by searching through the files I see that ACTIONS.DISMANTLE is the component action portablecookware uses (actions.lua) it runs further checks so seems like this action only works for that component. Also further checks in componentactions.lua. So I would have thought a custom component action is needed unless you've done this and something else is the cause. I can only really guess without seeing the files.

I followed this exact train of thought last night. You are correct "portablecookware " is linked to componentactions.lua and a few other files. As of now all the "portable" items in the game are cooking related so the code it tangled in with other cooking related components and scripts. My item thus far is not working because I tried to remove all the code for cooking. My next attempt it going to be flushing out exactly what line of code I removed that broke dismantle and place actions. Wish me luck ill post what I find out.

 

p.s.

The interesting this about the "object" and "object_item" prefabs is that "object_item" does not have its own .lua file. It only exist inside of "object.lua". When working with items like this you will get errors saying "object_item.lua" is mission if you mess something up which it handy.

Edited by its zea
Link to comment
Share on other sites

@maliblues

I got it working as intended I have a few more tweaks to do before its 100% finished but I'm happy with the outcome.

 

Here is the lastest LUA, I didn't remove anything from the original portablecrockpot.lua but I did comment out sections so you can see what I had to do.

 

 

 

portalick.lua

Edited by its zea
Link to comment
Share on other sites

6 minutes ago, maliblues said:

Yes this method of keeping portablecookware component just to pass those checks for the action to work is much simpler. Glad it's working as intended now :)

Agreed, next step it making it so that other characters cannot dismantle it. Unfortunately that means I have to replace portablecookware with a custom component, then create a custom component action then create a custom action.... Gonna call this version 1.00 and move on for now.

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...