Author Topic: Event Request - onPlayerDeath  (Read 2741 times)

Technically it's only a function request. If someone can write up the function, I can package it into an event, but if you wanna jog the extra mile, go for it.

WHAT IT DOES:
Simple. It calls a function when the player dies. I know there are the "minigame events" but they are buggy and don't work well at all.
[onPlayerDeath] > [VictimClient] > [BottomPrint] > [You Have Died]

The old minigame events use KillerPlayer/KillerClient for the Killer, and Client/Player for the Victim Client/Player. I want it so that the Client/Player is the Killer and the Victim is called as the "Victim Client/Victim Player" I would prefer if this function worked both in and out of minigames, and I didn't have to enable "Use all Players Bricks".

The old minigame events has "onMinigameDeath " and "onMiniGameKill"
onMinigameDeath works only when dying from Self Delete, falling, and other "natural" dying conditions. onMiniGameKill works only when death occurs via murder.

It seems more efficient to make the input more simple.
onPlayerDeath : Called when the player dies; Under any circumstance. (murder or natural death)
------------------------------------------------------------------------------------------------

Could somebody please make this? I don't know why this isn't a default event already but I assume their are reasons for it (some type of stupid abuse?)
I am in desperate need of this event to make a working freekill jail system via events.

If someone could please do this I would greatly appreciate it!

I don't get it. You want a function, but there is already a gameConnection::onDeath function.

there's also the matter of knowing what to call the event on

you're gonna have a bad time if you loop through every brick in the simulation every time someone dies

I don't get it. You want a function, but there is already a gameConnection::onDeath function.

I think he wants someone to turn it into a basic input event to target the player/client who died.

there's also the matter of knowing what to call the event on

you're gonna have a bad time if you loop through every brick in the simulation every time someone dies
Not a problem at all. When I have such a case with an event, I just store all of the appropriate bricks in a global variable when the event is added, and remove them when the event is removed.

I think he wants someone to turn it into a basic input event to target the player/client who died.
If someone can write up the function, I can package it into an event

I meant to write out a function for the events system, with the whole registerInputEvent, or should I say package/parent the function and make it work with the event system?

Not a problem at all. When I have such a case with an event, I just store all of the appropriate bricks in a global variable when the event is added, and remove them when the event is removed.
ah right, i felt like i was forgetting some trickery like that

Please use my Support_MultiSourceEvents script: http://greek2me.us/code/Support_MultiSourceEvents.cs

It has one function (registerMultiSourceInputEvent()) to register the event, onPlayerKilled, and another function (processMultiSourceInputEvent()) to call it on all the bricks that have the event.




Edit: I was bored so I wrote the script in a couple minutes:
Code: [Select]
exec("./Support_MultiSourceEvents.cs");

registerMultiSourceInputEvent(
"fxDtsBrick",
"onPlayerDeath",
"Self fxDtsBrick" TAB "Player(Killer) Player" TAB "Client GameConnection" TAB "Client(Killer) GameConnection" TAB "Minigame Minigame",
false);

package Event_onPlayerDeath
{
function GameConnection::onDeath(%this, %obj, %killer, %type, %area)
{
parent::onDeath(%this, %obj, %killer, %type, %area);
%mini = getMinigameFromObject(%this);
$InputTarget_["Client"] = %this;
$InputTarget_["Player(Killer)"] = %killer.player;
$InputTarget_["Client(Killer)"] = %killer;
$InputTarget_["Minigame"] = %mini;
processMultiSourceInputEvent("onMinigameDeath", %this, %mini);
}
};
activatePackage(Event_onPlayerDeath);

Include that script and the file I linked above and you have a fully-functioning mod.

However, this reminded me that Slayer already has this event built-in. It's called "onMinigameDeath" in Slayer and includes targets for the killer and the victim - don't enable the old minigame events; I've already replicated everything they did in Slayer. You can find a complete listing of events in the Help tab of the GUI.
« Last Edit: December 19, 2014, 10:56:25 PM by Greek2me »

I don't get it. You want a function, but there is already a gameConnection::onDeath function.
I know this, but I wasn't sure about how to write up the whole function with %killer and all that.

there's also the matter of knowing what to call the event on

you're gonna have a bad time if you loop through every brick in the simulation every time someone dies
I would like it if the event was called on the brick, yes. I could use only one brick for the event
onPlayerDeath > Client > BottomPrint > You have died
Thats a simple example. I mainly need this event so I can do this:
onPlayerDeath > Client > VCE_ifVar > Wanted = 1;
onVarFalse > KillerClient > BottomPrint > You have freekilled!
onVarFalse > namedBrick > doPlayerTeleport > Jail > Relative?

