Raised This Month: $81 Target: $400
 20% 

[L4D2] Fix for Medkit Density


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
rtokuda
Senior Member
Join Date: Dec 2019
Old 10-01-2020 , 16:14   [L4D2] Fix for Medkit Density
Reply With Quote #1

I know that this plugin has been discontinued because it causes crashes, but is there any possibility to fix this plugin? I didn't find anything like that that works to replace the medikts in a match that has more than four player


Reason for Unapproving:
PHP Code:
Precaching in OnPluginStartwill lead to crashes 
Source Code

PHP Code:
/********************************************************************************************
* Plugin    : [L4D2] Medkit Density in Versus/TeamVersus or Coop/Realism/Versus/TeamVersus
* Version    : 1.5.
* Game        : Left 4 Dead 2
* Author    : SwiftReal (Yves)
* Testers    : Myself, SwiftReal
* Website    : forums.alliedmods.net

* Purpose    : This plugin removes, replaces, doubles or leaves medkits
*               at the start of a campaign, at checkpoints/safehouses and in the outdoors.

* WARNING    : Please use sourcemod's latest 1.3 branch snapshot.

* Version 1.5
*         - added FCVAR_NOTIFY cvar flags to all cvars
*         - added ability to have infite medkits at start, saferoom and outdoors
*         - removed round_freeze_end event, applied different method
* Version 1.4
*         - remove abilities to double, tripple or quadruple medkitcount at start, checkpoints and outdoors
*         - added ability to set a specified amount of medkits at start and checkpoints
*         - added ability to replace each outdoor medkit with specified amount of medkits
*         - fixed case where random outdoor medkit was treated like a saferoom medkit
*         - changed method of spawning saferoom medkits to gradually spawning
*         - changed the method of finding entities
*         - sm_md_start now effects every medkit at start of every map in versus games
* Version 1.3.2
*         - fixed a bug where a survivor has his medkit removed from him/her
*         - other minor changes 
* Version 1.3.1
*         - applied another way to carry over the correct amount of medkits at checkpoint to next map
*         - added a reset on closest medkit location on mapchange
*         - changed convar limits for tripple, quadruple and 1defib+3medkits to work
* Version 1.3
*         - really fixed carrying over the correct amount of medkits at checkpoint to next map
*         - fixed replacing some outdoor medkits that the director spawned late into the game
*         - added the abilities to tripple or quadruple medkitcount at start, checkpoints and outdoors
*         - added the ability to replace 1 of 4 medkits with 1 defibrillator at start and checkpoints
* Version 1.2
*         - fixed carrying over the correct amount of medkits at checkpoint to next map
* Version 1.1
*         - set convar min and max limits
*         - fixed issue with spawning way too many medkits after a few fail rounds
* Version 1.0
*          - Initial release

********************************************************************************************/

#include <sourcemod>
#include <sdktools>

#define PLUGIN_VERSION        "1.5"
#define CVAR_FLAGS            FCVAR_PLUGIN|FCVAR_NOTIFY
#define MEDKIT                "models/w_models/weapons/w_eq_medkit.mdl"
#define DEFIB                "models/w_models/weapons/w_eq_defibrillator.mdl"
#define PILLS                "models/w_models/weapons/w_eq_painpills.mdl"

new Handle:h_PluginEnabled
new Handle:h_OnlyVersus
new Handle:h_KitsStart
new Handle:h_KitsStartCount
new Handle:h_KitsSaferoom
new Handle:h_KitsSaferoomCount
new Handle:h_KitsOutdoors
new Handle:h_KitsOutdoorsCount
new Handle:timer_DensityOutdoors INVALID_HANDLE
new String:g_MapName[128]
new 
String:g_GameMode[32]
new 
Float:vecLocationStart[3]
new 
Float:vecClosestKitStart[3]
new 
Float:vecLocationCheckpoint[3]
new 
Float:vecClosestKitCheckpoint[3]
new 
g_iCount 0
new bool:g_bFirstItemPickedUp
new bool:g_bMissionLost
new bool:g_bRoundStarted

