orlyx

[solved]My mod is unstable in multiplayer

Recommended Posts

orlyx    2
Posted (edited)

I made character and weapons mod. In single player this mod works very good. I send this file for my friend an he said that when he play with his friend his game crash when not host select mod character and use special weapons.

QrchuckRemastered0.1.rar

Edited by orlyx

Share this post


Link to post
Share on other sites
Ultroman    447
Posted (edited)

Your weapons are lacking both the SetPristine() call and an ismastersim check before adding all the components. Only the server needs components added. The clients are just a "shell".

As an example, your t0 weapon's fn() should be changed like so:

local function fn(colour)
	local inst = CreateEntity()
	local trans = inst.entity:AddTransform()
	local anim = inst.entity:AddAnimState()
	inst.entity:AddMiniMapEntity()
	MakeInventoryPhysics(inst)
	inst.entity:AddNetwork()
	
	inst:AddTag("flute")
	--inst.components.onplayed.sanity:DoDelta(TUNING.SANITY_MED)
	--sanityreward = TUNING.SANITY_MED,

	anim:SetBank("sw_t01")
	anim:SetBuild("sw_t01")
	anim:PlayAnimation("idle")
	
	inst.MiniMapEntity:SetIcon( "images/map_icons/sw_t01.tex")
	
	inst.entity:SetPristine()

	if not TheWorld.ismastersim then
		return inst
	end

	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.imagename = "sw_t01"
	inst.components.inventoryitem.atlasname = "images/inventoryimages/sw_t01.xml"

	inst:AddComponent("inspectable")
	inst:AddComponent("instrument")
	inst.components.instrument.range = TUNING.PANFLUTE_SLEEPRANGE *1
	inst.components.instrument:SetOnHeardFn(HearPanFlute)
	inst.components.instrument.onplayed = OnPlayed
	--inst.components.instrument.sound_noloop = "scripts/sound/efaja.mp3" 

	inst:AddComponent("tool")
	inst.components.tool:SetAction(ACTIONS.PLAY)

	inst:AddComponent("finiteuses")
	inst.components.finiteuses:SetMaxUses(TUNING.PANFLUTE_USES)
	inst.components.finiteuses:SetUses(TUNING.PANFLUTE_USES)
	inst.components.finiteuses:SetOnFinished( onfinished)
	inst.components.finiteuses:SetConsumption(ACTIONS.PLAY, 1)
	
	return inst
end

 

Edited by Ultroman
  • Like 1

Share this post


Link to post
Share on other sites
orlyx    2

@UltromanThanks but there is still problem. When no host try to select custom character game crashes there is problem with inventoryitem but game works fine for host

Share this post


Link to post
Share on other sites
Ultroman    447
Posted (edited)

You need to provide these crash reports, otherwise we have no chance of helping you. Also a zip with the newest code. See the newcomer post for information about where to find the logs.

That said, I'm gonna venture a guess that it's because in all your onfinished functions in your prefabs, you call inst:Remove() and then proceed to try to use inst for something after that. inst:Remove() removes the item from the game, so you should do that as the very last thing in onfinished. Also, why are you trying to get the owner from the inventoryitem component, when the owner is already passed to onfinished as a parameter?

Edited by Ultroman

Share this post


Link to post
Share on other sites
orlyx    2

@Ultroman 

I have multiple attempts to fix this bug but i still dont know why there is problem with inventoryitem script in dst.

Dst log:

Spoiler

Dont starve Log