-coolsnip
Thanks! I do not use Slayer, I use a modified version of Spaceguys TDM. I like Slayer and all, I just find the original TDM to be more simple for the things I need. I sometimes switch to Slayer when I need something specific (such as a dedicated server minigame, or for spawning next round upon joining)

If I were to make this without being depandant upon other mods, would it be something like this?
Code: [Select]
registerInputEvent(fxDtsBrick,"onPlayerDeath","Self fxDtsBrick\tPlayer Player\tVictimPlayer Player\tVictimClient GameConnection\tClient GameConnection\tMinigame Minigame");

function GameConnection::onDeath(%this, %client, %obj, %killer, %type, %pos)
{
parent::onDeath(%this, %client, %obj, %killer, %type, %pos);
              
               %mini = getMinigameFromObject(%this);
               %pos = %this.getTransform();

$InputTarget_["Client"] = %client;
                $InputTarget_["Player"] = %client.player;
$InputTarget_["KillerClient"] = %killer.client;
$InputTarget_["KillerPlayer"] = %killer.player;
$InputTarget_["Minigame"] = %mini;
%mini.processInputEvent("onPlayerDeath", %client, %mini);
         }

Also, I haven't tested, but will that work both in and out of minigames?
« Last Edit: December 20, 2014, 02:17:15 PM by Goth77 »

No, you'd do exactly what I said in that post. Just copy/paste that code and include the script in your add-on.

No, you'd do exactly what I said in that post. Just copy/paste that code and include the script in your add-on.
I follow'd your instructions and everything seems to work good. Thank you. The one issue I notice is that when you Self Delete it counts as you killing yourself, so both victim and killer events are called. An easy way to prevent this is to toggle Self Delete off, and since I am using this for a basic jailing system, Self Delete will be disabled anyhow. onMiniGameDeath and onMiniGameKill are probably separate events for this reason.

When I get back on a computer I'll show you the code to fix that.

When I get back on a computer I'll show you the code to fix that.
Alright. Thank you. I really appreciate the help.

Here's the new version:

Code: [Select]
exec("./Support_MultiSourceEvents.cs");

registerMultiSourceInputEvent(
"fxDtsBrick",
"onPlayerDeath",
"Self fxDtsBrick" TAB "Player(Killer) Player" TAB "Client GameConnection" TAB "Client(Killer) GameConnection" TAB "Minigame Minigame",
false);

package Event_onPlayerDeath
{
function GameConnection::onDeath(%this, %obj, %killer, %type, %area)
{
parent::onDeath(%this, %obj, %killer, %type, %area);
%mini = getMinigameFromObject(%this);
%Self Delete = (%this == %killer || !isObject(%killer);
$InputTarget_["Client"] = %this;
$InputTarget_["Player(Killer)"] = (%Self Delete ? 0 : %killer.player);
$InputTarget_["Client(Killer)"] = (%Self Delete ? 0 : %killer);
$InputTarget_["Minigame"] = %mini;
processMultiSourceInputEvent("onMinigameDeath", %this, %mini);
}
};
activatePackage(Event_onPlayerDeath);

Here's the new version:

exec("./Support_MultiSourceEvents.cs");

registerMultiSourceInputEvent(
   "fxDtsBrick",
   "onPlayerDeath",
   "Self fxDtsBrick" TAB "Player(Killer) Player" TAB "Client GameConnection" TAB "Client(Killer) GameConnection" TAB "Minigame Minigame",
   false);

package Event_onPlayerDeath
{
   function GameConnection::onDeath(%this, %obj, %killer, %type, %area)
   {
      parent::onDeath(%this, %obj, %killer, %type, %area);
      %mini = getMinigameFromObject(%this);
      %Self Delete = (%this == %killer || !isObject(%killer);
      $InputTarget_["Client"] = %this;
      $InputTarget_["Player(Killer)"] = (%Self Delete ? 0 : %killer.player);
      $InputTarget_["Client(Killer)"] = (%Self Delete ? 0 : %killer);
      $InputTarget_["Minigame"] = %mini;
      processMultiSourceInputEvent("onPlayerDeath", %this, %mini);
   }
};
activatePackage(Event_onPlayerDeath);

Thanks so much! I am testing it now. I made sure to change the process input to onPlayerDeath, wasn't sure if you left it as onMinigameDeath intentional or not

Everything outta work great, thanks again.