Jump to content
WaffleFish

Help with reload system

Recommended Posts

I am trying to update my Fletchery mod to Build 27, but I am having sudden problems with the reload system. The code for it is here:

local wepBow0 = { name = getItemText("Crossbow"),	moduleName = 'Fletchery',	reloadClass = 'ISShotgunWeapon',	ammoType = 'Bolts',	shootSound = 'arrowFire',	clickSound = 'click',	ejectSound = 'arrowReload',	insertSound = 'arrowReload',	rackSound = 'arrowReload',	maxCapacity = 1,	reloadTime = 20,	rackTime = 10};local wepBow1 = { name = getItemText("Homemade Bow"),	moduleName = 'Fletchery',	reloadClass = 'ISShotgunWeapon',	ammoType = 'Arrows',	shootSound = 'arrowFire',	clickSound = 'click',	ejectSound = 'arrowReload',	insertSound = 'arrowReload',	rackSound = 'arrowReload',	maxCapacity = 1,	reloadTime = 15,	rackTime = 10};local wepBow2 = { name = getItemText("Bow"),	moduleName = 'Fletchery',	reloadClass = 'ISShotgunWeapon',	ammoType = 'Arrows',	shootSound = 'arrowFire',	clickSound = 'click',	ejectSound = 'arrowReload',	insertSound = 'arrowReload',	rackSound = 'arrowReload',	maxCapacity = 1,	reloadTime = 10,	rackTime = 10};local wepSling = { name = getItemText("Sling"),	moduleName = 'Fletchery',	reloadClass = 'ISShotgunWeapon',	ammoType = 'Stones',	shootSound = 'slingFire',	clickSound = 'click',	ejectSound = 'arrowReload',	insertSound = 'arrowReload',	rackSound = 'arrowReload',	maxCapacity = 1,	reloadTime = 10,	rackTime = 10};	ReloadUtil:addWeaponType(wepBow0)ReloadUtil:addWeaponType(wepBow1)ReloadUtil:addWeaponType(wepBow2)ReloadUtil:addWeaponType(wepSling)

The crossbow, sling and bow (wepBow0, wepBow2 and wepSling) work fine, but the Homemade Bow (wepBow1) will not reload in-game. When I attempt to do so, I get the following error message in the console:

 

Error.jpg

 

I have no idea what to do here, I've tried everything I can think of. Any help would be appreciated!

 

EDIT: My guess would be that this is because both bows are trying to use the same ammo type, so the second is overwriting the first, but I want them to use the same arrows, so what I think I need is a workaround to use the same ammo.

Edited by WaffleFish

Share this post


Link to post
Share on other sites

Can you check that wepBow1 variable is assigned immediately after creating it (do a print statement or something).

 

The complaint is that it can't find the ammoType field in a null table.... i.e the table doesn't exist. I'm concerned the assignment to the wepBow1 variable is being lost somehow....

 

 

Things to try:

 

1. Change the variable from local to global by removing the local keyword.... Maybe the table is being deleted.

2. Check the addWeaponType function is actually working. Put some print statments in the reload util lua

Share this post


Link to post
Share on other sites

Can you check that wepBow1 variable is assigned immediately after creating it (do a print statement or something).

 

The complaint is that it can't find the ammoType field in a null table.... i.e the table doesn't exist. I'm concerned the assignment to the wepBow1 variable is being lost somehow....

 

 

Things to try:

 

1. Change the variable from local to global by removing the local keyword.... Maybe the table is being deleted.

2. Check the addWeaponType function is actually working. Put some print statments in the reload util lua

I've tried what you said, but it doesn't seem to have come up with anything. The code is now:

wepBow0 = { name = getItemText("Crossbow"),	moduleName = 'Fletchery',	reloadClass = 'ISShotgunWeapon',	ammoType = 'Bolts',	shootSound = 'arrowFire',	clickSound = 'click',	ejectSound = 'arrowReload',	insertSound = 'arrowReload',	rackSound = 'arrowReload',	maxCapacity = 1,	reloadTime = 20,	rackTime = 10};	ReloadUtil:addWeaponType(wepBow0)print(wepBow0.ammoType)wepBow1 = { name = getItemText("Homemade Bow"),	moduleName = 'Fletchery',	reloadClass = 'ISShotgunWeapon',	ammoType = 'Arrows',	shootSound = 'arrowFire',	clickSound = 'click',	ejectSound = 'arrowReload',	insertSound = 'arrowReload',	rackSound = 'arrowReload',	maxCapacity = 1,	reloadTime = 15,	rackTime = 10};	ReloadUtil:addWeaponType(wepBow1)print(wepBow1.ammoType)	wepBow2 = { name = getItemText("Bow"),	moduleName = 'Fletchery',	reloadClass = 'ISShotgunWeapon',	ammoType = 'Arrows',	shootSound = 'arrowFire',	clickSound = 'click',	ejectSound = 'arrowReload',	insertSound = 'arrowReload',	rackSound = 'arrowReload',	maxCapacity = 1,	reloadTime = 10,	rackTime = 10};	ReloadUtil:addWeaponType(wepBow2)print(wepBow2.ammoType)wepSling = { name = getItemText("Sling"),	moduleName = 'Fletchery',	reloadClass = 'ISShotgunWeapon',	ammoType = 'Stones',	shootSound = 'slingFire',	clickSound = 'click',	ejectSound = 'arrowReload',	insertSound = 'arrowReload',	rackSound = 'arrowReload',	maxCapacity = 1,	reloadTime = 10,	rackTime = 10};ReloadUtil:addWeaponType(wepSling)print(wepSling.ammoType)

