Jump to content

Custom weapon = Client freeze


Recommended Posts

Hy,

I am trying to give my character mod a weapon, but it isn't shown ingame and as soon as I throw the weapon on the ground every client freezes.

For the start I just wanted to remake the spear.

I copied the code from the Spear weapon and the two anim files, I renamed them and changed the build.bin with the Build Renamer.

The code:

local assets = {
	Asset("ANIM",  "anim/momsknife.zip"),
    Asset("ANIM",  "anim/swap_momsknife.zip"),
    Asset("ATLAS", "images/inventoryimages/momsknife.xml"),
}

local function onequip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_object", "swap_momsknife", "swap_momsknife")
    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

local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
	
	MakeInventoryPhysics(inst)
	
	inst.AnimState:SetBank("momsknife")
    inst.AnimState:SetBuild("momsknife")
    inst.AnimState:PlayAnimation("idle")
	
	inst:AddTag("sharp")
	inst:AddTag("pointy")
	
    inst.entity:SetPristine()
	
	if not TheWorld.ismastersim then
        return inst
    end
	
	inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE)
	
	-------

    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(TUNING.SPEAR_USES)
    inst.components.finiteuses:SetUses(TUNING.SPEAR_USES)
	
    inst.components.finiteuses:SetOnFinished(inst.Remove)
	
	inst:AddComponent("inspectable")
	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "images/inventoryimages/momsknife.xml"
	
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip(onequip)
    inst.components.equippable:SetOnUnequip(onunequip)
    
    MakeHauntableLaunch(inst)

    return inst
end

return Prefab("momsknife", fn, assets)

I renamed every spear to momsknife and added the inventory icon. The inventory icon is the only thing that works.

I can change 

owner.AnimState:OverrideSymbol("swap_object", "swap_momsknife", "swap_momsknife")

inst.AnimState:SetBank("momsknife")
inst.AnimState:SetBuild("momsknife")

to

owner.AnimState:OverrideSymbol("swap_object", "swap_spear", "swap_spear")
inst.AnimState:SetBank("spear")
inst.AnimState:SetBuild("spear")

to show the weapon ingame, which is the spear but not really what I want. I want to change the look of the weapon later.

 

As soon as I throw the weapon on the ground, the client crashes with the following log:

  1. [00:00:56]: Can't find prefab momsknife
  2. [00:00:56]: RakNet detected a missing replica (117288)
  3. [00:00:56]: RakNet detected a missing replica (57601)

and the line "Raknet detected a missing replica" is repeated 100 times.

In modmain.lua I have

PrefabFiles = {
	"isaac",
	"momsknife",
}

and

GLOBAL.STRINGS.NAMES.MOMSKNIFE = "Mom's Knife"
GLOBAL.STRINGS.CHARACTERS.GENERIC.DESCRIBE.MOMSKNIFE = "Stab stab stab."

 

I don't understand how this can make any problems at all, since it's pretty much just the spear.lua with different variable names.

It has to be something really stupid...

Somebody has tips on what I should look at?

I won't respond today anymore, pretty late here.

 

 - statistnr1

Link to comment
Share on other sites

11 hours ago, statistnr1 said:

I renamed them and changed the build.bin with the Build Renamer

As I know it doesn't work well. It's better to decompile animation as a Spriter project and compile again with your custom name and improvements.

Link to comment
Share on other sites

1 hour ago, Maris said:

As I know it doesn't work well. It's better to decompile animation as a Spriter project and compile again with your custom name and improvements.

It work well for simple things, and decompile animation sometimes give stranges things.

Ok so i tried some changes. At least the game isn't crashing, but i can't manage to make the spear appears when in isaac hand. I should forgot something but even when looking at others mods, can't figure what.

momsknife.lua

It's the only file i changed.

When you just rename the build, you can't use SetBank("prefabname"), you should use the name of the item you "copy". Here, spear. This way, the game isn't searching an non existant anim file.


	inst.AnimState:SetBank("spear")
    inst.AnimState:SetBuild("momsknife")
    inst.AnimState:PlayAnimation("idle")
	

 

Also, if i'm not wrong, this part should be like this :


local function onequip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_object", "swap_momsknife", "swap_spear")
    owner.AnimState:Show("ARM_carry")
    owner.AnimState:Hide("ARM_normal")
end

With, again, the name of the bank of the item you are using as a base. But here it's not enough to make the item show so maybe the error is somewhere here.

Link to comment
Share on other sites

6 hours ago, Maris said:

As I know it doesn't work well. It's better to decompile animation as a Spriter project and compile again with your custom name and improvements.

Do you have a guide for me on how to do this?
Would appreciate it!

 

4 hours ago, Lumina said:

At least the game isn't crashing

I hosted the server and let a friend join it.

As soon as I threw it on the ground, his game froze while I had no problems at all. Did you manage to fix these crashes?

I googled that issue and found, that somebody else had the same problem and error message, but the ismastersim line fixed it for him.

 

Can you tell me what the following exactly does?

inst.AnimState:SetBank("spear")
inst.AnimState:SetBuild("momsknife")
inst.AnimState:PlayAnimation("idle")

What does SetBank and SetBuild mean?

Until now it just worked with copying stuff to get it to work, but obviously this doesn't work anymore. :<

 

Thanks for you help!

 

 - statistnr1

Link to comment
Share on other sites

Sorry, i miss some things reading the first post.


Bank is the anim you are using.
Build is the image (the .txt + build.bin)

 

For example, the different pigmen use the "pigman" bank, but a different pigman build.

The koalefant have the same bank, but different builds (winter and summer).

The build (atlas-0.tex + build.bin) is basically the body part. The bank is the anim part.

When you rename a build, it change only things about build, but it's still linked to the original bank. Renaming a build "momsknife" doesn't change the name of the bank to "momsknife", so you still have to tell the game "my build is "momsknife", but the bank is "spear"".

It's why decompiling and recompiling is ofter better when you make something new : you could change name of bank and ending with an item with bank and build named "momsknife". It's useful if you want to add things (elements not in the .tex, or new anim).


It's why i understand of how things work. It could be false in some point.

 

I will try to see if i can help you with the crash, can't garanty anything.

 

Link to comment
Share on other sites

@statistnr1 : so i tried again in a dedicated server (should work as if i'm client instead of host), and all seems to work fine for me. If you still have problems with the code let me know.

I add this line :

    inst.components.inventoryitem.imagename = "momsknife"


I guess it's needed when you make a custom item.

 

momsknife.lua

 

Hope it will work. Let me know.

Edited by Lumina
Link to comment
Share on other sites

@Lumina

Thanks for the explanation, helps me a lot.

My friends are still crashing as soon as I drop the weapon, while I have no problems.

And they can't see the weapon ingame.

Unfortunately I am not one to give up, so I will waste some more days with this problem.

If you have more ideas I am happy to hear them.

Thanks for your help

Edit:

I copied the custom weapon from another character mod with the anim files and the stuff from the exported folder. Just changed the name in momsknife.lua but the same problems.

It has to be a problems outside of momsknife.lua

 - statistnr1

Edited by statistnr1
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...