Jump to content

Weapon with mental resilience that applies only to mod characters


Recommended Posts

If the sentence is awkward because I'm using a translator, I'll apologize in advance for that...

I'm creating a character mod with an item (weapons) added. I fixed my invisible weapon and made sure my character files were working fine. I've been looking for forums a lot... But I didn't really know how to find the relevant content, so I wrote it.

Anyway, to get straight to the point, I want to know the code that restores a small amount of mental strength when a particular character uses a weapon. The weapon is a melee type weapon and I want to apply it only to certain characters (mode characters). I think the recovery amount would be appropriate to recover 3 on 1 hit.

I tried making the code myself, but I'm still very inexperienced, so I kept failing.. Thank you in advance to anyone who reads this or worries about it, and have a good day.

  • Wavey 1
Link to comment
Share on other sites

local function onattack(inst, owner, target)
		if owner.components.sanity ~= nil and 
           owner:HasTag("Character_Tag") and
           not (target:HasTag("wall") or target:HasTag("engineering")) then
	        owner.components.sanity:DoDelta(TUNING.CUSTOM_WEAPON_SANITY_GAIN)
		end
    end
end

    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(TUNING.CUSTOM_WEAPON_DAMAGE) -- can be numbers like 34 (spear damage)
    inst.components.weapon.onattack = onattack

This is based on the bat bat from the base game

Tunings are to be implemented or changed to actual numbers depending on what you want.

The local function will make 3 checks for the effect to take place: if the character has sanity, if the character has a tag that your custom character will have and the target is not a placed object to avoid exploiting the game.

Add this to your item itself.

  • Wavey 1
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...