When the file is loaded, the console prints:

Bolts

Arrows

Arrows

Stones

 

So I have no idea what the problem is. (Also, it definitely something specific to the Homemade Bow because I tried switching the order around and nothing changed.)

Share this post


Link to post
Share on other sites

Ok... as a sanity check, can you just try removing the space from the item name.... 'Homemade Bow' -> 'HomemadeBow'

 

Also, check every field in the item (I can't remember and don't have the code in front of me... apologies). My concern is that one of the reloading scripts is using the name to identify the weapon type and there is some sort of mismatch or the name is null

Share this post


Link to post
Share on other sites

Ok... as a sanity check, can you just try removing the space from the item name.... 'Homemade Bow' -> 'HomemadeBow'

 

Also, check every field in the item (I can't remember and don't have the code in front of me... apologies). My concern is that one of the reloading scripts is using the name to identify the weapon type and there is some sort of mismatch or the name is null

I am afraid I am on holiday today and tomorrow so I can't try out what you're suggesting, but I think you are probably right, as I looked at the code on Dropbox and the only difference I can see between any of them is that the Homemade bow is two words and the others are all one. I'll try it when I get back!

Share this post


Link to post
Share on other sites

I have looked, and I can't seem to find anything - changing the name didn't fix anything. Here is the code for the item (the reloading code is unchanged). Maybe you can spot something?

