Minor changes

This commit is contained in:
Jackzie 2024-11-14 08:56:04 -06:00
parent e54f7aa61a
commit 247dca0087
6 changed files with 92 additions and 83 deletions

Binary file not shown.

View file

@ -585,14 +585,12 @@ bool CheckBlacklist(int entity) {
return false; return false;
} }
} }
if(StrContains(buffer, "prop_") > -1) {
GetEntPropString(entity, Prop_Data, "m_ModelName", buffer, sizeof(buffer)); GetEntPropString(entity, Prop_Data, "m_ModelName", buffer, sizeof(buffer));
for(int i = 0; i < MAX_FORBIDDEN_MODELS; i++) { for(int i = 0; i < MAX_FORBIDDEN_MODELS; i++) {
if(StrEqual(FORBIDDEN_MODELS[i], buffer)) { if(StrEqual(FORBIDDEN_MODELS[i], buffer)) {
return false; return false;
} }
} }
}
GetEntPropString(entity, Prop_Data, "m_iName", buffer, sizeof(buffer)); GetEntPropString(entity, Prop_Data, "m_iName", buffer, sizeof(buffer));
if(StrContains(buffer, "randomizer") == 0) { if(StrContains(buffer, "randomizer") == 0) {
return false; return false;

View file

@ -4,7 +4,7 @@
#define DIRECTOR_WITCH_MIN_TIME 120 // The minimum amount of time to pass since last witch spawn for the next extra witch to spawn #define DIRECTOR_WITCH_MIN_TIME 120 // The minimum amount of time to pass since last witch spawn for the next extra witch to spawn
#define DIRECTOR_WITCH_CHECK_TIME 30.0 // How often to check if a witch should be spawned #define DIRECTOR_WITCH_CHECK_TIME 30.0 // How often to check if a witch should be spawned
#define DIRECTOR_WITCH_MAX_WITCHES 5 // The maximum amount of extra witches to spawn #define DIRECTOR_WITCH_MAX_WITCHES 5 // The maximum amount of extra witches to spawn
#define DIRECTOR_WITCH_ROLLS 3 // The number of dice rolls, increase if you want to increase freq #define DIRECTOR_WITCH_ROLLS 4 // The number of dice rolls, increase if you want to increase freq
#define DIRECTOR_MIN_SPAWN_TIME 13.0 // Possibly randomized, per-special, in seconds #define DIRECTOR_MIN_SPAWN_TIME 13.0 // Possibly randomized, per-special, in seconds
ConVar directorSpawnChance; // Base chance of a special spawning, changed by player stress ConVar directorSpawnChance; // Base chance of a special spawning, changed by player stress
#define DIRECTOR_CHANGE_LIMIT_CHANCE 0.05 // The chance that the maximum amount per-special is changed #define DIRECTOR_CHANGE_LIMIT_CHANCE 0.05 // The chance that the maximum amount per-special is changed

View file

@ -2,6 +2,7 @@
#endinput #endinput
#endif #endif
#define _overlay_included #define _overlay_included
#include <ripext>
public SharedPlugin __pl_overlay = { public SharedPlugin __pl_overlay = {
name = "overlay", name = "overlay",
@ -25,18 +26,38 @@ native bool IsOverlayConnected();
// myplugin:action_name // myplugin:action_name
// Handles any action for actionNamespace and actionName // Handles any action for actionNamespace and actionName
native void RegisterActionHandler(const char[] actionNamespace, const char[] actionName, ActionFallbackHandlerCallback cb); native void RegisterActionHandler(const char[] actionNamespace, const char[] commandName, ActionFallbackHandlerCallback cb);
// Handles all actions for namespace that were not caught by RegisterActionHandler // Handles all actions for namespace that were not caught by RegisterActionHandler
native void RegisterActionAnyHandler(const char[] actionNamespace, ActionHandlerCallback cb); native void RegisterActionAnyHandler(const char[] actionNamespace, ActionHandlerCallback cb);
enum struct ClientAction {
char steamid[32];
char ns[64];
char instanceId[64];
char command[128];
char input[512];
}
// Utility to get arguments from an action input.
methodmap UIActionEvent { methodmap UIActionEvent {
public UIActionEvent(ArrayList list) { public UIActionEvent(ArrayList list) {
return view_as<UIActionEvent>(list); return view_as<UIActionEvent>(list);
} }
// 1 indexed. 0 returns full action string
public void GetArg(int argNum, char[] output, int maxlen) { public void GetArg(int argNum, char[] output, int maxlen) {
view_as<ArrayList>(this).GetString(argNum, output, maxlen); view_as<ArrayList>(this).GetString(argNum, output, maxlen);
} }
public int GetArgInt(int argNum) {
char buffer[32];
this.GetArg(argNum, buffer, sizeof(buffer));
return StringToInt(buffer);
}
public float GetArgFloat(int argNum) {
char buffer[32];
this.GetArg(argNum, buffer, sizeof(buffer));
return StringToFloat(buffer);
}
public void _Delete() { public void _Delete() {
delete view_as<ArrayList>(this); delete view_as<ArrayList>(this);
@ -48,10 +69,11 @@ methodmap UIActionEvent {
} }
methodmap UIElement < JSONObject { methodmap UIElement < JSONObject {
public UIElement(const char[] elemNamespace, const char[] elemId) { public UIElement(const char[] elemNamespace, const char[] templateId, const char[] instanceId) {
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
obj.SetString("namespace", elemNamespace); obj.SetString("namespace", elemNamespace);
obj.SetString("elem_id", elemId); obj.SetString("instance_id", instanceId);
obj.SetString("template_id", templateId);
obj.SetBool("visibility", false); obj.SetBool("visibility", false);
obj.Set("steamids", new JSONArray()); obj.Set("steamids", new JSONArray());
obj.Set("variables", new JSONObject()); obj.Set("variables", new JSONObject());
@ -68,23 +90,31 @@ methodmap UIElement < JSONObject {
} }
} }
public void SetVariable(const char[] id, JSON json) { public void GetTemplateId(char[] buffer, int maxlen) {
view_as<JSONObject>(this).GetString("template_id", buffer, maxlen);
}
public void GetInstanceId(char[] buffer, int maxlen) {
view_as<JSONObject>(this).GetString("instance_id", buffer, maxlen);
}
public void SetVar(const char[] id, JSON json) {
view_as<JSONObject>(this).Set(id, json); view_as<JSONObject>(this).Set(id, json);
} }
public void SetVariableInt(const char[] id, int value) { public void SetVarInt(const char[] id, int value) {
view_as<JSONObject>(this).SetInt(id, value); view_as<JSONObject>(this).SetInt(id, value);
} }
public void SetVariableFloat(const char[] id, float value) { public void SetVarFloat(const char[] id, float value) {
view_as<JSONObject>(this).SetFloat(id, value); view_as<JSONObject>(this).SetFloat(id, value);
} }
public void SetVariableString(const char[] id, const char[] value) { public void SetVarString(const char[] id, const char[] value) {
view_as<JSONObject>(this).SetString(id, value); view_as<JSONObject>(this).SetString(id, value);
} }
public void SetVariableBool(const char[] id, bool value) { public void SetVarBool(const char[] id, bool value) {
view_as<JSONObject>(this).SetBool(id, value); view_as<JSONObject>(this).SetBool(id, value);
} }
@ -376,6 +406,7 @@ enum AudioState {
Audio_Play Audio_Play
} }
// List of clients to send an element to. If empty, it will default to all connected clients.
methodmap ClientList < JSONArray { methodmap ClientList < JSONArray {
public ClientList() { public ClientList() {
return view_as<ClientList>(new JSONArray()); return view_as<ClientList>(new JSONArray());
@ -449,6 +480,8 @@ methodmap AudioResource < JSONObject {
} }
} }
native int FindClientBySteamId2(const char[] steamid);
#if !defined REQUIRE_PLUGIN #if !defined REQUIRE_PLUGIN
public void __pl_overlay_SetNTVOptional() { public void __pl_overlay_SetNTVOptional() {
MarkNativeAsOptional("IsOverlayConnected"); MarkNativeAsOptional("IsOverlayConnected");
@ -462,5 +495,7 @@ public void __pl_overlay_SetNTVOptional() {
MarkNativeAsOptional("AudioResource.Play"); MarkNativeAsOptional("AudioResource.Play");
MarkNativeAsOptional("AudioResource.Stop"); MarkNativeAsOptional("AudioResource.Stop");
MarkNativeAsOptional("AudioResource.Pause"); MarkNativeAsOptional("AudioResource.Pause");
MarkNativeAsOptional("FindClientBySteamId2");
} }
#endif #endif

View file

@ -10,7 +10,6 @@ static float EMPTY_ANG[3] = { 0.0, 0.0, 0.0 };
#include <sourcemod> #include <sourcemod>
#include <sdktools> #include <sdktools>
#include <left4dhooks>
#include <clientprefs> #include <clientprefs>
#include <jutils> #include <jutils>
#include <gamemodes/ents> #include <gamemodes/ents>
@ -399,35 +398,6 @@ public void Event_HatsEnableChanged(ConVar convar, const char[] sOldValue, const
} }
} }
ArrayList GetSpawnLocations() {
ArrayList list = new ArrayList();
ArrayList newList = new ArrayList();
L4D_GetAllNavAreas(list);
for(int i = 0; i < list.Length; i++) {
Address nav = list.Get(i);
if(L4D_GetNavArea_SpawnAttributes(nav) & NAV_SPAWN_THREAT) {
newList.Push(nav);
}
}
delete list;
PrintToServer("[Hats] Got %d valid locations", newList.Length);
return newList;
}
void ChooseRandomPosition(float pos[3], int ignoreClient = 0) {
if(NavAreas.Length > 0 && GetURandomFloat() > 0.5) {
int nav = NavAreas.Get(GetURandomInt() % (NavAreas.Length - 1));
L4D_FindRandomSpot(nav, pos);
} else {
int survivor = GetRandomClient(5, 1);
if(ignoreClient > 0 && survivor == ignoreClient) survivor = GetRandomClient(5, 1);
if(survivor > 0) {
GetClientAbsOrigin(survivor, pos);
}
}
}
public Action OnPlayerRunCmd(int client, int& buttons, int& impulse, float vel[3], float angles[3], int& weapon, int& subtype, int& cmdnum, int& tickcount, int& seed, int mouse[2]) { public Action OnPlayerRunCmd(int client, int& buttons, int& impulse, float vel[3], float angles[3], int& weapon, int& subtype, int& cmdnum, int& tickcount, int& seed, int mouse[2]) {
float tick = GetGameTime(); float tick = GetGameTime();
////////////////////////////// //////////////////////////////
@ -492,12 +462,12 @@ public Action OnPlayerRunCmd(int client, int& buttons, int& impulse, float vel[3
EquipHat(client, entity); EquipHat(client, entity);
} }
// If bot is commandable and reversed (player reverse-hat common/survivor), change position: // // If bot is commandable and reversed (player reverse-hat common/survivor), change position:
if(HasFlag(client, HAT_COMMANDABLE | HAT_REVERSED) && tickcount % 200 == 0) { // if(HasFlag(client, HAT_COMMANDABLE | HAT_REVERSED) && tickcount % 200 == 0) {
float pos[3]; // float pos[3];
ChooseRandomPosition(pos, client); // ChooseRandomPosition(pos, client);
L4D2_CommandABot(entity, client, BOT_CMD_MOVE, pos); // L4D2_CommandABot(entity, client, BOT_CMD_MOVE, pos);
} // }
} }
// Detect E + R to offset hat or place down // Detect E + R to offset hat or place down
if(buttons & IN_USE && buttons & IN_RELOAD) { if(buttons & IN_USE && buttons & IN_RELOAD) {
@ -682,14 +652,12 @@ bool CheckBlacklist(int entity) {
return false; return false;
} }
} }
if(StrContains(buffer, "prop_") > -1) {
GetEntPropString(entity, Prop_Data, "m_ModelName", buffer, sizeof(buffer)); GetEntPropString(entity, Prop_Data, "m_ModelName", buffer, sizeof(buffer));
for(int i = 0; i < MAX_FORBIDDEN_MODELS; i++) { for(int i = 0; i < MAX_FORBIDDEN_MODELS; i++) {
if(StrEqual(FORBIDDEN_MODELS[i], buffer)) { if(StrEqual(FORBIDDEN_MODELS[i], buffer)) {
return false; return false;
} }
} }
}
GetEntPropString(entity, Prop_Data, "m_iName", buffer, sizeof(buffer)); GetEntPropString(entity, Prop_Data, "m_iName", buffer, sizeof(buffer));
if(StrContains(buffer, "randomizer") == 0) { if(StrContains(buffer, "randomizer") == 0) {
return false; return false;
@ -726,16 +694,6 @@ stock bool FindGround(const float start[3], float end[3]) {
return true; return true;
} }
stock bool L4D_IsPlayerCapped(int client) {
if(GetEntPropEnt(client, Prop_Send, "m_pummelAttacker") > 0 ||
GetEntPropEnt(client, Prop_Send, "m_carryAttacker") > 0 ||
GetEntPropEnt(client, Prop_Send, "m_pounceAttacker") > 0 ||
GetEntPropEnt(client, Prop_Send, "m_jockeyAttacker") > 0 ||
GetEntPropEnt(client, Prop_Send, "m_pounceAttacker") > 0 ||
GetEntPropEnt(client, Prop_Send, "m_tongueOwner") > 0)
return true;
return false;
}
stock void LookAtPoint(int entity, const float destination[3]){ stock void LookAtPoint(int entity, const float destination[3]){
float angles[3], pos[3], result[3]; float angles[3], pos[3], result[3];
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", pos); GetEntPropVector(entity, Prop_Send, "m_vecOrigin", pos);

View file

@ -66,6 +66,8 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("UIElement.SendTo", Native_UpdateUI); CreateNative("UIElement.SendTo", Native_UpdateUI);
CreateNative("TempUI.SendAll", Native_UpdateTempUI); CreateNative("TempUI.SendAll", Native_UpdateTempUI);
CreateNative("TempUI.SendTo", Native_UpdateTempUI); CreateNative("TempUI.SendTo", Native_UpdateTempUI);
CreateNative("FindClientBySteamId2", Native_FindClientBySteamId2);
return APLRes_Success; return APLRes_Success;
} }
@ -128,8 +130,11 @@ Action Command_Overlay(int client, int args) {
ReplyToCommand(client, "URL: %s", managerUrl); ReplyToCommand(client, "URL: %s", managerUrl);
ReplyToCommand(client, "Socket Connected: %b | WS Connected: %b", g_ws.SocketOpen(), g_ws.WsOpen()); ReplyToCommand(client, "Socket Connected: %b | WS Connected: %b", g_ws.SocketOpen(), g_ws.WsOpen());
ReplyToCommand(client, "Auth State: %d", g_authState); ReplyToCommand(client, "Auth State: %d", g_authState);
} else if(StrEqual(arg, "players")) {
SendAllPlayers();
} else if(StrEqual(arg, "test")) { } else if(StrEqual(arg, "test")) {
SendAllPlayers(); SendAllPlayers();
// TODO: server can send: steamids[], steamid, or none (manager knows who was connected)
JSONObject temp = new JSONObject(); JSONObject temp = new JSONObject();
temp.SetString("type", "text"); temp.SetString("type", "text");
@ -276,38 +281,45 @@ stock int ExplodeStringToArrayList(const char[] text, const char[] split, ArrayL
} }
void OnAction(JSONObject obj) { void OnAction(JSONObject obj) {
char steamid[32]; ClientAction action;
obj.GetString("steamid", steamid, sizeof(steamid)); obj.GetString("steamid", action.steamid, sizeof(action.steamid));
char ns[64]; obj.GetString("namespace", action.ns, sizeof(action.ns));
obj.GetString("namespace", ns, sizeof(ns)); obj.GetString("instance_id", action.instanceId, sizeof(action.instanceId));
char id[64]; obj.GetString("command", action.command, sizeof(action.command));
obj.GetString("elem_id", id, sizeof(id)); if(obj.HasKey("input"))
char action[256]; obj.GetString("input", action.input, sizeof(action.input));
obj.GetString("action", action, sizeof(action));
int client = FindClientBySteamId2(steamid); int client = FindClientBySteamId2(action.steamid);
if(client <= 0) return;
StringMap nsHandler; StringMap nsHandler;
PrivateForward fwd; PrivateForward fwd;
if(!actionNamespaceHandlers.GetValue(ns, nsHandler) || !nsHandler.GetValue(id, fwd)) { if(!actionNamespaceHandlers.GetValue(action.ns, nsHandler) || !nsHandler.GetValue(action.command, fwd)) {
if(!actionFallbackHandlers.GetValue(ns, fwd)) { if(!actionFallbackHandlers.GetValue(action.ns, fwd)) {
// No handler or catch all namespace handler // No handler or catch all namespace handler
PrintToServer("[Overlay] Warn: No handler found for action \"%s:%s\"", action.ns, action.command);
return; return;
} }
} }
ArrayList args = new ArrayList(ACTION_ARG_LENGTH); ArrayList args = new ArrayList(ACTION_ARG_LENGTH);
ExplodeStringToArrayList(action, " ", args, ACTION_ARG_LENGTH); args.PushString(action.input);
ExplodeStringToArrayList(action.input, " ", args, ACTION_ARG_LENGTH);
UIActionEvent event = UIActionEvent(args); UIActionEvent event = UIActionEvent(args);
Call_StartForward(fwd); Call_StartForward(fwd);
Call_PushCell(event); Call_PushCell(event);
Call_PushCell(client); Call_PushCell(client);
Call_Finish(); Call_Finish();
if(StrEqual(action.ns, "game")) {
if(CheckCommandAccess(client, action.command, 0)) {
FakeClientCommand(client, "%s %s", action.command, action.input);
}
}
event._Delete(); event._Delete();
} }
int _FindClientBySteamId2(const char[] steamid) {
int FindClientBySteamId2(const char[] steamid) {
for(int i = 1; i <= MaxClients; i++) { for(int i = 1; i <= MaxClients; i++) {
if(StrEqual(steamidCache[i], steamid)) { if(StrEqual(steamidCache[i], steamid)) {
return i; return i;
@ -316,7 +328,6 @@ int FindClientBySteamId2(const char[] steamid) {
return -1; return -1;
} }
bool ConnectManager() { bool ConnectManager() {
DisconnectManager(); DisconnectManager();
if(authToken[0] == '\0') return false; if(authToken[0] == '\0') return false;
@ -537,3 +548,10 @@ any Native_ActionHandler(Handle plugin, int numParams) {
} }
return 1; return 1;
} }
any Native_FindClientBySteamId2(Handle plugin, int numParams) {
char steamid[32];
GetNativeString(1, steamid, sizeof(steamid));
return _FindClientBySteamId2(steamid);
}