Getting something to work on player spawn

I was trying to get this suit to automatically apply when I spawned into the game. Right now it’s tied to a vest and when you walk into it, it applies. Can anyone help me with making the suit be applied every time I respawn and when I start the map? I know no lua whatsoever.



AddCSLuaFile()

ENT.Type 			= "anim"
ENT.Base 			= "base_anim"
ENT.PrintName		= "Combine Engineer Suit"
ENT.Author			= "FiLzO"
ENT.Information		= "Badass."
ENT.Category		= "Combine Suits"

ENT.Spawnable		= true
ENT.AdminOnly		= false

S1 = "npc/combine_soldier/zipline_clothing1.wav"
S2 = "npc/combine_soldier/zipline_clothing2.wav"

local Spawn = {}
	Spawn[1] = (S1)
	Spawn[2] = (S2)
	
Die_Another_Day = {
	"npc/combine_soldier/die1.wav",
	"npc/combine_soldier/die2.wav",
	"npc/combine_soldier/die3.wav"
}
	
if SERVER then

function ENT:Initialize()
	self:SetModel("models/combine_vests/outlandvest.mdl")
	self:SetNoDraw(false)
	self:DrawShadow(true)
	self:PhysicsInit( SOLID_VPHYSICS )
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid( SOLID_VPHYSICS )
	self:SetTrigger( true )
end

function ENT:Touch( activator, ent )
	


if ( activator.wearsuit == true ) then
	activator:EmitSound("buttons/combine_button_locked.wav")
	else
self:SetNoDraw(true)
self:DrawShadow(false)
self:SetCollisionGroup( COLLISION_GROUP_DEBRIS )
		self:SetModel("models/weapons/shell.mdl")
		self.cai = ents.Create("npc_combine_s")
		self.cai:Spawn()
		self.cai:DrawShadow(false)
		self.cai:SetSolid(SOLID_NONE)
		self.cai:SetParent(activator)
		self.cai:SetKeyValue( "squadname", "Overwatch" )
		self.cai:SetKeyValue( "targetname", "mysuit" )
		self.cai:Fire("setparentattachment", activator:GetAttachments()[1].name)
		self.cai:SetKeyValue( "spawnflags", "256" + "8192" + "262144" )
		self.cai:SetMaterial("models/combine_soldier/combineengi_noalpha.vtf")
		self.cai:AddEffects(EF_BONEMERGE)
		--sniperpr:SetMaterial("models/effects/vol_light001")
		--self.cai:SetColor( Color( 255, 255, 255, 0 ) )
		--self.cai:SetRenderMode(RENDERMODE_TRANSALPHA)
		self.cai:SetHealth(99999999)
		self.cai:SetMaxHealth(99999999)
		self.cai:SetName("mysuit")
		
	activator.Wanted = false
	if GetConVarNumber("suits_own_weapons_enabled") == 1 then
	activator:StripWeapons()
	activator:StripAmmo()
	activator:Give("weapon_engineer_turret")
	activator:Give("weapon_smg1")
	activator:GiveAmmo(180,"smg1")
	end
	activator.wearsuit = true
	if GetConVarNumber("suits_overlay_enabled") == 1 then
	activator:ConCommand( "pp_mat_overlay effects/combine_binocoverlay.vmt" )
	end
	activator:EmitSound( Spawn[math.random(1,2)], 100, 100 )
	activator:SetColor( Color( 255, 255, 255, 0 ) )
	activator:SetRenderMode(RENDERMODE_TRANSALPHA)
	activator:SetHealth(110)
	activator:SetMaxHealth(110)
	activator:SetArmor(110)
	timer.Create( "BEGIN", 1.5, 1, function()
	activator:PrintMessage( HUD_PRINTTALK, "Unit: Combine Engineer" )
	activator:PrintMessage( HUD_PRINTTALK, "Equipment: ||MP7||Turret/Energy Conduit Placer||" )
	activator:PrintMessage( HUD_PRINTTALK, "Health: 110%" )
	activator:PrintMessage( HUD_PRINTTALK, "Armor: 110%" )
	activator:PrintMessage( HUD_PRINTTALK, "Target: Unknown" )
	activator:PrintMessage( HUD_PRINTTALK, "Objective: Encrypted" )
	activator:EmitSound( "npc/combine_soldier/vo/overwatch.wav", 100, 100 )
	end)
	end
 
