09-22-2007, 02:24 PM | #1 |
Nutcracker
|
Getting attacker on player_killed
Here's what I have so far and it works, too:
Code:
function player_killed( player_entity, damage ) local victim = CastToPlayer( player_entity ) local flag = GetInfoScriptByName( "flag" ) if ( victim:HasItem( "flag" ) ) then flag:Drop(-1, 0.0) -- If player is killed by something else than another player, this produces an error which ends this script. -- It works but should be checked here... how?? local killer = CastToPlayer( damage:GetAttacker() ) if not (victim:GetTeamId() == killer:GetTeamId()) then killer:AddFortPoints(100, "Killing the Flag Holder") -- Also adds the default 100 points for a frag so we get 200 points total end end end Is it possible to use exceptions? How do they work in lua? Also, any idea how to detect the killer if the player is killed by a sentry gun? Last edited by A1win; 09-22-2007 at 02:45 PM. |
|
09-26-2007, 09:15 AM | #2 |
Not choking. Yet.
Lua Team
Wiki Team Fortress Forever Staff Join Date: Jul 2007
Location: Scotland
Class/Position: Demo/Def - Spy/Off Gametype: Anything but yet more fucking CTF Affiliations: FF.AvD [FF AvD/ID guild] Posts Rated Helpful 0 Times
|
I'm trying to do a similar thing (minus the flag stuff), and having a similar problem.... So bump!
Though A1win, have you tried using damage:GetInflictor() instead of damage:GetAttacker()? I've just noticed it in the LUA commands topic and I'm gonna try it out myself (once I find someone to rope into testing with me). |
|
09-26-2007, 09:27 AM | #3 | |
Nutcracker
|
Quote:
|
|
|
09-26-2007, 09:35 AM | #4 |
Not choking. Yet.
Lua Team
Wiki Team Fortress Forever Staff Join Date: Jul 2007
Location: Scotland
Class/Position: Demo/Def - Spy/Off Gametype: Anything but yet more fucking CTF Affiliations: FF.AvD [FF AvD/ID guild] Posts Rated Helpful 0 Times
|
Surely it should be called GetInflicted() (or something else, seeing as the word Inflictor means "the person causing" not "the person affected") if that's the case then?
Bah, thought I might have had something there though Last edited by Pon; 09-26-2007 at 09:41 AM. |
|
09-26-2007, 10:08 AM | #5 | |
Nutcracker
|
Quote:
|
|
|
09-26-2007, 10:21 AM | #6 |
Not choking. Yet.
Lua Team
Wiki Team Fortress Forever Staff Join Date: Jul 2007
Location: Scotland
Class/Position: Demo/Def - Spy/Off Gametype: Anything but yet more fucking CTF Affiliations: FF.AvD [FF AvD/ID guild] Posts Rated Helpful 0 Times
|
Yeah, I know that, I just wondered that seeing as GetAttacker and GetInflictor sound like they have a very similar function (which logically they should, seeing as Attacker and Inflictor pretty much mean the same thing in the context of FF), I just wondered if GetInflictor would return something more useful in this situation...
Although, thinking about it a bit more, perhaps it's a typo/misprint/mistake? Maybe meant to be Infector? Anyways, I'll shut up now. I don't wanna take this post off topic too much as I'm interested in finding a solution to the problem too |
|
09-26-2007, 02:46 PM | #7 |
Retired FF Staff
|
Inflictor should be the weapon causing the damage.
__________________
Head of the Orca Revolution (TM) |
|
09-26-2007, 05:39 PM | #8 |
Join Date: Sep 2007
Posts Rated Helpful 0 Times
|
Use this as a check before calling damage:GetAttacker()
Code:
if (getmetatable(damage).__index(damage, "GetAttacker") ~= nil) then ... end edit: I would also do the usual IsPlayer check before CastToPlayer (after you know GetAttacker will work) because you don't know that it only returns player entities. |
|
09-26-2007, 05:54 PM | #9 |
Nutcracker
|
Thanks, although I don't need the function anymore as the feature would make the gameplay unbalanced
But I'll save it if I need it later! |
|
09-26-2007, 06:00 PM | #10 |
Join Date: Sep 2007
Posts Rated Helpful 0 Times
|
Yeah, if you ever are wanting to dig into damage and kills this issue will probably pop up.
|
|
09-27-2007, 03:52 AM | #11 |
Retired FF Staff
|
That's clever w/ the metatable.
__________________
Head of the Orca Revolution (TM) |
|
09-28-2007, 01:52 PM | #12 |
Not choking. Yet.
Lua Team
Wiki Team Fortress Forever Staff Join Date: Jul 2007
Location: Scotland
Class/Position: Demo/Def - Spy/Off Gametype: Anything but yet more fucking CTF Affiliations: FF.AvD [FF AvD/ID guild] Posts Rated Helpful 0 Times
|
That did the trick for me, though. Thanks Infidel!
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|