public Plugin:myinfo 
{
    
name            "[L4D2] Medkit Density",
    
author            "SwiftReal",
    
description        "Removes, replaces or adds medkits at start, saferooms and outdoors",
    
version            PLUGIN_VERSION,
    
url                "http://forums.alliedmods.net/showthread.php?p=1121462"
}

public 
OnPluginStart()
{
    new 
String:GameFolder[50]
    
GetGameFolderName(GameFoldersizeof(GameFolder))
    if(!
StrEqual(GameFolder"left4dead2"false))
        
SetFailState("Medkit Density supports Left 4 Dead 2 only")
    
    if(!
IsModelPrecached(MEDKIT)) PrecacheModel(MEDKITtrue)    
    if(!
IsModelPrecached(DEFIB)) PrecacheModel(DEFIBtrue)    
    if(!
IsModelPrecached(PILLS)) PrecacheModel(PILLStrue)
    
    
// Register Cmds and Cvars
    
CreateConVar("medkitdensity_version"PLUGIN_VERSION"Medkit Density version"CVAR_FLAGS|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_DONTRECORD)
    
SetConVarString(FindConVar("medkitdensity_version"), PLUGIN_VERSION)
    
    
h_PluginEnabled         CreateConVar("sm_md_enabled""1""Should the plugin be on? 1[on] 2[off]"CVAR_FLAGStrue0.0true1.0)
    
h_OnlyVersus             CreateConVar("sm_md_versusonly""0""Change medkit density in versus games only? 0[coop,realism,versus,teamversus] 1[versus,teamversus]"CVAR_FLAGStrue0.0true1.0)
    
h_KitsStart                CreateConVar("sm_md_start""1""What to do with medkits at the start? (coop: start of campaign)(versus: start of every map) 0[do nothing] 1[use sm_md_start_medkitcount] 2[remove medkits] 3[replace with pills] 4[replace with defibrillators] 5[infinite medkits] 6[change 1 medkit to 1 defibrillator]"CVAR_FLAGStrue0.0true6.0)
    
h_KitsStartCount        CreateConVar("sm_md_start_medkitcount""8""At start, replace medkits with how many medkits?"CVAR_FLAGStrue4.0true20.0)
    
h_KitsSaferoom             CreateConVar("sm_md_saferoom""1""What to do with medkits in saferooms? 0[do nothing] 1[use sm_md_checkpoint_medkitcount] 2[remove medkits] 3[replace with pills] 4[replace with defibrillators] 5[infinite] 6[replace 1 medkit with 1 defibrillator]"CVAR_FLAGStrue0.0true6.0)
    
h_KitsSaferoomCount        CreateConVar("sm_md_saferoom_medkitcount""12""In saferooms, replace medkits with how many medkits?"CVAR_FLAGStrue4.0true20.0)
    
h_KitsOutdoors             CreateConVar("sm_md_outdoors""1""What to do with each medkit outdoors? 0[do nothing] 1[use sm_md_outdoors_medkitcount] 2[remove medkits] 3[replace with pills] 4[replace with defibrillators] 5[infinite]"CVAR_FLAGStrue0.0true5.0)
    
h_KitsOutdoorsCount        CreateConVar("sm_md_outdoors_medkitcount""2""With how many medkits should each medkit in the outdoors be replaced?"CVAR_FLAGStrue2.0true10.0)

    
// Hook Events
    
HookEvent("item_pickup"evtItemPickup)
    
HookEvent("mission_lost"evtMissionLost)
    
HookEvent("round_start"evtRoundStarted)
    
    
// Execute or create cfg
    
AutoExecConfig(true"l4d2medkitdensity")
}

public 
OnMapStart()
{
    
g_bFirstItemPickedUp false
    g_bMissionLost 
false
    g_bRoundStarted 
false
}

public 
evtItemPickup(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(
GetConVarBool(h_PluginEnabled))
    {
        if(!
g_bFirstItemPickedUp)
        {
            
CreateTimer(3.0Timer_DelayChangeDensity)            
            
g_bFirstItemPickedUp true
        
}
        else if(
g_bMissionLost && g_bRoundStarted)
        {
            
CreateTimer(1.0Timer_DelayChangeDensity)
        }
    }
}

