1. Hey all,

    So I'm looking at the Inventory-Guardian.lua, [http://oxidemod.org/plugins/inventory-guardian.773/]
    (hoping to change maps tomorrow and keep players inventories)

    and it hasn't been updated in a while, and since recent changes to items from updates the last couple of weeks, it hasn't worked.

    so, line 287 is throwing an error in console, and the relevant code looks like this:

    Code:
      -- Create an inventory item
            local itemEntity = global.ItemManager.CreateByName(item.name, item.amount)
          
            -- Check for Blueprint field
            if item.bp then
              -- Set Item as Blueprint
              itemEntity.isBlueprint = true
            -- Check for Health field
            elseif item.condition and self.Settings.KeepItemCondition then
              -- Define item health
              itemEntity.condition = item.condition     
            end
    line 287 being "itemEntity.isBlueprint = true"... the error being "isblueprint filed or property does not exist"



    Anyone have any ideas on how I might fix this? I'm still very new to working on plugins.

    Thanks for any help you can give. :)
     
  2. itemEntity.isBlueprint() = true
     
  3. But now it's throwing a syntax error. Same line. "near ="
    ...
     
  4. IsBlueprint() actually, the I is capital. They changed it from a property to a function call in a recent patch.
     
  5. Oh yeah i forgot about that .... happens.
     
  6. So I changed it to a capital I... still didn't change the syntax error on 287...

    Do I have to initialize that function before I call it or anything? Or does it know it from the assembly automatically....

    Something isn't working in the plugin still... :(
     
  7. Wulf

    Wulf Community Admin

    It would have changed the error. Please provide the updated log.
     
  8. Yeah, it's been showing a "syntax error" when I reload the plugin, since changing it to a function call.

    Here's what the error says in it's entirety:
    Code:
    [RCON][188.165.226.225:53825] oxide.reload Inventory-Guardian
    [Oxide] 12:51 PM [Error] Failed to load plugin Inventory-Guardian
    File: Inventory-Guardian.lua Line: 287 syntax error near '=':
    at NLua.Lua.ThrowExceptionFromError (Int32 oldTop) [0x00000] in :0
    at NLua.Lua.LoadString (System.String chunk, System.String name) [0x00000] in :0
    at Oxide.Ext.Lua.Plugins.LuaPlugin.Load () [0x00000] in :0
    at Oxide.Ext.Lua.Plugins.LuaPluginLoader.Load (System.String directory, System.String name) [0x00000] in :0
    at Oxide.Core.OxideMod.LoadPlugin (System.String name) [0x00000] in :0 
     
  9. Wulf

    Wulf Community Admin

    Please post that portion of the code you are editing, the error is different though.
     
  10. Sure, the code I've been editing is that snippet at the top in my first post. At line 287.


    Code:
      -- Create an inventory item
            local itemEntity = global.ItemManager.CreateByName(item.name, item.amount)
         
            -- Check for Blueprint field
            if item.bp then
              -- Set Item as Blueprint
              itemEntity.IsBlueprint() = true
            -- Check for Health field
            elseif item.condition and self.Settings.KeepItemCondition then
              -- Define item health
              itemEntity.condition = item.condition    
            end
    That's how the code should now read in the file I'm uploading to my server. That's what's throwing the "syntax error" near "=" on 287 (itenEntity.IsBlueprint() = true)...
     
  11. Try this version
     

    Attached Files:

  12. Same error.
     
  13. Wulf

    Wulf Community Admin

    You could use this instead: itemEntity.SetFlag(Item.Flag.Blueprint, true).
     
  14. Progress!

    Now, it is at least loading, throwing no errors...

    I am guessing there will be problems with the rest of the code, and the old property itemEntity.isBlueprint (it's frequently used in some sections of the plugin... so I'll need to change that to the new flag system somehow?) -- any tips?

    Also, for my knowledge in learning, how can I figure this stuff out? I was aware that something with items changed and it broke the plugin, but where would I find that the change was the property isBlueprint to the function call IsBlueprint() ? (assembly?) , and where did you pull SetFlag from?

    Just trying to get better at troubleshooting stuff myself, too. :)


    I'll play around with saving and restoring, and ask more questions as errors are popping up
     
  15. Wulf

    Wulf Community Admin

    You can use itemEntity.IsBlueprint() in most of those situations.
     
  16. Newest error:
    -- While moving things from my inventory to a box, after saving it (to restore later)
    Code:
    File: Inventory-Guardian.lua Line: 287 attempt to index global 'Item' (a nil value):
    at NLua.Lua.ThrowExceptionFromError (Int32 oldTop) [0x00000] in :0
    at NLua.Lua.CallFunction (System.Object function, System.Object[] args, System.Type[] returnTypes) [0x00000] in :0
    at NLua.LuaFunction.Call (System.Object[] args, System.Type[] returnTypes) [0x00000] in :0
    at NLua.Method.LuaDelegate.CallFunction (System.Object[] args, System.Object[] inArgs, System.Int32[] outArgs) [0x00000] in :0
    at LuaGeneratedClass1.CallFunction () [0x00000] in :0
    at Oxide.Core.Libraries.Timer+TimerInstance.Update () [0x00000] in :0 
    Same error gets thrown when trying to restore saved items.
    [DOUBLEPOST=1440104501][/DOUBLEPOST]
    This code seems to clear the syntax error problem that I was having, but I'm still having the "nil" value for "Item" on that line...
    if I change the I to an i... like itemEntity... it says Flag is the nil value in the error...

    Help?
     
  17. Wulf

    Wulf Community Admin

    Hmmm, try itemEntity:SetFlag(global.Item.Flag.Blueprint, true) instead.
     
  18. lol, /ig.restore gave me all my items as blueprints. xD ... 1000 Wood in a stack, as a blueprint. xD
    -- I'd say that's more progress, tho!!!

    So, now there's something going on, either when they get saved, or the if/else isn't getting skipped if it's not a blueprint or something?

    Thank you so much for the help! I think we've almost got it. :D
    [DOUBLEPOST=1440105874][/DOUBLEPOST]Current error: ... when I do /ig.save

    Code:
    [Oxide] 2:21 PM [Error] Failed to call hook 'cmdSaveInventory' on plugin 'Inventory-Guardian v0.1.5'
    File: Inventory-Guardian.lua Line: 199 instance method 'IsBlueprint' requires a non null target object:
    at NLua.Lua.ThrowExceptionFromError (Int32 oldTop) [0x00000] in :0
    at NLua.Lua.CallFunction (System.Object function, System.Object[] args, System.Type[] returnTypes) [0x00000] in :0
    at NLua.Lua.CallFunction (System.Object function, System.Object[] args) [0x00000] in :0
    at NLua.LuaFunction.Call (System.Object[] args) [0x00000] in :0
    at Oxide.Ext.Lua.Plugins.LuaPlugin.OnCallHook (System.String hookname, System.Object[] args) [0x00000] in :0
    at Oxide.Core.Plugins.Plugin.CallHook (System.String hookname, System.Object[] args) [0x00000] in :0 
    relevant code:
    Code:
    -- Loop by the Main Items
      while mainItems:MoveNext() do
        -- Save current item to player's inventory table
        self.Data.GlobalInventory[playerID]['main'][tostring(mainCount)] = {name = tostring(mainItems.Current.info.shortname), amount = mainItems.Current.amount, condition =  mainItems.Current.condition, bp = mainItems.Current.IsBlueprint()}
        -- Increment the count
        mainCount = mainCount + 1
      end
    line 199 starts on "self.Data.GlobalInventory...." and ends after "... .IsBlueprint()}
    [DOUBLEPOST=1440111904][/DOUBLEPOST]Okay, so, after some fiddling, I can get /ig.save to work, and save inventory, by setting the end of line 199 to isBlueprint. (Not a function call)

    BUT

    when doing /ig.restore, that for some reason triggers the "Set Item as Blueprint" trigger on whatever it's saving...

    Code:
      -- Create an inventory item
            local itemEntity = global.ItemManager.CreateByName(item.name, item.amount)
         
            -- Check for Blueprint field
            if item.bp then
              -- Set Item as Blueprint
             itemEntity.SetFlag(Item.Flag.Blueprint, true)
            -- Check for Health field
            elseif item.condition and self.Settings.KeepItemCondition then
              -- Define item health
              itemEntity.condition = item.condition    
            end
    So,
    What's the correct way I should be having this plugin check if the item is a blueprint?
    IsBlueprint() throws an error in console (see above)
    and isBlueprint passes a true value to the Blueprint/SetFlag function...