Page 2 of 5

Posted: Mon Mar 15, 2004 12:57 am
by small_sumo
So can someone help me with the code?

Posted: Mon Mar 15, 2004 3:27 am
by dcoshea
Can anyone tell us how to find out who killed a player? You can obviously see it come up as text on your screen, but is there any way to determine it via script other than by using an external program? Perhaps by using a trigger_multiple that responds to bullets - I'm not sure what parm.other is for such a trigger when a bullet hits it, would it point to the Player object of the shooter?

Regards,
David

Posted: Mon Mar 15, 2004 4:41 am
by dcoshea
dcoshea wrote:Can anyone tell us how to find out who killed a player? You can obviously see it come up as text on your screen, but is there any way to determine it via script other than by using an external program? Perhaps by using a trigger_multiple that responds to bullets - I'm not sure what parm.other is for such a trigger when a bullet hits it, would it point to the Player object of the shooter?
I checked that out, and if I spawn a trigger around a player with 'spawnflags 128' ("damage"), parm.other is the Player object of the shooter (or basher) after a 'waittill trigger'. It seems that you can 'glue' a trigger_multiple to a Player, but not 'bind' it, which is fine. I think it would be pretty impossible to make the trigger_multiple exactly match the hitbox of the player since it isn't square, but that doesn't matter too much since you'd want to use 'isalive' to determine whether the player was killed anyway.

The flaw with this method is that if players A and B shoot at player Z, with player A shooting just before player B (like a fraction of a second) and player A's shot misses player Z and player B's shot kills them, you might process player A's shot, find that player Z is dead, and think that player A was the person who killed player Z. I guess it depends on the order in which the game processes events.

What I think would work is to have the trigger_multiple have a setthread to a thread which checks for the player 'isalive', and if they're not, goes ahead and does the kill cam stuff.

Note that every time a player fires, they'll trigger their own trigger_multiple since the bullets are leaving the general area of their body :) Those events will need to be filtered out. They could potentially cause high CPU load if lots of shots are being fired, I guess!

I'm not sure how player respawning will be handled - the trigger may still be glued to the player after they respawn.

Here is some code which supports detecting when one player shot at and/or killed another - note that the killed bit is the part we'd be interested in for this kill cam thing. Note that while it suggests it can detect a player killing themselves, it only handles them killing themselves with a weapon - cratering won't be detected since it doesn't cause damage to the trigger. There are other cases I haven't looked into yet - what happens when a turret weapon kills you, what happens when you're blown up by an exploding barrel, etc.

Code: Select all

//
// bullet_detect_init -
//
// Call this thread once for each player.  self points to the Player object
// we wish to monitor.
//
bullet_detect_init:
	local.trigger = spawn trigger_multiple origin local.player.origin setthread bullet_detect_trigger spawnflags 128 // DAMAGE
	local.trigger setsize ( -32 -32 0) ( 32 32 96) // I think the bounding box for the player is actually ( -16 -16 0) ( 16 16 96), but with that size, not all bullets were detected, probably because the 'glue'ing of the trigger to the player isn't perfect and the trigger is probably not always completely aligned with the player, hence a margin around the player is needed
	local.trigger glue self // attach trigger to player
	local.trigger.player = self // so setthread thread can work out which player the trigger is attached to
end


//
// bullet_detect_trigger -
//
// Called when the trigger_multiple glued to a player is damaged.
//
bullet_detect_trigger:
	local.player = self.player // the player who this trigger is attached to
	local.shooter = parm.other // the player who fired the bullet
	if (isalive local.player) {
		if (local.player == local.shooter) {
			iprintln_noloc "Player " local.player.entnum " fired/bashed with his weapon" // or injured himself with his own grenade
		} else {
			iprintln_noloc "Player " local.shooter.entnum " shot at player " local.player.entnum
		}
	} else {
		if (local.player == local.shooter) {
			iprintln_noloc "Player " local.player.entnum " killed himself" // or possibly was firing at the same moment he got killed by another player
		} else {
			iprintln_noloc "Player " local.shooter.entnum " killed player " local.player.entnum
		}
	}
end
Regards,
David

Posted: Mon Mar 15, 2004 4:49 am
by omniscient
even if we can tell who hit them, how do we get what THEY saw on theyre screen? i would think that would be that hardest part.

Posted: Mon Mar 15, 2004 4:54 am
by dcoshea
I forgot to mention, for applications other than the killcam, if you wanted to detect when the player was actually hit versus a bullet just missing them but still going through the trigger, you could keep track of the player's current health, and when the 'setthread' thread is called and their health has decreased from the last time you saw it, you could declare that the shot hit. However, there would be additional complications, such as the fact the player could pick up a health pack, so you'd need another thread running in the background, setting 'local.player.last_health = local.player.health', for instance, and hoping that between the time the bullet hits the player causing their health to decrease, and your 'setthread' to be called, the thread updating 'local.player.last_health' isn't called. It depends on how the scripting engine processes events - if you want a way to detect from within a script that a player shot another player, you could give it a try and see if it works that way.

Also, I did a bit more testing and found that:
- stupidly, I shouldn't have used the terms "shoot" and "bullet" since the script will of course respond to grenades as well :)
- if you shoot at a player with a mounted MG42, parm.other still points to the player using the mounted MG42; same for a portable MG42, and hopefully for other turret weapons like the Flak88 in Spearhead
- if a player is killed by a barrel blowing up, parm.other will point to the barrel entity; if you really wanted to, you could put trigger_multiples around barrels so you can detect who caused them to blow up, and then store that information for any deaths which are caused by those barrels, but in the game it just says "<player name> blew up" and the person who made them blow up gets no credit for the kill, so there's no need to address that for the kill cam, I don't think. Do note that the code I posted doesn't handle the barrel case properly; it should check for local.shooter.classname == "Player", and ignore the event otherwise.