public 
OnClientDisconnect(client)
{
    if(!
RealPlayersInGame(client))
    {
        if(
timer_DensityOutdoors != INVALID_HANDLE)
        {
            
KillTimer(timer_DensityOutdoors)
            
timer_DensityOutdoors INVALID_HANDLE
        
}
        
g_bFirstItemPickedUp false
        g_bMissionLost 
false
        g_bRoundStarted 
false
    
}
}

public 
evtMissionLost(Handle:event, const String:name[], bool:dontBroadcast)
{
    
g_bMissionLost true
    
if(timer_DensityOutdoors != INVALID_HANDLE)
    {
        
KillTimer(timer_DensityOutdoors)
        
timer_DensityOutdoors INVALID_HANDLE
    
}
}

public 
evtRoundStarted(Handle:event, const String:name[], bool:dontBroadcast)
{
    
g_bRoundStarted true
}

public 
Action:Timer_DelayChangeDensity(Handle:timer)
{
    
GetCurrentMap(g_MapNamesizeof(g_MapName))
    
GetConVarString(FindConVar("mp_gamemode"), g_GameModesizeof(g_GameMode))
    new 
bool:bOnlyVersus GetConVarBool(h_OnlyVersus)
    if((
StrContains(g_GameMode"versus"false) != -1) || ((StrContains(g_GameMode"scavenge"false) == -1) && !bOnlyVersus))
    {
        
FindLocationStart()
        
FindLocationSaferoom()
        
SetKitsDensity_Start()
        
SetKitsDensity_Saferoom()
        if(
timer_DensityOutdoors == INVALID_HANDLE)
            
timer_DensityOutdoors CreateTimer(10.0Timer_DensityOutdoors_TIMER_REPEAT)
    }
    return 
Plugin_Handled
}

public 
Action:Timer_DensityOutdoors(Handle:timer)
{
    
SetDensity_Outdoors()
    return 
Plugin_Continue
}

stock FindLocationStart()
{
    new 
ent
    decl Float
:vecLocation[3]
    
    if(
StrContains(g_MapName"m1_"false) != -1)
    {
        
// search for a survivor spawnpoint if first map of campaign
        
ent = -1
        
while((ent FindEntityByClassname(ent"info_survivor_position")) != -1)
        {
            if(
IsValidEntity(ent))
            {
                
GetEntPropVector(entProp_Send"m_vecOrigin"vecLocation)
                
vecLocationStart vecLocation
                
break
            }
        }
    }
    else
    {
        
// Search for a locked exit door,
        
ent = -1
        
while((ent FindEntityByClassname(ent"prop_door_rotating_checkpoint")) != -1)
        {
            if(
IsValidEntity(ent))
            {
                if(
GetEntProp(entProp_Send"m_bLocked") == 1)
                {
                    
GetEntPropVector(entProp_Send"m_vecOrigin"vecLocation)
                    
vecLocationStart vecLocation
                    
break
                }
            }
        }
    }    
    
// search for an ammo pile close to spawnpoint or exit door
    
ent = -1
    
while((ent FindEntityByClassname(ent"weapon_ammo_spawn")) != -1)
    {
        if(
IsValidEntity(ent))
        {
            
GetEntPropVector(entProp_Send"m_vecOrigin"vecLocation)
            if(
GetVectorDistance(vecLocationStartvecLocationfalse) < 1000)
            {
                
vecLocationStart vecLocation
                
break
            }
        }
    }
    return
}

stock FindLocationSaferoom()
{
    new 
ent
    decl Float
:vecLocation[3]
    
    
// Search for a locked checkpoint door,
    
ent = -1
    
while((ent FindEntityByClassname(ent"prop_door_rotating_checkpoint")) != -1)
    {
        if(
IsValidEntity(ent))
        {
            if(
GetEntProp(entProp_Send"m_bLocked") != 1)
            {
                
GetEntPropVector(entProp_Send"m_vecOrigin"vecLocation)
                
vecLocationCheckpoint vecLocation
            
}
        }
    }
    
    if((
StrContains(g_MapName"c2m3"false) != -1) || (StrContains(g_MapName"cm4m"false) != -1))
        return
    
    
// search for an ammo pile close to checkpoint door
    
ent = -1
    
while((ent FindEntityByClassname(ent"weapon_ammo_spawn")) != -1)
    {
        if(
IsValidEntity(ent))
        {
            
GetEntPropVector(entProp_Send"m_vecOrigin"vecLocation)
            if(
GetVectorDistance(vecLocationCheckpointvecLocationfalse) < 1000)
            {
                
vecLocationCheckpoint vecLocation
                
return
            }
        }
    }
    return
}

