Page 1 of 2
Keeping dead bodies from disappearing
Posted: Sun Mar 22, 2015 6:45 pm
by razac920
A neat trick I found to keep bodies from disappearing:
Code: Select all
OnObjectKill(function(object,killer)
DeactivateObject(object)
end)
Two main bugs with it are that killed players cannot respawn (including humans), and that at a distance dead bodies can appear to be alive until you approach. I suppose the no-respawn could be a feature for quick last-man-standing games. If you want the human to be able to spawn, just modify the code to not deactivate a human's character unit object. No idea about the draw-distance issue.
Another small bug is that it will keep bodies that die in midair floating, so if you wanted to get really fancy, you could set a timer and deactivate the body object only after it stopped moving.
Re: Keeping dead bodies from disappearing
Posted: Sun Mar 22, 2015 6:49 pm
by Noobasaurus
Oh, wow, this is really cool! Great find. I love how it is so simple yet effective. This makes me want to start modding again even more...maybe soon.
Re: Keeping dead bodies from disappearing
Posted: Sun Mar 22, 2015 6:55 pm
by razac920
Thanks! Also, if you later activate the object again, then the dead player can respawn. So it doesn't have to be a permanent body, with timers you can just increase how long bodies stay (though you'd have to keep in mind that there is a max limit on how many timers you can run at once).
Re: Keeping dead bodies from disappearing
Posted: Sun Mar 22, 2015 8:09 pm
by Noobasaurus
Do you know what this means? A revival weapon for allies and enemies is now a reality. Instead of having constantly respawning troops, they can stay dead until someone revives them. This could make for some really amazing things.
Re: Keeping dead bodies from disappearing
Posted: Sun Mar 22, 2015 8:23 pm
by razac920
Okay, I just did a test and found that deactivated dead bodies do NOT respond to damage anymore, OnObjectDamage will not trigger. (Oddly, I did hear a scream of pain after having a grenade explode on a "dead" body though

)
But yes, revival weapons should still be possible -- just more involved as you'd need to move some sort of gravestone object over the body, wait for it to be hit with a particular weapon, and then activate the body (maybe move it away) and spawn the character in its place.
Although, I have no idea if this works in MP or not.
Re: Keeping dead bodies from disappearing
Posted: Sun Mar 22, 2015 8:55 pm
by AnthonyBF2
This is really cool, but when I saw this I thought "Can't you just stick a if character is human in there and if it human let them die normally?"
I can't do coding or I would be willing to test this thoroughly.
Edit:
Thinking about the revival thing, I think it would fit best when the "dead" body is hit with a medpack or a fusion cutter that could generate health.. maybe that for CIS, and health for humans.
Re: Keeping dead bodies from disappearing
Posted: Sun Mar 22, 2015 9:00 pm
by Locutus
razac920 wrote:Although, I have no idea if this works in MP or not.
It should.
I've used all mentioned commands (DeactivateObject, OnObjectDamage, GetObjectLastHitWeaponClass, etc.) in a MP-stable map before.
anthonybf2 wrote:I can't do coding or I would be willing to test this thoroughly.
Simply try it like this:
Code: Select all
OnObjectKill(
function(object, killer)
if IsCharacterHuman(object) then
return
else
DeactivateObject(object)
end
end
)
Re: Keeping dead bodies from disappearing
Posted: Sun Mar 22, 2015 9:25 pm
by AnthonyBF2
Your code didn't work. I tried on stock map dea1g_1flag with max 32 bots. When it started I jumped in the hole to test, it paused for a short moment and respawned me as soldier unit (I was currently using the rocket troop)
I test again by respawning (on the ground not on a hole) and my body didn't stick. AI bodies didn't stick either.
The first code razac posted is working and it's really cool.
I might have some future warnings, as I have messed with dead body stuff before.
1) stuck bodies (that are rotating) will drop all the power ups and they cannot be dispensed by engineer or other dead bodies. This only happens when the dead body is in falling animation.
2) Too many dead bodies on the game at once will cause long pauses for spawning, and will result in spawning as the first character in selection, which happens to be "soldier" probably because the way setup_teams is designed. You can still go the CP and pick the character you want.
Edit: It also seems dead bodies continue to trigger mines.
Re: Keeping dead bodies from disappearing
Posted: Sun Mar 22, 2015 10:12 pm
by razac920
IsCharacterHuman only works on characters (i.e. numbers) not objects (the result of GetCharacterUnit). If you don't want the human to be stuck from respawning, try
Code: Select all
human = nil
OnCharacterSpawn(function(character)
if IsCharacterHuman(character) then
human = GetCharacterUnit(character)
end
end)
OnObjectKill(function(object,killer)
if object ~= human then
DeactivateObject(object)
end
end)
You'd have to change human into a list for MP.
Re: Keeping dead bodies from disappearing
Posted: Sun Mar 22, 2015 11:57 pm
by AnthonyBF2
I just tried your last code and here are the results I got:
Played on Mos Eisley assault, with max 32 bots per team. I didn't play, only waited for a while for all bots to kill each other until they were no longer spawning. I had to finish off the last one of course. The ai bodies remained, I alone, then respawned. Well I could not respawn.
I then played the same level with no bots, I respawned several times in a row without issues. Since I was human I was not leaving bodies, so I had infinite respawns.
It seems over all with both of your scripts, humans and bots can keep respawning until there is so many bodies on the map. I think maybe around 50. I will see if I can count them later, I'm tired and need sleep. I will try it on XL later
Again thanks, this is a cool mod

