(Nutscript HL2RP) "attempt to call "Register" (a nil value)"

Hello,
I’m trying to get plugins to work on my Nutscript HL2RP server. I keep getting these two errors:



[ERROR] gamemodes/hl2rp/plugins/hl2_combinelight/sh_plugin.lua:5: attempt to call field 'Register' (a nil value)
  1. unknown - gamemodes/hl2rp/plugins/hl2_combinelight/sh_plugin.lua:5
   2. include - [C]:-1
    3. include - gamemodes/nutscript/gamemode/core/sh_util.lua:17
     4. load - gamemodes/nutscript/gamemode/core/libs/sh_plugin.lua:44
      5. loadFromDir - gamemodes/nutscript/gamemode/core/libs/sh_plugin.lua:189
       6. initialize - gamemodes/nutscript/gamemode/core/libs/sh_plugin.lua:180
        7. Call - gamemodes/nutscript/gamemode/shared.lua:75
         8. unknown - lua/includes/modules/gamemode.lua:38
          9. DeriveGamemode - [C]:-1
           10. unknown - gamemodes/hl2rp/gamemode/init.lua:2

[ERROR] gamemodes/hl2rp/plugins/hl2_stuffs/sh_plugin.lua:45: attempt to call field 'Register' (a nil value)
  1. unknown - gamemodes/hl2rp/plugins/hl2_stuffs/sh_plugin.lua:45
   2. include - [C]:-1
    3. include - gamemodes/nutscript/gamemode/core/sh_util.lua:17
     4. load - gamemodes/nutscript/gamemode/core/libs/sh_plugin.lua:44
      5. loadFromDir - gamemodes/nutscript/gamemode/core/libs/sh_plugin.lua:189
       6. initialize - gamemodes/nutscript/gamemode/core/libs/sh_plugin.lua:180
        7. Call - gamemodes/nutscript/gamemode/shared.lua:75
         8. unknown - lua/includes/modules/gamemode.lua:38
          9. DeriveGamemode - [C]:-1
           10. unknown - gamemodes/hl2rp/gamemode/init.lua:2


Here’s the sh_plugin.lua code for both plugins:


PLUGIN.name = "Combine Light"
PLUGIN.author = "robinkooli"
PLUGIN.desc = "Portable light sources used to illuminate dark areas in support of Combine operations."

nut.command.Register({
    adminOnly = true,
    syntax = "[bool disabled]",
    onRun = function(client, arguments)
        local entity = scripted_ents.Get("hl2_combinelight"):SpawnFunction(client, client:GetEyeTraceNoCursor())

        if (IsValid(entity)) then
            nut.util.Notify("You have created a Combine Light.", client)
        end
    end
}, "placecl")


PLUGIN.name = "Half Life 2 Stuffs"
PLUGIN.author = "Black Tea"
PLUGIN.desc = "Gives you more Half-Life 2 Stuffs."
PLUGIN.comlock = {}

if SERVER then
    function PLUGIN:LoadData()
        local restored = nut.util.ReadTable("comlocks")

        if (restored) then
            for k, v in pairs(restored) do
                local position = v.position
                local angles = v.angles
                local door = v.door
                if !door then continue end

                local entity = ents.Create("nut_reader")
                entity:SetPos(position)
                entity:SetAngles(angles)
                entity.door = door
                entity:Spawn()
            end
        end
    end    
    
    function PLUGIN:SaveData()
        local data = {}
        for k, v in pairs( ents.FindByClass("nut_reader") ) do
            data[#data + 1] = {
                position = v:GetPos(),
                angles = v:GetAngles(),
                door = v.door
            }
        end
        nut.util.WriteTable("comlocks", data)        
    end
    
end

local function IsDoor(entity)
    return string.find(entity:GetClass(), "door")
end


nut.command.Register({
    adminOnly = true,
    syntax = "[bool showTime]",
    onRun = function(client, arguments)
        local name = arguments[1]
        tr = {}
        tr.start = client:GetShootPos()
        tr.endpos = tr.start + client:GetAimVector() * 200
        tr.filter = client
        trace = util.TraceHull(tr)
    
        if (!client:GetNutVar("comlock")) then
            if trace.Entity:IsValid() and trace.Entity:GetClass() == "nut_reader" then
                client:SetNutVar("comlock", trace.Entity)
                nut.util.Notify("Now face the door. and with name.", client)
            end
        else
            if trace.Entity:IsValid() and IsDoor( trace.Entity ) then
                
                local comlock = client:GetNutVar("comlock")
                comlock.door = trace.Entity:GetPos()

                client:SetNutVar("comlock", nil)
                nut.util.Notify("You've added a new combine lock.", client)
            else
                client:SetNutVar("comlock", nil)
                nut.util.Notify("Resetted selection.", client)
            end
        end
        
    end
}, "addcomlock")

Any help would be appreciated.

As I can see, you seem to be running Nutscript 1.1 and trying to register commands with Nutscript 1.0 functions.

To fix this, what you have to do is change nut.command.Register for nut.command.add
and also put the 2nd argument as the first one, having the data after it.

And also, t here is no need to create that function that you’ve which is IsDoor.
Nutscript has got already a door check function which is, in fact ENTITY:isDoor()

Thank you - I’ll check if this worked.
Edit: It worked! Danke, mein freunde. But now I’m getting this error twice:


[ERROR] gamemodes/nutscript/gamemode/core/libs/sh_command.lua:9: attempt to index a string value with bad key ('syntax' is not part of the string library)
  1. error - [C]:-1
   2. __index - lua/includes/extensions/string.lua:297
    3. add - gamemodes/nutscript/gamemode/core/libs/sh_command.lua:9
     4. unknown - gamemodes/hl2rp/plugins/hl2_combinelight/sh_plugin.lua:5
      5. include - [C]:-1
       6. include - gamemodes/nutscript/gamemode/core/sh_util.lua:17
        7. load - gamemodes/nutscript/gamemode/core/libs/sh_plugin.lua:44
         8. loadFromDir - gamemodes/nutscript/gamemode/core/libs/sh_plugin.lua:189
          9. initialize - gamemodes/nutscript/gamemode/core/libs/sh_plugin.lua:180
           10. unknown - gamemodes/nutscript/gamemode/shared.lua:65

I think I should be showing this to rebel1324 (the current developer for Nutscript’s framework, as far as I know.)

I think thats a problem of your code and not Nutscript’s.
Also, if you really want basically, sort of live support with your Nutscript things you should come over to our discord.