Jump to content

Need Help: Overwriting the Razor to do DMG


Recommended Posts

Hey y'all,

I've been programming an update for my character, and part of it is the need to overwrite the razor file in DST to be somewhat like a spear. I'm admittedly timid of starting to use overwrite functions, given I've only added things to the game, so I would really appreciate some assisstance.

I need the razor to be equipable, similarly to a spear, and also have the animations of sword that enable the razor to attack. I would also like these razor modification features to be exclusive to one character, which is the one I modded in. In other words: only he can attack using the razor while other characters can only use it to shave. It would just deal damage like a spear would.

Code for this would be heavily appreciated, as I've ran into multiple dead ends on my part. Also, to the person who had replied to my earlier trouble, thank you a ton! Your contribution was stellar to my mod development and helped me get it published.

Link to comment
Share on other sites

local function OnEquip(inst, owner)
	owner.AnimState:OverrideSymbol("swap_object", "swap_spear", "swap_spear") -- Reusing Spear assets, make sure to make your own
	owner.AnimState:Show("ARM_carry")
	owner.AnimState:Hide("ARM_normal")
end

local function OnUnequip(inst, owner)
	owner.AnimState:Hide("ARM_carry")
	owner.AnimState:Show("ARM_normal")
end

AddPrefabPostInit("razor", function(inst)
	if not GLOBAL.TheWorld.ismastersim then
		return inst
	end
	
	inst:AddComponent("equippable")
	inst.components.equippable:SetOnEquip(OnEquip)
	inst.components.equippable:SetOnUnequip(OnUnequip)
	inst.components.equippable.restrictedtag = "razorweapontag" -- Your character must have this tag to equip it, name the tag whatever you want
	
	inst:AddComponent("weapon")
	inst.components.weapon:SetDamage(GLOBAL.TUNING.SPEAR_DAMAGE) -- Spear damage is 34, you can change this to whatever
end)

 

16 hours ago, RussianChattus said:

Also, to the person who had replied to my earlier trouble, thank you a ton! Your contribution was stellar to my mod development and helped me get it published.

You're welcome! :)

  • Like 2
  • Shopcat 1
Link to comment
Share on other sites

6 hours ago, ClumsyPenny said:
local function OnEquip(inst, owner)
	owner.AnimState:OverrideSymbol("swap_object", "swap_spear", "swap_spear") -- Reusing Spear assets, make sure to make your own
	owner.AnimState:Show("ARM_carry")
	owner.AnimState:Hide("ARM_normal")
end

local function OnUnequip(inst, owner)
	owner.AnimState:Hide("ARM_carry")
	owner.AnimState:Show("ARM_normal")
end

AddPrefabPostInit("razor", function(inst)
	if not GLOBAL.TheWorld.ismastersim then
		return inst
	end
	
	inst:AddComponent("equippable")
	inst.components.equippable:SetOnEquip(OnEquip)
	inst.components.equippable:SetOnUnequip(OnUnequip)
	inst.components.equippable.restrictedtag = "razorweapontag" -- Your character must have this tag to equip it, name the tag whatever you want
	
	inst:AddComponent("weapon")
	inst.components.weapon:SetDamage(GLOBAL.TUNING.SPEAR_DAMAGE) -- Spear damage is 34, you can change this to whatever
end)

 

You're welcome! :)

First off, it's a pleasure seeing you again, and thank you a million for contributing again!

However, a minor inconvenience has come to the table where when i put all this code into the razor script in my mod prefabs, the game will say that there was an error generating the server when I make a new one. I made an entirely new LUA file and pasted this all in there, located with my other scripts, with the changes that i named the tag "razorwelder" and set the damage to = 25. I'm not really sure where the issue could be, so I'd appreciate if you helped me out a little bit.

Thank you for your time!

Link to comment
Share on other sites

7 hours ago, RussianChattus said:

i put all this code into the razor script in my mod prefabs

No, you're supposed to put the code I made in modmain.lua. I made the code so you don't override the "razor.lua" prefab file itself, it's a bad practice to override files directly (makes them less compatible with mods and quickly outdated if Klei updates the prefab with something).

  • Shopcat 1
Link to comment
Share on other sites

15 hours ago, ClumsyPenny said:

No, you're supposed to put the code I made in modmain.lua. I made the code so you don't override the "razor.lua" prefab file itself, it's a bad practice to override files directly (makes them less compatible with mods and quickly outdated if Klei updates the prefab with something).

I put this all into modmain.lua (both local funtions, and addprefabpostinit function), however on trying to generate a world with the new code in my modmain and deleting the razor.lua file in my scripts, it gets stuck in an infinite loop of trying to generate a world. After I deleted your code from my modmain.lua, the world would generate as usual without an infinite loop, so I think there could be an issue.

Also, in the razor.lua in-game file, there is a tag added that is "donotautoequip". I theorize that maybe this would need to be utilizing RemovePrefabPostInit? But I am unsure. Thank you for your time, and if you happen to modify the code so it could run without a worldgen loop I would appreciate it!

Link to comment
Share on other sites

7 hours ago, RussianChattus said:

it gets stuck in an infinite loop of trying to generate a world. After I deleted your code from my modmain.lua, the world would generate as usual without an infinite loop, so I think there could be an issue.

A crash log would be infinitely useful. I tested my code before sending it to you and it worked, so there's likely an issue or conflict with some of your other code or mods. You can find it in Documents\Klei\DoNotStarveTogether\master_server_log.lua, send me this file once you ran the world and encountered the issue (this file contains the server log for the most recent world you played).

7 hours ago, RussianChattus said:

Also, in the razor.lua in-game file, there is a tag added that is "donotautoequip".

The tag is "donotautopick", it's just so that The Lazy Forager and similar mechanics ignore the Razor as a valid item to pick up.

7 hours ago, RussianChattus said:

I theorize that maybe this would need to be utilizing RemovePrefabPostInit? But I am unsure.

There's no such thing as RemovePrefabPostInit, you just use AddPrefabPostInit and remove things there as needed. But we don't need to do that here.

  • Shopcat 1
Link to comment
Share on other sites

14 hours ago, ClumsyPenny said:

A crash log would be infinitely useful. I tested my code before sending it to you and it worked, so there's likely an issue or conflict with some of your other code or mods. You can find it in Documents\Klei\DoNotStarveTogether\master_server_log.lua, send me this file once you ran the world and encountered the issue (this file contains the server log for the most recent world you played).

The tag is "donotautopick", it's just so that The Lazy Forager and similar mechanics ignore the Razor as a valid item to pick up.

There's no such thing as RemovePrefabPostInit, you just use AddPrefabPostInit and remove things there as needed. But we don't need to do that here.

Here is the crash log, which I fetched when the game ran into the loop again: master_server_log.txt

I realize reading through it, there is an unexpected coding error. I will try and resolve it myself real quick, and if it works, I will inform you.

Edit: Fixed, epic, thank you a bajillion!!! the crash log was the key to success you were right! Now I'll just make some fun assets yay

Edited by RussianChattus
  • GL Happy 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...