Re: Keeping dead bodies from disappearing
Posted: Mon Mar 23, 2015 12:03 am
by razac920
Huh. Interesting. Why do you say humans and bots can "keep respawning"? If I understand it correctly, I don't think any deactivated player can respawn, and the appearance of bots spawning is just DIFFERENT bots that spawn midgame (not all the AI spawns immediately at the start of a round). Maybe try with a force spawn of all the AI at the same time that the human spawns, and wait around at a CP looking for new spawns after?
Re: Keeping dead bodies from disappearing
Posted: Mon Mar 23, 2015 12:23 am
by AnthonyBF2
Using both of your codes, I was able to respawn repeatedly(pause, suicide, and respawn) until there was too many bodies. The ai deaths of course take most of the dead body space, giving the human less respawns.
Just tried this on Hoth XL and came up with more bugs and stuff. (the 2nd script you posted)
I spawned in, and waited for each team to spawn a good chunk of bots. I used fake console to kill all ai on team 1 and team 2 to make it faster. The bots kept respawning, but after I commanded 2 or 3 waves to die, they did not reappear. I went around the map and count roughly 250 dead bots between empire and rebels.
Note: Hoth XL has 120 units max per side, which is 240 total. My counting wasn't perfect but the dead bodies seem to be able to be created until units have been reached. When I did the same script on Mos Eisley assault, there were abou 60 total bodies, and that's because the units for each team is 32.
I now guess the total bodies allowed depends on total units per team.
Now back to Hoth XL, with some bugs.
1) if Dark troopers were flying, they died and layed down flat in the air, just like the little dudes on the ground.
2) if rebels were in Snowspeeders, the speeders would explode and go away like usual, but the pilot and copilot lay dead in the air like the Dark troopers.
3) Killing an unpiloted Tauntaun resulted in the Tauntaun freezing instead of falling over and dying.
The same result you would get if the Tauntaun were a prop.
Re: Keeping dead bodies from disappearing
Posted: Mon Mar 23, 2015 12:43 am
by razac920
Right, well I'm thinking that the reason why the total max body count depends on the number of units per team is simply because each unit on a team dies exactly once and leaves exactly one body.
Ah right vehicles, my initial code was rather crude and imprecise and doesn't distinguish between units and vehicles.
If I wanted to be more precise about it, I would go for something like this:
Code: Select all
playercount = 0
players = {}
bodies = {}
OnCharacterSpawn(function(player)
local new = false
local i = 1
for i = 1, playercount do
if players[i] == player then
new = false
bodies[i] = GetCharacterUnit(player)
end
end
if new then
playercount = playercount + 1
players[playercount] = player
bodies[playercount] = GetCharacterUnit(player)
end
end)
OnObjectKill(function(object,killer)
local i = 1
for i = 1,playercount do
if bodies[i] == object and not IsCharacterHuman(players[i]) then
DeactivateObject(object)
end
end
end)
This should fix the vehicle issue. Maybe later I'll write some code to postpone the deactivation until the dead character stops moving.
Re: Keeping dead bodies from disappearing
Posted: Wed Mar 25, 2015 3:58 am
by jedimoose32
Just popping in to say, nice find!
I'll be using this in Assassination Mode to prevent the player from returning to the character selection screen when he gets killed on his last life, hopefully.
Re: Keeping dead bodies from disappearing
Posted: Wed Mar 25, 2015 10:59 pm
by razac920
Eh, well technically it doesn't seem to stop the player from returning to the character selection after death -- just when you try to spawn afterwards, nothing happens (except you might return to the view of your dead body? I forget exactly)
Re: Keeping dead bodies from disappearing
Posted: Wed Mar 25, 2015 11:17 pm
by jedimoose32
Shoot. I extended the defeat timer as per your suggestion but now it looks funny because the player dies and then the spawn screen shows for about a second before the defeat message shows.
Re: Keeping dead bodies from disappearing
Posted: Wed Mar 25, 2015 11:22 pm
by razac920
Well you can always shorten it by a second or so

It was like a 1 second delay? How long is it now?
Re: Keeping dead bodies from disappearing
Posted: Wed Mar 25, 2015 11:29 pm
by jedimoose32
It used to be 1 second. Changed it to 5. I rather like it at 5... But I'll reduce it to 3 or 4. Do you know whether there is a way to prevent the player from accessing the spawn screen? That would be pretty cool.
Re: Keeping dead bodies from disappearing
Posted: Wed Mar 25, 2015 11:46 pm
by razac920
No, I don't know how to do that... Other than by forcibly spawning the player the moment after he dies. But why is 5 seconds so special? It would seem so much easier to just reduce the time between death and defeat by a second or two.
Re: Keeping dead bodies from disappearing
Posted: Wed Mar 25, 2015 11:48 pm
by jedimoose32
Oh it's not 'special', per se. I was just curious.