Sign in to follow this  
Psychomaniac

Need HELP to make Blunderbuss deal specific dmg vs mob has tag "animal" [SOLVED]

Recommended Posts

Psychomaniac    222

Hi guys, thank for coming here!

Ok! The thing is: I used a mod that bring Blunderbuss to DST. i want to made it deal 1000 dmg to mob that has tag "animal" so i can one shot them (for Hunting role play :D, only a few mob has tag animal: koalefant, beefalo, volt goat...).

In Blunderbuss.lua file, there are lines:

Spoiler

local function OnAttack(inst, attacker, target)
    print("OnAttack")
    if inst:HasTag("blunderbuss") then
        inst.components.inventory:RemoveItemBySlot(1)
        OnLoseAmmo(inst, attacker)
    end
    --spear.components.weapon:OnAttack(attacker, target, true)
end

Which i think made Blunderbuss remove ammo when fired a shot.

I then tried add these line into Blunderbuss.lua file:

Spoiler

local function onattackanimal(inst, attacker, target)
    if target:HasTag("animal") then
        inst.components.weapon:SetDamage(1000)
    else
        inst.components.weapon:SetDamage(damage)
    end
end

and this line under local function fn() section of Blunderbuss.lua file:

Spoiler

    inst.components.weapon:SetOnAttack(onattackanimal)

Log-in to the game: 

First shot on a beeffalo deal base dmg, but not consume the ammo like it should, 2nd shot deal 1000 dmg still not consume ammo and so on...

after a couple more shots the game crash.

Then i deleted all the code that i added and tried to improvise something like this (add a part of the code into the original "OnAttack"):

Spoiler

local function OnAttack(inst, attacker, target)
    print("OnAttack")
    if inst:HasTag("blunderbuss") then
        inst.components.inventory:RemoveItemBySlot(1)
        OnLoseAmmo(inst, attacker)
    end
    --spear.components.weapon:OnAttack(attacker, target, true)

    if target:HasTag("animal") then
        inst.components.weapon:SetDamage(1000)
    else
        inst.components.weapon:SetDamage(damage)
    end
end

Log-in to the game: 

Blunderbuss now function like normal (deal base dmg, consume ammo, like those extra code i added was nothing).

Please help if you can!!!

Thank for reading.

Share this post


Link to post
Share on other sites
-t-    109

Doing something like this for a certain weapon can be tricky since weapon component, unlike combat component, doesn't have bonusdamagefn. But you can approach this problem in a different way. If you know every entity with the animal tag you can manually create a table with their prefabs and add a function to kill it if the weapon is a blunderbuss:

local table = { -- The table with prefabs of animals
	"beefalo",
	"koalafant",
	...
}

for k,v (table) do -- Loop for all the prefabs in the table
	AddPrefabPostInit(v, function(inst) -- Add prefab, 'v' being prefabs from the table
		local function OnAttacked(inst, weapon) -- OnAttacked function
    		if inst.components.health and weapon.prefab == "blunderbuss" then -- Check for health component and what is the weapons prefab
				inst.components.health:Kill() -- Kill, if all conditions are met
			end
		end

		inst:ListenForEvent("attacked", OnAttacked) -- Listen for event 'attacked'
	end)
end

 

This method will allow you to basically have full control over what entity is one-shot kill from the blunderbuss. Other way you can do it is by checking every prefab in the game with a 'for' loop and checking if it has the "animal" tag, then adding the function above. Of course this method is a bit less tidy and controllable.

The only other option you have is probably overriding the weapon component, adding some sort of bonusdamagefn, similar to the combat component, but that's a lot of work and I think there are better options.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
Psychomaniac    222

Hi guys (@IThatGuyI, @penguin0616) !, first i want to thank you for taking your time to help me with my stuff.

The reason why i didn't post anything until now is because of my coding skill level is like next to zero, for that i can't make the magic happen (even how detail @IThatGuyI explain the code :D), and i don't want to trouble you guy more.

After many tries and fail, i'm kinda give up, then i went on Steam's Workshop (like i always do) search for items, or char that have items that deal extra dmg to a specific type of mob. After many hours, i found a few mods that does.

Then after a few hours digging, i finally cooked up some lines:

if (target:HasTag("animal") or target:HasTag("pig")) then	-- you can add more mob tag into the "()"
		target.components.combat:GetAttacked(attacker, 1000, inst)	-- 1000+ bonus damage
	end

Then i saw @penguin0616 mentioned OnHitFn, i then search for OnHit in blunderbuss.lua file, and did find one.

One more try doesn't hurt, i then added the new code in:

local function OnHit(inst, attacker, target, weapon)
    local impactfx = SpawnPrefab("impact")
    if impactfx and attacker then
        local follower = impactfx.entity:AddFollower()
        follower:FollowSymbol(target.GUID, target.components.combat.hiteffectsymbol, 0, 0, 0)
        impactfx:FacePoint(attacker.Transform:GetWorldPosition())
    end

	-- Deal extra dmg vs mobs have tag mentioned, you can add more mob tag into the "()"
	if (target:HasTag("animal") or target:HasTag("pig")) then
		target.components.combat:GetAttacked(attacker, 1000, inst)	-- 1000+ bonus damage
	end

    inst:Remove()
end

and it's worked :D. OMG :D :D :D  !!!

Again, thank you for your help, much appreciated. GG.

Edited by Psychomaniac

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
Sign in to follow this