stock SetKitsDensity_Start()
{    
    new 
ent
    decl Float
:vecLocation[3]
    new 
iKitsStart GetConVarInt(h_KitsStart)
    new 
iKitsStartCount GetConVarInt(h_KitsStartCount)
    
    
// Find closest medkit nearby survivors start
    
ent = -1
    
while((ent FindEntityByClassname(ent"weapon_first_aid_kit_spawn")) != -1)
    {
        if(
IsValidEntity(ent))
        {
            
GetEntPropVector(entProp_Send"m_vecOrigin"vecLocation)
            
            
// If vecClosestKit is zero, then this must be the first medkit we found.
            
if((vecClosestKitStart[0] + vecClosestKitStart[1] + vecClosestKitStart[2]) == 0.0)
                
vecClosestKitStart vecLocation
            
            
// If this medkit is closer than the last medkit, record its location.
            
if(GetVectorDistance(vecLocationStartvecLocationfalse) < GetVectorDistance(vecLocationStartvecClosestKitStartfalse))
                
vecClosestKitStart vecLocation
        
}
    }
    
// Remove, replace or leave the medkits near it
    
ent = -1
    
while((ent FindEntityByClassname(ent"weapon_first_aid_kit_spawn")) != -1)
    {
        if(
IsValidEntity(ent))
        {
            
GetEntPropVector(entProp_Send"m_vecOrigin"vecLocation)
            if(
GetVectorDistance(vecClosestKitStartvecLocationfalse) < 200)
            {
                if((
StrContains(g_MapName"m1_"false) != -1) || (StrContains(g_GameMode"versus"false) != -1))
                {
                    switch(
iKitsStart)
                    {
                        case 
0:
                        {
                            break
                        }
                        case 
1:
                        {
                            if(
iKitsStartCount 4)
                            {
                                
// set medkit count (1 medkit found, 6 medkits in total)
                                
if(StrContains(g_MapName"c4m1"false) != -1)
                                {
                                    if(
iKitsStartCount 6)
                                    {
                                        
iKitsStartCount -= 5
                                    
}
                                    else if(
iKitsStartCount == 5)
                                    {
                                        
AcceptEntityInput(ent"Kill")
                                        break
                                    }
                                    else
                                    {
                                        break
                                    }
                                }
                                
// set medkit count (1 medkit found, 4 medkits in total)
                                
else
                                {
                                    
iKitsStartCount -= 3                                    
                                
}                                
                                new 
Float:fCount float(iKitsStartCount)
                                
DispatchKeyValueFloat(ent"count"fCount)
                                break
                            }
                        }
                        case 
2:
                        {
                            
AcceptEntityInput(ent"Kill")
                        }
                        case 
3:
                        {
                            
ReplaceOrAddEnt(ent"weapon_pain_pills"true)
                        }
                        case 
4:
                        {
                            
ReplaceOrAddEnt(ent"weapon_defibrillator"true)
                        }
                        case 
5:
                        {
                            
DispatchKeyValueFloat(ent"count"100.0)
                        }
                        case 
6:
                        {
                            
// replace one kit with defib and stop
                            
ReplaceOrAddEnt(ent"weapon_defibrillator"true)
                            break
                        }
                    }
                }
                else if((
StrContains(g_MapName"m1_"false) == -1) || (StrContains(g_GameMode"versus"false) != -1))
                {
                    if(
GetConVarInt(h_KitsSaferoom) == 5)
                    {
                        
DispatchKeyValueFloat(ent"count"100.0)
                    }
                }
            }
        }
    }
    return
}

