How could I save data from a hook and it run once round ends?

So I have a hook when a player levels up, it will store the leveler, and the level they reached, then sends everyone a message on the server.


hook.Add( "onLevelUp", "CurGamingLvlUp" , function(ply, level, tilnextlevel) 
	lvlerup = ply
	plylvlup = level
	curiumgive = plylvlup*5

	LevelUpMsgPly() -- Print message to leveler
	ply:PS_GivePoints(curiumgive)

	LevelUpMsgAll()
end)  


The function LevelUpMsgAll() being the function that networks and sends a message to everyone. The thing I need is a delay before the function is called, which would delay until the round ends.

Now I’m wanting to make the message be sent at a later time, which would be the moment the round ended. There’s a few hooks with TTT called TTTEndRound and TTTCheckForWin which I’m not sure if they’ll help me at all here. Such as: Player levels up during the round but it does NOT tell everyone that he leveled up (because that would kinda give away who’s the Traitor) until the round actually ends. I’m scratching my head because it seems simple but I can’t for the life of me figure it out on my own.

Basically what you would do is make a semi-global table, and store the players names in the table. Then, at the end of the round, loop through that table and print our all the names. Storing names instead of the player entity itself will prevent errors if the player leaves during the round. Then, once you’ve printed out all the names, simply empty the table.



local round_levels = {}
hook.Add( "onLevelUp", "CurGamingLvlUp", function( ply, lvl, xptonext )
    table.insert( round_levels, ply:Name() )
end )
hook.Add( "TTTEndRound", "lvlupecho, function()
    for _, name in ipairs( round_levels ) do
        print( name )
    end
    round_levels = {}
end )


I saw about what you did there and instead did this:


 round_levels = {}
hook.Add( "onLevelUp", "CurGamingLvlUp" , function(ply, level, tilnextlevel) 
	lvlerup = ply
	nick = ply:Nick()
	plylvlup = level
	curiumgive = plylvlup*5

	LevelUpMsgPly() -- Print message to leveler
	ply:PS_GivePoints(curiumgive)

	table.insert(round_levels, nick)
	table.insert(round_levels, plylvlup)

end) 

hook.Add("TTTEndRound", "MsgOnEndRound", function(result)
	if result == WIN_INNOCENT or result == WIN_TRAITOR or result == WIN_TIMELIMIT then
		if table.Count(round_levels) >= 2 then
			LevelUpMsgAll()
			table.Empty(round_levels)
		end
	end
end)

	net.Receive( "LvlUpMsgAll", function()
		local round_levels = net.ReadTable()

		for i=1,table.Count(round_levels)/2 do
			chat.AddText(orange, "[",
								blue, "LEVEL",
								orange, "] ",
								blue, round_levels*,
								orange, " just leveled up to level ",
								blue, round_levels[i+1],
								orange, "!")
		end
	end ) 


and got exactly what I was looking for. :slight_smile: