Zhilo Posted December 13, 2020 Share Posted December 13, 2020 (edited) So, a long time ago I created a modded character, and i got help in these forums to make a script to enable her to hit herself sometimes every time she hit an enemy, the code being: local function HitSelf(inst) local rng = math.random(1,10) -- 10% if rng == 1 then inst.components.combat:GetAttacked(inst, 5, nil) -- Hurt myself local rt = math.floor(math.random() * 3) if (rt == 0) then inst.components.talker:Say("Dangit!", 2.5, 0) end if (rt == 1) then inst.components.talker:Say("Ow! I hit myself!", 2.5, 0) end if (rt >= 2) then inst.components.talker:Say("I need a bandaid!", 2.5, 0) end end end Which works great fo rmy purposes, but upon playtesting, some issues turned up. This self damage counts towards armor degradation, which puts the character at too much of a minus on resources spent to fight compared to other characters, not to mention the animation of "being hit" that she triggers on her own interrupts her attempts to attack, which can make fighting mobile things like merms and clockwork knights incredibly difficult. I've been thinking on ways to sort out these issues, without outright removing the self-harm from the character since thats unique from the main cast and interesting. First Idea i had is to make it so self-hits don't cost armor durability, is this possible to do? if not, perhaps I may have to look into giving her passive damage reduction but that feelslike a cop out. Another thing I am unsure if is possible, is to accelerate the "hurt" animation. hopefully just for the self hits, but if not, in general as a character perk? Don't want to remove it because the visual feedback is important, but as it is the character currently suffers too much from stunlock between the enemies and her own attacks. I'm still trying to brainstorm ways to fix these issues withotu compromising the character identity as a high risk, high reward bruiser. Edited December 13, 2020 by Zhilo Link to comment Share on other sites More sharing options...
DecDuck Posted December 13, 2020 Share Posted December 13, 2020 (edited) Couldn't you just use health:DoDelta to minus the damage that the current weapon does? Edited December 13, 2020 by decduck3 Link to comment Share on other sites More sharing options...
Zhilo Posted December 14, 2020 Author Share Posted December 14, 2020 Well I didn't want to lose the being hit animation of the hit self event, so i left it as it was. Some compensation I did was to give her a 75% natural absorption, and the inability to wear any armor at all. I will be testing this for balance, but she will probably need some means of enhacing her survival in the long term since she will be permanently on a little less than a log suit agaisnt bosses and such. Is it possible to add a multipler for all forms of healing received? that is, food, craftable salves and the like, and sleeping? I tried so look at Wortox's code since he heals less for food, but i couldn't find what I was looking for. Link to comment Share on other sites More sharing options...
penguin0616 Posted December 14, 2020 Share Posted December 14, 2020 You can override your :DoDelta to multiply the argument it provides if it is positive. Wortox's comes from his absorptions on his eater component. 1 Link to comment Share on other sites More sharing options...
Zhilo Posted December 14, 2020 Author Share Posted December 14, 2020 I have to apologize, since I really am new to coding in its entirety, i can sort of understand the logic if i look at the scripts, but I don't know how to work the sintax. I hate to be so bothersome, but could I have a sample of how to check for the DoDelta and then override it? I am assuming this still happens in charactername.lua Link to comment Share on other sites More sharing options...
IronHunter Posted December 14, 2020 Share Posted December 14, 2020 I think the simplest way to do this is just forcefully change your state to the hit one, and health:DoDelta to simulate the raw direct damage. You can simulate the getting hit but not actually getting hit. To the average player it'll look no different. 1 Link to comment Share on other sites More sharing options...
penguin0616 Posted December 14, 2020 Share Posted December 14, 2020 (edited) This is an example of the syntax, picture is from the game code. Spoiler I also recommend you check out the Lua manual, since it's generally the best place to learn stuff like the syntax. It's pretty detailed, which is nice. https://www.lua.org/manual/5.1/manual.html Edited December 14, 2020 by penguin0616 additional resources 1 Link to comment Share on other sites More sharing options...
Zhilo Posted December 17, 2020 Author Share Posted December 17, 2020 (edited) Alright, got it working!, this is what the code ended up looking like. local function HitSelf(inst) local rng = math.random(1,10) -- 10% if rng == 1 then inst.sg:GoToState("hit") inst.components.health:DoDelta(-7) -- Hurt myself local rt = math.floor(math.random() * 3) if (rt == 0) then inst.components.talker:Say("Dangit!", 2.5, 0) end if (rt == 1) then inst.components.talker:Say("Ow! I hit myself!", 2.5, 0) end if (rt >= 2) then inst.components.talker:Say("I need a bandaid!", 2.5, 0) end end end Edited December 18, 2020 by Zhilo Link to comment Share on other sites More sharing options...
Thomas Die Posted December 18, 2020 Share Posted December 18, 2020 local hurtie_amount = inst.components.inventory:ApplyDamage(damage, attacker, weapon) bing bong, this is just something i wanted to drop but it should for resistances and e.c woops nvm 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