[00:03:02]: Mod: workshop-1802254303 (Qrchuck Remastered)	Registering prefabs	
[00:03:02]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/qrchucks	
[00:03:02]: Mod: workshop-1802254303 (Qrchuck Remastered)	    qrchucks	
[00:03:02]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/qrchucks_none	
[00:03:02]: Mod: workshop-1802254303 (Qrchuck Remastered)	    qrchucks_none	
[00:03:02]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t0	
[00:03:02]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t0	
[00:03:02]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t01	
[00:03:02]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t01	
[00:03:02]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t02	
[00:03:02]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t02	
[00:03:02]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t03	
[00:03:02]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t03	
[00:03:02]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t04	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t04	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t05	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t05	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t10	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t10	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t11	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t11	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t12	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t12	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t13	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t13	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t14	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t14	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t15	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t15	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t20	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t20	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t21	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t21	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t22	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t22	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t23	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t23	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t24	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t24	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering prefab file: prefabs/sw_t25	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	    sw_t25	
[00:03:03]: Mod: workshop-1802254303 (Qrchuck Remastered)	  Registering default mod prefab	
[00:03:03]: Could not preload undefined prefab (maxwell_book_fx)
[00:03:03]: Could not preload undefined prefab (maxwell_book_fx)
[00:03:03]: Could not preload undefined prefab (maxwell_book_fx)
[00:03:04]: 	LOAD BE	
[00:03:17]: 	LOAD BE: done	
[00:03:17]: MiniMapComponent::AddAtlas( minimap/minimap_data.xml )
[00:03:17]: MiniMapComponent::AddAtlas( ../mods/workshop-1802254303/images/map_icons/qrchucks.xml )
[00:03:17]: MiniMapComponent::AddAtlas( ../mods/workshop-1802254303/images/inventoryimages/sw_t0.xml )
[00:03:17]: Loading 16 new character(s)	
[00:03:18]: Total 16 character(s) loaded	
[00:03:18]: Loading Nav Grid	
[00:03:18]: World generated on version 358771, using seed: 1565516056	
[00:03:18]: Reconstructing topology	
[00:03:18]: 	...Sorting points	
[00:03:18]: 	...Sorting edges	
[00:03:18]: 	...Connecting nodes	
[00:03:18]: 	...Validating connections	
[00:03:18]: 	...Housekeeping	
[00:03:18]: 	...Done!	
[00:03:18]: ModIndex: Load sequence finished successfully.	
[00:03:18]: Reset() returning
[00:03:21]: Attempting to send resume request
[00:03:21]: ReceiveResumeNotification
[00:03:21]: Deleting user: session/23F7170A8669C629/A7N6023I05PU/0000000001
[00:03:28]: Could not find anim build FROMNUM
[00:03:28]: Could not find anim build FROMNUM
[00:03:28]: Movement prediction enabled	
[00:03:28]: Could not find anim [anim] in bank [sanity2]
[00:03:28]: [string "scripts/components/inventoryitem.lua"]:10: attempt to index field 'inventoryitem' (a nil value)
LUA ERROR stack traceback:
scripts/components/inventoryitem.lua:10 in (field) ? (Lua) <9-11>
   self =
      inst = 102379 -  (valid:true)
      _ = table: 4E0774E0
   owner = nil
scripts/class.lua:30 in () ? (Lua) <23-32>
   t = table: 4E0773C8
   k = owner
   v = nil
   p = table: 4E0779E0
   old = nil
scripts/components/inventoryitem.lua:45 in (field) _ctor (Lua) <42-71>
   self =
      inst = 102379 -  (valid:true)
      _ = table: 4E0774E0
   inst = 102379 -  (valid:true)
scripts/class.lua:181 in (local) cmp (Lua) <171-184>
   class_tbl = table: 369A0C20
   arg = nil
   obj = table: 4E0773C8
scripts/entityscript.lua:533 in (method) AddComponent (Lua) <522-544>
   self (valid:true) =
      GUID = 102379
      Transform = Transform (35D07950)
      inlimbo = false
      actionreplica = table: 3699F3E8
      event_listening = table: 3699F848
      actioncomponents = table: 3699F668
      lower_components_shadow = table: 3699F640
      entity = Entity (3FDD5030)
      AnimState = AnimState (35D07610)
      Network = Network (35D07730)
      Physics = Physics (35D07910)
      MiniMapEntity = MiniMapEntity (35D076D0)
      event_listeners = table: 3699F7D0
      spawntime = 6.6333336792886
      replica = table: 3699F690
      SoundEmitter = SoundEmitter (35D07650)
      components = table: 3699F528
      persists = true
   name = inventoryitem
   lower_name = inventoryitem
   cmp = table: 369A0C20
../mods/workshop-1802254303/scripts/prefabs/sw_t0.lua:30 in (field) fn (Lua) <12-43>
   colour = Sim (0D32FC60)
   inst = 102379 -  (valid:true)
   trans = Transform (35D07950)
   anim = AnimState (35D07610)
scripts/mainfunctions.lua:258 in () ? (Lua) <247-289>
   name = sw_t0
   prefab = Prefab sw_t0 - 

[00:03:28]: [string "scripts/components/inventoryitem.lua"]:10: attempt to index field 'inventoryitem' (a nil value)
LUA ERROR stack traceback:
    scripts/components/inventoryitem.lua:10 in (field) ? (Lua) <9-11>
    scripts/class.lua:30 in () ? (Lua) <23-32>
    scripts/components/inventoryitem.lua:45 in (field) _ctor (Lua) <42-71>
    scripts/class.lua:181 in (local) cmp (Lua) <171-184>
    scripts/entityscript.lua:533 in (method) AddComponent (Lua) <522-544>
    ../mods/workshop-1802254303/scripts/prefabs/sw_t0.lua:30 in (field) fn (Lua) <12-43>
    scripts/mainfunctions.lua:258 in () ? (Lua) <247-289>
	

QrchuckRemastered.rar

Its just 10 more items I added 

Share this post


Link to post
Share on other sites
Ultroman    447

It's very simple. Items should not have components on the client. In your sw_t0.lua you add an inventoryitem component before your ismastersim check. The ismastersim check is the cutoff between which things are done on the server AND client (code before the check) and which things are only done on the server (code after the check).

  • Like 1

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