module Fletchery{	imports 	{		Base, camping	}		item bow0	{		AmmoType	=	Bolts,		ImpactSound	=	null,		MaxRange	=	18,		RangeFalloff	=	TRUE,		WeaponSprite	=	null,		SoundVolume	=	200,		MinAngle	=	0.7,		Type	=	Weapon,		MinimumSwingTime	=	2,		ToHitModifier	=	1.5,		NPCSoundBoost	=	1.5,		KnockBackOnNoDeath	=	FALSE,		Ranged	=	TRUE,		SwingAmountBeforeImpact	=	0,		ProjectileCount	=	1,		ConditionLowerChanceOneIn	=	40,		Weight	=	4.0,		SplatNumber	=	1,		PushBackMod	=	0.8,		MaxDamage	=	2.3,		SubCategory	=	Firearm,		AimingMod	=	2,		ConditionMax	=	10,		ShareDamage	=	FALSE,		MaxHitCount	=	1,		IsAimedHandWeapon	=	TRUE,		IsAimedFirearm	=	TRUE,		DoorDamage	=	1,		IdleAnim	=	Idle_Weapon2,		UseEndurance	=	FALSE,		SwingAnim	=	Rifle,		WeaponWeight	=	2,		DisplayName	=	Crossbow,		MinRange	=	0.61,		SwingTime	=	2,		SwingSound = arrowFire,		AngleFalloff	=	TRUE,		MultipleHitConditionAffected	=	FALSE,		SoundRadius	=	5,		MinDamage	=	1.4,		KnockdownMod	=	8,		SplatBloodOnNoDeath	=	FALSE,		Icon	=	bow0,		RunAnim	=	Run_Weapon2,		TwoHandWeapon = TRUE,	}	item bow1	{		AmmoType	=	Arrows,		ImpactSound	=	null,		MaxRange	=	18,		RangeFalloff	=	TRUE,		WeaponSprite	=	null,		SoundVolume	=	200,		MinAngle	=	0.7,		Type	=	Weapon,		MinimumSwingTime	=	2,		ToHitModifier	=	1.5,		NPCSoundBoost	=	1.5,		KnockBackOnNoDeath	=	FALSE,		Ranged	=	TRUE,		SwingAmountBeforeImpact	=	0,		ProjectileCount	=	1,		ConditionLowerChanceOneIn	=	5,		Weight	=	3.0,		SplatNumber	=	1,		PushBackMod	=	0.8,		MaxDamage	=	1,		SubCategory	=	Firearm,		AimingMod	=	2,		ConditionMax	=	10,		ShareDamage	=	FALSE,		MaxHitCount	=	1,		IsAimedHandWeapon	=	TRUE,		IsAimedFirearm	=	TRUE,		DoorDamage	=	1,		IdleAnim	=	Idle_Weapon2,		UseEndurance	=	FALSE,		SwingAnim	=	Rifle,		WeaponWeight	=	2,		DisplayName	=	Homemade Bow,		MinRange	=	0.61,		SwingTime	=	2,		SwingSound = arrowFire,		AngleFalloff	=	TRUE,		MultipleHitConditionAffected	=	FALSE,		SoundRadius	=	5,		MinDamage	=	0.3,		KnockdownMod	=	8,		SplatBloodOnNoDeath	=	FALSE,		Icon	=	bow0,		RunAnim	=	Run_Weapon2,		TwoHandWeapon = TRUE,	}		item bow2	{		AmmoType	=	Arrows,		ImpactSound	=	null,		MaxRange	=	18,		RangeFalloff	=	TRUE,		WeaponSprite	=	null,		SoundVolume	= 200,		MinAngle	=	0.7,		Type	=	Weapon,		MinimumSwingTime	=	2,		ToHitModifier	=	1.5,		NPCSoundBoost	=	1.5,		KnockBackOnNoDeath	=	FALSE,		Ranged	=	TRUE,		SwingAmountBeforeImpact	=	0,		ProjectileCount	=	1,		ConditionLowerChanceOneIn	=	40,		Weight	=	3.0,		SplatNumber	=	1,		PushBackMod	=	0.8,		MaxDamage	=	1.8,		SubCategory	=	Firearm,		AimingMod	=	2,		ConditionMax	=	10,		ShareDamage	=	FALSE,		MaxHitCount	=	1,		IsAimedHandWeapon	=	TRUE,		IsAimedFirearm	=	TRUE,		DoorDamage	=	1,		IdleAnim	=	Idle_Weapon2,		UseEndurance	=	FALSE,		SwingAnim	=	Rifle,		WeaponWeight	=	2,		DisplayName	=	Bow,		MinRange	=	0.61,		SwingTime	=	2,		SwingSound = arrowFire,		AngleFalloff	=	TRUE,		MultipleHitConditionAffected	=	FALSE,		SoundRadius	=	5,		MinDamage	=	0.8,		KnockdownMod	=	8,		SplatBloodOnNoDeath	=	FALSE,		Icon	=	bow2,		RunAnim	=	Run_Weapon2,		TwoHandWeapon = TRUE,	}		item sling	{		AmmoType	=	Stones,		ImpactSound	=	null,		MaxRange	=	7,		RangeFalloff	=	TRUE,		WeaponSprite	=	null,		SoundVolume	=	200,		MinAngle	=	0.7,		Type	=	Weapon,		MinimumSwingTime	=	2,		ToHitModifier	=	1,		NPCSoundBoost	=	1.5,		KnockBackOnNoDeath	=	FALSE,		Ranged	=	TRUE,		SwingAmountBeforeImpact	=	0,		ProjectileCount	=	1,		ConditionLowerChanceOneIn	=	10,		Weight	=	0.2,		SplatNumber	=	1,		PushBackMod	=	0.8,		MaxDamage	=	0.4,		SubCategory	=	Firearm,		AimingMod	=	2,		ConditionMax	=	10,		ShareDamage	=	FALSE,		MaxHitCount	=	1,		IsAimedHandWeapon	=	TRUE,		IsAimedFirearm	=	TRUE,		DoorDamage	=	1,		IdleAnim	=	Idle_Weapon2,		UseEndurance	=	FALSE,		SwingAnim	=	Bat,		WeaponWeight	=	2,		DisplayName	=	Sling,		MinRange	=	0.61,		SwingTime	=	2,		SwingSound = slingFire,		AngleFalloff	=	TRUE,		MultipleHitConditionAffected	=	FALSE,		SoundRadius	=	1,		MinDamage	=	0.2,		KnockdownMod	=	8,		SplatBloodOnNoDeath	=	FALSE,		Icon	=	sling,		RunAnim	=	Run_Weapon2,	}	item Arrows	{		Count = 6,		Weight = 0.15,		AlwaysWelcomeGift	=	TRUE,		Type	=	Normal,		DisplayName	=	Arrows,		Icon	=	arrow,	}		item Stones	{		Count = 4,		Weight = 0.4,		Type	=	Normal,		DisplayName	=	Stones,		Icon	=	stone,	}	item Bolts	{		Count	=	12,		Weight	=	0.25,		AlwaysWelcomeGift	=	TRUE, 		Type	=	Normal,		DisplayName	=	Bolts,			Icon	=	bolt,	}	item ArrowShafts	{		Count	=	6,		Weight	=	0.05,		Type	=	Normal,		DisplayName	=	Arrow Shafts,			Icon	=	shaft,	}		item Feathers	{		Count = 6,		Weight = 0.001,		Type	=	Normal,		DisplayName	=	Feathers,		Icon	=	feather,	}	recipe Create Arrow Shafts	{		WoodenStick,		keep Saw,		Result:ArrowShafts,				SkillRequired:Woodwork=1,		Time:100.0	}	recipe Get Feathers	{		Pillow,		Result:Feathers,				Time:100.0	}		recipe Create Homemade Arrow	{			ArrowShafts = 6,		Feathers = 6,		DuctTape/Woodglue/Glue/Scotchtape = 6,		keep KitchenKnife,		Result:Arrows,				SkillRequired:Woodwork=1,		Time:360.0	}		recipe Create Sling	{		RippedSheets = 2,		Result:sling,				Time:200.0	}		recipe Create Homemade Bow	{		Plank = 2,		RippedSheets,		DuctTape/Woodglue/Glue/Scotchtape = 5,		Result:bow1,				SkillRequired:Woodwork=2,		Time:500.0	}		item HomemadeArrow	{		Count = 6,		Weight	=	0.1,		AlwaysWelcomeGift	=	TRUE,		Type	=	Normal,		DisplayName	=	Homemade Arrow,		Icon	=	arrow,	}	}module Base{		item DuctTape	{		Weight = 0.3,		AlwaysWelcomeGift	=	TRUE,		Type	=	Drainable,		UseDelta	=	0.05,		DisplayName	=	Duct Tape,		Icon	=	DuctTape,	}		item Glue    {        Weight	=	0.1,        Type	=	Drainable,        UseDelta	=	0.05,        UseWhileEquipped	=	FALSE,        DisplayName	=	Glue,        Icon	=	Glue,    }		item Woodglue    {        Type	            =	        Drainable,        UseDelta	        =	        0.05,        UseWhileEquipped	=	        FALSE,        DisplayName			=		    Wood glue,        Icon				=			Woodglue,        Weight				=			0.1,    }		item Scotchtape    {        Type				=			Drainable,		UseDelta			=			0.05,        DisplayName			=		    Scotch tape,        Icon				=			Scotchtape,        Weight				=			0.1,    }}

