Jump to content

Recommended Posts

Hello, can someone help me or just explain some code example:
 

local function OnLightning(inst)

        local owner = inst.components.inventoryitem.owner
        local damage = TUNING.TUNING.SPIKE_DAMAGE
			
		owner.components.health:DoDelta(damage)
		inst.components.fueled:DoDelta(TUNING.TINY_FUEL)
end

--in intem fn():
local function fn()
local inst = CreateEntity()
MakeInventoryPhysics(inst)
inst:AddComponent("weapon")
--......
inst:ListenForEvent("lightningstrike",  OnLightning)
return inst
end

Here I tried to make function that will change owner values like health, hunger or sanity by catch the "lightningstrike" event. But I have one big issue — OnLightning function will never achieve, if owner currently carry  this item. How to make it correctly?

Edited by dahl
Link to comment
https://forums.kleientertainment.com/forums/topic/66800-item-owner-events/
Share on other sites

The lightningstrike event is being pushed in components/weather.lua only for targets that have lightningrod tag (by default lightning rods and volt goats). If a player is the chosen target, DoStrike() function from its playerlightningtarget component is called (which by default does some damage to the player unless the player is WX-78). (Your listener is attached to the item itself which is not considered as a lightning target).

Now, I'm not sure how you intend this item to work.
While wearing it, should your damage replace the default damage or add to it?
Should it act as a lightning rod (i.e. the lightning will hit the player even if there is a nearby lightning rod)?
How should it behave if the player is lightning-proof (by wearing eyebrella, rain hat, or rain coat)?
How should it behave when worn by WX-78 with regards to his lightning perk?

 

Edited by Muche
6 minutes ago, Muche said:

While wearing it, should your damage replace the default damage or add to it?

I try to make refuel of item by lightning stike while player wear it. Is any paths to get owner parameters inside the item prefab and catch owner event?

 

Perhaps are you thinking of something like this?

This weapon (portablelightningrod) uses another prefab (portablelightningrod_aux) to catch lightning.

When the lightning is catched by portablelightningrod_aux, it gets its parent (portablelightningrod) and tries to do the function you want.

portablelightningrod.lua

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