Ok, so I had found this before, but I did not have my server running at the time. I know it is a relatively easy command, but I do not know where to put it or what to put. I want the smg grenade to respawn for hunters if they get a kill with it.
So on PlayerDeath hook, check the inflictor to see if it's the grenade, and the attacker is on the hunter team, you may also want to check that the victim isn't a hunter ( unless you don't allow tk ).
If those are true, then respawn the entity where-ever it is you respawn it.
When you add a hook, use return SPARINGLY. Only use it when you don't want the main function to run. So design the logic around executing only for your case.
[lua]hook.Add( "PlayerDeath", "", function( _victim, _inflictor, _attacker )
// All of the logic can be done on one line, for a massive if, but to make it easier to understand I did it this way
// If the victim, inflictor ( weapon used ) and attacker are all valid
if ( IsValid( _victim ) && IsValid( _inflictor ) && IsValid( _attacker ) ) then
// Lets make sure victim and attacker are players; and they're not on the same team
if ( _victim:IsPlayer( ) && _attacker:IsPlayer( ) && _victim:Team( ) != _attacker:Team( ) ) then
// Ok, they're valid, they're players, they're on different teams. Above, you could add the if for the proper team, so && _attacker:Team( ) == TEAM_HUNTER or whatever the team value is.
// Lets check the weapon used:
if ( _inflictor:GetClass( ) == "weapon_grenade" ) then
// It's weapon_grenade, awesome, now it's your turn to respawn it...
// ...
end
end
end
end );[/lua]
Ok, so I just wanted to make sure this was right. I went to game modes, player class, class_props and found the if command for when the player is killed.
[CODE]// Called when a player dies with this class
function CLASS:OnDeath(pl, attacker, dmginfo)
pl:RemoveProp()
end[/CODE]
Is this where I would put it? Like this? (I tried to follow the instructions)
[CODE]// Called when a player dies with this class
function CLASS:OnDeath(pl, attacker, dmginfo)
pl:RemoveProp()
hook.Add( "PlayerDeath", "", function( _victim, _inflictor, _attacker )
if ( IsValid( _victim ) && IsValid( _inflictor ) && IsValid( _attacker ) ) then
if ( _victim:IsPlayer( ) && _attacker:IsPlayer( ) && TEAM_PROPS != TEAM_HUNTER ) then
if ( _inflictor:GetClass( ) == "SMG1_Grenade" ) then
pl:GiveAmmo(1, "SMG1_Grenade")
end
end
end
end
end[/CODE]
There is no team killing allowed btw. Sorry if this seems a bother, just starting to really get into LUA coding.
I'm not sure what RemoveProp does... If you mean Remove( ), never call Remove on the player as it'll mess them up and they'll have to either rejoin, or restart gmod if they can't get to the menu.
What is TEAM_PROPS != TEAM_HUNTER about? That'll always return true if they're both a team because they won't be the same unless you set the reference to both of them to the same thing.
_attacker:Team( ) == TEAM_HUNTER would be what you're looking for.
Also, OnDeath? That's called differently that the hook. If you use that then you'd have to code it like this:
[lua]// Called when a player dies with this class
function CLASS:OnDeath( _p, _attacker, _dmginfo )
local _inflictor = _dmginfo:GetInflictor( );
if ( IsValid( _p ) && IsValid( _inflictor ) && IsValid( _attacker ) ) then
if ( _attacker:IsPlayer( ) && _attacker:Team( ) == TEAM_HUNTER ) then
if ( string.lower( _inflictor:GetClass( ) ) == "smg1_grenade" ) then
_attacker:GiveAmmo( 1, "SMG1_Grenade" );
end
end
end
end[/lua]
CHANGES:
So, _victim becomes pl, or _p in my case, if this is the player class, then we can skip _p:IsPlayer( ) but we will make sure they're valid. We have to GetInflictor from the damage info. We don't give the dying player the item, we give it to the attacker. It's good to set all string comparisons strings to lowercase; Linux doesn't like different cases, and if it's not properly typed the function won't work properly.
That should be it really... Test it out.
Don't add a hook inside of a function unless you're trying to limit use of that hook. Here's an example of doing just that, this will make a vgui element display for a short time after the player connects: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/display_something_on_initial_spawn.lua.html[/url]
So when the player connects, the server sends a message to the client. The client receives the message and adds HUDPaint hook; if a time is not set, it's set so it can last for x period of time. After x period of time has passed, the HUDPaint is hook.Remove'd.
Ok, so first thing: RemoveProp makes it so that when the player dies, their body and the prop disappear. If deleted, they player ragdolls, and the prop just stays there. For instance, I killed myself as the basic kleiner pose, and my body fell out of him, and he continued to stand there. As for the code you gave me, I don't think I am putting it in the right place.
Sorry, you need to Log In to post a reply to this thread.