pointshop icon indicating copy to clipboard operation
pointshop copied to clipboard

Pointshop breaks ucl.addUser/ucl.removeUser in my script

Open PatPeter opened this issue 10 years ago • 0 comments

I wrote a little script to add people to a regular group in ULX:

function onRegularJoin(ply)
    local uid = ply:UniqueID()
    print(uid)
    local row = sql.QueryRow("SELECT totaltime FROM utime WHERE player = \"" .. uid .. "\"")
    if not row then
        return
    end
    if not row.totaltime then
        return
    end

    local totaltime = tonumber(row.totaltime)
    if ply:IsUserGroup("user") and not ply:IsUserGroup("regular") and totaltime >= 86000 then
        ucl.addUser(uid, {}, {}, "regular")
        PrintMessage(HUD_PRINTTALK, "Congratulations " .. ply:GetName() .. "! You have been promoted to a regular for playing a day on the server.")
        ServerLog("Congratulations " .. ply:GetName() .. "! You have been promoted to a regular for playing a day on the server.")
    elseif ply:IsUserGroup("regular") and totaltime < 86000 then
        ucl.removeUser(uid)
        PrintMessage(HUD_PRINTTALK, ply:GetName() .. " has lost regular status for not playing on the server a day.")
        ServerLog(ply:GetName() .. " has lost regular status for not playing on the server a day.")
    end
end
hook.Add( "PlayerInitialSpawn", "MAWTTTRegularInitialSpawn", onRegularJoin)

When it reaches either the ucl.addUser/ucl.removeUser, it causes this errors to spam the console relentlessly and breaks the Pointshop:

L 12/28/2014 - 21:02:26: Lua Error:
[ERROR] addons/pointshop/lua/pointshop/sv_player_extension.lua:283: attempt to index field 'PS_Items' (a nil value)
  1. PS_HasItem - addons/pointshop/lua/pointshop/sv_player_extension.lua:283
   2. PS_HasItemEquipped - addons/pointshop/lua/pointshop/sv_player_extension.lua:287
    3. fn - addons/pointshop/lua/pointshop/sh_init.lua:145
     4. unknown - addons/ulib/lua/ulib/shared/hook.lua:183



[ERROR] addons/pointshop/lua/pointshop/sv_player_extension.lua:283: attempt to index field 'PS_Items' (a nil value)
  1. PS_HasItem - addons/pointshop/lua/pointshop/sv_player_extension.lua:283
   2. PS_HasItemEquipped - addons/pointshop/lua/pointshop/sv_player_extension.lua:287
    3. fn - addons/pointshop/lua/pointshop/sh_init.lua:145
     4. unknown - addons/ulib/lua/ulib/shared/hook.lua:183


[ERROR] addons/pointshop/lua/pointshop/sv_player_extension.lua:283: attempt to index field 'PS_Items' (a nil value)
  1. PS_HasItem - addons/pointshop/lua/pointshop/sv_player_extension.lua:283
   2. PS_HasItemEquipped - addons/pointshop/lua/pointshop/sv_player_extension.lua:287
    3. fn - addons/pointshop/lua/pointshop/sh_init.lua:145
     4. unknown - addons/ulib/lua/ulib/shared/hook.lua:183

Here is the source for the two methods:

https://github.com/Nayruden/Ulysses/blob/master/ulib/lua/ulib/server/ucl.lua#L569 https://github.com/Nayruden/Ulysses/blob/master/ulib/lua/ulib/server/ucl.lua#L736

PatPeter avatar Dec 29 '14 03:12 PatPeter