Minor fixes

This commit is contained in:
Jackzie 2021-03-18 10:51:21 -05:00
parent 3c2faf7792
commit 58133cabf8
No known key found for this signature in database
GPG key ID: 1E834FE36520537A
6 changed files with 93 additions and 97 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -20,8 +20,6 @@ int g_icPlayerManager; //entid -> typically 25 (MaxClients+1)
bool g_icHealing[MAXPLAYERS+1]; //state
bool g_icBeingHealed[MAXPLAYERS+1]; //state
ConVar g_icCouponCode, g_icCouponCoins;
public Plugin myinfo =
{
name = PLUGIN_NAME,
@ -52,23 +50,13 @@ public OnPluginStart()
FindConVar("z_difficulty").GetString(g_icDifficulty, sizeof(g_icDifficulty));
ConVar ic_gamemode = FindConVar("mp_gamemode");
ic_gamemode.GetString(g_icGamemode, sizeof(g_icGamemode));
if (ic_gamemode != null) ic_gamemode.AddChangeHook(Event_GamemodeChange);
ic_gamemode.AddChangeHook(Event_GamemodeChange);
GetCurrentMap(g_icCurrentMap, sizeof(g_icCurrentMap));
AutoExecConfig();
//setup advertisement
CreateConVar("l4d2_gameinfo_version", PLUGIN_VERSION, "plugin version", FCVAR_SPONLY | FCVAR_DONTRECORD);
g_icCouponCode = CreateConVar("l4d2_gameinfo_code","","Provide a coupon code");
g_icCouponCoins = CreateConVar("l4d2_gameinfo_coins","0","Provide a coupon code's zekoins", FCVAR_NONE, true, 0.0);
CreateTimer(400.0, Timer_PrintInfoMessage, _, TIMER_REPEAT);
}
// print info
public Action Timer_PrintInfoMessage(Handle timer)
{
PrintToChatAll("This is the Manual Director server. Access the panel, and info about the server at l4d2.jackz.me");
return Plugin_Continue;
}
public Action PrintGameInfo(int client, int args) {
//print server info
ReplyToCommand(client, ">map,diff,mode,tempoState,totalSeconds");
@ -76,8 +64,15 @@ public Action PrintGameInfo(int client, int args) {
int tempoState = GetEntProp(g_icPlayerManager, Prop_Send, "m_tempoState", 1);
ReplyToCommand(client, "%s,%s,%s,%d,%d",g_icCurrentMap,g_icDifficulty,g_icGamemode,tempoState,missionDuration);
//print client info
ReplyToCommand(client,">id,name,bot,health,status,throwSlot,kitSlot,pillSlot,modelName,velocity");
for (int i = 1; i < MaxClients;i++) {
ReplyToCommand(client,">id,name,bot,health,status,throwSlot,kitSlot,pillSlot,survivorType,velocity,primaryWpn,secondaryWpn");
char status[9];
char name[32];
char pillItem[32];
char kitItem[32];
char throwItem[32];
char character[9];
char primaryWeapon[32], secondaryWeapon[32];
for (int i = 1; i <= MaxClients; i++) {
if (!IsClientInGame(i)) continue;
if (GetClientTeam(i) != 2) continue;
int hp = GetClientRealHealth(i);
@ -87,13 +82,6 @@ public Action PrintGameInfo(int client, int args) {
bool blackandwhite = GetEntProp(i, Prop_Send, "m_bIsOnThirdStrike", 1) == 1;
int velocity = RoundFloat(GetPlayerSpeed(i));
char status[9];
char name[32];
char pillItem[32];
char kitItem[32];
char throwItem[32];
char character[9];
if(hp < 0) {
status = "dead";
}else if(incap) {
@ -109,14 +97,24 @@ public Action PrintGameInfo(int client, int args) {
}else{
status = "alive";
}
primaryWeapon[0] = '\0';
throwItem[0] = '\0';
kitItem[0] = '\0';
pillItem[0] = '\0';
GetItemSlotClassName(i, 0, primaryWeapon, sizeof(primaryWeapon), true);
GetItemSlotClassName(i, 1, secondaryWeapon, sizeof(secondaryWeapon), true);
GetItemSlotClassName(i, 2, throwItem, sizeof(throwItem), true);
GetItemSlotClassName(i, 3, kitItem, sizeof(kitItem), true);
GetItemSlotClassName(i, 4, pillItem, sizeof(pillItem), true);
/*if(StrEqual(secondaryWeapon, "melee", true)) {
GetMeleeWeaponName()
}*/
GetClientName(i, name, sizeof(name));
GetModelName(i, character, sizeof(character));
ReplyToCommand(client,"%d,%s,%d,%d,%s,%s,%s,%s,%s,%d", i, name, bot, hp, status, throwItem, kitItem, pillItem, character, velocity);
ReplyToCommand(client,"%d,%s,%d,%d,%s,%s,%s,%s,%s,%d,%s,%s", i, name, bot, hp, status, throwItem, kitItem, pillItem, character, velocity, primaryWeapon, secondaryWeapon);
}
}
@ -167,18 +165,6 @@ public PlayerManager_OnThinkPost(int playerManager) {
if (++g_ichuddelay >= 10) g_ichuddelay = 0;
}
#endif
public OnClientPutInServer(client)
{
PrintToChat(client, "Welcome to the Manual Director server! For information or access the panel go to l4d2.jackz.me.");
char coupon[9];
g_icCouponCode.GetString(coupon, sizeof(coupon));
if(strlen(coupon) > 0) {
char coins[32] = "free";
if (g_icCouponCoins.IntValue > 0) IntToString(g_icCouponCoins.IntValue, coins, sizeof(coins));
PrintToChat(client, "Signup with redemption code '%s' for %s initial coins", coupon, coins);
}
}
// METHODS //
stock float GetPlayerSpeed(int client) {
int iVelocity = FindSendPropInfo("CTerrorPlayer", "m_vecVelocity[0]");

View file

@ -107,7 +107,7 @@ public Action Command_SpawnMinigunBot(int client, int args) {
vPos[2] += 1.0;
int survivor = SpawnSurvivor(vPos, vAng, model, true);
if(survivor > -1) {
if(survivor > 0) {
GiveClientWeapon(survivor, "rifle_ak47", true);
}else{
ReplyToCommand(client, "Failed to spawn survivor.");
@ -151,7 +151,7 @@ public Action Command_SpawnHoldoutBot(int client, int args) {
}
int survivor = SpawnSurvivor(vPos, vAng, model, false);
if(survivor > -1) {
if(survivor > 0) {
GiveClientWeapon(survivor, wpn, true);
SetEntProp(survivor, Prop_Send, "m_survivorCharacter", survivorId);
}else{
@ -200,20 +200,16 @@ stock int SpawnSurvivor(const float vPos[3], const float vAng[3], const char[] m
LogError("Failed to match survivor, did they not spawn? [%d/%d]", bot_user_id, bot_client_id);
return -1;
}
if(spawn_minigun) SetClientName(bot_client_id, "MinigunBot");
else SetClientName(bot_client_id, "HoldoutBot");
TeleportEntity(bot_client_id, vPos, NULL_VECTOR, NULL_VECTOR);
if(spawn_minigun && !SpawnMinigun(vPos, vAng)) {
LogError("Failed to spawn minigun for client #%d", bot_client_id);
KickClient(bot_client_id, "AIMinigun:MinigunSpawnFailure");
return -1;
}
SetClientName(bot_client_id, spawn_minigun ? "MinigunBot" : "HoldoutBot");
TeleportEntity(bot_client_id, vPos, NULL_VECTOR, NULL_VECTOR);
SetEntityModel(bot_client_id, model); //set entity model to custom survivor model
//probably return user_id?
return bot_client_id;
return bot_user_id;
}
void AvoidCharacter(int type, bool avoid) {
for( int i = 1; i <= MaxClients; i++ )

View file

@ -42,12 +42,12 @@ public void OnPluginStart() {
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("round_end", Event_RoundEnd);
HookEvent("heal_success", Event_HealFinished);
HookEvent("map_transition", Event_MapTransition);
HookEvent("game_start", Event_GameStart);
HookEvent("round_end", Event_RoundEnd);
HookEvent("heal_success", Event_HealFinished);
HookEvent("map_transition", Event_MapTransition);
HookEvent("game_start", Event_GameStart);
hExtraItemBasePercentage = CreateConVar("l4d2_extraitem_chance", "0.056", "The base chance (multiplied by player count) of an extra item being spawned.", FCVAR_NONE, true, 0.0, true, 1.0);
hAddExtraKits = CreateConVar("l4d2_extraitems_kitmode", "0", "Decides how extra kits should be added.\n0 -> Overwrites previous extra kits, 1 -> Adds onto previous extra kits", FCVAR_NONE, true, 0.0, true, 1.0);
@ -107,51 +107,58 @@ public Action Event_GameStart(Event event, const char[] name, bool dontBroadcast
firstGiven = false;
extraKitsAmount = 0;
extraKitsStarted = 0;
abmExtraCount = 4;
hMinPlayers.IntValue = 4;
}
public Action Event_PlayerFirstSpawn(Event event, const char[] name, bool dontBroadcast) {
int client = GetClientOfUserId(event.GetInt("userid"));
if(GetClientTeam(client) == 2 && !IsFakeClient(client)) {
if(L4D_IsFirstMapInScenario()) {
//Check if all clients are ready, and survivor count is > 4.
abmExtraCount = GetSurvivorsCount();
if(AreAllClientsReady() && abmExtraCount > 4 && !firstGiven) {
firstGiven = true;
//Set the initial value ofhMinPlayers
if(hUpdateMinPlayers.BoolValue && hMinPlayers != null) {
hMinPlayers.IntValue = abmExtraCount;
if(AreAllClientsReady() && !firstGiven) {
abmExtraCount = GetRealSurvivorsCount();
if(abmExtraCount > 4) {
firstGiven = true;
//Set the initial value ofhMinPlayers
if(hUpdateMinPlayers.BoolValue && hMinPlayers != null) {
hMinPlayers.IntValue = abmExtraCount;
}
CreateTimer(1.0, Timer_GiveKits);
}
CreateTimer(1.0, Timer_GiveKits);
}
//TODO: Some logic to give extra kits on round failure on first map?
//Give kit if first map and kits given
if(firstGiven) {
}else if(firstGiven) {
RequestFrame(Frame_GiveNewClientKit, client);
}
}else {
//CreateTimer(1.0, Timer_UpdateMinPlayers);
RequestFrame(Frame_GiveNewClientKit, client);
}
}
}
public void Frame_GiveNewClientKit(int client) {
if(!DoesClientHaveKit(client)) {
if(!DoesClientHaveKit(client) && GetRealSurvivorsCount() > 4) {
CheatCommand(client, "give", "first_aid_kit", "");
}
}
public void Frame_GiveClientKit(int client) {
if(!DoesClientHaveKit(client)) {
public Action Timer_GiveClientKit(Handle hdl, int user) {
int client = GetClientOfUserId(user);
if(client > 0 && !DoesClientHaveKit(client)) {
UseExtraKit(client);
}
}
public Action Timer_UpdateMinPlayers(Handle hdl) {
//Set abm's min players to the amount of real survivors. Ran AFTER spawned incase they are pending joining
if(!hUpdateMinPlayers.BoolValue) return;
int newPlayerCount = abmExtraCount + 1;
if(hMinPlayers != null && newPlayerCount > 4 && hMinPlayers.IntValue < newPlayerCount && newPlayerCount < 18) {
abmExtraCount = newPlayerCount;
#if defined DEBUG
PrintToServer("update abm_minplayers -> %d", abmExtraCount);
#endif
hMinPlayers.IntValue = abmExtraCount;
int newPlayerCount = GetRealSurvivorsCount();
if(hUpdateMinPlayers.BoolValue && hMinPlayers != null) {
if(newPlayerCount > 4 && hMinPlayers.IntValue < newPlayerCount && newPlayerCount < 18) {
abmExtraCount = newPlayerCount;
#if defined DEBUG
PrintToServer("update abm_minplayers -> %d", abmExtraCount);
#endif
hMinPlayers.IntValue = abmExtraCount;
}
}
}
@ -159,9 +166,10 @@ public Action Timer_GiveKits(Handle timer) { GiveStartingKits(); }
//Provide extra kits when a player spawns (aka after a map transition)
public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast) {
int client = GetClientOfUserId(event.GetInt("userid"));
int user = event.GetInt("userid");
int client = GetClientOfUserId(user);
if(GetClientTeam(client) == 2) {
RequestFrame(Frame_GiveClientKit, client);
CreateTimer(0.5, Timer_GiveClientKit, user);
}
}
@ -177,7 +185,7 @@ public void OnMapStart() {
isFailureRound = false;
}else if(!L4D_IsFirstMapInScenario()) {
//Re-set value incase it reset.
hMinPlayers.IntValue = abmExtraCount;
//hMinPlayers.IntValue = abmExtraCount;
}
if(!isLateLoaded) {
CreateTimer(30.0, Timer_AddExtraCounts);
@ -188,21 +196,19 @@ public void OnMapStart() {
HookEntityOutput("trigger_changelevel", "OnStartTouch", EntityOutput_OnStartTouchSaferoom);
}
public void EntityOutput_OnStartTouchSaferoom(const char[] output, int caller, int client, float time) {
if(client > 0 && client <= MaxClients && !isCheckpointReached && IsValidClient(client) && GetClientTeam(client) == 2){
isCheckpointReached = true;
if(!isCheckpointReached && client > 0 && client <= MaxClients && IsValidClient(client) && GetClientTeam(client) == 2) {
isCheckpointReached = true;
int extraPlayers = GetSurvivorsCount() - 4;
#if defined DEBUG
PrintToConsoleAll("CHECKPOINT REACHED BY %N | EXTRA KITS: %d", client, extraPlayers);
#endif
float averageTeamHP = getAverageHP();
if(averageTeamHP <= 30) extraPlayers += extraPlayers; //if perm. health < 30, give an extra 4 on top of the extra
else if(averageTeamHP <= 50) ++extraPlayers; //if the team's average health is less than 50 (permament) then give another
//Chance to get 1-2 extra kits (might need to be nerfed or restricted to > 50 HP)
if(GetRandomFloat() < 0.5) ++extraPlayers;
if(GetRandomFloat() < 0.2) ++extraPlayers;
if(extraPlayers > 0) {
#if defined DEBUG
PrintToConsoleAll("CHECKPOINT REACHED BY %N | EXTRA KITS: %d", client, extraPlayers);
#endif
float averageTeamHP = GetAverageHP();
if(averageTeamHP <= 30) extraPlayers += extraPlayers; //if perm. health < 30, give an extra 4 on top of the extra
else if(averageTeamHP <= 50) ++extraPlayers; //if the team's average health is less than 50 (permament) then give another
//Chance to get 1-2 extra kits (might need to be nerfed or restricted to > 50 HP)
if(GetRandomFloat() < 0.5) ++extraPlayers;
if(GetRandomFloat() < 0.2) ++extraPlayers;
//If hAddExtraKits TRUE: Append to previous, FALSE: Overwrite
@ -229,7 +235,7 @@ public Action Event_MapTransition(Event event, const char[] name, bool dontBroad
PrintToServer("Map transition | Extra Kits Left %d | Starting Amount %d", extraKitsAmount, extraKitsStarted);
#endif
extraKitsStarted = extraKitsAmount;
abmExtraCount = GetSurvivorsCount();
abmExtraCount = GetRealSurvivorsCount();
}
@ -253,7 +259,7 @@ public Action Event_HealFinished(Event event, const char[] name, bool dontBroadc
Prioritize first aid kits somehow? Or split two groups: "utility" (throwables, kits, pill/shots), and "weapon" (all other spawns)
*/
public Action Timer_AddExtraCounts(Handle hd) {
int survivors = GetSurvivorsCount();
int survivors = GetRealSurvivorsCount();
if(survivors <= 4) return;
float percentage = hExtraItemBasePercentage.FloatValue * survivors;
@ -288,11 +294,9 @@ public Action Timer_AddExtraCounts(Handle hd) {
////////////////////////////////////
stock void GiveStartingKits() {
int skipLeft = 4, realPlayersCount = 0;
for(int i = 1; i < MaxClients + 1; i++) {
int skipLeft = 4;
for(int i = 1; i <= MaxClients; i++) {
if(IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == 2) {
if(!IsFakeClient(i))
++realPlayersCount;
//Skip at least the first 4 players, as they will pickup default kits.
//If player somehow already has it ,also skip them.
if(skipLeft > 0 || DoesClientHaveKit(i)) {
@ -308,7 +312,17 @@ stock void GiveStartingKits() {
stock int GetSurvivorsCount() {
int count = 0;
for(int i = 1; i <= MaxClients; i++) {
if(IsClientConnected(i) && IsClientInGame(i) && GetClientTeam(i) == 2 ) {
if(IsClientConnected(i) && IsClientInGame(i) && GetClientTeam(i) == 2) {
++count;
}
}
return count;
}
stock int GetRealSurvivorsCount() {
int count = 0;
for(int i = 1; i <= MaxClients; i++) {
if(IsClientConnected(i) && IsClientInGame(i) && GetClientTeam(i) == 2 && !IsFakeClient(i)) {
++count;
}
}
@ -326,7 +340,7 @@ stock bool AreAllClientsReady() {
stock bool DoesClientHaveKit(int client) {
char wpn[32];
if(GetClientWeaponName(client, 3, wpn, sizeof(wpn))) {
if(IsClientConnected(client) && IsClientInGame(client) && GetClientWeaponName(client, 3, wpn, sizeof(wpn))) {
if(StrEqual(wpn, "weapon_first_aid_kit")) {
return true;
}
@ -346,7 +360,7 @@ stock void UseExtraKit(int client) {
}
}
stock float getAverageHP() {
stock float GetAverageHP() {
int totalHP, clients;
for(int i = 1; i <= MaxClients; i++) {
if(IsClientConnected(i) && IsClientInGame(i) && GetClientTeam(i) == 2 && IsPlayerAlive(i)) {
@ -354,5 +368,5 @@ stock float getAverageHP() {
++clients;
}
}
return totalHP / clients;
return float(totalHP) / float(clients);
}