Jump to content

First time creating a mod. I'm trying to override Recipe.OnCreate.UpgradeSpear, but get "Error 0" when loading into saved game.

Recommended Posts


Folder structure (not sure if this is correct):

mods/Better Spear Upgrade/media/lua/client/recipecode.lua


mod.info file:


name=Better Spear Upgrade
description=Changes the formula for the starting condition of an upgraded spear




local _orig_UpgradeSpear = Recipe.OnCreate.UpgradeSpear

-- get a mix of spear & upgrade item to do a correct condition of the result
-- we take the craftedSpear condition and substract the attached weapon condition

function Recipe.OnCreate.UpgradeSpear(items, result, player, selectedItem)
  local spearCondition      = 0
  local spearConditionMax   = 0
  local weaponCondition     = 0
  local weaponConditionMax  = 0
  local conditionMax = 0;
  for i=0,items:size() - 1 do
      if items:get(i):getType() == "SpearCrafted" then
          spearCondition    = items:get(i):getCondition()
          spearConditionMax = items:get(i):getConditionMax()

  for i=0,items:size() - 1 do
      if instanceof (items:get(i), "HandWeapon") and items:get(i):getType() ~= "SpearCrafted" then
          weaponCondition     = items:get(i):getCondition()
          weaponConditionMax  = items:get(i):getConditionMax()
  local conditionPct  = ((spearCondition / spearConditionMax) + (weaponCondition / weaponConditionMax)) / 2
  conditionMax        = result:getConditionMax() * conditionPct
  if conditionMax > result:getConditionMax() then
      conditionMax = result:getConditionMax();
  if conditionMax < 2 then
      conditionMax = 2;



Edited by Undefined

Share this post

Link to post
Share on other sites

On 9/18/2022 at 7:50 PM, Hugo Qwerty said:

The vanilla function is in /server/ rather than /client/, so you should probably do likewise.

If that doesn't fix it, can you post the stack trace from the console?


Thanks for the response.


The TL;DR is that I switched the file to the "server" folder and renamed it to something other than "recipecode.lua" and it worked.




With the above in mind,  before changing the folder name and renaming the file, I checked console.txt and saw errors like "indexing null table UpgradeSpear" and that it also couldn't find other functions that were related to recipecode.lua


I figured the mod was replacing the original recipecode.lua and renamed it. I didn't check if changing the folder name had any effect on it, I'll get to that later and post back.

Edited by Undefined

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.

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.


  • Create New...