How can i make this better

Well, i started lua day before yesterday, and thought i would make a game mode called headcrab hunt. Where baically you…er…hunt headcrabs. The entire gamemode is prety much based off the killcounter i found on the gmod wiki example page. You can see how the player gets upgrades, and the headcrabs change at certain kill counts. Here is the coding:

[lua]

AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include( ‘shared.lua’ )

// Serverside only stuff goes here

function GM:PlayerSpawn(pl)
self.BaseClass:PlayerSpawn(pl)
pl:SetGravity(0.90)
pl:SetMaxHealth(100, true)
pl:SetWalkSpeed(350)
pl:SetRunSpeed(520)
end

function GM:PlayerLoadout(pl)

pl:StripWeapons()
pl:Give("weapon_crowbar")
pl:Give("weapon_pistol")

end

function GM:PlayerInitialSpawn(pl)

self.BaseClass:PlayerInitialSpawn(pl)
if pl:IsAdmin() then
pl:PrintMessage(HUD_PRINTTALK, "50 headcrabs to kill, 10 kills 'till weapon upgrade")
ActivateSpawn()
ChangeSpawnAmount(10)

end

end

function ActivateSpawn()
local Spawner = ents.FindByClass(“npc_template_maker”)
for k,v in pairs (Spawner) do
v:Fire(“Enable”, “”, 5)
end
end

function ChangeSpawnNpc(newNpc)
local Spawner = ents.FindByClass(“npc_template_maker”)
for k,v in pairs (Spawner) do
v:SetKeyValue(“TemplateName”, newNpc)
end
end

function ChangeSpawnAmount(newAmount)
local Spawner = ents.FindByClass(“npc_template_maker”)
for k,v in pairs (Spawner) do
v:SetKeyValue(“MaxNPCCount”, newAmount)
end
end

function KillCounter( victim, killer, weapon )

	if killer:GetNWInt("killcounter") == 10 then
		ChangeSpawnAmount(10)
		local players = player.GetAll()
		for k,v in pairs(players) do
        v:Give("weapon_shotgun")
		v:SetAmmo(5, "Buckshot")
		v:SetAmmo(10, "Pistol")
		v:PrintMessage(HUD_PRINTTALK, "SHOTGUN RECIEVED, EXISTING AMMO PARTIALLY REPLENISHED, 10 kills 'till next wave")
        end 
		
	end
	
	if killer:GetNWInt("killcounter") == 20 then 
		local players = player.GetAll()
			for k,v in pairs(players) do
			v:SetAmmo(10, "Buckshot")
			v:SetAmmo(10, "Pistol")
			v:Give("item_healthkit")
			v:PrintMessage(HUD_PRINTTALK, "WAVE 2 INITIATED, EXISTING AMMO PARTIALLY REPLENISHED, 15 kills 'till final swarm")
			ChangeSpawnAmount(15)
			ChangeSpawnNpc("FAST_HC_TEMPLATE")
		end
	end
		if killer:GetNWInt("killcounter") == 35 then 
		local players = player.GetAll()
			for k,v in pairs(players) do
			v:PrintMessage(HUD_PRINTTALK, "SMG RECIEVED, EXISTING AMMO PARTIALLY REPLENISHED, 15 kills 'till its all over")
			v:SetAmmo(5, "Buckshot")
			v:SetAmmo(5, "Pistol")
			v:SetAmmo(25, "SMG1")
			v:Give("item_healthkit")
			ChangeSpawnAmount(15)
			ChangeSpawnNpc("P_HC_TEMPLATE")
		end
	end
	if killer:GetNWInt("killcounter") == 50 then  
	local players = player.GetAll()
		for k,v in pairs(players) do
		player.GetAll():PrintMessage(HUD_PRINTTALK, "YOU WIN, CONGRATULATIONS!")
		end
	end
        killer:SetNWInt("killcounter", killer:GetNWInt("killcounter") + 1)  
end

hook.Add("OnNPCKilled","KillCounter", KillCounter)

[/lua]

I know some parts may seem messy, but as i said, im new.

Does anyone have suggestions for additions or things i can change?

PS: The gamemode has custom maps due to the spawner having to be initiated by lua, and the template npcs.

… What exactly do you want?

He wants to know if anything in the code could be done better, or what could be changed or added instead.

You should learn to read. He said it pretty clearly down the bottom.

Stop using NWvars, start using usermessages.

-snip-

Well, the “true” in “pl:SetMaxHealth(100, true)” is useless so you can delete it.

k thanks. Im watching youtube tutorials and stuff, so i dont know exactly whats right and wrong. Im also more used to c++ and am confused by the whole colon syntax(ent:Fire, player:Give)

Do you think you can clear that up at all?

The colon is basically lua’s way of emulating an OOP feel.
If in C++ you do obj.method() then in lua you do obj:method()
in most similiar scenarios.

Ah i see… i also like how lua scripts use “for k,v in pairs” i think thats hilarious compared to c++ “for” statements

If you know C++, Lua is a breeze.

yes now i understand that the colon syntax is basically just the same as dot syntax, and that “for k,v in pairs” is just iterating through an array(do yall call them tables?) it should be easier to understand.