Limiting respawns in Co-op play

Have a question, suggestion, or comment about Aleph One's features and functionality (Lua, MML, the engine itself, etc)? Post such topics here.

Limiting respawns in Co-op play

Post Apr 17th '16, 05:51

Playing through with a friend, and noticed that the unlimited respawning in the game really keeps the stakes from getting to the actual sweaty-palm level that I was hungry for.

Now, I know nothing about lua scripting. I've got the scripter's guide here in front of me, but to be honest, I don't think I have the time to drop into reading this whole thing and figuring out for myself how to make a script (or better, add onto the Co-op 2.2 script) that does what I'm looking for.

So maybe you guys are familiar enough with this stuff to show me how to do it. :wub:

Ideally, I'd like to see is what I'm calling "staggered respawning". Halo, Gears of War, Killzone?, Call of Duty? I think do this. Two or more players are in co-op. When you die, there's a timed wait until respawn. So long as at least one player remains alive, respawning is unlimited. But if all the players die, it's game over.

If that's too complicated/impossible to script, the next best thing would be to simply give each (or all) players limited lives.

What do you guys think?

Post Apr 17th '16, 19:01

The timed wait is built in: check "Penalize Dying" on the gather screen. (It's possible to build it in Lua, but this is simpler, if you're fine with the 10-second value.)

Then you need to exit the game when all players are dead. Exiting the game from Lua is easy: you set "Game.over" to true. The Lua API has a trigger (aka callback) when a player dies, so you know when one player is dead. From that trigger, you can check on the others, and exit if you can't find a survivor.

Putting that all together, you get:
Code: Select all
-- turn off the really old backward-compatibility stuff
Triggers = {}

-- each time a player dies, check for living teammates
function Triggers.player_killed(player, aggressor_player, action, projectile)
  -- don't do anything if we're not in co-op mode
  if Game.type ~= "cooperative play" then return end
  -- look for living players
  local player_alive = false
  for p in Players() do
    if p ~= player and not p.dead then
      player_alive = true
  -- end game if everyone is dead
  if not player_alive then
    Game.over = true
Any Marine
(530 Bytes) Downloaded 104 times
User avatar


Post Apr 18th '16, 07:43

Alright, I've got the opportunity to test it out tonight. Thanks for the reply. I'll let you know how it goes.

BTW, I've just pasted it into the co-op 2.2 script from John Irons. I know nothing about scripts, so I'm not sure if that's a fauxpas or some shit, or even if my random copy-paste job will work, but I'll let you know.

Post Apr 18th '16, 10:30

It worked great by itself. My attempt to just throw it into the co-opt script was unsuccessful. Probably because I don't know what I'm doing and just pasted in at random.

Post Apr 18th '16, 10:48

I haven't looked, but the co-op script likely already has a Triggers.player_killed() function defined. Copy-paste the body of the function that Hopper provided into the top of the same function in the co-op script and it will (probably) work.
User avatar

Crater Creator

Post Apr 23rd '16, 17:32

Started playing through Phoenix co-op with two of my brothers and yeah, I noticed the lack of punishment for dying kind of ruins the whole experience. We play on Total Carnage difficulty, and since you just respawn with the inventory you had prior to your death, we just die through the maps. There are no consequences anyway, and the beacons, as great as they are, don't help with that.

So, maybe I can interest you in the modifications to the co-op script I made. Basically, I made everyone die if just one player bites the dust. As soon as every player revived, the map reloads and you have to start the level all over, like in a single player game.

However, since you can't command the engine to reload from the last save state from LUA (at least not in a multiplayer game) this behavior is reverted in saved games until you enter the next level.

I took the script updated by Hopper, which resolved the out-of-sync problem, however, saving the game while a player is dead should be avoided, as far as I know. Best to try to avoid level jumping, too, while a player is dead.

Unfortunately, I didn't have the chance to thoroughly test it, since we didn't play since then. I tested by playing alone using my MacBook, and the modifications worked.

Give it a shot and tell me whether you find bugs and/or how you liked it! [MUp]
Co-Op-2.2 with
(5.76 KiB) Downloaded 97 times
User avatar

Germany, Bavaria

Return to Aleph One Discussion

Who is online

Users browsing this forum: No registered users