@@ -55,31 +55,30 @@ DFUNC(isUnconscious) =
5555 };
5656};
5757
58- // var nach Respwan zurück setzen
5958[" Respawn" , {
60-
61- {
62- player setVariable [" OPT_isUnconscious" , 0 , true ];
63- player setVariable [" OPT_isStabilized" , 0 , true ];
64- player setVariable [" OPT_isDragged" , 0 , true ];
65- GVAR(OPT_isDragging) = false ;
66- player allowDamage true ;
67- 1 enableChannel true ;
68- 1 fadeSound 1 ;
69- OPT_GELDZEIT_earplugsInUse = 1 ;
70- OPT_REVIVE_unconsciousHandler = nil ;
71- OPT_REVIVE_respawnedHandler = nil ;
72- player setVariable [" tf_unable_to_use_radio" , false ];
73-
74- // Schaden Freigeben
75- player allowDamage true ;
76- } call CFUNC(execNextFrame);
77-
59+ params [" _data" , " _args" ];
60+ _data params [" _newPlayer" , " _oldPlayer" ];
61+ _oldPlayer removeEventHandler [" HandleDamage" , GVAR(PLAYER_HANDLE_DAMAGE_EH_ID)];
62+
63+ // Respawn will change the player Object. We need to reassign the Eventhandler.
64+ GVAR(PLAYER_HANDLE_DAMAGE_EH_ID) = _newPlayer addEventHandler [" HandleDamage" , FUNC(playerHandleDamage)];
65+
66+ _newPlayer setVariable [" OPT_isUnconscious" , 0 , true ];
67+ _newPlayer setVariable [" OPT_isStabilized" , 0 , true ];
68+ _newPlayer setVariable [" OPT_isDragged" , 0 , true ];
69+ _newPlayer allowDamage true ;
70+ _newPlayer setVariable [" tf_unable_to_use_radio" , false ];
71+
72+ GVAR(OPT_isDragging) = false ;
73+ OPT_GELDZEIT_earplugsInUse = 1 ;
74+ OPT_REVIVE_unconsciousHandler = nil ;
75+ OPT_REVIVE_respawnedHandler = nil ;
76+
77+ 1 enableChannel true ;
7878}] call CFUNC(addEventhandler );
7979
8080// EH für Spielerabschüsslog
8181// Event Aüslösung bei bewustlosen Spieler.
82-
8382DFUNC(playercheckINCAPACITATED) =
8483{
8584 if ((lifeState GVAR(playerHandleDamage_unit) isEqualTo " INCAPACITATED" ) and isNil " OPT_REVIVE_unconsciousHandler" ) then
@@ -114,21 +113,29 @@ DFUNC(playerHandleDamage) =
114113 GVAR(playerHandleDamage_projectile) = _projectile ;
115114 GVAR(playerHandleDamage_damage) = _damage ;
116115
117- // Schade hoeher eingestellen Werte Blocken um Autorespwan zu verhindern.
118- if (_damage >= GVAR(MAX_DAMAGE)) then
119- {
120- _unit setDamage GVAR(MAX_DAMAGE);
121- };
116+ private _resultingDamage = _damage ;
122117
123- if (getDammage _unit >= GVAR(MAX_DAMAGE)) then
124- {
125- _unit setDamage GVAR(MAX_DAMAGE);
126- };
118+ if (_damage >= GVAR(MAX_DAMAGE)) then {
119+ [FUNC(playercheckINCAPACITATED), 1 ," " ] call CLib_fnc_wait ;
120+ // Player will be "down" from this point on.
121+
122+ // Making him invulnerable to prevent forced respawn and random damage that accumulates, if he get overkilled
123+ // the Revive-Function should set the desired damage after reviving the body.
124+ _resultingDamage = GVAR(MAX_DAMAGE);
125+ };
127126
128- [FUNC(playercheckINCAPACITATED), 1 ," " ] call CLib_fnc_wait ;
127+ _resultingDamage ;
128+ };
129+ // The initial EHs are not needed and resulting in strange problems adding a new EH, so we remove any.
130+ // still very bad practise that screams for sideeffects.
131+ // Just look away.
132+ for " _i" from 0 to 6 do {
133+ player removeEventHandler [" HandleDamage" , _i ];
129134};
135+ // ok now you may have a peek again
130136
131- player addEventHandler [" HandleDamage" , FUNC(playerHandleDamage)];
137+ // Initial assignment, Respawn Handler does not trigger on first-spawn.
138+ GVAR(PLAYER_HANDLE_DAMAGE_EH_ID) = player addEventHandler [" HandleDamage" , FUNC(playerHandleDamage)];
132139
133140// 3D Marker
134141GVAR(missionEH_draw3D) = addMissionEventHandler [" Draw3D" ,
0 commit comments