dahl Posted April 29, 2016 Share Posted April 29, 2016 (edited) 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 April 29, 2016 by dahl Link to comment https://forums.kleientertainment.com/forums/topic/66800-item-owner-events/ Share on other sites More sharing options...
Muche Posted April 29, 2016 Share Posted April 29, 2016 (edited) 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 April 29, 2016 by Muche Link to comment https://forums.kleientertainment.com/forums/topic/66800-item-owner-events/#findComment-761422 Share on other sites More sharing options...
dahl Posted April 29, 2016 Author Share Posted April 29, 2016 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? Link to comment https://forums.kleientertainment.com/forums/topic/66800-item-owner-events/#findComment-761457 Share on other sites More sharing options...
DarkXero Posted April 29, 2016 Share Posted April 29, 2016 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 Link to comment https://forums.kleientertainment.com/forums/topic/66800-item-owner-events/#findComment-761500 Share on other sites More sharing options...
dahl Posted April 29, 2016 Author Share Posted April 29, 2016 5 hours ago, DarkXero said: When the lightning is catched by portablelightningrod_aux, it gets its parent (portablelightningrod) and tries to do the function you want. Oh, thank you much! That can help me. Link to comment https://forums.kleientertainment.com/forums/topic/66800-item-owner-events/#findComment-761666 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