#Custom death

1 messages · Page 1 of 1 (latest)

steel oriole
#

I wanted to create custom death. When the player die, his death changes to death by laser gun. I create a fake player and then kill him with a laser gun. But when I run my plugin, the fake player doesn't die.

Why doesn't the player die?

My code

        private void PlayerEvents_Death(LabApi.Events.Arguments.PlayerEvents.PlayerDeathEventArgs ev)
        {
            var d = DummyUtils.SpawnDummy();
            d.roleManager.ServerSetRole(ev.OldRole, RoleChangeReason.Respawn);
            d.transform.position.Set(ev.Player.Position.x, ev.Player.Position.y, ev.Player.Position.z);
            d.playerStats.KillPlayer(new DisruptorDamageHandler(null, UnityEngine.Vector3.up, int.MaxValue));
        }
snow field
#

you're probably causing a stack overflow

#

skip the handler if the player is a dummy

#

also, you can't move the player just by setting their position
use d.TryOverridePosition(player.Position)

#

use -1 for the damage btw

steel oriole
#

Ok

steel oriole
# snow field you're probably causing a stack overflow

I get this error. I don't understand why it occurs.

025-08-16 12:56:23.306 +00:00] [ERROR] [LabApi] 'MethodAccessException' occured while invoking 'PlayerEvents_Death' on 'MapEditorKevin.MapEditorKevin': 'Method `PlayerStatsSystem.DisruptorDamageHandler.set_FiringState(InventorySystem.Items.Firearms.Modules.DisruptorActionModule/FiringState)' is inaccessible from method `MapEditorKevin.MapEditorKevin.PlayerEvents_Death(LabApi.Events.Arguments.PlayerEvents.PlayerDeathEventArgs)'', stack trace:
                                   at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_throw_method_access(intptr,intptr)
                                   at MapEditorKevin.MapEditorKevin.PlayerEvents_Death (LabApi.Events.Arguments.PlayerEvents.PlayerDeathEventArgs ev) [0x00044] in <bfc6cb847a14405f9759c2440ee2c0af>:0
                                   at LabApi.Events.EventManager.InvokeEvent[TEventArgs] (LabApi.Events.LabEventHandler`1[TEventArgs] eventHandler, TEventArgs args) [0x0001d] in <bd83d6009c394d05b0e4e2080b3f314d>:0
snow field
steel oriole
viral sundial
viral sundial
#
public override void OnPlayerDeath(PlayerDeathEventArgs ev)
{
  Timing.CallDelayed(Timing.WaitForOneFrame, () =>
  {
    Ragdoll? ragdoll = Ragdoll.List.LastOrDefault(x => x.Base.NetworkInfo.OwnerHub == ev.Player.ReferenceHub);
    if (ragdoll == null) return;
    ragdoll.DamageHandler = new DisruptorDamageHandler(null, Vector3.zero, 0);
  });
}
#

You'll want to filter for what player you want to do this for

steel oriole
# viral sundial ```c# public override void OnPlayerDeath(PlayerDeathEventArgs ev) { Timing.Cal...

I have the same idea

        private void PlayerEvents_Death(LabApi.Events.Arguments.PlayerEvents.PlayerDeathEventArgs ev)
        {
            //var d = DummyUtils.SpawnDummy();
            var r = Ragdoll.List.FirstOrDefault(x => x.DamageHandler == ev.DamageHandler && x.Nickname == ev.Player?.Nickname && x.Role == ev.OldRole);

            r.DamageHandler = new DisruptorDamageHandler(null, UnityEngine.Vector3.zero, -1) { FiringState = FiringState.FiringSingle };

            //d.roleManager.ServerSetRole(ev.OldRole, RoleChangeReason.Respawn);
            //d.TryOverridePosition(ev.OldPosition);
            //Logger.Info(ev.OldCameraRotation.ToString());

            //d.playerStats.KillPlayer(new DisruptorDamageHandler(null, UnityEngine.Vector3.zero, -1) { FiringState = FiringState.FiringSingle });
            //NetworkServer.Destroy(d.gameObject);
        }
viral sundial
viral sundial
steel oriole
#

I see you have Vector3.zero, but why, if the corpse will fly to the top anyway?

viral sundial
viral sundial
#

All damagehandlers have a StartVelocity they prescribe to

#

I have an idea

#

So I realized

#
public override void OnPlayerSpawnedRagdoll(PlayerSpawnedRagdollEventArgs ev)
{
  ev.Ragdoll.DamageHandler = new CustomReasonDamageHandler("Hi!");
}
snow field
#

wouldn't you need spawning...

#

nevermind xd

#

does this sync though?

viral sundial
#

You can change a ragdoll's damage handler at any time

#

And it'll sync

snow field
viral sundial
#

Also

#

Turns out I probably just didn't push the update or something