SenL Posted March 7, 2015 Share Posted March 7, 2015 Hi, I'm creating a custom deployable that accepts item where the item changes its behavior.Example: Give "goldnugget" and it will do mode A or give "gears" and it will do mode B.Question: How does this "mode" get saved between session (server disconnects)? In character prefab, it has "OnSave" and "OnPreLoad" but I don't know if these exist in regular prefab. Idea/hint? Thanks. Link to comment Share on other sites More sharing options...
rezecib Posted March 7, 2015 Share Posted March 7, 2015 @SenL, They exist for entities in general. See birdtrap.lua, for example. Note that you can't just declare an OnSave/OnLoad function, you have to attach it to the instance: inst.OnSave = OnSave inst.OnLoad = OnLoad Link to comment Share on other sites More sharing options...
SenL Posted March 8, 2015 Author Share Posted March 8, 2015 Thanks rezecib. It works.I do have another question. This deployable item (it's a totem) has health component because I want this to be destroyable on the field.However when in inventory, there is an option to "murder" just as if it was a rabbit/bird, lol.How do I remedy this? I could spawn another clone prefab (that doesn't have health component) and remove self just like "eyeturret" but then I also want this item to undeploy when player picks up. Thanks. Link to comment Share on other sites More sharing options...
Kzisor Posted March 9, 2015 Share Posted March 9, 2015 @SenL, don't add the health component until you've deployed the item. Link to comment Share on other sites More sharing options...
SenL Posted March 9, 2015 Author Share Posted March 9, 2015 @Kzisor Right but once deployed how do I make it "un-deploy" able? Link to comment Share on other sites More sharing options...
rezecib Posted March 9, 2015 Share Posted March 9, 2015 @SenL, Remove inventoryitem and deployable components, I guess? Link to comment Share on other sites More sharing options...
SenL Posted March 9, 2015 Author Share Posted March 9, 2015 @rezecib It makes the totem deploys right on ground instead of going to the inventory and cannot be picked up.I want it to be in inventory, deploy on field, and pick it up. So it'd be a portable destroyable healing station. Yes, sure make the game easier ... well it's optional mod . Link to comment Share on other sites More sharing options...
Kzisor Posted March 9, 2015 Share Posted March 9, 2015 @SenL, take a look at the tooth trap as that does exactly what you're wanting to achieve. Link to comment Share on other sites More sharing options...
SenL Posted March 9, 2015 Author Share Posted March 9, 2015 @Kzisor Tooth trap, yes. It has inventoryitem, deployable but no health. It has finite uses instead. Link to comment Share on other sites More sharing options...
Kzisor Posted March 9, 2015 Share Posted March 9, 2015 @Kzisor Tooth trap, yes. It has inventoryitem, deployable but no health. It has finite uses instead. Yeah...I don't understand your point. We've told you how to fix it.Use the tooth trap code as a base, simply add the health component once it's deployed at the same time remove the deployable component. When you pick the item back up remove the health component and add the deployable component. Doesn't seem like it'd be that difficult to accomplish, nor a giant leap from what both rezecib and I have said. Link to comment Share on other sites More sharing options...
SenL Posted March 9, 2015 Author Share Posted March 9, 2015 Ok that makes sense. In inventory: remove health and add deployable. Once deployed: add health and remove deployable.It doesn't sound difficult but I've never done it.Thanks. Link to comment Share on other sites More sharing options...
Kzisor Posted March 9, 2015 Share Posted March 9, 2015 @SenL, remember to save the important information such as durability, uses, etc. so you can maintain it across placements and across saves. This will need to be done on the item itself; inside the OnSave and OnLoad functions. Link to comment Share on other sites More sharing options...
SenL Posted March 9, 2015 Author Share Posted March 9, 2015 Yes I have OnSave and OnLoad. Thank you. So I'm not at home so I can't test/play but here's my draft code. I have a question of to use "ListenForEvent" or to use inventoryitem's SetOnPickupFn ... Code is:--... local function ondeploy(inst, pt, deployer) --add health component if not inst.components.health then inst:AddComponent("health") end inst.components.health:SetMaxHealth(333) inst.components.health:StartRegen(12, 3) --12s, 3hp --remove deployable component if inst.components.deployable then inst:RemoveComponent("deployable") endend local function onpickup(inst) --remove health component if inst.components.health then inst:RemoveComponent("health") end --add deployable component if not inst.components.deployable then inst:AddComponent("deployable") end inst.components.deployable.ondeploy = ondeployend local function fn() local inst = CreateEntity() --... inst:AddComponent("deployable") inst.components.deployable.ondeploy = ondeploy inst:ListenForEvent("onpickup", onpickup) --this? inst.components.inventoryitem:SetOnPickupFn(onpickup) --or this? --... return instend return Prefab("common/mydeployabledestroyablehealingtotem", fn, assets) Suggestion? Link to comment Share on other sites More sharing options...
seronis Posted March 9, 2015 Share Posted March 9, 2015 If you're still confused and want more examples to flesh out your understanding then look at Mandrakes. They have health and pickable components added and removed based on whether the mandrake is in the ground, in inventory, or following you. 1 Link to comment Share on other sites More sharing options...
SenL Posted March 10, 2015 Author Share Posted March 10, 2015 Ahh mandrake, yes - I'll take a look. Ty. Link to comment 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