Jump to content

Custom deployable that accepts item


Recommended Posts

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

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

@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

@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

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

@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

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")
  end
end
 
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 = ondeploy
end
 
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 inst
end
 
return Prefab("common/mydeployabledestroyablehealingtotem", fn, assets)
 
Suggestion?
Link to comment
Share on other sites

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.

  • Like 1
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...