overmouse Posted June 6, 2016 Share Posted June 6, 2016 Hello. Does any1 can give me a simple script like MiniTools 1.2 with another functions? Actually i need to understand how to make a lightning strike right into my character (with damage and etc.) and how to spawn any creature in random position around character by keypress I'm dumb in LUA, spent about 2 hours trying to combine minitools and some LUA text from DS, but get success only in sound and visual effects around, but can not get lightning strike to hit player. Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/ Share on other sites More sharing options...
whismerhill Posted June 7, 2016 Share Posted June 7, 2016 take a look at "books.lua" in particular "firefn" function it's the function that create lightning strikes for the appropriate book of wickerbottom Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-780481 Share on other sites More sharing options...
overmouse Posted June 7, 2016 Author Share Posted June 7, 2016 Thanks for answer! Okay. i taking function firefn from books.lua, copy-paste it in to commands.Lua in MiniTools, assign an a hotkey, remove sanity debuff(i don't need it) and... got an errors on "reader" part of function when i trying to call it in game. So i guess "reader" it's a some active class or action or something, while player clicking on book and calling reader.lua Okay. goin next. Remove "reader." part because we don't reading any book, just trying to call function by key. And i still haven't success: function firefn(inst) local num_lightnings = 16 for k = 0, num_lightnings do local rad = math.random(3, 15) local angle = k*((4*PI)/num_lightnings) local pos = Vector3(Transform:GetWorldPosition()) + Vector3(rad*math.cos(angle), 0, rad*math.sin(angle)) GetSeasonManager():DoLightningStrike(pos) Sleep(math.random( .3, .5)) end end Got an error here: calling 'GetWorldPosition' on bad self (Transform expected, got table) Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-780508 Share on other sites More sharing options...
whismerhill Posted June 7, 2016 Share Posted June 7, 2016 wow wow wow xD ok first thing first, rename that function, it's kinda bad practice to keep the same name for a function which is supposed to do something else. It's not supposed to cause issues I believe but still. 2nd unless you wanna reuse that function in yet another mod, it should be kept local so add "local " before "function" 3rd you removed the "reader" entity from transform:getworldposition() which means you're basically asking it to get the world position of nothing ? since now there is no "self" entity anymore if inst (the passed argument) is your character, then I believe it should be inst.Transform:GetWorldPosition() if not then you need to get the player from global local player = GLOBAL.GetPlayer() and pass "player" instead of "inst" Also you do realize that function will create 16 lightning strikes at random around your character ? hope that's what you want, or you'll need to modify it further xD Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-780789 Share on other sites More sharing options...
overmouse Posted June 8, 2016 Author Share Posted June 8, 2016 (edited) thanks for keep answering... I'm very appreciate for it. Okay i will rename it for something like to me. It's not a prob, i understand that i should rename it in 2 files. So okay. Now i understand - "inst" it's a random 4 letters like "abcd", is using to keep something in memory... Used local inst = GetPlayer() (Global.GetPlayer makes game crash for "Global" part, dunno why) So code looks like this now: CodeImage (don't know why i can't paste a code of it here, forum blocking it) And now i passed all syntax errors and it... Still not works: (don't know how i should copy-paste errors from this) So i see that we have error for "sleep" function. I don't need it. Removing. And it works! Got some strikes around my character. Finally a little succes from me, with your patience and help, @whismerhill! So now i will try to close radius of striking to 0 and i will get hits in to my character: Deleted Vector3(rad*math.cos(angle), 0, rad*math.sin(angle)) Because it's making a big circle around Player position and... I see lightning strike now, i hear it, but it makes 0 damage to my Character, looks like Strike hits in a front of him. Checked it - moved character behind a tree, and yes - Strike hits tree, not character. What i did wrong again? Edited June 8, 2016 by overmouse Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-780930 Share on other sites More sharing options...
whismerhill Posted June 8, 2016 Share Posted June 8, 2016 (edited) it should be GLOBAL not Global it's case sensitive as far as I know. otherwise I don't really know why your character is not hit by the lightning strike. You seem on the right track Edited June 8, 2016 by whismerhill Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-781050 Share on other sites More sharing options...
overmouse Posted June 8, 2016 Author Share Posted June 8, 2016 (edited) With GLOBAL it's still make error. Variable 'GLOBAL' is not declared. Think it's not much important. I guess i don't get hit by lighning because i taked function from SpellBook, it's not organized to hit player. So i need to understand how the lightning hitting player when weather goes rainy... Edited June 8, 2016 by overmouse Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-781072 Share on other sites More sharing options...
overmouse Posted June 8, 2016 Author Share Posted June 8, 2016 So. We have playerlightningtarget.lua He explains how player can get be hitted by strike. But can i modify it and call strike with these parameters? Didn't thought that LUA will be so... strange and hard. Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-781130 Share on other sites More sharing options...
whismerhill Posted June 9, 2016 Share Posted June 9, 2016 you could indeed try to add the wx78 component that makes him a lightning target with something like : GetPlayer():AddComponent("playerlightningtarget") before the lightning strike Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-781320 Share on other sites More sharing options...
overmouse Posted June 9, 2016 Author Share Posted June 9, 2016 Not works. Nil Value Looked for seasonmanagers in other places - they haven't "CanBeHit" method, but i don't understand how to call them to avoid this error... Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-781367 Share on other sites More sharing options...
whismerhill Posted June 9, 2016 Share Posted June 9, 2016 you're not on DST right ? Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-781395 Share on other sites More sharing options...
overmouse Posted June 9, 2016 Author Share Posted June 9, 2016 (edited) No ofc, I need it for DS ShipWrecked for example. Edited June 9, 2016 by overmouse Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-781428 Share on other sites More sharing options...
whismerhill Posted June 9, 2016 Share Posted June 9, 2016 I don't have any more ideas, don't even understand why GLOBAL.GetPlayer() doesn't work in your mod. Strange stuff among the wall of text, this explains why GLOBAL.GetPlayer & not GetPlayer : Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-781476 Share on other sites More sharing options...
overmouse Posted June 9, 2016 Author Share Posted June 9, 2016 Doh... does any1 in forum make scripts for payment? I can make a donation for it, we spend too much time in discussion this... Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-781540 Share on other sites More sharing options...
overmouse Posted June 9, 2016 Author Share Posted June 9, 2016 Em... i don't know what happends. function shootme() local num_lightnings = 1 local inst = GetPlayer() for k = 0, num_lightnings do local rad = math.random(3, 15) local angle = k*((4*PI)/num_lightnings) local pos = Vector3(inst.Transform:GetWorldPosition()) + Vector3(rad*math.cos(angle), 0, rad*math.sin(angle)) GetPlayer():AddComponent("playerlightningtarget") GetSeasonManager():DoLightningStrike(pos) GetClock():DoLightningLighting(.5) end end Works. Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-781608 Share on other sites More sharing options...
overmouse Posted June 9, 2016 Author Share Posted June 9, 2016 (edited) Upd: removed GetClock():DoLightningLighting(.5) Still works. Removed radius of lightning - still works: function shootme() local num_lightnings = 10 local inst = GetPlayer() for k = 1, num_lightnings do local pos = Vector3(inst.Transform:GetWorldPosition()) GetPlayer():AddComponent("playerlightningtarget") GetSeasonManager():DoLightningStrike(pos) end end So sometimes it hits player, sometimes hit in front of player. It's located in local pos = Vector3(inst.Transform:GetWorldPosition()) So radius a bit higher than character's coords. Can i make radius a bit lower? And game takes parameters of lightning rod, if it near - player didn't get hits.. Any idea how to solve it? Edited June 9, 2016 by overmouse Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-781612 Share on other sites More sharing options...
whismerhill Posted June 9, 2016 Share Posted June 9, 2016 you should have understood how to work stuff out by now watch getseasonmanager():dolightningstrike() function (in seasonmanager.lua) I believe I saw a paramater exactly for this if I'm not mistaken Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-781618 Share on other sites More sharing options...
overmouse Posted June 9, 2016 Author Share Posted June 9, 2016 (edited) Ye, i get some knowledge, you helps a lot in it, but i'm stull dumbed xD I saw in seasonmanager these options. Rod and chance of hit. I dn't understand how i may change these for few moments like: buttonpressed - script takes values of modified parameters from script folder, then make hit, then return parameters like it was in game. (i mean i don't want to change game files) So i should make personal .lua file with these parameters and load it on buttonpressed otherwise of seasonmanagers options... next level of Lua scripting. Edited June 9, 2016 by overmouse Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-781620 Share on other sites More sharing options...
overmouse Posted June 9, 2016 Author Share Posted June 9, 2016 (edited) So okay. I taked TwitchPlays mod as example and saw, that they in modmain.lua do this: local require = GLOBAL.require local TwitchPlaysButton = require("widgets/twitchplaysbutton") They call modified files with these text. So i did the same with playerlightningtarget.lua with another name. Tryed to modify it, but still no reaction with hitChance. Going next: Taked SeasonManager_sw.lua, renamed it into SeasonForStrike, croped a lot of stuff from it(which works on seasons, autumn, tornado etc). Renamed a lightningningstrike function into DoLightningStrikeHitMe Now i have these: ModMain.lua local require = GLOBAL.require local PlayerTargetStrike = require("components/PlayerTargetStrike") local SeasonForStrike = require("components/SeasonForStrike") Commands.lua function shootme() local num_lightnings = 1 local inst = GetPlayer() for k = 1, num_lightnings do local pos = Vector3(inst.Transform:GetWorldPosition()) GetPlayer():AddComponent("PlayerTargetStrike") GetSeasonForStrike():DoLightningStrikeHitMe(pos) end end I put PlayerTargetStrike.lua and SeasonFroStrike.lua into components folder. But now it makes an error for me: Variable 'GetSeasonForStrike is not declared. Why in previous post these works perfectly? GetSeasonManager():DoLightningStrike(pos) Can i find workaround in this way? Edited June 9, 2016 by overmouse Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-781665 Share on other sites More sharing options...
whismerhill Posted June 10, 2016 Share Posted June 10, 2016 I have trouble understanding what you're saying what I was pointing at however is that there's an additional parameter for the function " getseasonmanager():dolightningstrike() " as long as you're in the RoG folder the function is declared like this: (I can't check about SW, check it out if you're gonna use that) function SeasonManager:DoLightningStrike(pos, ignoreRods) local rod = nil local player = nil if not ignoreRods then which means when calling it you can write it as such GetSeasonManager():DoLightningStrike(pos, true) and it should ignore rods no need to rewrite functions or any nonsense like this imho Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-781784 Share on other sites More sharing options...
overmouse Posted June 10, 2016 Author Share Posted June 10, 2016 Okay. But in playerlightningtarget it declares some protection from items when strike can hit local DefaultOnStrike = function(inst) if inst.components.health and not inst.components.health:IsDead() then local protected = false if GetPlayer().components.inventory:IsInsulated() then protected = true end if not protected then local mult = TUNING.ELECTRIC_WET_DAMAGE_MULT * inst.components.moisture:GetMoisturePercent() local damage = -(TUNING.LIGHTNING_DAMAGE + (mult * TUNING.LIGHTNING_DAMAGE)) -- Magic hit point stuff that isn't being used right now -- if damage >= inst.components.health.currenthealth - 5 and inst.components.health.currenthealth > 10 then -- damage = inst.components.health.currenthealth - 5 -- end inst.components.health:DoDelta(damage, false, "lightning") inst.sg:GoToState("electrocute") else inst:PushEvent("lightningdamageavoided") end end end Also declared hit chance: local PlayerLightningTarget = Class(function(self, inst) self.inst = inst self.hitchance = 0.3 self.onstrikefn = DefaultOnStrike end) I need to ignore all varietes when strike can't hit player. For example now: you show me how to ignore rods, but it still not hitting me when player get SnakeSkin Hat, or SnakeSkin Jacket or something else what can protect in SW from strike. That's why i wanted to make my personal .LUA files in script directory, to load all these settings, overwrite it in memory of game when we press button to strike(ignoring rods and all stuff that make immune to hit), and after strike leave it for default settings. Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-781836 Share on other sites More sharing options...
overmouse Posted June 13, 2016 Author Share Posted June 13, 2016 So no idea what to do? :/ Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-783314 Share on other sites More sharing options...
Arkathorn Posted June 13, 2016 Share Posted June 13, 2016 --This variable is the class definition for the season manager local SeasonManager = require "components/seasonmanager" --Register a new function to do a lightning strike ignoring all distractions --Use the target argument to make things easier; this is the thing that will be hit function SeasonManager:DoImmutableLightningStrike(pos,target) local lightning = SpawnPrefab("lightning") lightning.Transform:SetPosition(pos:Get()) if target then pos = Vector3(target.Transform:GetWorldPosition()) end if target then if target.components.playerlightningtarget then target.components.playerlightningtarget:DoStrike() else target:PushEvent("lightningstrike", {rod=target}) end else local ents = TheSim:FindEntities(pos.x, pos.y, pos.z, 3, nil, {"FX", "NOCLICK", "DECOR", "INLIMBO"}) for k,v in pairs(ents) do if not v:IsInLimbo() then if v.components.burnable and not v.components.fueled and not v.components.burnable.lightningimmune then v.components.burnable:Ignite() end end end end end This code defines a function that does an immutable lightning strike (ignores lightning rods and hit chance). Call the function like so: --To call the function on a location, provide it with a Vector3: (These are arbitrary coordinates, they could be anything) GetSeasonManager():DoImmutableLightningStrike(Vector3(5,0,-27)) --To call the function on a target, provide it with a nil value, followed by the target's instance GetSeasonManager():DoImmutableLightningStrike(nil, GetPlayer()) Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-783339 Share on other sites More sharing options...
overmouse Posted June 13, 2016 Author Share Posted June 13, 2016 (edited) Another way to realise lightning strike with ignoring rods Thanks @Arkathorn But character still immune while wearing SnakeSkin Hat and Jacket :/ Edited June 13, 2016 by overmouse Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-783363 Share on other sites More sharing options...
overmouse Posted June 13, 2016 Author Share Posted June 13, 2016 (edited) Combined playerlightningtarget local inst=GetPlayer() local mult = TUNING.ELECTRIC_WET_DAMAGE_MULT * inst.components.moisture:GetMoisturePercent() local damage = -(TUNING.LIGHTNING_DAMAGE + (mult * TUNING.LIGHTNING_DAMAGE)) inst.components.health:DoDelta(damage, false, "lightning") inst.sg:GoToState("electrocute") - so it makes function SeasonManager:DoImmutableLightningStrike(pos,target,inst) local inst=GetPlayer() local lightning = SpawnPrefab("lightning") pos = Vector3(target.Transform:GetWorldPosition()) lightning.Transform:SetPosition(pos:Get()) if target then if target.components.playerlightningtarget then local mult = TUNING.ELECTRIC_WET_DAMAGE_MULT * inst.components.moisture:GetMoisturePercent() local damage = -(TUNING.LIGHTNING_DAMAGE + (mult * TUNING.LIGHTNING_DAMAGE)) inst.components.health:DoDelta(damage, false, "lightning") inst.sg:GoToState("electrocute") target.components.playerlightningtarget:DoStrike() else target:PushEvent("lightningstrike", {rod=target}) end else local ents = TheSim:FindEntities(pos.x, pos.y, pos.z, 3, nil, {"FX", "NOCLICK", "DECOR", "INLIMBO"}) for k,v in pairs(ents) do if not v:IsInLimbo() then if v.components.burnable and not v.components.fueled and not v.components.burnable.lightningimmune then v.components.burnable:Ignite() end end end end end Now it hits me and ignoring SnakeCloth. But game thinks, that player still immune - and after hit he says the immune phrase. That's not serious problem anyway. Thanks guys! You help a lot! Edited June 13, 2016 by overmouse Link to comment https://forums.kleientertainment.com/forums/topic/67948-dummy-question-about-mod/#findComment-783383 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