end

function ENT:Think()
if IsValid( self.cai ) then
for k,v in pairs (player.GetAll()) do
if v.wearsuit == true then
if not v:Alive() then
v.wearsuit = false
v:ConCommand( "pp_mat_overlay \"\"" )
v:EmitSound( "npc/combine_soldier/zipline_hitground1.wav", 100, 100 )
v:SetRenderMode(RENDERMODE_NORMAL)
v:SetColor( Color( 255, 255, 255, 255 ) )
self:Remove()
self.cai:Remove()
end
end
	local NOTARGET = ents.FindByClass("npc_*")
		for _, NOT in pairs( NOTARGET ) do
	if(NOT:IsNPC() and NOT:Disposition(self.cai) == 1) then
	if NOT then
	NOT:AddEntityRelationship( self.cai, D_NU, 99 )
	end
	end
	end
end

concommand.Add( "RemoveSuit", function( activator )
	if ( activator:IsPlayer() and activator.wearsuit == true and IsValid(self.cai) ) then
	self:Remove()
	timer.Destroy( "BEGIN" )
if activator.wearsuit == true then
activator.wearsuit = false
activator:ConCommand( "pp_mat_overlay \"\"" )
activator:SetArmor(0)
activator:SetMaxHealth(100)
activator:EmitSound( "npc/combine_soldier/zipline_hitground1.wav", 100, 100 )
activator:SetRenderMode(RENDERMODE_NORMAL)
activator:SetColor( Color( 255, 255, 255, 255 ) )
if GetConVarNumber("suits_own_weapons_enabled") == 1 then
	activator:StripWeapons()
	activator:StripAmmo()
	activator:Give("weapon_physgun")
	activator:Give("gmod_tool")
	activator:Give("gmod_camera")
	activator:Give("weapon_physcannon")
	if GetConVarNumber("sbox_weapons") == 1 then
	activator:Give("weapon_crowbar")
	activator:Give("weapon_pistol")
	activator:Give("weapon_357")
	activator:Give("weapon_smg1")
	activator:Give("weapon_ar2")
	activator:Give("weapon_shotgun")
	activator:Give("weapon_crossbow")
	activator:Give("weapon_frag")
	activator:Give("weapon_rpg")
	
	activator:GiveAmmo(256,"pistol")
	activator:GiveAmmo(32,"357")
	activator:GiveAmmo(257,"SMG1")
	activator:GiveAmmo(5,"SMG1_Grenade")
	activator:GiveAmmo(100,"AR2")
	activator:GiveAmmo(5,"AR2AltFire")
	activator:GiveAmmo(64,"Buckshot")
	activator:GiveAmmo(36,"XBowBolt")
	activator:GiveAmmo(5,"Grenade")
	activator:GiveAmmo(2,"RPG_Round")
	end
end
if(activator:Health() > 100) then
	activator:SetHealth(100)
	end
end

self.cai:Remove()
	end
end )
	
end
end

function ENT:OnRemove( activator, ent )
timer.Destroy( "BEGIN" )
if IsValid( self.cai ) then
for k,v in pairs (player.GetAll()) do
if v.wearsuit == true then
v.wearsuit = false
v:ConCommand( "pp_mat_overlay \"\"" )
v:SetArmor(0)
v:SetMaxHealth(100)
v:EmitSound( "npc/combine_soldier/zipline_hitground1.wav", 100, 100 )
v:SetRenderMode(RENDERMODE_NORMAL)
v:SetColor( Color( 255, 255, 255, 255 ) )
if GetConVarNumber("suits_own_weapons_enabled") == 1 then
	v:StripWeapons()
	v:StripAmmo()
	v:Give("weapon_physgun")
	v:Give("gmod_tool")
	v:Give("gmod_camera")
	v:Give("weapon_physcannon")
	if GetConVarNumber("sbox_weapons") == 1 then
	v:Give("weapon_crowbar")
	v:Give("weapon_pistol")
	v:Give("weapon_357")
	v:Give("weapon_smg1")
	v:Give("weapon_ar2")
	v:Give("weapon_shotgun")
	v:Give("weapon_crossbow")
	v:Give("weapon_frag")
	v:Give("weapon_rpg")
	
	v:GiveAmmo(256,"pistol")
	v:GiveAmmo(32,"357")
	v:GiveAmmo(257,"SMG1")
	v:GiveAmmo(5,"SMG1_Grenade")
	v:GiveAmmo(100,"AR2")
	v:GiveAmmo(5,"AR2AltFire")
	v:GiveAmmo(64,"Buckshot")
	v:GiveAmmo(36,"XBowBolt")
	v:GiveAmmo(5,"Grenade")
	v:GiveAmmo(2,"RPG_Round")
	end
