Jump to content

Coding custom character perks (help)


Recommended Posts

One option is to give them a small boost each time they attack an enemy (similar to wigfrid but smaller, and only for sanity). I'm not sure there are other ways to be sure a character is "active" in a fight.

Link to comment
Share on other sites

7 hours ago, toasterbathbomb said:

Any luck finding anything? I'm not sure how i can look at Wigfrids code, i'm not good at that stuff

Go in the folder of the game, then in data, then in databundle. There, you have a scripts.zip : open the archive somewhere. In scripts/prefabs search for the wathgrith.lua file (you can open it with any text editor, but i suggest notepad++).


About your perk i would try something like this :

local function IsValidVictim(victim)
    return victim ~= nil
        and not ((victim:HasTag("prey") and not victim:HasTag("hostile")) or
                victim:HasTag("veggie") or
                victim:HasTag("structure") or
                victim:HasTag("wall") or
                victim:HasTag("companion"))
        and victim.components.health ~= nil
        and victim.components.combat ~= nil
end

local function OnAttackOther(inst, data)
    local victim = data.victim
    if IsValidVictim(victim) then
		inst.components.sanity:DoDelta(-TUNING.SANITY_SMALL)
    end
end

 

    inst:ListenForEvent("onattackother", OnAttackOther)

 

You probably want to adjust the list of valid victim (it's here so you don't gain sanity when attacking walls, for example). The second line goes in the master_postinit function.

 

Code is untested, so there could be errors.

Edited by Lumina
Link to comment
Share on other sites

Search in your character.lua file. Then if you still don't know how to put it, look at other character files to have some idea (or other creatures). Don't hesitate to search, a lot. The option "search in all files" is very useful.

If you still don't find or are unsure, then ask again :)

Link to comment
Share on other sites

4 hours ago, Lumina said:

Search in your character.lua file. Then if you still don't know how to put it, look at other character files to have some idea (or other creatures). Don't hesitate to search, a lot. The option "search in all files" is very useful.

If you still don't find or are unsure, then ask again :)

Alright, i checked out wathgrithr.lua and looked at the code, then put the code you sent into my prefab file like so

image.png.b897a834d73d052f4761263ad9c1ec6d.png

image.png.99a90e2e2e816e5a5453c135f397e056.png

 

The game didnt have any problems, no crashes or errors, but after i killed a couple birds and rabbits with a boomerang, i had no sanity boost. Did I put the code in the wrong place?

Link to comment
Share on other sites

Try to kill a spider. The code used, at the moment, will not consider birds and rabbits as valid victim, because of this line :

        and not ((victim:HasTag("prey") and not victim:HasTag("hostile")) or

(Rabbits and birds are prey and not hostile).

This could be changed, i'm just unsure about how exactly :D (Yeah, i'm not good with logic and stuff like this).

Link to comment
Share on other sites

1 hour ago, Lumina said:

Try to kill a spider. The code used, at the moment, will not consider birds and rabbits as valid victim, because of this line :


        and not ((victim:HasTag("prey") and not victim:HasTag("hostile")) or

(Rabbits and birds are prey and not hostile).

This could be changed, i'm just unsure about how exactly :D (Yeah, i'm not good with logic and stuff like this).

my sanity... dropped? how do i make it increase?

Link to comment
Share on other sites

 

16 minutes ago, toasterbathbomb said:

my sanity... dropped? how do i make it increase?

Oops :D

I took a code i use for sanity loss. Just change :

		inst.components.sanity:DoDelta(-TUNING.SANITY_SMALL)

Into :

		inst.components.sanity:DoDelta(TUNING.SANITY_SMALL)

 


local function IsValidVictim(victim)
    return victim ~= nil
        and not victim:HasTag("veggie") or
                victim:HasTag("structure") or
                victim:HasTag("wall") or
                victim:HasTag("companion"))
        and victim.components.health ~= nil
        and victim.components.combat ~= nil
end

If you want to include bird, rabbit, and all the prey in the code, try this version of the "isvalidvictim" function. Not tested, tell me if you encounter problems.

Link to comment
Share on other sites

 

13 minutes ago, toasterbathbomb said:

Let me know if this works better with this :

local function IsValidVictim(victim)
    return victim ~= nil
        and not (victim:HasTag("veggie") or
                victim:HasTag("structure") or
                victim:HasTag("wall") or
                victim:HasTag("companion"))
        and victim.components.health ~= nil
        and victim.components.combat ~= nil
end

Also, don't use twice the "isValidVictim" function, replace one by the other, or comment the unused one, or you risk to cause crashs.

For example :


--New code, delete it if the game crashes
-- local function IsValidVictim(victim)
    -- return victim ~= nil
        -- and not ((victim:HasTag("prey") and not victim:HasTag("hostile")) or
                -- victim:HasTag("veggie") or
                -- victim:HasTag("structure") or
                -- victim:HasTag("wall") or
                -- victim:HasTag("companion"))
        -- and victim.components.health ~= nil
        -- and victim.components.combat ~= nil
-- end
--More new code
local function IsValidVictim(victim)
    return victim ~= nil
        and not (victim:HasTag("veggie") or
                victim:HasTag("structure") or
                victim:HasTag("wall") or
                victim:HasTag("companion"))
        and victim.components.health ~= nil
        and victim.components.combat ~= nil
end

If you really want to keep the old function somewhere for the time of test. But i suggest to remove it after.

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