• Making up for delay between 2 lines of code
    6 replies, posted
I have a function that adds a player to a new usergroup: RunConsoleCommand( "ulx", "adduserid", ply:SteamID(), Rank ) After that line, I run this right after: net.Start( "PromotionMessage" ) net.WriteTable( team.GetColor( ply:Team() ) ) net.WriteString( ply:Name() ) net.WriteString( team.GetName ( ply:Team() ) ) net.Broadcast() I need to send the new information about the player after the promotion, however, the above code does not do that, it still sends the old info about the player. A weak, imo, workaround I did was this: timer.Simple( 1, function()  net.Start( "PromotionMessage" ) net.WriteTable( team.GetColor( ply:Team() ) ) net.WriteString( ply:Name() ) net.WriteString( team.GetName ( ply:Team() ) ) net.Broadcast() end ) This gets the job done, but I wanted to know if there is a better way to do this.... A better question is, would this always work (with a 1 second timer) if it works when all the server is doing is this single function with no other load. My guess is this won't work if my server is full and has a ton of other stuff it has to do in the background, but I'm not sure. Any help would be appreciated! Thanks Note: Each rank (I use ULX in my case) has its own unique team attached to it, so when the user is added to a new usergroup, their team is automatically assigned to the team that corresponds to that rank by ULX.
what i'd do is just find the concommand function where ulx added the adduserid and add your net message to the end of it function ulx.adduserid( calling_ply, id, group_name ) id = id:upper() -- Steam id needs to be upper -- Check for valid and properly formatted ID if not checkForValidId( calling_ply, id ) then return false end -- Now add the fool! ULib.ucl.addUser( id, allows, denies, group_name ) if ULib.ucl.users[ id ] and ULib.ucl.users[ id ].name then ulx.fancyLogAdmin( calling_ply, "#A added #s to group #s", ULib.ucl.users[ id ].name, group_name ) else ulx.fancyLogAdmin( calling_ply, "#A added userid #s to group #s", id, group_name ) end net.Start( "PromotionMessage" ) net.WriteTable( team.GetColor( calling_ply:Team() ) ) net.WriteString( calling_ply:Name() ) net.WriteString( team.GetName ( calling_ply:Team() ) ) net.Broadcast() end could also use hooks function ulx.adduserid( calling_ply, id, group_name ) id = id:upper() -- Steam id needs to be upper -- Check for valid and properly formatted ID if not checkForValidId( calling_ply, id ) then return false end -- Now add the fool! ULib.ucl.addUser( id, allows, denies, group_name ) if ULib.ucl.users[ id ] and ULib.ucl.users[ id ].name then ulx.fancyLogAdmin( calling_ply, "#A added #s to group #s", ULib.ucl.users[ id ].name, group_name ) else ulx.fancyLogAdmin( calling_ply, "#A added userid #s to group #s", id, group_name ) end hook.Run("promatedUser", calling_ply) end hook.Add("promatedUser", function() net.Start( "PromotionMessage" ) net.WriteTable( team.GetColor( calling_ply:Team() ) ) net.WriteString( calling_ply:Name() ) net.WriteString( team.GetName ( calling_ply:Team() ) ) net.Broadcast() end) probably some other ways i'm not thinking of too, but the timer.simple will probably work just fine, ulx probably has a "async" attribute too it where it doesn't wait for it too finish before going to the next line (honestly idk im guessing it does)
Problem is I don't want this to run every time this function is ran... Only in this one instance where I'm running it. I'm afraid that solution would not be too useful for me, but it's a great idea for anyone who is trying to for that. Thanks
ah okay, you could do something like this then function ulx.adduserid( calling_ply, id, group_name, shouldShowPromotionMessage ) id = id:upper() -- Steam id needs to be upper -- Check for valid and properly formatted ID if not checkForValidId( calling_ply, id ) then return false end -- Now add the fool! ULib.ucl.addUser( id, allows, denies, group_name ) if ULib.ucl.users[ id ] and ULib.ucl.users[ id ].name then ulx.fancyLogAdmin( calling_ply, "#A added #s to group #s", ULib.ucl.users[ id ].name, group_name ) else ulx.fancyLogAdmin( calling_ply, "#A added userid #s to group #s", id, group_name ) end if (shouldShowPromotionMessage) then net.Start( "PromotionMessage" ) net.WriteTable( team.GetColor( calling_ply:Team() ) ) net.WriteString( calling_ply:Name() ) net.WriteString( team.GetName ( calling_ply:Team() ) ) net.Broadcast() end end local adduserid = ulx.command( CATEGORY_NAME, "ulx adduserid", ulx.adduserid, nil, false, false, true ) adduserid:addParam{ type=ULib.cmds.StringArg, hint="SteamID, IP, or UniqueID" } adduserid:addParam{ type=ULib.cmds.StringArg, completes=ulx.group_names_no_user, hint="group", error="invalid group \"%s\" specified", ULib.cmds.restrictToCompletes } adduserid:addParam{ type=ULib.cmds.BoolArg, hint="Show Promotion message" } adduserid:defaultAccess( ULib.ACCESS_SUPERADMIN ) adduserid:help( "Add a user by ID to specified group." ) RunConsoleCommand( "ulx", "adduserid", ply:SteamID(), Rank, true ) --shows the promotion message RunConsoleCommand( "ulx", "adduserid", ply:SteamID(), Rank, false ) --shows the promotion message here's a pastebin cause facepunch formats code badly.. [Lua] function ulx.adduserid( calling_ply, id, group_name, shoul..
Why are you running the console command from Lua? You could just run the code that the console command does, directly. In the case of ulx adduserid, that would be ULib.ucl.addUser ULib.ucl.addUser(ply:SteamID(), Rank) net.Start( "PromotionMessage" )     net.WriteTable( team.GetColor( ply:Team() ) )     net.WriteString( ply:Name() )     net.WriteString( team.GetName ( ply:Team() ) ) net.Broadcast() That right there should work.
bad argument #2 to ULib.ucl.addUser (nil,table expected, got string) Get this error using that..
I looked into ULX and it uses a queueing system in ULib to assign the team to a player, meaning that there's at least one frame between when you set their rank and when the team change is reflected. The queue processors seems to only run one item from each queue on each frame, so depending on server framerate and how many things are sitting in the queue before the team change, yes that 0.1 second timer could fail as well. You can counter this, by also using the ULib queue system: ULib.ucl.addUser(ply:SteamID(), {}, {}, Rank) ULib.queueFunctionCall( function()     if ( not IsValid (ply ) ) then return end -- if the player disconnected quickly, prevent this from erroring     net.Start( "PromotionMessage" )         net.WriteTable( team.GetColor( ply:Team() ) )         net.WriteString( ply:Name() )         net.WriteString( team.GetName ( ply:Team() ) )     net.Broadcast() end)
Sorry, you need to Log In to post a reply to this thread.