Fortress Forever

Go Back   Fortress Forever > Editing > Mapping

Reply
 
Thread Tools Display Modes
Old 09-22-2007, 02:24 PM   #1
A1win
Nutcracker
 
A1win's Avatar
 
Join Date: Sep 2007
Location: Kuopio, Finland
Posts Rated Helpful 0 Times
Send a message via MSN to A1win
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
There's one problem, though. When the player is killed by another player, this function is called with player_killed(Player, Damage). However, when the player is killed by something else, for example by typing "kill" in the console, this function is called with player_killed(Player, Player). Now Player is a base entity, but Damage is not. How can I end executing the script before I call the function "damage:GetAttacker()"? Because if "damage" is a player entity, it doesn't have GetAttacker() function and produces an error (it still works but meh). I tried IsPlayer(damage) but IsPlayer() only accepts base entities as its parameters, and Damage is not a base entity.

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.
A1win is offline   Reply With Quote


Old 09-26-2007, 09:15 AM   #2
Pon
Not choking. Yet.
Lua Team
Wiki Team
Fortress Forever Staff
 
Pon's Avatar
 
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).
Pon is offline   Reply With Quote


Old 09-26-2007, 09:27 AM   #3
A1win
Nutcracker
 
A1win's Avatar
 
Join Date: Sep 2007
Location: Kuopio, Finland
Posts Rated Helpful 0 Times
Send a message via MSN to A1win
Quote:
Originally Posted by Pon
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).
Inflictor is the player who is taking the damage, which we already know.
A1win is offline   Reply With Quote


Old 09-26-2007, 09:35 AM   #4
Pon
Not choking. Yet.
Lua Team
Wiki Team
Fortress Forever Staff
 
Pon's Avatar
 
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.
Pon is offline   Reply With Quote


Old 09-26-2007, 10:08 AM   #5
A1win
Nutcracker
 
A1win's Avatar
 
Join Date: Sep 2007
Location: Kuopio, Finland
Posts Rated Helpful 0 Times
Send a message via MSN to A1win
Quote:
Originally Posted by Pon
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
GetAttacker() does work for getting the attacker. It's just that the script returns an error if the attacker wasn't a player.
A1win is offline   Reply With Quote


Old 09-26-2007, 10:21 AM   #6
Pon
Not choking. Yet.
Lua Team
Wiki Team
Fortress Forever Staff
 
Pon's Avatar
 
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
Pon is offline   Reply With Quote


Old 09-26-2007, 02:46 PM   #7
Mulchman MM
Retired FF Staff
 
Mulchman MM's Avatar
 
Join Date: Dec 2004
Location: Lacey, WA
Posts Rated Helpful 0 Times
Send a message via ICQ to Mulchman MM Send a message via AIM to Mulchman MM Send a message via MSN to Mulchman MM Send a message via Yahoo to Mulchman MM Send a message via Skype™ to Mulchman MM
Inflictor should be the weapon causing the damage.
__________________
Head of the Orca Revolution (TM)
Mulchman MM is offline   Reply With Quote


Old 09-26-2007, 05:39 PM   #8
[P]Infidel
 
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
This checks the damage object to see if it has a method GetAttacker first. If it does then you can continue processing as you were, and if it doesn't then you don't give a shit right?

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.
[P]Infidel is offline   Reply With Quote


Old 09-26-2007, 05:54 PM   #9
A1win
Nutcracker
 
A1win's Avatar
 
Join Date: Sep 2007
Location: Kuopio, Finland
Posts Rated Helpful 0 Times
Send a message via MSN to A1win
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!
A1win is offline   Reply With Quote


Old 09-26-2007, 06:00 PM   #10
[P]Infidel
 
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.
[P]Infidel is offline   Reply With Quote


Old 09-27-2007, 03:52 AM   #11
Mulchman MM
Retired FF Staff
 
Mulchman MM's Avatar
 
Join Date: Dec 2004
Location: Lacey, WA
Posts Rated Helpful 0 Times
Send a message via ICQ to Mulchman MM Send a message via AIM to Mulchman MM Send a message via MSN to Mulchman MM Send a message via Yahoo to Mulchman MM Send a message via Skype™ to Mulchman MM
That's clever w/ the metatable.
__________________
Head of the Orca Revolution (TM)
Mulchman MM is offline   Reply With Quote


Old 09-28-2007, 01:52 PM   #12
Pon
Not choking. Yet.
Lua Team
Wiki Team
Fortress Forever Staff
 
Pon's Avatar
 
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!
Pon is offline   Reply With Quote


Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:37 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.