Somewhat new to Lua, couple of kinks

Hey guys!

I’ve recently decided to code a game mode, after having taken a break from coding SWEPs and learning supporter programming languages (C++, C#, Java). There are a lot of little qwerks and minor details I’m trying to figure out, since I haven’t had formal education in Lua programming.

Here’s a list of the things I’m trying to accomplish:



Temporarily darken a player's screen
Display, then erase text after a certain time limit
Prevent players from spawning
Randomly select a player to be part of a certain team


Thats all that springs to mind at the moment. I’ve tried trudging through the GMod Lua Wiki but nothing in there seems to indicate any of my above problems except the last one. I managed to figure something out, I was hoping you could provide some debugging assistance with it so I don’t hopelessly run GMod 50 times until I find one problem.




 function GM:PlayerSpawn ( ply )
		RunConsoleCommand("team_1")
	if isOver = true then
		local table_Winner = player.GetAll()
		local num = math.random(1,table.count(table_Winner))
		for x = 0, table.Count(table_Winner) do
			table_ID[x] = ply:GetByID(x)
		end
		timer.Create("random selection timer", 15, 1, 
		function()
			if table_ID[num] = table_Winner[num] then
				RunConsoleCommand("team_2")
			else
				ply:Give("weapon_crowbar")
			end if
		end)
	end if
end


isOver is a boolean for determining if a new round has started or not, since a player can join a game and “initially” spawn, but then spawn subsequent times after a round ends.

Unfortunately, the logic for dealing with players as a whole and assuring that the effects I want are going to the right player doesn’t sit well with me.
I have made text print on the screen, I just can’t find a function to clear it (and any other possible text) from the user’s screen.
I also have no clue how to change their overlay alpha / RGB.
If you could provide any clearing up of that, the listed issues, and my posted code, I would be incredibly grateful!

tl;dr: Need some coding help, please read/help :smiley:

<3 for anyone who helps me!

-NeoHazard

You don’t need to sign your post we know who you are.

Thanks! That solves EVERY SINGLE one of my issues!
I’ll remember that next time I’m scripting in Lua, so I’ll never have to post so you won’t make stupid posts!

If you don’t know how to help me, please refrain from posting.

To overlay the HUD, you can use **[G.DrawColorModify

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=G.DrawColorModify)** function or just draw directly to the HUD through the use of HUDPaint.

Well, I tried just drawing a box during HUDPaint, but now how do I get rid of it?

[lua]hook.Remove(“HUDPaint”,“your hook name”)[/lua]

Edit: Got outside help, fixed the overlay issue.

Random picking is working (as far as I can tell)

Still need help on preventing spawning naturally.

:irony:

Two things:

  1. That was a stupid post
  2. This is facepunch, stupid posts are going to be there whether you like it or not

Anyway to answer the question on spawning:
In the base gamemode **[Gamemode.PlayerDeathThink

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.PlayerDeathThink)** is used to respawn players (ref: http://luabin.foszor.com/code/gamemodes/base/gamemode/player.lua @ 221)
You should be able to just override it by redefining it, and you can then stop people from spawning at will.
E.g.
[lua]
function GM:PlayerDeathThink( ply )
–Respawn logic
end
[/lua]