Jump to content

How to add custom weapon to the character mod?


Recommended Posts

I finally made the character mod to work! But unfortunately when I tried to put my custom weapon to the game it crashes... 

Can someone give me an example of how to put custom weapon to mod character?

Also, is it possible to make custom bonfire item that can resurrect when you interact to it? 

캡처.PNG

캡처gg.PNG

Link to comment
Share on other sites

This mod makes firepits able to resurrect players. You could take a look at that code, to see how to do this. If you want to create a new custom prefab from the firepit, do that first since it'll give you enough trouble as it is to make a duplicate of that, and then take a look at the code for this mod to see what code is needed to make your new prefab do this.

  1. Did your custom weapon work before you put it into your character mod?
  2. Which error do you get in your logs? If you post a log file, I would also need to see a zip of your mod.
  3. Is this item supposed to be "locked" to your character somehow? Like, only your char can craft it or pick it up or something?

There are plenty of mod characters who have custom weapons. Check out the code for those. It might even be easier to start by making the item as a stand-alone mod, and then when it works you can move it into your character mod.

Once you've created your weapon, if you want to make a character-specific recipe for it or make other characters unable to pick it up, this post shows how to do that. That post also has a small paragraph at the beginning, which tells you how to move a stand-alone item mod into a character mod.

Link to comment
Share on other sites

Thank you Ultroman.

1. I made the character mod first and after that I tried making weapon in the same file.

2.here you go. The character itself is functioning good but I can't see or spawn the weapon as it crash as soon as I spawn it.

3. The weapon itself is locked on to the character as well as to craft or pick it up.

I've been looking at others mod a while but it does help me somehow the coding is all different. I can't figure out which form I should take..  

artorias.zip

client_log.txt

Link to comment
Share on other sites

That's not it. They're called server_log.txt. The paths are in the newcomer post.

If there are no such files, then you need to let the game run for at least one clock segment before making it crash (sometimes the server log files aren't generated until this point).

Link to comment
Share on other sites

You're welcome :)

2 hours ago, HEAN said:

If I want to make custom character to be stronger against certain mobs

Look at the combat component. There's a function called CalcDamage. You can extend that, and multiply the damage done if the target is one of those mobs. You can make a dictionary of modifiers with prefab names as keys, in order to easily change or add entries.

-- Put this first part somewhere above your character's master_postinit:

-- damage_modifiers is a dictionary with creature prefab names as keys
-- and the modifiers as values.
local damage_modifiers = {
	butterfly = 1.2, -- 20% damage increase
	crow = 0.8,      -- 20% damage decrease
}


-- Put this next part at the bottom of your character Lua's master_postinit:

local oldCalcDamage = inst.components.combat.CalcDamage
inst.components.combat.CalcDamage = function(self, target, weapon, multiplier, ...)
	local damage = oldCalcDamage(self, target, weapon, multiplier, ...)
	if damage ~= 0 and target.prefab ~= nil then
		-- We look up the kill penalty in our dictionary, using the prefab-variable (prefab name)
		-- of the target we are attacking.
		local damage_modifier = damage_modifiers[target.prefab]
		
		-- If we found an entry in our damage_modifiers dictionary for the target, apply the modifier.
		if damage_modifier ~= nil then
			damage = damage * damage_modifier
		end
	end
	return damage
end)

 

Edited by Ultroman
Link to comment
Share on other sites

Umm am I doing it right? Do I need to add anything more?

 

 

-- Put this first part somewhere above your character's master_postinit:

-- damage_modifiers is a dictionary with creature prefab names as keys
-- and the modifiers as values.
local damage_modifiers = {
    crawlinghorror = 1.2, -- 20% damage increase     
    crawlingnightmare = 1.2,
    terrorbeak = 1.2,
    nightmarebeak = 1.2,
    stalker = 1.25,
    stalker_forest = 1.25,
    stalker_atrium = 1.25,
    shadow_knight = 1.25,
    shadow_bishop = 1,25,
    shadow_rook = 1.25,
}

-- This initializes for the server only. Components are added here.
local master_postinit = function(inst)

local oldCalcDamage = inst.components.combat.CalcDamage
inst.components.combat.CalcDamage = function(self, target, weapon, multiplier, ...)
    local damage = oldCalcDamage(self, target, weapon, multiplier, ...)
    if damage ~= 0 and target.prefab ~= nil then
        -- We look up the kill penalty in our dictionary, using the prefab-variable (prefab name)
        -- of the target we are attacking.
        local damage_modifier = damage_modifiers[target.prefab]
        
        -- If we found an entry in our damage_modifiers dictionary for the target, apply the modifier.
        if damage_modifier ~= nil then
            damage = damage * damage_modifier
        end
    end
    return damage
end)

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