I need to call a function when there is only one player left alive in a minigame. To do this, I have a loop that looks for when one player remains and calls my function when this is true.
But, I think my function is not being called because there's a default function that executes instead - the default function that gives the chat message "%1 is the last man standing" when minigame respawntime is set to -1. I need to have respawntime set to -1 because players should not be able to respawn in my gamemode.
I think I have 2 options, neither of which I've figured out how to do:
- Set respawntime to something other than -1, and prevent players from manually respawning.
- Keep respawntime at -1, but somehow call my function before the default 'last man standing' function calls.
Solution:
This prevents the countdown until respawn centerprint from showing up:
function gameConnection::onDeath(%cl,%sourceObject,%sourceClient,%damageType,%damageArea)
{
parent::onDeath(%cl,%sourceObject,%sourceClient,%damageType,%damageArea);
messageClient(%cl,'MsgYourSpawn');
centerPrint(%cl,"",1);
}
This prevents people from respawning, but also messes with admin orb mode and some other stuff:
package noObserverRespawn
{
function Observer::onTrigger(%this,%cam,%btn,%state)
{
return;
parent::onTrigger(%this,%cam,%btn,%state);
}
};
ActivatePackage(noObserverRespawn);
This does the same as the above code but also allows dead players to watch other players that are still alive. You can click to cycle to different players. To make it work,
change "findclientbyname(fara).minigame" to whatever your minigame is.
package noObserverRespawn
{
function Observer::onTrigger(%this,%cam,%btn,%state)
{
%client = %cam.getControllingClient();
%client.centerPrint("", 1);
if(%state == 1)
{
%c = findclientbyname(fara).minigame.numMembers;
%aliveCount = 0;
for(%i = 0; %i < %c; %i++)
{
%member = findclientbyname(fara).minigame.member[%i];
if(!isObject(%member.player)) continue;
%aliveCount += 1;
%livingList[%aliveCount] = %member;
}
talk("observingClient: " @ %client.observingClient);
if(%aliveCount >= 1)
{
//talk("aliveCount >= 1");
if(!%client.observingClient)
{
//talk("clicker has no predefined observer - set player 1");
%client.observingClient = 1;
%client.camera.setOrbitMode(%livingList[1].player, %livingList[1].player.getTransform(), 0.5, 10, 20, false);
%client.setControlObject(%client.camera);
}
else
{
%client.observingClient += 1;
if(%client.observingClient > %aliveCount)
{
//talk("clicker has a predefined observer >> but it was the last player - set player 1");
%client.observingClient = 1;
%client.camera.setOrbitMode(%livingList[1].player, %livingList[1].player.getTransform(), 0.5, 10, 20, false);
%client.setControlObject(%client.camera);
}
else
{
//talk("clicker has a predefined observer >> set to next player");
%client.camera.setOrbitMode(%livingList[%client.observingClient].player, %livingList[%client.observingClient].player.getTransform(), 0.5, 10, 20, false);
%client.setControlObject(%client.camera);
}
}
}
}
return;
parent::onTrigger(%this,%cam,%btn,%state);
}
};
ActivatePackage(noObserverRespawn)