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 :>
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 :>
How does one explose?
Do you want it to explode when a player is within a certain proximity(say 200 units) or when it is touched?
His first language might not be english.
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.
ur welcomefunction 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
Is fucking Easy
If you don't change it to folder name then it don't work!!!!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
CL_INIT!
SHARED!!!Code:include('shared.lua')
here is You Sofa it Will Work (Work Fine For me :D)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
Remenber to change model
And the IMPORTANT!!!
You Folders Name!!!
That!!Code:local ent = ents.Create("exploding_sofa") // Fucking important change it to you folder name!!!
There Have you the Exploding Sofa :D
Your coding style seriously makes me cry. BRB Lemme write better code.
!-.-! Thx For That
!That is my coding style have you a problem!
Create a folder 'Exploding Sofa' in addons and add an info.txt file, here's mine:
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:Code:"AddonInfo" { "name" "Exploding Sofa" "version" "1.0" "author_name" "Overv" "author_url" "http://www.overvprojects.nl" "info" "An exploding sofa" }
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![]()
Maybe You Have a Better Scripting Style But
The 2 Codes Works
Thanks ;D im srry for my bad english only so u know im from sweden xD Thanks a lot ;D wee :)
:D
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
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![]()
Yeah its helped a lot thanks ;D you are best :)
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
hwo can i test the lua :D? in gmod. hehe this is the first time i testing script in lua :) i downloaded notepad++ yesterday >.<
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
no i mean how i can test it in the game :D?
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: :(
where put you the folder??
i followed overv instructions D: maby i did something wrong :(?
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
You ask for more help then anybody else on the forums....
http://wiki.garrysmod.com/wiki/?titl...s_Example_SENT follow that, it might help.
yea im srry D: u guys dont need to answer if u want :(
I don't care if he don't ask about that on the threat i help him anyway
I was talking to victi
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
then i now some threat i have started whas a little idiots Threat's it whas easy things :/
But lolfish Work It?
Yaaaaaaaay its working now yippy :D
its just one problem. Its exploding when it touches another prop or vehicle. D: plz help ;D
Change Ent:StarTouch for this :DCode:function ENT:StartTouch() local Player = LocalPlayer() if ( ent:GetClass() == "Player" then self.Entity:Explode() end
I think is like this
[not tested]
:) thx
it did't work D:
Use my code, it explodes when a player other than the spawner/owner gets near like you wanted in the OP.
ok
im sweden and i spek perfekt english.![]()
but u said im sweden. Thats not right its: Im swedish and i speak perfect english. Haha lol :)