Jump to content

Call lightning strikes?


Recommended Posts

So I'm 90% done with the mod I want to do, and I've been able to get the item to appear in game, give it most of the custom properties I want like crafting recipe and descriptions and all that. I was even able to make it summon lightning on que, problem is I wanted to be able to control where the lighting is summoned, and be able to call lightning to strike enemies, however, when trying to strike anything that's not the ground the character says "I can't do that" and no lightning appears. Can anyone point me in the right direction? I've tried looking for a way to track where the player's cursor is to spawn lightning there but haven't found it yet. I'm happy to provide extra information if need be, I'm so close to completion so I'd be really grateful for any help.

Link to comment
Share on other sites

TheWorld:PushEvent("ms_sendlightningstrike", put_location_here)

--this somethimes won't work with lightning rods and e.c because they don't

 

image.thumb.png.8d976697b8cf465ca37c019f537571c8.png

SpawnPrefab("lightning").Transform:SetPosition(put_position_here)

--oor

object_name_here:PushEvent("lightningstrike")

so use these 2 instead

if you want to see how to make it follow the cursor look in to the wortox file he uses something so he can teleport over the cursor location

Link to comment
Share on other sites

Ok so weirdly enough even after trying both those methods and I still get the character saying "I can't do that." when I try to cast the spell on something, so I'm not sure if the lightning is the problem and maybe there's a problem with the spell casting? although strangely it only happens when targeting enemies or objects.

Link to comment
Share on other sites

I think you need two actions then? One for lightning call on ground and one for enemies/etc.

Also check your animation because depending on which animation is set for using the item, the action can finish before the animation which triggers the dialogue but still works.

Link to comment
Share on other sites

Well I tested it without calling lightning in any method, just the durability drain, and it'd still play the animation but the character would still say "I can't do that." upon right clicking the target, so I believe that the spell function isn't being played at all and it skips that function and only plays the spell cast animation when right clicking. I've already shut down my PC so I won't be able to work on the mod until tomorrow, but I think that the lightning itself isn't the issue, rather casting the spell on an enemy/object. I've been trying to look at the telelocator staff's scripts in the staff.lua file to figure it out what allows the player to cast spells on enemies/objects but I'm still stumped.

Link to comment
Share on other sites

Ok so I made a bit of progress, I am able to summon lightning on enemies, so that much works as intended, however I'm not sure how to make it so the lightning does it's own set amount of damage, I could use target.components.health.DoDelta(damage) but in doing so I would be making it so that the damage would be dealt even if the lightning didn't hit the target as sometimes it doesn't. I tried using these lines to spawn lightning:

SpawnPrefab("lightning").Transform:SetPosition(put_position_here)

--oor

object_name_here:PushEvent("lightningstrike")

However those lines ended up either not spawning lightning or crashing the game, so I had to use "ms_sendlightningstrike" to get any results. Any suggestions as to how to control the amount of damage the lightning does? I would prefer it if I could make it so the lightning does the same damage as a melee attack, including if the user has damage penalties ect if possible. If I can't figure it out I might have to settle for the mod as it is currently.

Link to comment
Share on other sites

I did some looking around, and the game has a parameter for lightning damage (TUNING,LIGHTNING_DAMAGE) (but it benefits from the electric multiplier) that is only used once in the code. I believe you can swap the damage on cast and swap back after a few instants. This is a bit dirty but I don't think the chance of a neutral strike calling in is relevant at all.

Link to comment
Share on other sites

Thanks for looking into it for me, I have thought more about it and I'm actually planning to make a copy of the lightning prefab and tweak it to make my own special lightning and spawn that, and also I believe TUNING, LIGHTNING DAMAGE is for applying to player characters, I don't think it applies to other entities as when non-player entitites are struck they take no damage and are simply ignited, so that's why I'll need to do more investigation. I did post my mod to the steam workshop as is though so if you'd like to take a look at the code so far be my guest, there's probably going to be some leftover lines from when you where able to cast lightning on the ground ect so it's not the cleanest piece of work. https://steamcommunity.com/sharedfiles/filedetails/?id=2283627408&searchtext=Levin+sword

Link to comment
Share on other sites

Why would you try and code a copy of the lightning prefab then? If the game does not assign damage to the contact action (instead, it calls both at the same time) then the lightning prefab is just the sfx. You can use the old one no problem.

I believe what you need to do is create a copy of the lightning target component, no?

Edited by AndRay
Link to comment
Share on other sites

Possibly, I've managed to get the lightning prefab to spawn and that is purely an SFX so it does nothing atm, it doesn't seem to line up exactly with the entity though so I might need to increase y value so it lines up with the enemy a bit more, after that I just need to add damage and make it so that the enemy actually does the take damage animation when hit by the lightning. I was hoping it could do the same damage as a melee attack so ideally it would be good if I could keep it all within item's prefab

Link to comment
Share on other sites

Ok so update, sfx and attack damage are functioning, so all that's left is making the enemy do the take damage animation, but I don't know how to make it check for damage reduction before doing damage (like how rock lobsters can turn into rocks to absorb damage) so once the animation and damage reduction are implemented it'd function exactly as intended.

Link to comment
Share on other sites

Even if I'm using target.components.health:DoDelta(damageValue)? Since that technically isn't dealling damage normally, I think it's more similar to taking damage from eating food, but in light of this I'm realising that because the lightning is just sfx right now then it won't have the properties of lightning like being able to charge WX78, so might need to use something other that "SpawnPrefab("lightning").Transform:SetPosition(position)" but I couldn't get PushEvent("lightningstrike") to actually spawn lightning, and "ms_sendlightningstrike" (which is what the workshop version of the mod is using) misses sometimes. If I could figure out how PushEvent("lightningstrike") works I might be able to make some progress.

Link to comment
Share on other sites

ok so another update, while using target.sg:GoToState("hit") I can make enemies go into the hit state, so if there's a player specific state for being struck by lightning, which I'm fairly sure there is as there's a unique animation for being struck by lighting as a player, then I could do a nested if statement that checks if the target is a player and if so put them in the appropriate state. If I can figure that out the only thing that concerns me is if using target.components.health:DoDelta(damageValue) means true damage because if so then the sword may end up being a little more overpowered than intended.

Link to comment
Share on other sites

If there is a function for setting a health absorption rate, there must be a variable, function or check to see which value it currently has, In the worst case, you can just look at the code for the Set function to see where it stores the result.

Link to comment
Share on other sites

Yeah maybe, I'm not 100% sure how to make external objects run functions in lua because I think it works differently from C# which is what I'm used to. Finding the damage reduction and also finding out how to make WX78 go into his charged state both rely on being able to activate functions for external objects.

Link to comment
Share on other sites

Well, you're talking about a method, so it's always the same code, just running thing:TheFunction().

All interactions in the game do this in a sense, since TheWorld calls the needed functions.

Or were you talking about something different?

EDIT: sending WX to its charged state should be a call of sg:GoToState([the state name]), if I'm not mistaken. You can check the stategraph file for more info.

Edited by AndRay
Link to comment
Share on other sites

I could directly send him to the charge state, however then he would not be announcing his charge, there are also several other events that happen during this function, and WX doesn't actually have a state on the state graph for being charged, so sg:GoToState doesn't work for this context, I could however add the tag that makes him charged however I'd still have the problem of him not doing his initial announcement of being charged ect. And in terms of using target:onlightningstrike() the game normally freezes, so I'm not sure what the issue is there. I'm having it go through a nested if statement right now so it only attempts to run target:onlightningstrike() if it's target is WX78

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