• Getting something to work on player spawn
    28 replies, posted
[B]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.[/B] [code] 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 [/code] [B][url]http://steamcommunity.com/profiles/76561198018489153/[/url] is the addon where the code comes from.[/B]
put the code in code/lua tags please, its unreadable
[QUOTE=whitestar;48410582]put the code in code/lua tags please, its unreadable[/QUOTE] How do I do that?
[QUOTE=tomswift;48410589]How do I do that?[/QUOTE] [LUA] code [backslashLUA]
[CODE]function placefunctionnamehere( ply ) stuffHere end hook.Add( "PlayerSpawn", "playerspawnhook", placefunctionnamehere) [/CODE] add what you want to call when player spawns at the function. a example, [CODE] function placefunctionnamehere( ply ) print("i just spawned!") end hook.Add( "PlayerSpawn", "playerspawnhook", placefunctionnamehere) [/CODE]
[QUOTE=DaRkWoRlD1337;48410600][CODE]function placefunctionnamehere( ply ) stuffHere end hook.Add( "PlayerSpawn", "playerspawnhook", placefunctionnamehere) [/CODE] add what you want to call when player spawns at the function. a example, [CODE] function placefunctionnamehere( ply ) print("i just spawned!") end hook.Add( "PlayerSpawn", "playerspawnhook", placefunctionnamehere) [/CODE][/QUOTE] Wat.
are you going to fully c+p? damn.
[QUOTE=DaRkWoRlD1337;48410622]are you going to fully c+p? damn.[/QUOTE] Well, I don't know how to code.
so all you want is when you spawn, suit applies?
[QUOTE=DaRkWoRlD1337;48410644]so all you want is when you spawn, suit applies?[/QUOTE] 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).
[QUOTE=Zet0r;48413034]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).[/QUOTE] 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.
[QUOTE=Zet0r;48415678]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.[/QUOTE] But what do you mean by everything inside ENT:Touch? Activator, ENT?
[QUOTE=tomswift;48416027]But what do you mean by everything inside ENT:Touch? Activator, ENT?[/QUOTE] No, the ENT:Touch function. Use CTRL + F
[QUOTE=code_gs;48416417]No, the ENT:Touch function. Use CTRL + F[/QUOTE] Yeah, but what does he mean by everything inside it?
[QUOTE=tomswift;48416470]Yeah, but what does he mean by everything inside it?[/QUOTE] some functions: [CODE] function setEntHealth(x, y) Entity(x):SetHealth(y) end function printSomething() print("hello world") end setEntHealth(1,25) printSomething() [/CODE] inside printSomething() function, there is print("hello world") inside healEnt() function, there is Entity(x):SetHealth(50) use your brain man.
[QUOTE=tomswift;48416470]Yeah, but what does he mean by everything inside it?[/QUOTE] [CODE]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) [/CODE] 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.
[QUOTE=tomswift;48416601]It didn't work, it just broke it really.[/QUOTE] Edited to use P:Use() instead of touch, see my previous post and copy the code again :V
can i get your steam, tomswift, or can you just add me? (the steam picture below my avatar)
It's uh, still broken.
Here just :s. Undo my changes, make a file in this location /garrysmod/lua/autorun/server/combinesuit.lua place this in it. [LUA] hook.Add("PlayerSpawn","Worthless",function(P) if !P.wearsuit then local CES = ents.Create("combine_engineer_suit") CES:Spawn() CES:Use(P,P,1,1) end end) [/LUA] Then save it. Apparently this addon force downloads from the workshop if it can.
Still not working. omg ;-; [editline]9th August 2015[/editline] I don't spawn with the new weapons and stuff, instead I just see the model of a combine soldier moderately far away to the right of where I spawn.
[QUOTE=tomswift;48416828]Still not working. omg ;-;[/QUOTE] The above method worked fine for me. I spawn with the requested suit.
[QUOTE=Freezebug;48416865]The above method worked fine for me. I spawn with the requested suit.[/QUOTE] The suit spawns away from where I spawn. Should I have undone all of the changes or kept the stuff from the first post you sent?
[QUOTE=tomswift;48416885]The suit spawns away from where I spawn. Should I have undone all of the changes or kept the stuff from the first post you sent?[/QUOTE] [QUOTE=Freezebug;48416772] Undo my changes [/QUOTE] I never thought for once in my life I'd actually discover rocket science
By [I]everything inside ENT:Touch()[/I] I mean everything between the line where the function is defined ("function ENT:Touch()") and the "end" that is bound to it. Whatever program you write the code in will likely highlight and connect the 'end's to whatever statement they end. (It is the end above 'function ENT:Think()')
Sorry, you need to Log In to post a reply to this thread.