stock SetKitsDensity_Saferoom()
{    
    new 
ent
    decl Float
:vecLocation[3]
    new 
iKitsSaferoom GetConVarInt(h_KitsSaferoom)
    new 
iKitsSaferoomCount GetConVarInt(h_KitsSaferoomCount)
    
    
// Find closest medkit nearby a checkpoint door
    
ent = -1
    
while((ent FindEntityByClassname(ent"weapon_first_aid_kit_spawn")) != -1)
    {
        if(
IsValidEntity(ent))
        {
            
GetEntPropVector(entProp_Send"m_vecOrigin"vecLocation)
            
// If vecClosestKit is zero, then this must be the first medkit we found.
            
if((vecClosestKitCheckpoint[0] + vecClosestKitCheckpoint[1] + vecClosestKitCheckpoint[2]) == 0.0)
                
vecClosestKitCheckpoint vecLocation
            
            
// If this medkit is closer than the last medkit, record its location.
            
if(GetVectorDistance(vecLocationCheckpointvecLocationfalse) < GetVectorDistance(vecLocationCheckpointvecClosestKitCheckpointfalse))
                
vecClosestKitCheckpoint vecLocation
        
}
    }
    
// Remove, replace or leave the medkits near it
    
ent = -1
    
while((ent FindEntityByClassname(ent"weapon_first_aid_kit_spawn")) != -1)
    {
        if(
IsValidEntity(ent))
        {
            
GetEntPropVector(entProp_Send"m_vecOrigin"vecLocation)
            if(
GetVectorDistance(vecClosestKitCheckpointvecLocationfalse) < 200)
            {
                switch(
iKitsSaferoom)
                {
                    case 
0:
                    {
                        break
                    }
                    case 
1:
                    {
                        if(
iKitsSaferoomCount 4)
                        {
                            
// set medkit count (1 medkit found, 6 medkits in total)
                            
if(StrContains(g_MapName"c4m1"false) != -1)
                            {
                                if(
iKitsSaferoomCount 6)
                                {
                                    
iKitsSaferoomCount -= 6
                                
}
                                else if(
iKitsSaferoomCount == 5)
                                {
                                    
AcceptEntityInput(ent"Kill")
                                    break
                                }
                                else
                                {
                                    break
                                }
                            }
                            
// set medkit count (1 medkit found, 4 medkits in total)
                            
else
                            {
                                
iKitsSaferoomCount -= 4                                    
                            
}
                            
// spawn medkits (above it) every second
                            
new ref EntIndexToEntRef(ent)
                            new 
Handle:datapack
                            CreateDataTimer
(1.5Timer_GraduallySpawnMedkitsdatapackTIMER_REPEAT)
                            
WritePackCell(datapackref)
                            
WritePackCell(datapackiKitsSaferoomCount)            
                            break
                        }
                    }
                    case 
2:
                    {
                        
AcceptEntityInput(ent"Kill")
                    }
                    case 
3:
                    {
                        
ReplaceOrAddEnt(ent"weapon_pain_pills"true)
                    }
                    case 
4:
                    {
                        
ReplaceOrAddEnt(ent"weapon_defibrillator"true)
                    }
                    case 
5:
                    {
                        
DispatchKeyValueFloat(ent"count"100.0)
                    }
                    case 
6:
                    {
                        
// replace one kit with defib
                        
ReplaceOrAddEnt(ent"weapon_defibrillator"true)
                        
// stop replacing anything else
                        
break
                    }
                }
            }
        }
    }
    return
}

