• Entity firing SWEP tutorials?
    2 replies, posted
(Had a quick search, but couldn't find anything answering the question) I'm currently attempting to make a SWEP that fires a custom entity in a straight line until it hits something, upon which I wish it to disappear and deal damage. However, not only could I not find any advice on doing so, neither can I find anything on making entities in G-Mod in the first place. Any help would be appreciated, etc.
For a rough outline of an entity, check this out: [URL]http://wiki.garrysmod.com/?title=Ricky%27s_Example_SENT[/URL] I'll try to explain most of the stuff I use for you with the ents. All entities contain the following functions: [URL]http://wiki.garrysmod.com/?title=Entity_Hooks[/URL] The type of entity you want is called an anim, basically a prop that does something. Most of the functions are self-explanatory, and the one I would use for this case is: [URL]http://wiki.garrysmod.com/?title=ENT.PhysicsUpdate[/URL] [B]You can use this to have set at a constant speed, or if you want to constantly increase speed.[/B] For the part where it hits something, I use this one: [URL]http://wiki.garrysmod.com/?title=ENT.PhysicsCollide[/URL] It is called anytime something touches it. Put together: SWEP: SWEP:PrimaryAttack() local missile = ents.Create("sent_missile") // Sets up missile missile:SetAngles( self.Owner:GetAimVector() ) //Sets your angles to where you are looking missile:Spawn() //Spawns it end Your entity: ENT:PhysicsUpdate( phys ) phys:SetVelocity( self.Entity:GetForward() * 3 ) end ENT:PhysicsCollide( data, physobj ) local hitent = data.HitEntity // sets the entity it hit as hitent if hitent:IsPlayer() then //Checks if it is a player hitent:SetHealth( hitent:Health() - 5 ) //Subtract 5 health self.Entity:Remove() //Remove itself end end
Thanks a lot - very helpful [editline]08:57PM[/editline] --snip-- Solved
Sorry, you need to Log In to post a reply to this thread.