MrDoge124 Posted September 3, 2018 Share Posted September 3, 2018 I'm working on a mod for a friend and they wanted them to have the ability to summon lightning when press a button, at the cost of some sanity. Maybe 10? I would also like for it to have a cool down time maybe around 30 seconds? Link to comment Share on other sites More sharing options...
Ultroman Posted September 14, 2018 Share Posted September 14, 2018 That's not too hard. Find a mod that does keypresses, like "Cook Key". Summoning lighting can be done in many ways, like spawning a prefab that emits light. Like this: local pos = inst:GetPosition() GLOBAL.SpawnPrefab("spawnlight_multiplayer").Transform:SetPosition(pos.x, pos.y, pos.z) "inst" is a player instance. You can replace the position parameters in the SetPosition function call with whatever you want. You could get the mouse position, or you can use the player instance position (like I did in the example above). The sanity cost (and check for whether the player has enough sanity) is trivial. Get the sanity component on the player, check his current sanity, and use DoDelta to apply a sanity change. Link to comment Share on other sites More sharing options...
Fluxistence Posted September 18, 2018 Share Posted September 18, 2018 @Ultroman I think he meant "lightning" rather than "lighting." =) There's actually a debug key that summons lightning at the position of the mouse cursor (Shift+F5). This is what it does: local pos = TheInput:GetWorldPosition() TheWorld:PushEvent("ms_sendlightningstrike", pos) I'd include the code for binding it to the Shift+F5 key, but that bit uses a debug key so it's not what you want. For that you should do like Ultroman said and copy it off of a mod that has something done on key press. There's also one thing you should note: while the lightning is summoned at the given position pos, it can hit somewhere else nearby instead - namely, it can hit the summoning player. This is because lightning bolts randomly target nearby points of interest I guess, or maybe specifically the player. So you might want to make your character immune to lightning, or make it a pre-known risk. You can probably give your character temporary lightning immunity just for that lightning strike, but personally I don't like that idea as it affects other lightning strikes as well. You can look into how the event itself works to circumvent the location randomization; I haven't looked into that but it should be possible. Link to comment 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