I have been trying to get a RPG Swep to display damage info for TTT. So it has valid damage and who the attacking player was instead of saying you were killed by the world. I have tried to get it working but I have had no success.
So I am posting here to see if anyone has some ideas for me to try.
Here's the the primary attack function.
[CODE]function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + 0.2 )
if not self:CanPrimaryAttack() then return end
if ( self.Owner:GetAmmoCount( "RPG_Round" ) < 0 ) then return end
self.Weapon:EmitSound("Weapon_RPG.Single")
self.Weapon:SetNextPrimaryFire(CurTime() + 1)
self.Weapon:SetNextSecondaryFire(CurTime() + 1)
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
--self:Remove();
self.Weapon:TakePrimaryAmmo(1)
if ( SERVER ) then
local grenade = ents.Create( "rpg_rocket" )
grenade:SetPos( self.Owner:GetShootPos() )
grenade:SetOwner( self.Owner )
grenade.FlyAngle = self.Owner:GetAimVector():Angle()
grenade:Spawn()
local phys = grenade:GetPhysicsObject()
if (phys:IsValid()) then
phys:SetVelocity( self.Owner:GetAimVector() * 3000 )
end
end
end[/CODE]
What is rpg_rocket? Post it's code here.
[code]
hook.Add("PlayerDeath", "ProperKil", function( victim, entity )
if entity:GetClass() == "rpg_rocket" then
print( victim:Name() .. " was killed by " .. entity:GetOwner():Name() ) // Example of getting owner, change this to add the death notification.
end
end)
[/code]
maybe this?
[QUOTE=G4MB!T;45551832]What is rpg_rocket? Post it's code here.[/QUOTE]
It's the RPG from Half Life. And part of the base files included in Garry's mod including the view models and the RPG head.
[url]https://developer.valvesoftware.com/wiki/Weapon_rpg[/url]
[editline]31st July 2014[/editline]
[QUOTE=AnonTakesOver;45551854][code]
hook.Add("PlayerDeath", "ProperKil", function( victim, entity )
if entity:GetClass() == "rpg_rocket" then
print( victim:Name() .. " was killed by " .. entity:GetOwner():Name() ) // Example of getting owner, change this to add the death notification.
end
end)
[/code]
maybe this?[/QUOTE]
I just tried this but no luck. It registers as the world killing the player.
[QUOTE=King Traitor;45552003]It's the RPG from Half Life. And part of the base files included in Garry's mod including the view models and the RPG head.
[url]https://developer.valvesoftware.com/wiki/Weapon_rpg[/url]
[editline]31st July 2014[/editline]
I just tried this but no luck. It registers as the world killing the player.[/QUOTE]
Did you change the code or leave it? Obviously it will still register if you left it, that just shows how you can get the killer, just change it so it shows the player killing, not sure how you're handling death notifications.
I left your code as is without changing anything, I then aimed at the ground and killed myself with the RPG.
I usually use this code on my server.
[CODE]hook.Add("PlayerDeath", "TTT_PlayerDeath_SayRole", function(victim, weapon, killer)
if gmod.GetGamemode().Name == "Trouble in Terrorist Town" then
if killer:IsPlayer() then
victim:ChatPrint("You were killed by "..killer:GetName()..", he was "..string.Capitalize(killer:GetRoleString())..".")
elseif killer == victim then
victim:ChatPrint("You just killed yourself...")
else
victim:ChatPrint("You were killed by the world.")
end
end
end)
[/CODE]
It's almost like the the RPG's entity explosion does not accept the owner so it defaults to world. It also appears as a world kill in the damage logs.
[code]
hook.Add("PlayerDeath", "ProperKil", function( victim, entity )
if entity:GetClass() == "rpg_rocket" then
victim:ChatPrint("You were killed by " .. entity:GetOwner():Name() )
return
end
end)
[/code]
[QUOTE=AnonTakesOver;45552112][code]
hook.Add("PlayerDeath", "ProperKil", function( victim, entity )
if entity:GetClass() == "rpg_rocket" then
victim:ChatPrint("You were killed by " .. entity:GetOwner():Name() )
return
end
end)
[/code][/QUOTE]
Tried it and it did not work.
I solved it today after messing around with it for an hour.
[CODE]local explosion = ents.Create( "env_explosion" ) explosion:SetPos(trace.HitPos) explosion:SetKeyValue( "iMagnitude" , "80" ) explosion:SetPhysicsAttacker(owner) explosion:SetOwner(owner) explosion:Spawn() explosion:Fire("explode","",0) explosion:Fire("kill","",0 )[/CODE]
Sorry, you need to Log In to post a reply to this thread.