Share this post


Link to post
Share on other sites

Keep noticing something new each time I look.

 

The command window screenshot you posted says that the error occurs in ISSemiAutoWeapon.lua. However, the file that it should be using is ISShotgunWeapon. This is determined by: reloadClass = 'ISShotgunWeapon'.

 

Why it is using the wrong one for this weapon only I still can't understand.

 

From a new game, put a bunch of print statements in the ISReloadUtil:setUpGun(weapon) function and the ISReloadUtil:syncItemToReloadable(item) function. Try and determine why it would be going into the ISSemiAutoWeapon branches of each of those.

Share this post


Link to post
Share on other sites

Keep noticing something new each time I look.

 

The command window screenshot you posted says that the error occurs in ISSemiAutoWeapon.lua. However, the file that it should be using is ISShotgunWeapon. This is determined by: reloadClass = 'ISShotgunWeapon'.

 

Why it is using the wrong one for this weapon only I still can't understand.

 

From a new game, put a bunch of print statements in the ISReloadUtil:setUpGun(weapon) function and the ISReloadUtil:syncItemToReloadable(item) function. Try and determine why it would be going into the ISSemiAutoWeapon branches of each of those.

I am afraid I don't really understand the reload system (I just looked at the code and tried to figure out what was going on to make the mod in the first place). I tried putting some print statements in, but I couldn't see anything in the console. Please could you be more specific about what and where to put them, as I'm not sure what to do.

Share this post


Link to post
Share on other sites
  • Solution

I'm at work so I can't see the fields but here we go...

 

The principle of the setUpGun method is to determine whether the item that has been clicked on is a reloadable item.....

 

It checks that there is a corresponding lua weapon type (which was created and added into ReloadUtil:addWeaponType(wepBow1)) for the item that was clicked on and uses the item name to do so.

 

If it finds one, it looks at the lua weapon type's reloadClass field... and then sets up the item to use the corresponding lua file for performing the reload activities.

 

It is important to remember that this is done once for an item. After the first time, it uses the item's modData (information about the item that is saved out each time PZ saves). One of the pieces of information saved is the reloadClass.

 

What I want to do is twofold...

 

1. Everytime you see an if statement checking the reload class in the two functions I mentioned, print the reloadClass before the if statement so we can make sure it is correct.

 

2. Make sure you are using a clean save so that nothing incorrect has persisted.

 

I'll admit the reloading stuff can be a bit confusing. I can try the script myself and see if it works. Is there anything in addition to the snippets you've posted to test this?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...