Right now I have it so it paints on a players screen **Player1 is Spectating Player2**. I was wondering how I would list every player that is spectating Player2? I THINK I know how to add all the specs to a table but I don't know how to print them in a list type format meaning one entry below the other. As always thanks a bunch, I love learning something new!
It depends how you want to list them. To get the list, you can do something like:
[lua]local tab = {}
for k, v in pairs( player.GetAll() ) do
if v:GetObserverTarget() == player2 then
tab[#tab+1] = v
end
end[/lua]
Then you would have a table of all the players spectating that person. In HUDPaint, or whatever place you're drawing the list, just loop through the table. If you don't want yourself to be in the list, either add a check when adding to the table, or add a check when drawing the table.
[lua]for i = 1, #tab do
draw.SimpleText( tab[i]:Nick(), "Default", ScrW()/2, 13 * i, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER )
end[/lua]
Beware The Skiddy Noob Code Above Im Feeling Generous So Have My Code From My Hera Basehook
Function GM:Think()
If 1 + 1 == 2 Then
If Pl:GetObserverTarget() == LocalPlayer() Then
Print( Pl:Name() )
End
End
End
Thanks Shadow I understand how to add tables in now, i was missing the [i] before. Ive been messing around with this for about 30 minutes and I still can't seem to get it working right. I know its really basic stuff and I am going to kick myself in the ass when I see it but I can't figure out how to only add the player to the table if they are specing player2.
And thanks a bunch! I'm not just copy/pasting and forgetting about :)
[QUOTE=wearing12;38093153]Beware The Skiddy Noob Code Above Im Feeling Generous So Have My Code From My Hera Basehook
Function GM:Think()
If 1 + 1 == 2 Then
If Pl:GetObserverTarget() == LocalPlayer() Then
Print( Pl:Name() )
End
End
End[/QUOTE]
Don't call somebody else's code awful when you add gems like 1 + 1 == 2
Im not sure but i think thats the joke.
[QUOTE=joe_sandwich;38093575]Don't call somebody else's code awful when you add gems like 1 + 1 == 2[/QUOTE]
u got troled
Anyways, is this what you want to do?
[lua]
hook.Add("HUDPaint", "SpectatorStuff", function()
local Spectators = {} -- Create a new table.
local Spectators_Text = "Spectators:"
for k, v in pairs(player.GetAll()) do
if whatever then
table.Insert(Spectators, v) // Insert the player into the table.
Spectators_Text = Spectators .. "\n" .. v:Name() -- '..' adds strings together, '\n' makes a new line. This will add a new line to the text with the player's name on it.
end
end
draw.DrawText(whatever)
end)
[/lua]
[QUOTE=dylanb5123;38093932]u got troled
[/QUOTE]
And this is why I generally avoid the lua section...
Sorry, you need to Log In to post a reply to this thread.