end
if(v:Health() > 100) then
	v:SetHealth(100)
	end
end
end

self.cai:Remove()
end
end


end


http://steamcommunity.com/profiles/76561198018489153/ is the addon where the code comes from.

put the code in code/lua tags please, its unreadable

How do I do that?

[LUA]
code
[backslashLUA]


function placefunctionnamehere( ply )
	stuffHere
end
hook.Add( "PlayerSpawn", "playerspawnhook", placefunctionnamehere)


add what you want to call when player spawns at the function. a example,



function placefunctionnamehere( ply )
	print("i just spawned!")
end
hook.Add( "PlayerSpawn", "playerspawnhook", placefunctionnamehere)


Wat.

are you going to fully c+p? damn.

Well, I don’t know how to code.

so all you want is when you spawn, suit applies?

Yeah. I’ve looked around on the Gmod wiki and tried messing around but I couldn’t figure it out.

Copy everything in the ENT:Touch function into function that you hook.Add onto PlayerSpawn (just like DaRkWoRlD1337 did). Remove all lines with “self:”. Replace “self.cai” with anything you wanna call it, such as “suit”. Put ‘local’ in front of the line that says ‘[whatever name you chose to replace self.cai] = ents.Create(“npc_combine_s”)’. Replace “activator” with whatever you called your first argument in the function. (In DaRkWoRlD’s example, it’s ply).

Wait what. “Copy everything in the ENT:Touch function into function that you hook.Add onto PlayerSpawn” what does that mean. What would it look like and where do I put it? Also, should I replace everything with activator in it and change it to ply or whatever?

It’s the simplest way I can put it. If you can’t figure it out still, you’d probably need to learn a bit of lua before this will work out for you.

You hook a function by first making the function and call it whatever. Then under that you use “hook.Add” to hook onto “PlayerSpawn” (first argument of hook.Add). It is exactly like DaRkWoRlD did it. He made a function called ‘placefunctionnamehere’ and hooked it. It is inside this function you want to paste all everything from inside ENT:Touch.

But what do you mean by everything inside ENT:Touch? Activator, ENT?

No, the ENT:Touch function. Use CTRL + F

Yeah, but what does he mean by everything inside it?

some functions:



function setEntHealth(x, y)
     Entity(x):SetHealth(y)
end 

function printSomething()
  print("hello world")
end

setEntHealth(1,25)
printSomething()


inside printSomething() function, there is print(“hello world”)
inside healEnt() function, there is Entity(x):SetHealth(50)
use your brain man.


AddCSLuaFile()

ENT.Type 			= "anim"
ENT.Base 			= "base_anim"
ENT.PrintName		= "Combine Engineer Suit"
ENT.Author			= "FiLzO"
ENT.Information		= "Badass."
ENT.Category		= "Combine Suits"

ENT.Spawnable		= true
ENT.AdminOnly		= false

S1 = "npc/combine_soldier/zipline_clothing1.wav"
S2 = "npc/combine_soldier/zipline_clothing2.wav"

local Spawn = {}
	Spawn[1] = (S1)
	Spawn[2] = (S2)
	
Die_Another_Day = {
	"npc/combine_soldier/die1.wav",
	"npc/combine_soldier/die2.wav",
	"npc/combine_soldier/die3.wav"
}
	
if SERVER then

function ENT:Initialize()
	self:SetModel("models/combine_vests/outlandvest.mdl")
	self:SetNoDraw(false)
	self:DrawShadow(true)
	self:PhysicsInit( SOLID_VPHYSICS )
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid( SOLID_VPHYSICS )
	self:SetTrigger( true )
