When I use ply:TakeDamage I get an error saying I couldnt use ply. Does anyone know if I am suppose to use ply in a function or if I can use it just like that. I am trying to make an explosion so it doesnt damage the maker of the explosion.
Make sure ply is defined.
I get the same error if I use player:TakeDamage too
Make sure player is defined; regardless of the variable name, it needs to be set.
Here’s an example using TakeDamageInfo: https://dl.dropboxusercontent.com/u/26074909/tutoring/takedamageinfo_example.lua.html
So, it creates a function in the player meta-table called Bleed. Now, all the way at the bottom of the file, see EntityTakeDamage? So, when an entity takes damage, that code is executed. It passes in the victim of the damage and the damage-info.
We’re interested in _victim. _victim is “player” or “ply” or “_p” or “Player” or whatever the variable name is defined as. Of course, in the example it is _victim.
_victim:Bleed( 3, 1, 20, _dmgInfo:GetInflictor( ), _dmgInfo:GetAttacker( ) );
So, _victim is an entity, more specifically it is a player entity. When we added a function to the player meta-table, it allows us to call the function we added ( bleed ) on any player entity. Just like Player:TakeDamage( blah ) is a function within the player meta-table, Bleed is too.
When you call a function from a parent, the parent must be set. If you are just using random variable names it doesn’t help us.
If you’re doing it inside of a SWEP, player would be self.Owner
If you show us code, we can be more specific.
Basically all I am doing is making a explosion when I use the swep. I want to set the explosion to damage anyone and kill them if caught in the explosion except the one who made the explosion. I have been at this for many days and I still havent gotten it.
Here is the code I have ended up at.
Like I said I have been at this for days and even after reading through your post I still dont understand how I am suppose to set this up. I tried to add the local META_PLAYER = (“Player”) but that didn’t work. I do realize I probably have to make a function like the first function in the lua script you posted. I am just unsure of how I would make it.
It almost appears as though it is inside a swep; the variables are almost all correct except Player should be self.Owner ( where you have if self.Owner then Player… ) else whatever…
If it is inside a swep, self isn’t set unless the function is SWEP:Damagethem( )… But, do you want to hurt the person using the weapon?
We need the context of where, when, how, etc… the function is called. If you wanted to make a helper function to “damage them” then you could add the player as a function argument to pass in…
Huh, that’s quite a complex script for what I’m assuming is going to be your first.
Let’s see if I can help you with this. I’m assuming in your SWEP:PrimaryFire you’re calling Damagethem(), so that’s okay. However, your Damagethem function isn’t getting what it needs to actually… work.
I’d recommend you look at the following functions:
ents.FindInSphere() – To find things hit by your “explosion”
GetEyeTrace() – Something to do with the vector origin of ents.FindInSphere. Use HitPos or whatever.
util.Effect() – To make your actual “explosion” effect. Once again, using the trace we found.
It looks like you have an okay understanding of how dmginfo works, so all you have to do is apply some of the functions I recommended and you should be able to get it <3.
People here won’t exactly write the code for you, but if you want you can add me on Steam and I might be able to give a little more in depth advice.