Jump to content

Modded character hits self, is there a way to avoid armor damage?


Recommended Posts

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 by Zhilo
Link to comment
Share on other sites

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

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

This is an example of the syntax, picture is from the game code.

Spoiler

image.thumb.png.342d4be6fbfb1c7381233e3bd03efbf1.png

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 by penguin0616
additional resources
  • Like 1
Link to comment
Share on other sites

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