Author Topic: Why isn't ULX saving assigned user groups?  (Read 2586 times)

0 Members and 1 Guest are viewing this topic.

Offline PatPeter

  • Newbie
  • *
  • Posts: 14
  • Karma: -1
Why isn't ULX saving assigned user groups?
« on: November 22, 2014, 03:15:16 PM »
So basically, if a user matches a certain criteria to be a regular on my server, I add them to the regular group:

Code: [Select]
hook.Add( "PlayerInitialSpawn", "MAWTTTRegularInitialSpawn", function(p)
local uid = p:UniqueID()
local row = sql.QueryRow( "SELECT totaltime FROM utime WHERE player = " .. uid .. ";" )
if not row then
return
end

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

But it is not saving the user to the users.txt file. How do I fix ULX to save users after adding them to groups with a script?
« Last Edit: November 23, 2014, 07:28:56 PM by PatPeter »

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Why isn't ULX saving assigned user groups?
« Reply #1 on: November 22, 2014, 05:36:23 PM »
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline PatPeter

  • Newbie
  • *
  • Posts: 14
  • Karma: -1
Re: Why isn't ULX saving assigned user groups?
« Reply #2 on: November 23, 2014, 07:46:55 PM »
I posted the full contents of my script. So I've run into a drastic problem where it's removing the player's row in the playerpdata table. Is there something catastrophically wrong with my script? As you can tell, it uses utime to count player hours.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Why isn't ULX saving assigned user groups?
« Reply #3 on: November 24, 2014, 05:55:06 AM »
I don't see any operations in your script that would remove the data
Experiencing God's grace one day at a time.

Offline PatPeter

  • Newbie
  • *
  • Posts: 14
  • Karma: -1
Re: Why isn't ULX saving assigned user groups?
« Reply #4 on: November 24, 2014, 06:26:20 PM »
I know! I'm running what should be a harmless SELECT statement, and for whatever reason it either deletes the user row or resets the column to 0. I don't know if transactionality or anything like that would ever come into account with Garry's Mod.

It's also worth noting that this script does not add users to the regular group in ULX.

Offline PatPeter

  • Newbie
  • *
  • Posts: 14
  • Karma: -1
Re: Why isn't ULX saving assigned user groups?
« Reply #5 on: December 07, 2014, 12:40:32 AM »
I found out what the problem is (I think)... when ucl.addUser(uid, {}, {}, "regular") is run, it causes these errors in my Pointshop:

Code: [Select]
L 12/07/2014 - 02:35:48: Lua Error:
[ERROR] addons/pointshop/lua/sv_player_extension.lua:299: attempt to index field 'PS_Items' (a nil value)
  1. PS_HasItem - addons/pointshop/lua/sv_player_extension.lua:299
   2. PS_HasItemEquipped - addons/pointshop/lua/sv_player_extension.lua:303
    3. fn - addons/pointshop/lua/sh_pointshop.lua:135
     4. unknown - addons/ulib/lua/ulib/shared/hook.lua:183

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

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

And because it's mid-way between adding the user, it blanks the hours? I'm not sure.