Regards,
David

Posted: Mon Mar 15, 2004 5:12 am
by dcoshea
omniscient wrote:even if we can tell who hit them, how do we get what THEY saw on theyre screen? i would think that would be that hardest part.
At the time when the player was hit, you just find out the player's origin and the shooter's origin and spawn a camera at the shooter's origin looking at the player's origin. You can get the shooter's position to find out if they are crouching or standing and adjust the location of the camera up by the height of their eyes. I'm not sure if it's possible to find out if they're leaning, and which way, and of course it won't have the HUD of the shooter, but otherwise it'll be pretty close to being what the shooter's view was, I think.

Regards,
David

Posted: Mon Mar 15, 2004 5:14 am
by dcoshea
More information about that script: I noticed that it detects the player firing a portable MG42 but not a fixed one. I guess that's because the fixed one is not inside of the trigger_multiple. If someone wanted to use this code to detect the player firing (not sure why, since you can use 'fireheld' to detect that, except that it won't account for the weapon being out of ammo or reloading) then they'd have to make the trigger bigger, I guess.

Regards,
David

Posted: Mon Mar 15, 2004 8:52 am
by dcoshea
It just occured to me (I keep thinking about this since I wish I had the time right now to do the whole "kill cam" thing :) ) that, in conjunction with the (unfinished code) I posted on TMT which can get information about a player's weapon, you could display the name of the weapon that the player was killed by, as people sometimes wonder about that kind of thing. This would depend on checking what weapon the "shooter" is holding when the player dies, so in the case of the player being killed by a grenade it wouldn't quite work, since the "shooter" could have changed away from grenades to a gun by the time the player dies. I guess the message could say something like "Your killer is currently holding a BAR" rather than "You were killed with a BAR" since the latter could be wrong :)

Regards,
David
[Edit: fixed up url tag]

Posted: Mon Mar 15, 2004 11:13 am
by jv_map
I didn't read all of the interesting posts, so this comment might sound incredibly stupid... hence a :oops: in advance.
you could display the name of the weapon that the player was killed by
Doesn't mohaa does that automatically? It for example says 'jv_map was machinegunned by a machinegunner in the left foot' :( or 'a machinegunner was sniped by jv_map in the head' :)

Posted: Mon Mar 15, 2004 2:53 pm
by dcoshea
jv_map wrote:I didn't read all of the interesting posts, so this comment might sound incredibly stupid... hence a :oops: in advance.
you could display the name of the weapon that the player was killed by
Doesn't mohaa does that automatically? It for example says 'jv_map was machinegunned by a machinegunner in the left foot' :( or 'a machinegunner was sniped by jv_map in the head' :)
Yes :P I mean display the exact weapon name like "BAR" or "KAR98 Sniper".

Regards,
David

Posted: Tue Mar 16, 2004 1:33 am
by small_sumo
Can someoen help me with my code from the last page, dont loose sight of the basics dudes.

:)

Posted: Tue Mar 16, 2004 2:28 am
by dcoshea
small_sumo wrote:Can someoen help me with my code from the last page, dont loose sight of the basics dudes.
I thought figuring out who killed the player was one of the basics? :)

Anyway I see you said:
All I need is some code that makes the player when dead to setthread suchnsuch and in that I will use some code to force 3rdperson for a few seconds then revert back, that should do it.
That's probably not hard, I guess, but it's not really kill cam if you just make the player who died have a 3rd person perspective of their dead corpse for a few seconds :) Is that really what you want to do? Or did you mean you want it to be 3rd person on the shooter, not the person who died?

Regards,
David

Posted: Tue Mar 16, 2004 3:02 am
by small_sumo
dcoshea wrote:
small_sumo wrote:Can someoen help me with my code from the last page, dont loose sight of the basics dudes.
I thought figuring out who killed the player was one of the basics? :)

Anyway I see you said:
All I need is some code that makes the player when dead to setthread suchnsuch and in that I will use some code to force 3rdperson for a few seconds then revert back, that should do it.
That's probably not hard, I guess, but it's not really kill cam if you just make the player who died have a 3rd person perspective of their dead corpse for a few seconds :) Is that really what you want to do? Or did you mean you want it to be 3rd person on the shooter, not the person who died?

Regards,
David
Yep thats all I want I dont like the look up and spin around thing I would rather justdie and then see third person of self, I think it would look better.

That would be great man.

Thanks.

Posted: Tue Mar 16, 2004 5:14 am
by dcoshea
small_sumo wrote:Yep thats all I want I dont like the look up and spin around thing I would rather justdie and then see third person of self, I think it would look better.
3rd person of yourself? Aww thats boring, and after all the work I went to of figuring out how you determine who shot you :) I'll have a think about the best way of doing 3rd person on yourself when you die.

I dunno which way the camera will be facing - perhaps the direction you were facing before you died. Instead of going to 3rd person you could spawn a camera which rotates around your corpse at a certain height above the ground - that way you get more of a view of the area around you. If you just go to 3rd person, and you happened to be running toward a wall when you got killed, you might end up with a view of the wall which would be boring :)

Is anyone interested in the kill cam from the perspective of the shooter or am I only going to be writing that code to prove to myself it can be done, without the code ever being used? :)

Regards,
David

Posted: Tue Mar 16, 2004 6:20 am
by small_sumo
Well I am mad keen and will heap praises on you if you do it. I think the spawn camera orbit camera would rock.

Do it
Do it
Do it

:):):)