Jump to content

HELP-cannot craft weapon in my character mod on my friends server


Recommended Posts

Hello, need a little help here.

I made a character mod and added a few weapons in it, I test when I host the game and it work all fine, can be crafted and used. But when my friend host the game and he pick a different character, I pick my own mod character and we both can craft the weapon but it will not show in our inventory and it bug our inventory, seems like it becomes invisible.

HERE IS MY WEAPON CODE:

local assets =
{
 Asset("ANIM", "anim/knife_build.zip"),
 Asset("ANIM", "anim/swap_knife_build.zip"),
 Asset("ATLAS", "images/inventoryimages/knife.xml"),
 Asset("IMAGE", "images/inventoryimages/knife.tex"),
}

local prefabs =
{
 "knife",
}
local function OnEquip(inst, owner)
 owner.AnimState:OverrideSymbol("swap_object", "swap_knife_build", "swap_knife")
 owner.AnimState:Show("ARM_carry")
 owner.AnimState:Hide("ARM_normal")
 owner.components.combat.min_attack_period = 0.4
 
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()
 
 MakeInventoryPhysics(inst)
 
 inst.AnimState:SetBank("knife_build")
 inst.AnimState:SetBuild("knife_build")
 inst.AnimState:PlayAnimation("knife_idle")
 
 -- inst:AddComponent("finiteuses")
 -- inst.components.finiteuses:SetMaxUses(120)
 -- inst.components.finiteuses:SetUses(120)
 -- inst.components.finiteuses:SetOnFinished(inst.Remove)
 
 inst.entity:SetPristine()
 
 if not TheWorld.ismastersim then
        return inst
    end
    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(40)
 
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip(OnEquip)
    inst.components.equippable:SetOnUnequip(OnUnequip)
 inst:AddComponent("inventoryitem")
 inst.components.inventoryitem.imagename = "knife"
 inst.components.inventoryitem.atlasname= "images/inventoryimages/knife.xml"
    -------
    inst:AddComponent("inspectable")
    MakeHauntableLaunchAndPerish(inst)
 
 inst.components.weapon.quickAttack=true
 
 return inst
end
return Prefab("common/inventory/knife", fn, assets, prefabs)
 
 
 
 
 
 
HERE IS MY CHARACTER CODE
 

local MakePlayerCharacter = require "prefabs/player_common"

local assets = {
    Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
}
local prefabs = {}
-- Custom starting items
local start_inv = {
}
-- When the character is revived from human
local function onbecamehuman(inst)
 -- Set speed when reviving from ghost (optional)
 inst.components.locomotor:SetExternalSpeedMultiplier(inst, "ranger_speed_mod", 1)
end
local function onbecameghost(inst)
 -- Remove speed modifier when becoming a ghost
   inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "ranger_speed_mod")
end
-- When loading or spawning the character
local function onload(inst)
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)
    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    else
        onbecamehuman(inst)
    end
end

-- This initializes for both the server and client. Tags can be added here.
local common_postinit = function(inst)
 -- Minimap icon
 inst.MiniMapEntity:SetIcon( "ranger.tex" )
end
-- This initializes for the server only. Components are added here.
local master_postinit = function(inst)
 -- choose which sounds this character will play
 inst.soundsname = "willow"
 
 -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
    --inst.talker_path_override = "dontstarve_DLC001/characters/"
 
 -- Stats 
 inst.components.health:SetMaxHealth(180)
 inst.components.hunger:SetMax(170)
 inst.components.sanity:SetMax(200)
 inst.components.builder.bonus_tech_level = 1
 inst.components.combat.min_attack_period = .2
 inst.components.sanity.night_drain_mult = -1
 
 -- Damage multiplier (optional)
    inst.components.combat.damagemultiplier = 1.3
 
 -- Hunger rate (optional)
 inst.components.hunger.hungerrate = 0.75 * TUNING.WILSON_HUNGER_RATE
 
 inst.OnLoad = onload
    inst.OnNewSpawn = onload
 
end
return MakePlayerCharacter("ranger", prefabs, assets, common_postinit, master_postinit, start_inv)
 
 
If need, I attach some other scripts down below
Thank you so much

ranger_none.lua

modmain.lua

modinfo.lua

Link to comment
Share on other sites

1 hour ago, Lumina said:

You should have a


    inst.entity:AddNetwork()

somewhere. I suggest you to compare your code to a weapon of the game and see the difference and what else could be missing.

Hello, I know where the problem is. My mod does not work with cave xD... Do you know how to fix that, in the meantime I am still searching for the solution.

1 hour ago, Lumina said:

You should have a


    inst.entity:AddNetwork()

somewhere. I suggest you to compare your code to a weapon of the game and see the difference and what else could be missing.

Thank you! That is exactly what I need for solving cave problem, thank you very much! 

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