Senior Member
Join Date: Sep 2015
Location: Location:
|
01-08-2020
, 09:26
Re: [L4D2] Hybrid SP-VScript to fix weapons and medkits for 5+ survivor
|
#4
|
Ah, I made my own plugin that spawns extra first aid kits for each survivor, but it seems you're beating me to it with adjusting the weapon count as well.
Here's the source code of my plugin:
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#pragma newdecls required
#pragma semicolon 1
#define PLUGIN_NAME_SHORT "First Aid Manager"
#define PLUGIN_NAME "[L4D2] First Aid Manager"
#define PLUGIN_AUTHOR "Shadowysn"
#define PLUGIN_DESC "Manage the amount of first aid kits spawned for survivors."
#define PLUGIN_VERSION "1.0.2"
#define PLUGIN_URL "tobeadded"
#define PLUGIN_TARGETNAME "f_aid_manager_plugin"
#define CFG "l4d_firstaid_manager"
#define MDL_FIRSTAID "models/w_models/weapons/w_eq_medkit.mdl"
ConVar version_cvar = null;
//ConVar Manager_AllowOnInitialStart = null;
ConVar Manager_TimeLimit = null;
ConVar Manager_Multiply = null;
ConVar Manager_FinaleMultiply = null;
//ConVar Manager_ManageType = null;
//ConVar Manager_FinaleManageType = null;
ConVar Manager_ForEachSurvivorOnSurvivor = null;
ConVar Manager_ForEachSurvivorOnMedkit = null;
ConVar Manager_ForEachMedkit = null;
static int survivorCount = 0;
//static bool mustSetCloneMedkit = false;
//static bool isCloneMedkit[2048] = false;
//static Handle registeredPositions[2048] = null;
static bool hasRoundEnded = false;
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
if(GetEngineVersion() == Engine_Left4Dead2)
{
return APLRes_Success;
}
strcopy(error, err_max, "Plugin only supports Left 4 Dead 2.");
return APLRes_SilentFailure;
}
public Plugin myinfo =
{
name = PLUGIN_NAME,
author = PLUGIN_AUTHOR,
description = PLUGIN_DESC,
version = PLUGIN_VERSION,
url = PLUGIN_URL
}
public void OnPluginStart()
{
char cvar_str[500];
Format(cvar_str, sizeof(cvar_str), "%s plugin version.", PLUGIN_NAME_SHORT);
version_cvar = CreateConVar("sm_firstaid_manager", PLUGIN_VERSION, cvar_str, 0|FCVAR_NOTIFY|FCVAR_REPLICATED|FCVAR_DONTRECORD);
if(version_cvar != null)
SetConVarString(version_cvar, PLUGIN_VERSION);
//Format(cvar_str, sizeof(cvar_str), "Should the %s plugin spawn medkits on initial map start?", PLUGIN_NAME_SHORT);
//Manager_AllowOnInitialStart = CreateConVar("sm_faid_manager_start", "1.0", cvar_str, FCVAR_ARCHIVE, true, 0.0, true, 1.0);
Format(cvar_str, sizeof(cvar_str), "The delay before the %s plugin registers survivors and spawns medkits.", PLUGIN_NAME_SHORT);
Manager_TimeLimit = CreateConVar("sm_faid_manager_delay", "1.0", cvar_str, FCVAR_ARCHIVE, true, 0.5, false, 100.0);
Format(cvar_str, sizeof(cvar_str), "Excluding finales, the number for the %s plugin to multiply by.", PLUGIN_NAME_SHORT);
Manager_Multiply = CreateConVar("sm_faid_manager_multiply", "1.0", cvar_str, FCVAR_ARCHIVE, true, 1.0, false, 20.0);
Format(cvar_str, sizeof(cvar_str), "For finales, the number for the %s plugin to multiply by.", PLUGIN_NAME_SHORT);
Manager_FinaleMultiply = CreateConVar("sm_faid_manager_multiply_finale", "2.0", cvar_str, FCVAR_ARCHIVE, true, 1.0, false, 20.0);
//char type_str[] = "0 = Spawn for each survivor, on survivor. 1 = Spawn for each survivor, on medkit spawns. 2 = Spawn for each medkit spawn. 3 = Spawn for each survivor, doubled on both survivor and medkit spawn.";
//Format(cvar_str, sizeof(cvar_str), "Excluding finales, what type of spawning should the %s plugin use? %s", PLUGIN_NAME_SHORT, type_str);
//Manager_ManageType = CreateConVar("sm_faid_manager_type", "0.0", cvar_str, FCVAR_ARCHIVE, true, 0.0, true, 3.0);
//Format(cvar_str, sizeof(cvar_str), "For finales, what type of spawning should the %s plugin use? %s", PLUGIN_NAME_SHORT, type_str);
//Manager_FinaleManageType = CreateConVar("sm_faid_manager_type_finale", "3.0", cvar_str, FCVAR_ARCHIVE, true, 0.0, true, 3.0);
char type_str[] = "0 = Don't enable. 1 = Enable, excluding finales. 2 = Enable, only finales. 3 = Enable for both.";
Format(cvar_str, sizeof(cvar_str), "Toggle %s's 'Spawn for each survivor, on survivor' method. %s", PLUGIN_NAME_SHORT, type_str);
Manager_ForEachSurvivorOnSurvivor = CreateConVar("sm_faid_manager_mode_1", "3.0", cvar_str, FCVAR_ARCHIVE, true, 0.0, true, 3.0);
Format(cvar_str, sizeof(cvar_str), "Toggle %s's 'Spawn for each survivor, on medkit spawns' method. %s", PLUGIN_NAME_SHORT, type_str);
Manager_ForEachSurvivorOnMedkit = CreateConVar("sm_faid_manager_mode_2", "2.0", cvar_str, FCVAR_ARCHIVE, true, 0.0, true, 3.0);
Format(cvar_str, sizeof(cvar_str), "Toggle %s's 'Spawn for each medkit spawn' method. %s", PLUGIN_NAME_SHORT, type_str);
Manager_ForEachMedkit = CreateConVar("sm_faid_manager_mode_3", "0.0", cvar_str, FCVAR_ARCHIVE, true, 0.0, true, 3.0);
//HookEvent("game_init", game_init, EventHookMode_PostNoCopy);
HookEvent("player_spawn", player_spawn, EventHookMode_Post);
HookEvent("round_end", round_end, EventHookMode_PostNoCopy);
AutoExecConfig(true, CFG);
}
public void OnMapStart()
{
//if (GetConVarBool(Manager_AllowOnInitialStart)) hasRoundEnded = true;
hasRoundEnded = true;
if (!IsModelPrecached(MDL_FIRSTAID)) PrecacheModel(MDL_FIRSTAID, true);
}
public void player_spawn(Handle event, const char[] name, bool dontBroadcast)
{
//PrintToServer("%s plugin detected event: %s", PLUGIN_NAME_SHORT, name);
if (!hasRoundEnded) return;
int clientID = GetEventInt(event, "userid");
int client = GetClientOfUserId(clientID);
if (!IsValidClient(client) || !IsSurvivor(client)) return;
hasRoundEnded = false;
ManageFirstAidFunction();
}
public void round_end(Handle event, const char[] name, bool dontBroadcast)
{
//PrintToServer("%s plugin detected event: %s", PLUGIN_NAME_SHORT, name);
hasRoundEnded = true;
}
bool IsValidClient(int client, bool replaycheck = true)
{
if (!IsValidEntity(client)) return false;
if (client <= 0 || client > MaxClients) return false;
if (!IsClientInGame(client)) return false;
//if (GetEntProp(client, Prop_Send, "m_bIsCoaching")) return false;
if (replaycheck)
{
if (IsClientSourceTV(client) || IsClientReplay(client)) return false;
}
return true;
}
bool IsSurvivor(int client)
{
if (!IsValidClient(client)) return false;
if (GetClientTeam(client) == 2) return true;
return false;
}
void SpawnFirstAidKit(int entity)
{
if (!IsValidEntity(entity)) return;
float fPos[3];
float fAng[3];
if (IsValidClient(entity))
{
GetClientAbsOrigin(entity, fPos);
GetClientAbsAngles(entity, fAng);
fPos[2] += 10;
}
else
{
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", fPos);
GetEntPropVector(entity, Prop_Send, "m_angRotation", fAng);
}
int first_aid_kit = CreateEntityByName("weapon_first_aid_kit_spawn");
TeleportEntity(first_aid_kit, fPos, fAng, NULL_VECTOR);
DispatchKeyValue(first_aid_kit, "model", MDL_FIRSTAID);
DispatchKeyValue(first_aid_kit, "spawnflags", "3");
DispatchSpawn(first_aid_kit);
ActivateEntity(first_aid_kit);
char name_str[64];
Format(name_str, sizeof(name_str), "%s%i", PLUGIN_TARGETNAME, EntRefToEntIndex(first_aid_kit));
DispatchKeyValue(first_aid_kit, "targetname", name_str);
//SetVariantString("weapon_first_aid_kit");
/*DispatchKeyValue(first_aid_kit, "classname", "weapon_first_aid_kit"); // This will fill the edict slots with garbage and potentially crash the game
SetVariantString("OnUser1 !self:AddOutput:classname weapon_first_aid_kit_spawn:0.5:1");
AcceptEntityInput(first_aid_kit, "AddOutput");
AcceptEntityInput(first_aid_kit, "FireUser1");*/
//if (mustSetCloneMedkit)
//{ isCloneMedkit[first_aid_kit] = true; }
}
void RegisterSurvivors()
{
survivorCount = 0;
for (int client = 1; client <= MAXPLAYERS; client++) {
if (!IsValidClient(client)) continue;
if (!IsSurvivor(client)) continue;
survivorCount += 1;
}
}
int GetFirstSurvivor()
{
int firstClient = -1;
for (int client = 1; client <= MAXPLAYERS; client++) {
if (!IsValidClient(client)) continue;
if (!IsSurvivor(client)) continue;
if (!IsValidClient(firstClient))
{ firstClient = client; break; }
}
return firstClient;
}
void FirstAidAction(int special_Num = 0, int multi_Num = 1)
{
if (special_Num == 2)
{
for (int i = -1; i < GetMaxEntities(); i++)
{
if (!IsValidEntity(i)) continue;
char class[64];
GetEntityClassname(i, class, sizeof(class));
char name_str[64];
GetEntPropString(i, Prop_Data, "m_iName", name_str, sizeof(name_str));
if (!StrEqual(class, "weapon_first_aid_kit_spawn") || StrContains(name_str, PLUGIN_TARGETNAME, false) > -1) continue;
SpawnFirstAidKit(i);
}
}
else if (special_Num == 1)
{
survivorCount -= 4;
if (multi_Num > 1) survivorCount *= multi_Num;
for (int i = -1; i < GetMaxEntities(); i++)
{
if (survivorCount <= 0) break;
if (!IsValidEntity(i)) continue;
char class[64];
GetEntityClassname(i, class, sizeof(class));
char name_str[64];
GetEntPropString(i, Prop_Data, "m_iName", name_str, sizeof(name_str));
if (!StrEqual(class, "weapon_first_aid_kit_spawn") || StrContains(name_str, PLUGIN_TARGETNAME, false) > -1) continue;
SpawnFirstAidKit(i);
survivorCount -= 1;
}
//for (int i = 0; i < sizeof(isCloneMedkit); i++)
//{ isCloneMedkit[i] = false; }
//mustSetCloneMedkit = true;
/*int base_Ent = FindEntityByClassname(-1, "weapon_first_aid_kit_spawn");
for (int i = 4; i < (survivorCount*2); i++)
{
if (IsValidEntity(base_Ent))
{
int temp = FindEntityByClassname(base_Ent, "weapon_first_aid_kit_spawn");
if (!IsValidEntity(temp))
{ temp = FindEntityByClassname(-1, "weapon_first_aid_kit_spawn"); }
//if (isCloneMedkit[temp])
//{ temp = FindEntityByClassname(temp, "weapon_first_aid_kit_spawn"); }
base_Ent = temp;
}
if (!IsValidEntity(base_Ent)) continue;
SpawnFirstAidKit(base_Ent);
}*/
//mustSetCloneMedkit = false;
}
else
{
survivorCount -= 4;
if (multi_Num > 1) survivorCount *= multi_Num;
//PrintToServer("%i", survivorCount);
int entity = GetFirstSurvivor();
if (!IsValidClient(entity) || !IsSurvivor(entity)) return;
for (int i = 0; i < survivorCount; i++)
{
SpawnFirstAidKit(entity);
}
}
}
//void FirstAidManage(int client)
Action FirstAidManage(Handle timer)
{
RegisterSurvivors();
if (survivorCount <= 4) return;
int finale_ent = FindEntityByClassname(-1, "trigger_finale");
//int cvar_int = GetConVarInt(Manager_ManageType);
//int finale_cvar_int = GetConVarInt(Manager_FinaleManageType);
int mode_1 = GetConVarInt(Manager_ForEachSurvivorOnSurvivor);
int mode_2 = GetConVarInt(Manager_ForEachSurvivorOnMedkit);
int mode_3 = GetConVarInt(Manager_ForEachMedkit);
bool isFinale = IsValidEntity(finale_ent);
//bool useSpecial_1 = (isFinale && finale_cvar_int >= 1) || (!isFinale && cvar_int >= 1);
//bool useSpecial_2 = (isFinale && finale_cvar_int >= 2) || (!isFinale && cvar_int >= 2);
//bool useSpecial_3 = (isFinale && finale_cvar_int >= 3) || (!isFinale && cvar_int >= 3);
bool useMode_1 = (mode_1 >= 3) || (isFinale && mode_1 == 2) || (!isFinale && mode_1 & 1);
bool useMode_2 = (mode_2 >= 3) || (isFinale && mode_2 == 2) || (!isFinale && mode_2 & 1);
bool useMode_3 = (mode_3 >= 3) || (isFinale && mode_3 == 2) || (!isFinale && mode_3 & 1);
int multi_Num = RoundToFloor(isFinale ? GetConVarFloat(Manager_FinaleMultiply) : GetConVarFloat(Manager_Multiply));
//if (useSpecial_3)
//{
// FirstAidAction(0, multi_Num);
// RegisterSurvivors();
// FirstAidAction(1, multi_Num);
//}
//else if (useSpecial_2)
//{ FirstAidAction(2, multi_Num); }
//else if (useSpecial_1)
//{ FirstAidAction(1, multi_Num); }
//else
//{ FirstAidAction(0, multi_Num); }
if (useMode_1)
{ FirstAidAction(0, multi_Num); }
if (useMode_2)
{ FirstAidAction(1, multi_Num); }
if (useMode_3)
{ FirstAidAction(2, multi_Num); }
//int first_aid_kit = GetNearestEntity(entity, "weapon_first_aid_kit_spawn");
//if (!IsValidEntity(first_aid_kit)) return;
}
void ManageFirstAidFunction()
{
if (Manager_TimeLimit != null)
{
float delay = GetConVarFloat(Manager_TimeLimit);
CreateTimer(delay, FirstAidManage);
}
else
{ CreateTimer(1.0, FirstAidManage); }
}
/*int GetNearestEntity(int client, const char[] classname)
{
//Get the first entity
int nearestEntity = FindEntityByClassname(entity, classname);
if (!IsValidEntity(nearestEntity))
{
return -1;
}
float clientVecOrigin[3], entityVecOrigin[3];
GetEntPropVector(client, Prop_Data, "m_vecOrigin", clientVecOrigin);
GetEntPropVector(nearestEntity, Prop_Data, "m_vecOrigin", entityVecOrigin);
//Get the distance between the first entity and client
float distance, nearestDistance = GetVectorDistance(clientVecOrigin, entityVecOrigin);
//Find all the entity and compare the distances
int entity = -1;
while (entity = FindEntityByClassname(entity, classname) != -1)
{
GetEntPropVector(entity, Prop_Data, "m_vecOrigin", entityVecOrigin);
distance = GetVectorDistance(clientVecOrigin, entityVecOrigin);
if (distance < nearestDistance)
{
nearestEntity = entity;
nearestDistance = distance;
}
}
return nearestEntity;
}*/
__________________
|
|