function playerDied( ammo, attacker, weapon, bodypart )
gDiedX, gDiedY, gDiedZ= getElementPosition(source) -- We save wheres he/she dies
end
addEventHandler("onPlayerWasted", getRootElement(), playerDied)
You need to research more at the wiki.
You can edit the arguments in spawnPlayer( player, -711+math.random(1,5), 957+math.random(5,9), 12.4, 90, math.random(9,288) ) and set the arguments what you need. Example: You can set there the players pos in the last death IF he/she died.
(x=blue, y=green, z=red)
https://wiki.multitheftauto.com/wiki/SpawnPlayer