Jump to content

Undefined

Member
  • Posts

    15
  • Joined

  • Last visited

Posts posted by Undefined

  1. 4 hours ago, Hugo Qwerty said:

    You might be able to use the Event system: https://pzwiki.net/wiki/Modding:Lua_Events

     

    Not sure which event would be best, OnPlayerUpdate perhaps?  Then check the players inventory for a tool box, however I expect that event runs a lot so it might be excessive for something like this.

    Thanks for the link!

     

    I noticed the OnGameStart event, which I first saw from looking at Item Tweaker API's code.

     

    I think this or OnLoad would have the least overhead, but I'd still need a way to pull an array with all the toolboxes (or items spawned) in the current game. Optionally, I would save the name of the game file to to a text file so it only runs one time per game. The problem is getting an array with the items, which I don't know how to go about.

     

    The OnPlayerUpdate would be easier since I'd just have to check the player's inventory and I'm sure getting the player's inventory is better documented. The problem would be the overhead, which would be excessive and unnecessary.

     

    So now the next step is, how to get an array of all the world items to loop through them and setWeightReduction.

     

    If you  happen to know a method that returns the items in the world, I would be grateful if you could share it. In the meantime, I'll be looking around to see if such a method exists.

  2. I thought that maybe someone in the workshop might have this figured out so I looked around for other weight reduction mods.

     

    The only workaround I've found is someone who added a crafting recipe where you use the old item to craft a new item of the same type, which then has the changed attribute.

     

    If it's not possible to change the attribute of a spawned item, this will have to suffice.

  3. 12 minutes ago, Hugo Qwerty said:

    Thanks. I've known about that method and have looked through the code base for statements that call setWeightReduction (link), but I'm not sure how I would implement it.

     

    I was thinking I'd need to loop through all Toolboxes in the game and then call setWeightReduction, but I don't know the name of the array (or what method I can call that returns an array of all spawned toolboxes).

     

    I also figured that maybe the toolbox attributes where saved in the game files once they spawned so it might not even be possible.

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

  5.  

    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

     

  6. My question is about the "items" parameter: is it all the items in the player's inventory or just the Crafted Spear or Hand Weapon that the player selected?

     

    I left the code snippet below for your convenience.

     

    
    -- 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 conditionMax = 0;
        for i=0,items:size() - 1 do
            if items:get(i):getType() == "SpearCrafted" then
                conditionMax = items:get(i):getCondition()
            end
        end
        
        for i=0,items:size() - 1 do
            if instanceof (items:get(i), "HandWeapon") and items:get(i):getType() ~= "SpearCrafted" then
                conditionMax = conditionMax - ((items:get(i):getConditionMax() - items:get(i):getCondition())/2)
            end
        end
        
        if conditionMax > result:getConditionMax() then
            conditionMax = result:getConditionMax();
        end
        if conditionMax < 2 then
            conditionMax = 2;
        end
    
        result:setCondition(conditionMax);
    end

     

  7. > Version: 41.71

    > SP/MP: Single player

    > Solo/Host/Dedicated: Solo

    > Mods: None

    > New/Current Save: Either

    > Reproduce: Not possible, it's just how it is

     

    I figured this is just how the game renders them and was trying to mod it to make it bigger, but someone suggested that I report this as a bug.

     

    I was told to include my font settings, so here they are:

     

    UI:

     * Inventory Container Button Size: Large

     

    Fonts:

     * Font Size: 3x

     * Context Menu Font: Large

     * Inventory Font: Large

     * Tooltip Font: Large

     

    image.png.06496224f4ae1efbf86dce44b4c76288.png

     

     

  8. EDIT: the function I was looking for is isSpice.

     

    So:

     

    item:IsSpice()

     

    I found the function using this link: https://projectzomboid.com/modding/

     

    ------

     

    I'm trying to modify the AutoCook mod to exclude spices.

     

    Relevant section of code (I think). The last line in particular is where I would add the check to see if the item is a spice, but I don't know the function to call on the item object for checking its spice value.

     

    function AutoCook:chooseItem(items,baseItem, recipe)
        if AutoCook.Verbose then print ("AutoCook:chooseItem "..baseItem:getName()) end
        if not items or items:size() == 0 then--if there is no more available items stop auto cook
            return nil
        end
    
        
    --take the one that will become rotten the fastest ?
    --take the one that gives most nutrition ?
    --take the one that gives most happiness ?
        local evoItem = nil
        local listItemsNotAlreadyUsed = {}
        local listItemsUsedOnce = {}
        for i=1,items:size() do
            local item = items:get(i-1);
            if instanceof(item, "Food") and not self.playerObj:isKnownPoison(item) and (recipe:isCookable() or not item:isbDangerousUncooked() or item:isCooked()) then--do we risk to apply also survivor / carpentry / .. recipes ?

     

×
×
  • Create New...