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.


Undefined

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
poster=
id=BetterSpearUpgrade
description=Changes the formula for the starting condition of an upgraded spear
url=

 

Code:

 

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()

      end
  end
  
  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()
      end
  end
  
  local conditionPct  = ((spearCondition / spearConditionMax) + (weaponCondition / weaponConditionMax)) / 2
  conditionMax        = result:getConditionMax() * conditionPct
  
  if conditionMax > result:getConditionMax() then
      conditionMax = result:getConditionMax();
  end
  if conditionMax < 2 then
      conditionMax = 2;
  end

  result:setCondition(conditionMax);
end

 

Edited by Undefined
Link to comment
Share on other sites

  • Undefined changed the title to First time creating a mod. I'm trying to override Recipe.OnCreate.UpgradeSpear, but get "Error 0" when loading into saved game.
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
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
×
×
  • Create New...