APromote, Need help assigning a group upon first Connect.

Hello thank you for taking the time to read! :slight_smile:

So my problem is this, whenever someone joins my server they are defined as Group > User by default. So if you press Tab and look at their rank it just says user. I would like them to be in another group and team by default. I have set up APromote in ULX to have the following groups and teams

user (default and can’t be deleted)

Group: Newbie > Team: Newbie ------------- Set to AutoPromote in 0 Hours
Group: Trusted > Team: Trusted ----------- Set to AutoPromote in 1 Hours
Group: Master > Team: Master ------------- Set to AutoPromote in 5 Hours
Group: Elite > Team: Elite ------------------ Set to AutoPromote in 10 Hours
Group: VIP > Team: VIP -------------------- Set to AutoPromote in 72 Hours
Group: Moderator > Team: Admin ----------- Set to AutoPromote in -1 Hours
Group: Admin > Team: Admin -1 Hours
Group: SuperAdmin > Team: SuperAdmin -1 Hours

Also I tried setting the default user group to the Newbie team, but it was still not putting them in their. This is quite a big problem because the ranks define all the different tools and props etc etc that each one can use.

Another problem that this seems to be causing is that, if they join they are not being saved to a group at all, so when they rejoin they are still user even if they had played for x amount of hours. But if I manually add someone to a group they are saved, all works fine ?

Sorry if this is all a bit confusing but I really dont know how to word it on text.

Please feel free to check out the problem and possibly chat to me by connecting to the server here:

Thank you

hook.Add( "PlayerInitialSpawn", "addPlyToNewbie", function( ply )
     if ply:IsUserGroup( "user" ) then -- idk if the "u" is caps or not
          RunConsoleCommand( "ulx", "adduserid", ply:SteamID(), "Newbie" )
end )

You know you can just check how long the player has been connected and give ranks according to that? It’d be pretty simple to implement mysql.

Thank you Jack, you are a life saver!

So you are implying I must stay on 24/7 and promote my players as they hit their required times?
I knew their was a simple way to do it via ULX and LUA but I have figured out the problem now, and Jack has provided me with a simple workaround…

But I will explain for anyone who ever runs into the same problem.

The Group (users) is the default group assigned to every player when they connect to a server.

But the problem is when a player connects they technically don’t spawn with a timer of 0, instead 00:00:00:01 (DD:HH:MM:SS) so when APromote looks for 0, it can’t find it, and when they hit 1 hour and are supposed to be promoted again, it won’t because it knows there’s is a promotion under it that the player never received, in other words it won’t allow it to skip a rank and 0 never existed.

There are two work arounds I have found, 1 is the code Jack has posted above, which will automatically place a player in the specified group on first connect allowing APromote to start wherever you please, or the older version of UTime v2.0 which returns only whole numbers in hours. E.g ( 0 Hours, 1 Hours etc).

The downfall of using the UTime 2.0 is that it looks tacky and doesn’t give an accurate reading of the time a player has been connected.

Also I have found for all you who are wanting to setup the same thing, that if the server crashes or restarts, players will lose their time counter, and be reset back to 1 seconds. There is a also a quick workaround to this which you can include.

**Code Courtesy of KillerLUA

local meta = FindMetaTable("Player")
function meta:GetPlayingTime()
   return self:GetNetworkedInt("PlayingTime")

if SERVER then
	function meta:SavePlayingTime()
		return self:SetPData("PlayingTime", self:GetPlayingTime() + self:TimeConnected())

if SERVER then
	local function LoadPlayingTime( ply )  // When spawning after joining the sever
		if ply:GetPData("PlayingTime") != nil then
			ply:SetNetworkedInt("PlayingTime", ply:GetPData("PlayingTime"))
	hook.Add("PlayerInitialSpawn", "LoadPlayingTime", LoadPlayingTime)

	local function SavePlayingTime( ply )
	hook.Add( "PlayerDisconnected", "SavePlayingTime", SavePlayingTime)

Have you Tried Clockyinstead? it is something simmilar to UTime, but with mysqloo/tmysql support.

I didn’t say manually, I said you could do it(Lua being implied).