A keepinventory/combat datapack

I want to have a mechanic in my minecraft server where keepinventory is turned on, but if killed by a player you drop your items. Shoud i even use a datapack for this? I don't really wanna bother with mods but im not sure if a datapack is even possible for my plan. The server is quite small so the datapack doesn't have to be perfect.

Continue to help post