dudedudedude

[solved] Make character take self damage when attacking unarmed, and have chance to poison when attacked?

6 posts in this topic

Posted (edited)

Hello, so I am just new to modding so a lot of thanks in advance.

I want to make my character take a certain amount of damage every time it uses unarmed attack, and have a certain chance to poison enemy every time it gets attacked.

I have seen mods that let characters do damage over time on its own attacks, but I haven't seen mods that have an effect like I want.

Can anyone please help?  Or maybe I haven't looked around the workshop enough, in which case I'm sorry can you show me mods that let the character have some effect on itself when it attacks?

Edited by dudedudedude

Share this post


Link to post
Share on other sites

With this code you can make your character take damage & look like he was hit when you hit something with your fists.

Put it in yourcharacter.lua inside the master_postinit area.

inst:ListenForEvent("onattackother", function(inst, data)
	local handslot = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
	if not handslot then
		inst.components.health:DoDelta(-10)
		inst.sg:GoToState("hit")
	end
end)

 

And for a code to poison enemies if I remember there's a "Sans" mod on the workshop that also poisons enemies when he hits them, so I would suggest you download that & look through it, good luck :)!

1 person likes this

Share this post


Link to post
Share on other sites
On 6/8/2017 at 10:44 AM, dudedudedude said:

Hello, so I am just new to modding so a lot of thanks in advance.

I want to make my character take a certainarrow-10x10.png amount of damage every time it uses unarmed attack, and have a certain chance to poison enemy every time it gets attacked.

I have seen mods that let characters do damage over time on its own attacks, but I haven't seen mods that have an effect like I want.

Can anyone please helparrow-10x10.png?  Or maybe I haven't looked around the workshop enough, in which case I'm sorry can you show me mods that let the character have some effect on itself when it attacks?

Hey, I'm trying to do the same thing, but I don't understand the difference between the normal postinit area and the master postinit area, where is each?

Share this post


Link to post
Share on other sites

@FashionablyRin If you're using the Extended Sample Character template, then you have the common_postinit and master_postinit functions in the scripts/prefabs/esctemplate.lua file. The former runs for both the client and server BEFORE any of the components are added and the latter runs only for the server AFTER all the components are loaded (see scripts/player_common.lua for the exact code).

Share this post


Link to post
Share on other sites

@Yabumi I have this in my esctemplate.lua

local MakePlayerCharacter = require "prefabs/player_common"


local assets = {

        Asset( "ANIM", "anim/player_basic.zip" ),
        Asset( "ANIM", "anim/player_idles_shiver.zip" ),
        Asset( "ANIM", "anim/player_actions.zip" ),
        Asset( "ANIM", "anim/player_actions_axe.zip" ),
        Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),
        Asset( "ANIM", "anim/player_actions_shovel.zip" ),
        Asset( "ANIM", "anim/player_actions_blowdart.zip" ),
        Asset( "ANIM", "anim/player_actions_eat.zip" ),
        Asset( "ANIM", "anim/player_actions_item.zip" ),
        Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),
        Asset( "ANIM", "anim/player_actions_bugnet.zip" ),
        Asset( "ANIM", "anim/player_actions_fishing.zip" ),
        Asset( "ANIM", "anim/player_actions_boomerang.zip" ),
        Asset( "ANIM", "anim/player_bush_hat.zip" ),
        Asset( "ANIM", "anim/player_attacks.zip" ),
        Asset( "ANIM", "anim/player_idles.zip" ),
        Asset( "ANIM", "anim/player_rebirth.zip" ),
        Asset( "ANIM", "anim/player_jump.zip" ),
        Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),
        Asset( "ANIM", "anim/player_teleport.zip" ),
        Asset( "ANIM", "anim/wilson_fx.zip" ),
        Asset( "ANIM", "anim/player_one_man_band.zip" ),
        Asset( "ANIM", "anim/shadow_hands.zip" ),
        Asset( "SOUND", "sound/sfx.fsb" ),
        Asset( "SOUND", "sound/wilson.fsb" ),
        Asset( "ANIM", "anim/beard.zip" ),

        Asset( "ANIM", "anim/deku.zip" ),
}
local prefabs = {
	"examplefloatableitem",
}

-- Custom starting items
local start_inv = {
	"examplefloatableitem",
}

local fn = function(inst)
	
	-- choose which sounds this character will play
	inst.soundsname = "wilson"

	-- Minimap icon
	inst.MiniMapEntity:SetIcon( "deku.tex" )
	
	-- Base Stat Stuff	
	inst.components health:SetMaxHealth(175)
	inst.components.hunger:SetMax(150)
	inst.components.sanity:SetMax(125)
	
	-- Damage Related Stuff
    inst.components.combat.damagemultiplier = 1
	inst.components.combat.defaultdamage = 50
	inst.components.health:SetAbsorptionAmount(0)
	inst.components.health.fire_damage_scale = 1
	
	-- Hunger and Sanity Stuff
	inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE
	inst.components.eater.ignoresspoilage = false
	inst.components.hunger:SetKillRate(1)
	inst.components.hunger:SetRate(1)
	
	-- Movement Stuff
	inst.components.locomotor.walkspeed = 4
	inst.components.locomotor.runspeed = 6
end

return MakePlayerCharacter("deku", prefabs, assets, fn, start_inv)

The top line says player_common, I'm guessing this is the common_postinit area? Where is the master_postinit area? And am I supposed to include the end at the "end" and "end)" of this VVV Or am I supposed to removearrow-10x10.png the "end" from the first one after (see below) and paste it after?

      inst.components.locomotor.runspeed = 6     V

      end                                                                V

inst:ListenForEvent("onattackother", function(inst, data)
	local handslot = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
	if not handslot then
		inst.componentsHEALTH:DoDelta(-10)
		inst.sg:GoToState("hit")
	end
end)
Edited by FashionablyRin

Share this post


Link to post
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