Ulysses
General => Developers Corner => Topic started by: PatPeter 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:
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?
-
Use ucl.addUser (http://ulyssesmod.net/docs/files/lua/ulib/server/ucl-lua.html#ucl.addUser)
-
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 (http://forums.ulyssesmod.net/index.php?topic=3039.0) to count player hours.
-
I don't see any operations in your script that would remove the data
-
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.
-
I found out what the problem is (I think)... when ucl.addUser(uid, {}, {}, "regular") is run, it causes these errors in my Pointshop:
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.