I need to write a custom death message, but like SUFFOCATION, DROWNING, I don't write know these events. I just write about killing now,as shown in the figure
$ldamage->getDamager() returns an entity, so you should check if it's a player before then running getName() on it directly.
See this list of all entity events, it might help you: https://github.com/pmmp/PocketMine-MP/tree/master/src/pocketmine/event/entity