end

function ENT:Touch( activator, ent )
	


if ( activator.wearsuit == true ) then
	activator:EmitSound("buttons/combine_button_locked.wav")
	else
self:SetNoDraw(true)
self:DrawShadow(false)
self:SetCollisionGroup( COLLISION_GROUP_DEBRIS )
		self:SetModel("models/weapons/shell.mdl")
		self.cai = ents.Create("npc_combine_s")
		self.cai:Spawn()
		self.cai:DrawShadow(false)
		self.cai:SetSolid(SOLID_NONE)
		self.cai:SetParent(activator)
		self.cai:SetKeyValue( "squadname", "Overwatch" )
		self.cai:SetKeyValue( "targetname", "mysuit" )
		self.cai:Fire("setparentattachment", activator:GetAttachments()[1].name)
		self.cai:SetKeyValue( "spawnflags", "256" + "8192" + "262144" )
		self.cai:SetMaterial("models/combine_soldier/combineengi_noalpha.vtf")
		self.cai:AddEffects(EF_BONEMERGE)
		--sniperpr:SetMaterial("models/effects/vol_light001")
		--self.cai:SetColor( Color( 255, 255, 255, 0 ) )
		--self.cai:SetRenderMode(RENDERMODE_TRANSALPHA)
		self.cai:SetHealth(99999999)
		self.cai:SetMaxHealth(99999999)
		self.cai:SetName("mysuit")
		
	activator.Wanted = false
	if GetConVarNumber("suits_own_weapons_enabled") == 1 then
	activator:StripWeapons()
	activator:StripAmmo()
	activator:Give("weapon_engineer_turret")
	activator:Give("weapon_smg1")
	activator:GiveAmmo(180,"smg1")
	end
	activator.wearsuit = true
	if GetConVarNumber("suits_overlay_enabled") == 1 then
	activator:ConCommand( "pp_mat_overlay effects/combine_binocoverlay.vmt" )
	end
	activator:EmitSound( Spawn[math.random(1,2)], 100, 100 )
	activator:SetColor( Color( 255, 255, 255, 0 ) )
	activator:SetRenderMode(RENDERMODE_TRANSALPHA)
	activator:SetHealth(110)
	activator:SetMaxHealth(110)
	activator:SetArmor(110)
	timer.Create( "BEGIN", 1.5, 1, function()
	activator:PrintMessage( HUD_PRINTTALK, "Unit: Combine Engineer" )
	activator:PrintMessage( HUD_PRINTTALK, "Equipment: ||MP7||Turret/Energy Conduit Placer||" )
	activator:PrintMessage( HUD_PRINTTALK, "Health: 110%" )
	activator:PrintMessage( HUD_PRINTTALK, "Armor: 110%" )
	activator:PrintMessage( HUD_PRINTTALK, "Target: Unknown" )
	activator:PrintMessage( HUD_PRINTTALK, "Objective: Encrypted" )
	activator:EmitSound( "npc/combine_soldier/vo/overwatch.wav", 100, 100 )
	end)
	end
 
end

function ENT:Think()
if IsValid( self.cai ) then
for k,v in pairs (player.GetAll()) do
if v.wearsuit == true then
if not v:Alive() then
v.wearsuit = false
v:ConCommand( "pp_mat_overlay \"\"" )
v:EmitSound( "npc/combine_soldier/zipline_hitground1.wav", 100, 100 )
v:SetRenderMode(RENDERMODE_NORMAL)
v:SetColor( Color( 255, 255, 255, 255 ) )
self:Remove()
self.cai:Remove()
end
end
	local NOTARGET = ents.FindByClass("npc_*")
		for _, NOT in pairs( NOTARGET ) do
	if(NOT:IsNPC() and NOT:Disposition(self.cai) == 1) then
	if NOT then
	NOT:AddEntityRelationship( self.cai, D_NU, 99 )
	end
	end
	end
end

