1. Post #1
    lolfish's Avatar
    February 2009
    27 Posts
    Hi im a litle noob at lua. i just wonder how i can create a sofa which explosing when a player geting near it :D hehe maby little wierd but i just want to try :D plz help :>
    Reply With Quote Edit / Delete Reply Sweden Show Events Dumb Dumb x 3Bad Spelling Bad Spelling x 2Optimistic Optimistic x 1 (list)

  2. Post #2
    Gold Member
    conman420's Avatar
    January 2007
    1,795 Posts
    How does one explose?
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Agree Agree x 7Funny Funny x 6Bad Spelling Bad Spelling x 1 (list)

  3. Post #3
    Gold Member
    Nick99's Avatar
    September 2005
    1,681 Posts
    Do you want it to explode when a player is within a certain proximity(say 200 units) or when it is touched?

    How does one explose?
    His first language might not be english.
    Reply With Quote Edit / Delete Reply Canada Show Events Friendly Friendly x 7Agree Agree x 2Informative Informative x 1Dumb Dumb x 1 (list)

  4. Post #4
    XHeadHunterX's Avatar
    January 2008
    4 Posts
    I could bet he's french, I'm saying this because it is my first language and "exploser" means "to explode".

    It shouldn't be a big deal, just use ents.Create( "env_explosion" ) when the player is at X,Y of the prop.
    Reply With Quote Edit / Delete Reply Canada Show Events Agree Agree x 2 (list)

  5. Post #5

    March 2008
    9 Posts
    function ENT:Think()
    	for id,pl(in pairs(player.GetAll())do
    		if( pl:GetPos():Distance(self:GetPos()) < 400 )then
    			
    			--EXPLODING COAD HERE
    			
    			self:Remove()
    			break;
    		end
    	end
    end
    ur welcome
    Reply With Quote Edit / Delete Reply United States Show Events Dumb Dumb x 2Bad Spelling Bad Spelling x 1 (list)

  6. Post #6
    victi's Avatar
    December 2008
    144 Posts
    Is fucking Easy
    Code:
    AddCSLuaFile( "cl_init.lua" )
    AddCSLuaFile( "shared.lua" )
     
    include('shared.lua')
     
    ENT.LASTINGEFFECT = 45;
     
    function ENT:SpawnFunction(ply, tr)
    if (!tr.Hit) then return end
    local ent = ents.Create("exploding_sofa") // Fucking important change it to you folder name!!!
    ent:SetPos(tr.HitPos + Vector(0,0,15))
    ent:Spawn()
    ent:Activate()
    ent:SetName("exploding sofa")
    return ent
    end
     
    function ENT:OnRemove()
    end
     
    function ENT:Initialize()
    self.Entity:SetModel("models/props_junk/watermelon01.mdl")
    self.Entity:PhysicsInit(SOLID_VPHYSICS)
    self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
    self.Entity:SetSolid(SOLID_VPHYSICS)
    self.Entity:SetCollisionGroup( COLLISION_GROUP_PLAYER )
    local phys = self.Entity:GetPhysicsObject()
    if (phys:IsValid()) then        
    phys:Wake()     
    phys:SetMass(1)
       end
    end
     
    function ENT:Explode()
    
     	local explode = ents.Create( "env_explosion" )	
    	explode:SetPos( self.Entity:GetPos() ) 	
    	explode:Spawn() 	
    	explode:SetKeyValue( "iMagnitude", "220" ) 	
    	explode:Fire( "Explode", 0, 0 )  	
    	explode:EmitSound( "weapon_AWP.Single", 400, 400 )
    		
    	self.Entity:Remove()
    
    end
     
    function ENT:StartTouch()
    	self.Entity:Explode()
    end
     
    function ENT:OnRemove()
    end
     
    function ENT:Use()
    end
    
    function ENT:Use()
    end
    If you don't change it to folder name then it don't work!!!!

    CL_INIT!
    Code:
    include('shared.lua')
    SHARED!!!
    Code:
    ENT.Base = "base_anim"
    ENT.Type = "anim"
    ENT.Category 			= "Exploding things!"
    ENT.PrintName			= "Exploding Sofa"
    ENT.Author			= "Victi" // Change to you name :D
    ENT.Contact			= "Fuck OFF"
    ENT.Purpose			= "Helping Lolfish"
    ENT.Instructions		= ""
    ENT.Spawnable			= true
    ENT.AdminSpawnable		= true
    here is You Sofa it Will Work (Work Fine For me :D)

    Remenber to change model
    And the IMPORTANT!!!

    You Folders Name!!!
    Code:
    local ent = ents.Create("exploding_sofa") // Fucking important change it to you folder name!!!
    That!!

    There Have you the Exploding Sofa :D
    Reply With Quote Edit / Delete Reply Denmark Show Events Agree Agree x 2 (list)

  7. Post #7
    open.gl
    Overv's Avatar
    February 2007
    7,431 Posts
    Your coding style seriously makes me cry. BRB Lemme write better code.
    Reply With Quote Edit / Delete Reply Netherlands Show Events Agree Agree x 4Friendly Friendly x 2Funny Funny x 1 (list)

  8. Post #8
    victi's Avatar
    December 2008
    144 Posts
    Your coding style seriously makes me cry. BRB Lemme write better code.
    !-.-! Thx For That

    !That is my coding style have you a problem!
    Reply With Quote Edit / Delete Reply Denmark Show Events Funny x 3Dumb x 3Bad Reading x 1Agree x 1Bad Spelling x 1 (list)

  9. Post #9
    open.gl
    Overv's Avatar
    February 2007
    7,431 Posts
    Create a folder 'Exploding Sofa' in addons and add an info.txt file, here's mine:

    Code:
    "AddonInfo"
    {
    	"name"		"Exploding Sofa"
    	"version"	"1.0"
    	"author_name"	"Overv"
    	"author_url"	"http://www.overvprojects.nl"
    	"info"		"An exploding sofa"
    }
    Now, create a folder 'lua' and in that folder a folder 'entities' and in that folder a folder 'exploding_sofa'. Now create the following files in that folder and you're done:

    shared.lua
    ENT.Base = 			"base_anim"
    ENT.Type = 			"anim"
    ENT.Category = 		"Explosive SENTS"
    ENT.PrintName = 		"Exploding Sofa"
    ENT.Author = 		"Overv"
    ENT.Contact = 		"overv161@gmail.com"
    ENT.Purpose = 		"A sofa that explodes when a player gets within a certain range"
    ENT.Instructions =	"Just put it somewhere and it'll work."
    ENT.Spawnable =		true
    ENT.AdminSpawnable =	true

    cl_init.lua
    include( "shared.lua" )

    init.lua
    //Distribute files to clients
    AddCSLuaFile( "cl_init.lua" )
    AddCSLuaFile( "shared.lua" )
    
    //Include shared entity information
    include( "shared.lua" )
    
    //Constants
    EXPLODE_DISTANCE = 256 //Maximum safe distance before it explodes
    
    function ENT:SpawnFunction( ply, tr )
    	if !tr.Hit then return  end
    	
    	//Create the entity
    	local sofa = ents.Create( "exploding_sofa" )
    	sofa:SetPos( tr.HitPos + Vector(0, 0, 15) )
    	sofa:Spawn()
    	sofa:Activate()
    	sofa:SetName( "Exploding Sofa" )
    	sofa:SetOwner( ply ) //Add the owner so it doesn't explode when the owner is near
    	
    	//Also add it to the client's undo list
    	undo.Create( "prop" )
    		undo.AddEntity( sofa )
    		undo.SetPlayer( ply )
    	undo.Finish()
    	
    	return ent
    end
    
    function ENT:Initialize()
    	//Setting up the entity model and physics settings
    	local sofa = self.Entity
    	sofa:SetModel( "models/props_c17/FurnitureCouch001a.mdl" )
    	sofa:PhysicsInit( SOLID_VPHYSICS )
    	sofa:SetMoveType( MOVETYPE_VPHYSICS )
    	sofa:SetCollisionGroup( COLLISION_GROUP_PLAYER )
    end
    
    function ENT:Think()
    	for _, ply in pairs(player.GetAll()) do
    		if ply:GetPos():Distance( self.Entity:GetPos() ) < EXPLODE_DISTANCE and ply != self.Entity:GetOwner() then
    			self.Entity:Explode()
    		end
    	end
    end
    
    function ENT:Explode()
    	//Create the explosion
    	local explosion = ents.Create( "env_explosion" )
    	explosion:SetPos( self.Entity:GetPos() )
    	explosion:Spawn()
    	explosion:SetKeyValue( "iMagnitude", 220 )
    	explosion:Fire( "Explode", 0, 0 )
    	
    	//Remove the entity
    	self.Entity:Remove()
    end

    The sofa will explode when a player other than the owner gets within EXPLODE_DISTANCE of the sofa. The creator can undo it with 'z' like always.

    Hope I've helped you out
    Reply With Quote Edit / Delete Reply Netherlands Show Events Friendly Friendly x 2 (list)

  10. Post #10
    victi's Avatar
    December 2008
    144 Posts
    Maybe You Have a Better Scripting Style But

    The 2 Codes Works
    Reply With Quote Edit / Delete Reply Denmark Show Events Bad Spelling Bad Spelling x 5 (list)

  11. Post #11
    lolfish's Avatar
    February 2009
    27 Posts
    Thanks ;D im srry for my bad english only so u know im from sweden xD Thanks a lot ;D wee :)
    Reply With Quote Edit / Delete Reply Sweden Show Events Bad Spelling Bad Spelling x 2 (list)

  12. Post #12
    lolfish's Avatar
    February 2009
    27 Posts
    :D
    Reply With Quote Edit / Delete Reply Sweden Show Events Dumb Dumb x 3Funny Funny x 1 (list)

  13. Post #13
    victi's Avatar
    December 2008
    144 Posts
    But Lolfish Learn Lua You can't get the people to make the things for you
    www.garrysmod.com/wiki

    Learn there
    In the Start is a litle bit hard to understant but is easy when you now how :D

    I hope my code and this helped you
    Reply With Quote Edit / Delete Reply Denmark Show Events Dumb Dumb x 3Bad Spelling Bad Spelling x 2 (list)

  14. Post #14
    open.gl
    Overv's Avatar
    February 2007
    7,431 Posts
    Thanks ;D im srry for my bad english only so u know im from sweden xD Thanks a lot ;D wee :)
    I know someone from Sweden who's 13 years old and speaks perfect English so that's bullshit.

    @victi: Maybe we helped him a bit too much
    Reply With Quote Edit / Delete Reply Netherlands Show Events Dumb Dumb x 2Disagree Disagree x 2Informative Informative x 1Friendly Friendly x 1 (list)

  15. Post #15
    lolfish's Avatar
    February 2009
    27 Posts
    But Lolfish Learn Lua You can't get the people to make the things for you
    www.garrysmod.com/wiki

    Learn there
    In the Start is a litle bit hard to understant but is easy when you now how :D

    I hope my code and this helped you
    Yeah its helped a lot thanks ;D you are best :)
    Reply With Quote Edit / Delete Reply Sweden Show Events Bad Spelling Bad Spelling x 2Dumb Dumb x 1 (list)

  16. Post #16
    victi's Avatar
    December 2008
    144 Posts
    I know someone from Sweden who's 13 years old and speaks perfect English so that's bullshit.

    @victi: Maybe we helped him a bit too much
    Yea i think too

    He has learned nothing whe have maked it for him

    And if you need to get my code to work put the file on lua/entities

    I have don't maked it to a addon
    but you have a example from OverV

    But Good Luck Whit Learning Lua
    Reply With Quote Edit / Delete Reply Denmark Show Events Bad Spelling Bad Spelling x 5 (list)

  17. Post #17
    lolfish's Avatar
    February 2009
    27 Posts
    hwo can i test the lua :D? in gmod. hehe this is the first time i testing script in lua :) i downloaded notepad++ yesterday >.<
    Reply With Quote Edit / Delete Reply Sweden Show Events Bad Spelling Bad Spelling x 4 (list)

  18. Post #18
    victi's Avatar
    December 2008
    144 Posts
    Very Easy

    Go on you Pc things

    C/Programs/Steam/SteamApps/Username/Garrysmod/Garrysmod/lua

    In the Lua folder there is some other folder put the code there if it is a ent then on the folder entities

    Is there When i Test My Entities, Weapon, autorun What ever

    I not 100% on the file names i have a pc *Danish version* Im from denmark

    But If you are from sweden maybe you have the same names

    C/Programer/Steam/SteamApps/Garrysmod/Garrysmod/lua/

    I hope it helps
    Reply With Quote Edit / Delete Reply Denmark Show Events Bad Spelling Bad Spelling x 3Late Late x 1 (list)

  19. Post #19
    lolfish's Avatar
    February 2009
    27 Posts
    no i mean how i can test it in the game :D?
    Reply With Quote Edit / Delete Reply Sweden Show Events Bad Spelling Bad Spelling x 2Bad Reading Bad Reading x 1Useful Useful x 1 (list)

  20. Post #20
    victi's Avatar
    December 2008
    144 Posts
    play sanbox single/multi

    then if it work then you can spawn it
    or maybe it gives error

    i don't now what you mean 100%
    Reply With Quote Edit / Delete Reply Denmark Show Events Bad Spelling Bad Spelling x 3Late Late x 1 (list)

  21. Post #21
    lolfish's Avatar
    February 2009
    27 Posts
    play sanbox single/multi

    then if it work then you can spawn it
    or maybe it gives error

    i don't now what you mean 100%
    nope i cnat find it D: :(
    Reply With Quote Edit / Delete Reply Sweden Show Events Bad Spelling Bad Spelling x 2Dumb Dumb x 1Useful Useful x 1 (list)

  22. Post #22
    victi's Avatar
    December 2008
    144 Posts
    where put you the folder??
    Reply With Quote Edit / Delete Reply Denmark Show Events Bad Spelling Bad Spelling x 2Late Late x 1Artistic Artistic x 1 (list)

  23. Post #23
    lolfish's Avatar
    February 2009
    27 Posts
    where put you the folder??
    i followed overv instructions D: maby i did something wrong :(?
    Reply With Quote Edit / Delete Reply Sweden Show Events Bad Spelling Bad Spelling x 2Dumb Dumb x 1Useful Useful x 1 (list)

  24. Post #24
    victi's Avatar
    December 2008
    144 Posts
    Mnn try my code (Init, cl_init, shared)
    then put it on lua/entities

    also OverV's Code should work too but don't now how you do?
    also where you put it

    but follow that i say
    Reply With Quote Edit / Delete Reply Denmark Show Events Bad Spelling Bad Spelling x 2Artistic Artistic x 1 (list)

  25. Post #25

    April 2008
    16 Posts
    But Lolfish Learn Lua You can't get the people to make the things for you
    www.garrysmod.com/wiki

    Learn there
    In the Start is a litle bit hard to understant but is easy when you now how :D

    I hope my code and this helped you
    You ask for more help then anybody else on the forums....
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Funny Funny x 4Agree Agree x 1Late Late x 1 (list)

  26. Post #26
    LiamBrown's Avatar
    November 2008
    182 Posts
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Informative Informative x 2Late Late x 1 (list)

  27. Post #27
    lolfish's Avatar
    February 2009
    27 Posts
    You ask for more help then anybody else on the forums....
    yea im srry D: u guys dont need to answer if u want :(
    Reply With Quote Edit / Delete Reply Sweden Show Events Dumb Dumb x 2Bad Spelling Bad Spelling x 1Friendly Friendly x 1Artistic Artistic x 1 (list)

  28. Post #28
    victi's Avatar
    December 2008
    144 Posts
    You ask for more help then anybody else on the forums....

    I don't care if he don't ask about that on the threat i help him anyway
    Reply With Quote Edit / Delete Reply Denmark Show Events Bad Spelling Bad Spelling x 3 (list)

  29. Post #29
    lolfish's Avatar
    February 2009
    27 Posts
    I don't care if he don't ask about that on the threat i help him anyway
    :D
    Reply With Quote Edit / Delete Reply Sweden Show Events Bad Spelling Bad Spelling x 2Artistic Artistic x 1Dumb Dumb x 1 (list)

  30. Post #30

    April 2008
    16 Posts
    yea im srry D: u guys dont need to answer if u want :(
    I was talking to victi
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Funny Funny x 2Useful Useful x 1Late Late x 1 (list)

  31. Post #31
    victi's Avatar
    December 2008
    144 Posts
    You ask for more help then anybody else on the forums....
    yea :/

    I have many gamemodes projects in my head then sometimes i don't now what is wrong :D
    and some goes deaht

    then i don't think this
    You ask for more help then anybody else on the forums....
    then i now some threat i have started whas a little idiots Threat's it whas easy things :/

    But lolfish Work It?
    Reply With Quote Edit / Delete Reply Denmark Show Events Bad Spelling Bad Spelling x 3Late Late x 1 (list)

  32. Post #32
    lolfish's Avatar
    February 2009
    27 Posts
    Yaaaaaaaay its working now yippy :D
    Reply With Quote Edit / Delete Reply Sweden Show Events Dumb Dumb x 2Bad Spelling Bad Spelling x 1Artistic Artistic x 1 (list)

  33. Post #33
    lolfish's Avatar
    February 2009
    27 Posts
    its just one problem. Its exploding when it touches another prop or vehicle. D: plz help ;D
    Reply With Quote Edit / Delete Reply Sweden Show Events Bad Spelling Bad Spelling x 2Artistic Artistic x 1Dumb Dumb x 1 (list)

  34. Post #34
    victi's Avatar
    December 2008
    144 Posts
    Code:
    function ENT:StartTouch()
    local Player = LocalPlayer()
    if ( ent:GetClass() == "Player"  then	
    	self.Entity:Explode()
    end
    Change Ent:StarTouch for this :D

    I think is like this
    [not tested]
    Reply With Quote Edit / Delete Reply Denmark Show Events Bad Spelling Bad Spelling x 2Disagree Disagree x 1 (list)

  35. Post #35
    lolfish's Avatar
    February 2009
    27 Posts
    Code:
    function ENT:StartTouch()
    local Player = LocalPlayer()
    if ( ent:GetClass() == "Player"  then	
    	self.Entity:Explode()
    end
    Change Ent:StarTouch for this :D

    I think is like this
    [not tested]
    :) thx
    Reply With Quote Edit / Delete Reply Sweden Show Events Bad Reading Bad Reading x 2Artistic Artistic x 1Bad Spelling Bad Spelling x 1 (list)

  36. Post #36
    lolfish's Avatar
    February 2009
    27 Posts
    it did't work D:
    Reply With Quote Edit / Delete Reply Sweden Show Events Bad Reading Bad Reading x 1Bad Spelling Bad Spelling x 1Friendly Friendly x 1Dumb Dumb x 1 (list)

  37. Post #37
    open.gl
    Overv's Avatar
    February 2007
    7,431 Posts
    Use my code, it explodes when a player other than the spawner/owner gets near like you wanted in the OP.
    Reply With Quote Edit / Delete Reply Netherlands Show Events Useful Useful x 2Agree Agree x 1 (list)

  38. Post #38
    lolfish's Avatar
    February 2009
    27 Posts
    ok
    Reply With Quote Edit / Delete Reply Sweden Show Events Dumb Dumb x 2Bad Spelling Bad Spelling x 1 (list)

  39. Post #39
    Coolman12's Avatar
    April 2007
    189 Posts
    I know someone from Sweden who's 13 years old and speaks perfect English so that's bullshit.

    @victi: Maybe we helped him a bit too much
    im sweden and i spek perfekt english.
    Reply With Quote Edit / Delete Reply Sweden Show Events Bad Spelling x 6Funny x 6Dumb x 3Disagree x 1Friendly x 1 (list)

  40. Post #40
    lolfish's Avatar
    February 2009
    27 Posts
    but u said im sweden. Thats not right its: Im swedish and i speak perfect english. Haha lol :)
    Reply With Quote Edit / Delete Reply Sweden Show Events Dumb x 3Disagree x 3Bad Spelling x 3Funny x 2Agree x 1 (list)