Jump to content

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.

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.

@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 :).

@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. 

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?

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

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...