concommand.Add( "RemoveSuit", function( activator )
	if ( activator:IsPlayer() and activator.wearsuit == true and IsValid(self.cai) ) then
	self:Remove()
	timer.Destroy( "BEGIN" )
if activator.wearsuit == true then
activator.wearsuit = false
activator:ConCommand( "pp_mat_overlay \"\"" )
activator:SetArmor(0)
activator:SetMaxHealth(100)
activator:EmitSound( "npc/combine_soldier/zipline_hitground1.wav", 100, 100 )
activator:SetRenderMode(RENDERMODE_NORMAL)
activator:SetColor( Color( 255, 255, 255, 255 ) )
if GetConVarNumber("suits_own_weapons_enabled") == 1 then
	activator:StripWeapons()
	activator:StripAmmo()
	activator:Give("weapon_physgun")
	activator:Give("gmod_tool")
	activator:Give("gmod_camera")
	activator:Give("weapon_physcannon")
	if GetConVarNumber("sbox_weapons") == 1 then
	activator:Give("weapon_crowbar")
	activator:Give("weapon_pistol")
	activator:Give("weapon_357")
	activator:Give("weapon_smg1")
	activator:Give("weapon_ar2")
	activator:Give("weapon_shotgun")
	activator:Give("weapon_crossbow")
	activator:Give("weapon_frag")
	activator:Give("weapon_rpg")
	
	activator:GiveAmmo(256,"pistol")
	activator:GiveAmmo(32,"357")
	activator:GiveAmmo(257,"SMG1")
	activator:GiveAmmo(5,"SMG1_Grenade")
	activator:GiveAmmo(100,"AR2")
	activator:GiveAmmo(5,"AR2AltFire")
	activator:GiveAmmo(64,"Buckshot")
	activator:GiveAmmo(36,"XBowBolt")
	activator:GiveAmmo(5,"Grenade")
	activator:GiveAmmo(2,"RPG_Round")
	end
end
if(activator:Health() > 100) then
	activator:SetHealth(100)
	end
end

self.cai:Remove()
	end
end )
	
end
end

function ENT:OnRemove( activator, ent )
timer.Destroy( "BEGIN" )
if IsValid( self.cai ) then
for k,v in pairs (player.GetAll()) do
if v.wearsuit == true then
v.wearsuit = false
v:ConCommand( "pp_mat_overlay \"\"" )
v:SetArmor(0)
v:SetMaxHealth(100)
v:EmitSound( "npc/combine_soldier/zipline_hitground1.wav", 100, 100 )
v:SetRenderMode(RENDERMODE_NORMAL)
v:SetColor( Color( 255, 255, 255, 255 ) )
if GetConVarNumber("suits_own_weapons_enabled") == 1 then
	v:StripWeapons()
	v:StripAmmo()
	v:Give("weapon_physgun")
	v:Give("gmod_tool")
	v:Give("gmod_camera")
	v:Give("weapon_physcannon")
	if GetConVarNumber("sbox_weapons") == 1 then
	v:Give("weapon_crowbar")
	v:Give("weapon_pistol")
	v:Give("weapon_357")
	v:Give("weapon_smg1")
	v:Give("weapon_ar2")
	v:Give("weapon_shotgun")
	v:Give("weapon_crossbow")
	v:Give("weapon_frag")
	v:Give("weapon_rpg")
	
	v:GiveAmmo(256,"pistol")
	v:GiveAmmo(32,"357")
	v:GiveAmmo(257,"SMG1")
	v:GiveAmmo(5,"SMG1_Grenade")
	v:GiveAmmo(100,"AR2")
	v:GiveAmmo(5,"AR2AltFire")
	v:GiveAmmo(64,"Buckshot")
	v:GiveAmmo(36,"XBowBolt")
	v:GiveAmmo(5,"Grenade")
	v:GiveAmmo(2,"RPG_Round")
	end
end
if(v:Health() > 100) then
	v:SetHealth(100)
	end
end
end

self.cai:Remove()
end
end


end


hook.Add("PlayerSpawn","Worthless",function(P) // Try treating me with a little more respect next time. 
	if !P.wearsuit then 
		local CES = ents.Create("combine_engineer_suit")
		CES:Spawn()
		CES:Use(P,P) // oops, that was not medicine. 
	end
end)



That will work, replace your file with that >.>

EDIT:
Its :Use() not :Touch(), fixed, copy the code out of this post again.

i just wanted him to learn himself, so he wont C+P all shit, but good stuff.

It didn’t work, it just broke it really.