extraplayeritems: Detect end saferoom more reliabily

This commit is contained in:
Jackzie 2021-01-23 15:38:43 -06:00
parent 266f2ed081
commit a91bf82570
No known key found for this signature in database
GPG key ID: 1E834FE36520537A
2 changed files with 18 additions and 25 deletions

Binary file not shown.

View file

@ -31,32 +31,20 @@ then when you reach the saferoom, extraKitsAmount is set to the amount of player
Then on heal at the point, you get an extra kit. After a map transition when a player_spawn is fired, if they do not have a kit; give an extra kit if there is any. Then on heal at the point, you get an extra kit. After a map transition when a player_spawn is fired, if they do not have a kit; give an extra kit if there is any.
Any left over kits will be used on heals until depleted. Any left over kits will be used on heals until depleted.
*/ */
/*
extra utilities:
Far away player detection (ahead), start countdown if they continue to be farther away then a majority of the group (% based on Surv. count)
-> probably dynamic array if using % system.
Far away player detection (behind), tell players in chat.
*/
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) { public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) {
if(late) if(late) isLateLoaded = true;
isLateLoaded = true;
} }
public void OnPluginStart() public void OnPluginStart() {
{
EngineVersion g_Game = GetEngineVersion(); EngineVersion g_Game = GetEngineVersion();
if(g_Game != Engine_Left4Dead && g_Game != Engine_Left4Dead2) if(g_Game != Engine_Left4Dead && g_Game != Engine_Left4Dead2) {
{
SetFailState("This plugin is for L4D/L4D2 only."); SetFailState("This plugin is for L4D/L4D2 only.");
} }
HookEvent("player_spawn", Event_PlayerSpawn); HookEvent("player_spawn", Event_PlayerSpawn);
HookEvent("player_first_spawn", Event_PlayerFirstSpawn); HookEvent("player_first_spawn", Event_PlayerFirstSpawn);
HookEvent("round_end", Event_RoundEnd); HookEvent("round_end", Event_RoundEnd);
HookEvent("player_entered_checkpoint", Event_EnterSaferoom);
HookEvent("heal_success", Event_HealFinished); HookEvent("heal_success", Event_HealFinished);
HookEvent("map_transition", Event_MapTransition); HookEvent("map_transition", Event_MapTransition);
HookEvent("game_start", Event_GameStart); HookEvent("game_start", Event_GameStart);
@ -124,13 +112,11 @@ public Action Event_PlayerFirstSpawn(Event event, const char[] name, bool dontBr
firstGiven = true; firstGiven = true;
CreateTimer(1.0, Timer_GiveKits); CreateTimer(1.0, Timer_GiveKits);
} }
}else{ }else if(!DoesClientHaveKit(client)) {
if(!DoesClientHaveKit(client)) {
CheatCommand(client, "give", "first_aid_kit", ""); CheatCommand(client, "give", "first_aid_kit", "");
} }
} }
} }
}
public Action Timer_GiveKits(Handle timer) { GiveStartingKits(); } public Action Timer_GiveKits(Handle timer) { GiveStartingKits(); }
//Provide extra kits when a player spawns (aka after a map transition) //Provide extra kits when a player spawns (aka after a map transition)
@ -161,34 +147,41 @@ public void OnMapStart() {
} }
isFailureRound = false; isFailureRound = false;
} }
#if defined DEBUG #if defined DEBUG
PrintToServer(">>> MAP START. Extra Kits: %d", extraKitsAmount); PrintToServer(">>> MAP START. Extra Kits: %d", extraKitsAmount);
#endif #endif
if(!isLateLoaded) { if(!isLateLoaded) {
CreateTimer(30.0, Timer_AddExtraCounts); CreateTimer(30.0, Timer_AddExtraCounts);
isLateLoaded = false; isLateLoaded = false;
} }
//Hook the end saferoom as event
HookEntityOutput("info_changelevel", "OnStartTouch", EntityOutput_OnStartTouchSaferoom);
HookEntityOutput("trigger_changelevel", "OnStartTouch", EntityOutput_OnStartTouchSaferoom);
} }
public void Event_EnterSaferoom(Event event, const char[] name, bool dontBroadcast) { public void EntityOutput_OnStartTouchSaferoom(const char[] output, int caller, int client, float time) {
int client = GetClientOfUserId(event.GetInt("userid")); if(!isCheckpointReached && IsValidClient(client) && GetClientTeam(client) == 2){
if(client > 0 && !isCheckpointReached && GetClientTeam(client) == 2 && L4D_IsInLastCheckpoint(client)) {
isCheckpointReached = true; isCheckpointReached = true;
int extraPlayers = GetSurvivorsCount() - 4; int extraPlayers = GetSurvivorsCount() - 4;
if(extraPlayers > 0) { if(extraPlayers > 0) {
#if defined DEBUG #if defined DEBUG
PrintToConsoleAll("CHECKPOINT REACHED BY %N | EXTRA KITS: %d", client, extraPlayers); PrintToConsoleAll("CHECKPOINT REACHED BY %N | EXTRA KITS: %d", client, extraPlayers);
#endif #endif
//If hAddExtraKits TRUE: Append to previous, FALSE: Overwrite //If hAddExtraKits TRUE: Append to previous, FALSE: Overwrite
if(hAddExtraKits.BoolValue) if(hAddExtraKits.BoolValue)
extraKitsAmount += extraPlayers; extraKitsAmount += extraPlayers;
else else
extraKitsAmount = extraPlayers; extraKitsAmount = extraPlayers;
extraKitsStarted = extraKitsAmount; extraKitsStarted = extraKitsAmount;
PrintToServer(">>> Player entered saferoom. An extra %d kits will be provided", extraKitsAmount); PrintToServer(">>> Player entered saferoom. An extra %d kits will be provided", extraKitsAmount);
} }
} }
} }
public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast) { public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast) {
if(!isFailureRound) isFailureRound = true; if(!isFailureRound) isFailureRound = true;
} }