stock SetDensity_Outdoors()
{    
    new 
ent
    decl Float
:vecLocation[3]
    new 
iKitsOutdoors GetConVarInt(h_KitsOutdoors)
    new 
iKitsOutdoorsCount GetConVarInt(h_KitsOutdoorsCount)
    
    
// Find all medkits far from a safe area
    
ent = -1
    
while((ent FindEntityByClassname(ent"weapon_first_aid_kit_spawn")) != -1)
    {
        if(
IsValidEntity(ent))
        {
            
GetEntPropVector(entProp_Send"m_vecOrigin"vecLocation)            
            
// Remove, replace or leave the medkits away from a safe area
            
if((GetVectorDistance(vecClosestKitStartvecLocationfalse) > 800) && (GetVectorDistance(vecClosestKitCheckpointvecLocationfalse) > 800))
            {
                if(!
IsLocationFar(vecLocation[0], vecLocation[1], vecLocation[2]))
                {
                    break
                }
                else
                {
                    switch(
iKitsOutdoors)
                    {
                        case 
0:
                        {
                            break
                        }
                        case 
1:
                        {
                            
// set medkit count (1 medkit found, who knows how many medkits in total)
                            
if(iKitsOutdoorsCount 1)
                            {
                                new 
Float:fCount float(iKitsOutdoorsCount)
                                
DispatchKeyValueFloat(ent"count"fCount)
                            }
                            else
                            {
                                break
                            }
                        }
                        case 
2:
                        {
                            
AcceptEntityInput(ent"Kill")
                        }
                        case 
3:
                        {
                            
ReplaceOrAddEnt(ent"weapon_pain_pills"true)
                        }
                        case 
4:
                        {
                            
ReplaceOrAddEnt(ent"weapon_defibrillator"true)
                        }
                        case 
5:
                        {
                            
DispatchKeyValueFloat(ent"count"100.0)
                        }
                    }
                }
            }
        }
    }
    return
}

stock bool:IsLocationFar(const Float:vecX, const Float:vecY, const Float:vecZ)
{
    
decl Float:vecLocation[3]
    
vecLocation[0] = vecX
    vecLocation
[1] = vecY
    vecLocation
[2] = vecZ
    
    
for(new 1<= MaxClientsi++)
    {
        if(!
IsClientConnected(i))
            continue
        if(!
IsClientInGame(i))
            continue
        if(
GetClientTeam(i) != 2)
            continue
        
        
decl Float:vecOrigin[3]
        
GetClientAbsOrigin(ivecOrigin)
        
        if(
GetVectorDistance(vecOriginvecLocationfalse) < 500)
            return 
false
    
}
    return 
true
}

stock bool:RealPlayersInGame(client)
{
    for (new 
1<= MaxClientsi++)
    {
        if (
!= client)
        {
            if (
IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i))
                return 
true
        
}
    }    
    return 
false
}

public 
Action:Timer_GraduallySpawnMedkits(Handle:timerHandle:datapack)
{
    
ResetPack(datapackfalse)
    new 
ref ReadPackCell(datapack)
    new 
count ReadPackCell(datapack)
    
    new 
ent EntRefToEntIndex(ref)
    
ReplaceOrAddEnt(ent"weapon_first_aid_kit"false)    
    
g_iCount++
    
    if(
g_iCount == count)
    {
        
g_iCount 0
        
return Plugin_Stop
    
}    
    return 
Plugin_Continue
}

stock ReplaceOrAddEnt(any:ent, const String:entname[], bool:delent)
{
    if(!
IsValidEntity(ent)) return
    
    
decl Float:vecLocation[3]
    
GetEntPropVector(entProp_Send"m_vecOrigin"vecLocation)
    new 
entCreated CreateEntityByName(entname)
    if(
entCreated != -1)
    {
        
decl Float:vecAngles[3]
        
GetEntPropVector(entProp_Send"m_angRotation"vecAngles)
        
        if((
StrContains(entname"weapon_pain_pills"false) != -1) && vecAngles[0] == 90.0)
        {
            
vecAngles[0] = 0.0
            vecLocation
[2] -= 3.0
        
}
        
        if(
StrContains(entname"weapon_first_aid_kit"false) != -1)
            
vecLocation[2] += 32.0
        
        TeleportEntity
(entCreatedvecLocationvecAnglesNULL_VECTOR)
        
DispatchSpawn(entCreated)
        
        if(
delent)
            
AcceptEntityInput(ent"Kill")
    }
    return

rtokuda is offline
ururu
Junior Member
Join Date: Dec 2020
Location: japan
Old 12-06-2020 , 23:43   Re: [L4D2] Fix for Medkit Density
Reply With Quote #2

I found the problematic code about the problem that Medkit is generated indefinitely after Round Failed and the server lags.

look this code,

PHP Code:
public evtItemPickup(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(
GetConVarBool(h_PluginEnabled))
    {
        if(!
g_bFirstItemPickedUp)
        {
            
CreateTimer(3.0Timer_DelayChangeDensity)            
            
g_bFirstItemPickedUp true
        
}
        else if(
g_bMissionLost && g_bRoundStarted)
        {
            
CreateTimer(1.0Timer_DelayChangeDensity)
        }
    }
}

public 
evtMissionLost(Handle:event, const String:name[], bool:dontBroadcast)
{
    
g_bMissionLost true
    
if(timer_DensityOutdoors != INVALID_HANDLE)
    {
        
KillTimer(timer_DensityOutdoors)
        
timer_DensityOutdoors INVALID_HANDLE
    
}

It is a code of event processing when picking up an Item and event processing when Round Fail.
After Round Failed, g_bMissionLost becomes true, but g_bFirstItemPickedUp remains true and is not reset to false.
Therefore, every time pick up Medkit in the round after failure, a timer is created that calls the function that generates Medkit after 1 second.
This causes a lag, so I replaced it with code like this on my server:
From now on, the server will not lag if the round fails.

PHP Code:
public evtItemPickup(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(
GetConVarBool(h_PluginEnabled))
    {
        if(!
g_bFirstItemPickedUp)
        {
            
CreateTimer(0.1Timer_DelayChangeDensity)            
            
g_bFirstItemPickedUp true
        
}
    }
}

public 
evtMissionLost(Handle:event, const String:name[], bool:dontBroadcast)
{
    
g_bFirstItemPickedUp false
    
if(timer_DensityOutdoors != INVALID_HANDLE)
    {
        
KillTimer(timer_DensityOutdoors)
        
timer_DensityOutdoors INVALID_HANDLE
    
}

To be honest, I wasn't sure why to use g_bMissionLost.
So I removed the branch using g_bMissionLost.
I haven't thoroughly tested it in detail, so there may be problems, but i hope it helps you.

btw, I'm not very familiar with Sourcemod plugin development so I'm not sure about precaches causing crashes =_=

And I'm not very good at English, so I'm sorry if I have strange English.
ururu is offline
Lukey1028
Junior Member
Join Date: Jun 2019
Old 02-25-2021 , 22:43   Re: Recompiled Plugin
Reply With Quote #3

I DO NOT claim any ownership of the attached plugin. I am not claiming any credit for the updated code to fix server crashing. I am only uploading this here to help people who do not wish to recompile the plugin themselves. All credit to original plugin maker(s) and code fixer(s). Thanks.
Attached Files
File Type: smx l4d2medkitdensity.smx (9.1 KB, 117 views)
Lukey1028 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 02-26-2021 , 05:59   Re: [L4D2] Fix for Medkit Density
Reply With Quote #4

@Lukey1028, upload source file at least.
Bacardi is offline
ururu
Junior Member
Join Date: Dec 2020
Location: japan
Old 04-29-2021 , 07:42   Re: [L4D2] Fix for Medkit Density
Reply With Quote #5

my version
Attached Files
File Type: sp Get Plugin or Get Source (l4d2medkitdensity.sp - 343 views - 18.6 KB)
ururu is offline
bald14
Member
Join Date: Aug 2021
Old 09-25-2021 , 14:10   Re: [L4D2] Fix for Medkit Density
Reply With Quote #6

Quote:
// What to do with medkits in saferooms? 0[do nothing] 1[use sm_md_checkpoint_medkitcount] 2[remove medkits] 3[replace with pills] 4[replace with defibrillators] 5[replace 1 medkit with 1 defibrillator]
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "5.000000"
sm_md_saferoom "3"
Can someone develop it to replace 1 or 2 medkits as pill ? It's just that I wish at the saferoom there would be 2 medkits and 2 pills .
bald14 is offline
caphao1101
Junior Member
Join Date: Aug 2023
Location: HaNoi
Old 11-27-2023 , 10:54   Re: [L4D2] Fix for Medkit Density
Reply With Quote #7

Quote:
Originally Posted by ururu View Post
my version
Is there any way to change the entire medkit (outdoor) + medicine cabinet into Pain pills? Hope you respond
caphao1101 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:11.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode