From 466f7253b14b95ef08801def03ad472900f3c7be Mon Sep 17 00:00:00 2001 From: zaCade Date: Sat, 2 Mar 2019 15:18:51 +0100 Subject: [PATCH] plugins --- Plugins/autism_bot/scripting/autism_bot.sp | 258 +++ Plugins/hexprops/scripting/hexprops.sp | 1199 ++++++++++ Plugins/hextags/scripting/hextags.sp | 1327 +++++++++++ .../scripting/meteors.sp/meteors.sp | 446 ++++ .../scripting/simple-chatprocessor.sp | 854 +++++++ Plugins/tags_colors/scripting/tags_colors.sp | 384 ++++ .../translations/scp.csgo.phrases.txt | 53 + .../unloze_beams/scripting/unloze_beams.sp | 829 +++++++ .../scripting/unloze_eventScheduler.sp | 361 +++ .../scripting/unloze_ingamePoll.sp | 833 +++++++ .../scripting/unloze_maptimer.sp | 809 +++++++ .../scripting/unloze_spraytracers.sp | 974 ++++++++ .../scripting/include/unloze_zones.inc | 34 + .../unloze_zones/scripting/unloze_zones.sp | 1167 ++++++++++ Plugins/zonerewards/scripting/zoneRewards.sp | 1973 +++++++++++++++++ 15 files changed, 11501 insertions(+) create mode 100644 Plugins/autism_bot/scripting/autism_bot.sp create mode 100644 Plugins/hexprops/scripting/hexprops.sp create mode 100644 Plugins/hextags/scripting/hextags.sp create mode 100644 Plugins/meteorscsgo/scripting/meteors.sp/meteors.sp create mode 100644 Plugins/tags_colors/scripting/simple-chatprocessor.sp create mode 100644 Plugins/tags_colors/scripting/tags_colors.sp create mode 100644 Plugins/tags_colors/translations/scp.csgo.phrases.txt create mode 100644 Plugins/unloze_beams/scripting/unloze_beams.sp create mode 100644 Plugins/unloze_eventScheduler/scripting/unloze_eventScheduler.sp create mode 100644 Plugins/unloze_ingamePoll/scripting/unloze_ingamePoll.sp create mode 100644 Plugins/unloze_maptimer/scripting/unloze_maptimer.sp create mode 100644 Plugins/unloze_spraytracers/scripting/unloze_spraytracers.sp create mode 100644 Plugins/unloze_zones/scripting/include/unloze_zones.inc create mode 100644 Plugins/unloze_zones/scripting/unloze_zones.sp create mode 100644 Plugins/zonerewards/scripting/zoneRewards.sp diff --git a/Plugins/autism_bot/scripting/autism_bot.sp b/Plugins/autism_bot/scripting/autism_bot.sp new file mode 100644 index 00000000..e71b70e0 --- /dev/null +++ b/Plugins/autism_bot/scripting/autism_bot.sp @@ -0,0 +1,258 @@ +#pragma semicolon 1 + +#define DEBUG + +#define PLUGIN_AUTHOR "jenz" +#define PLUGIN_VERSION "1.01" + +#include +#include +#include +#include +#include +#include + + +//global +float g_IAdminspin; +float g_iBotairjump; +int g_iDelay; +bool g_bRoundStart; + +public Plugin myinfo = +{ + name = "autism bot", + author = PLUGIN_AUTHOR, + description = "spawns the bot on a team", + version = PLUGIN_VERSION, + url = "www.unloze.com" +}; + +public void OnMapStart() +{ + g_IAdminspin = 0.0; + g_iBotairjump = 1.0; + g_iDelay = 0; +} + +public void OnPluginStart() +{ + RegAdminCmd("sm_botspin", Cmd_botSpin, ADMFLAG_GENERIC); + RegAdminCmd("sm_botjump", Cmd_botJump, ADMFLAG_GENERIC); + + //hook + HookEvent("player_death", PlayerDeath); + HookEvent("round_start", Event_roundStart, EventHookMode_Post); +} + +public void OnClientPostAdminCheck(int client) +{ + if (IsFakeClient(client)) + { + SDKHook(client, SDKHook_OnTakeDamagePost, OnTakeDamagePost); + ChangeClientTeam(client, CS_TEAM_CT); + } +} +public void Event_roundStart(Handle event, const char[] name, bool dontBroadcast) +{ + g_bRoundStart = true; + for (int i = 1; i < MaxClients; i++) + { + if (IsClientConnected(i) && IsClientInGame(i) && IsClientSourceTV(i) && IsPlayerAlive(i)) + { + ForcePlayerSuicide(i); + CreateTimer(0.5, safeSpec, i); + break; + } + } +} + +public Action PlayerDeath(Handle event, const char[] name, bool dontBroadcast) +{ + int client = GetClientOfUserId(GetEventInt(event, "userid")); + if (IsClientSourceTV(client) && !g_bRoundStart) + { + CreateTimer(0.5, safeSpec, client); + CreateTimer(9.0, respawn_func, client); + } +} +public Action safeSpec(Handle timer, int client) +{ + ChangeClientTeam(client, CS_TEAM_SPECTATOR); +} + +public Action respawn_func(Handle timer, int client) +{ + if (!g_bRoundStart) + { + ChangeClientTeam(client, CS_TEAM_CT); + ServerCommand("sm_fakecommand %N say /zspawn", client); + //ZR_InfectClient(client); + } +} + +public Action Cmd_botSpin(int client, int args) +{ + char inputArgs[250]; + float input; + GetCmdArgString(inputArgs, sizeof(inputArgs)); + + input = StringToFloat(inputArgs); + PrintToChat(client, "spin value: %f", input); + if (input == 0.0) + { + PrintToChat(client, "input failed"); + return Plugin_Handled; + } + else if (input >= 360.0 || input <= -360.0) + { + PrintToChat(client, "Input Range: -360 to 360"); + return Plugin_Handled; + } + g_IAdminspin = input; + + return Plugin_Handled; +} + +public Action Cmd_botJump(int client, int args) +{ + char inputArgs[250]; + float input; + GetCmdArgString(inputArgs, sizeof(inputArgs)); + + input = StringToFloat(inputArgs); + PrintToChat(client, "jump value: %f", input); + if (input == 0.0) + { + PrintToChat(client, "input failed"); + return Plugin_Handled; + } + else if (input >= 10.0 || input <= -10.0) + { + PrintToChat(client, "Input Range: -10 to 10"); + return Plugin_Handled; + } + g_iBotairjump = input; + + return Plugin_Handled; +} + +public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float move[3], float angles[3], int &weapon, int &subtype, int &cmdnum, int &tickcount, int &seed, int mouse[2]) +{ + if (IsFakeClient(client)) + { + if (g_IAdminspin == 0.0) + { + angles[1] += 30.0; + if (angles[1] >= 360.0) + { + angles[1] = 0.0; + } + TeleportEntity(client, NULL_VECTOR, angles, NULL_VECTOR); + ++g_iDelay; + if (g_iDelay >= 10) + { + buttons |= IN_ATTACK; + g_iDelay = 0; + buttons |= IN_DUCK; + Client_Push(client); + } + return Plugin_Changed; + } + else + { + angles[1] += g_IAdminspin; + if (angles[1] >= 360.0) + { + angles[1] = 0.0; + } + TeleportEntity(client, NULL_VECTOR, angles, NULL_VECTOR); + ++g_iDelay; + if (g_iDelay >= 10) + { + buttons |= IN_ATTACK; + buttons |= IN_DUCK; + g_iDelay = 0; + Client_Push(client); + } + return Plugin_Changed; + } + } + return Plugin_Continue; +} + +public void Client_Push (int client) +{ + float newVel[3]; + int GroundEnt = GetEntPropEnt(client, Prop_Send, "m_hGroundEntity"); + if (GroundEnt == -1) + { + //PrintToChatAll("Bot %N is not on ground", client); + } + else + { + int i_nr = GetRandomInt(1, 4); + if (i_nr == 1) + { + newVel[1] += GetRandomInt(50, 350); + } + else if (i_nr == 2) + { + newVel[0] += GetRandomInt(50, 350); + } + else if (i_nr == 3) + { + newVel[0] -= GetRandomInt(50, 350); + } + else if (i_nr == 4) + { + newVel[1] -= GetRandomInt(50, 350); + } + newVel[2] += GetRandomInt(50, 350) * g_iBotairjump; + //newVel[1] += GetRandomFloat(0.10, 270.10); + Entity_SetAbsVelocity(client, newVel); + //PrintToChatAll("Bot %N is on ground", client); + } +} + +public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn) +{ + if (!motherInfect) + return; + for (int i = 1; i <= MaxClients; i++) + { + if (IsClientConnected(i) && IsClientInGame(i) && IsClientSourceTV(i)) + { + g_bRoundStart = false; + CreateTimer(1.0, respawn_func, i); + } + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: damageHook +//---------------------------------------------------------------------------------------------------- + +public Action OnTakeDamagePost(victim, &attacker, &inflictor, &Float:damage, &damagetype) +{ + // Don't pass alive players + if (IsPlayerAlive(victim)) + { + return Plugin_Handled; + } + if (attacker == 0) + { + // World + ServerCommand("sm_fakecommand #%i say \"fuck u world!\"", GetClientUserId(victim), attacker); + } + else if (victim == attacker) + { + // Suicide + ServerCommand("sm_fakecommand #%i say \"fuck ur admin abuse!\"", GetClientUserId(victim), attacker); + } + else if (1 <= attacker <= MaxClients) + { + ServerCommand("sm_fakecommand #%i say \"%N fuck u m8!\"", GetClientUserId(victim), attacker); + } + return Plugin_Handled; +} \ No newline at end of file diff --git a/Plugins/hexprops/scripting/hexprops.sp b/Plugins/hexprops/scripting/hexprops.sp new file mode 100644 index 00000000..e675d836 --- /dev/null +++ b/Plugins/hexprops/scripting/hexprops.sp @@ -0,0 +1,1199 @@ +#include +#include +#include +#include +#include + +#define PLUGIN_AUTHOR "Hexah" +#define PLUGIN_VERSION "" + +#pragma semicolon 1 +#pragma newdecls required + +//Handle +Handle fOnPressProp; +//Int +int iEntHP[MAX_ENTITIES]; + +//Boolean +bool bMoveProp[MAXPLAYERS+1]; +bool bPhysicProp[MAXPLAYERS+1]; + +//String +char sPropPath[PLATFORM_MAX_PATH]; + +//Kv +KeyValues PropKv; + +//Arrays +ArrayList PropsArray; + +#include HexProps/model_moving.sp + +//Plugin Info +public Plugin myinfo = +{ + name = "HexProps, jenz edit for fixing (or causing) bugs", + author = PLUGIN_AUTHOR, + description = "Place, edit & save props!", + version = PLUGIN_VERSION, + url = "github.com/Hexer10/HexProps" +}; + +//Startup +public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) +{ + + RegPluginLibrary("hexprops"); + CreateNative("IsEntProp", Native_IsEntProp); + + fOnPressProp = CreateGlobalForward("OnPlayerPressProp", ET_Ignore, Param_Cell, Param_Cell); +} + +public void OnPluginStart() +{ + PropsArray = new ArrayList(); + RegAdminCmd("sm_props", Cmd_Props, ADMFLAG_GENERIC); + HookEvent("round_poststart", Event_RoundPostStart); +} + +public void OnMapStart() +{ + PreparePropKv(); +} +public void OnMapEnd() +{ + delete PropKv; +} + +void PreparePropKv() +{ + char sMap[64]; + GetCurrentMap(sMap, sizeof(sMap)); + + BuildPath(Path_SM, sPropPath, sizeof(sPropPath), "configs/props/%s.props.txt", sMap); //Get the right "map" file + PropKv = new KeyValues("Props"); + + if (!FileExists(sPropPath)) //Try to create kv file. + if (!PropKv.ExportToFile(sPropPath)) + SetFailState(" - Props - Unable to (Kv)File: %s", sPropPath); + + if (!PropKv.ImportFromFile(sPropPath)) //Import the kv file + SetFailState("- Props - Unable to import: %s", sPropPath); +} + +//Commands +public Action Cmd_Props(int client, int args) +{ + CreateMainMenu(client).Display(client, MENU_TIME_FOREVER); + return Plugin_Handled; +} + +//Events +public void Event_RoundPostStart(Event event, const char[] name, bool dontBroadcast) +{ + PropsArray.Clear(); + LoadProps(); +} + +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]) +{ + Moving_OnPlayerRunCmd(client, buttons); + + if (buttons & IN_USE) + { + int iEnt = GetAimEnt(client); + + if (FindInArray(iEnt) == -1) + { + Call_StartForward(fOnPressProp); + Call_PushCell(client); + Call_PushCell(iEnt); + Call_Finish(); + } + } +} + + +//Menu +Menu CreateMainMenu(int client) +{ + //Prepare MainMenu + Menu MainMenu = new Menu(Handler_Main); + + MainMenu.SetTitle("Props"); + + + char sMoveDisplay[32]; + char sPhysicDisplay[32]; + Format(sMoveDisplay, sizeof(sMoveDisplay), "Move: %s", bMoveProp[client]? "On" : "Off"); + Format(sPhysicDisplay, sizeof(sPhysicDisplay), "Physic: %s", bPhysicProp[client]? "On" : "Off"); + + MainMenu.AddItem("Place", "Place New Prop"); + MainMenu.AddItem("Remove", "Remove Props"); + MainMenu.AddItem("Edit", "Edit Props"); + MainMenu.AddItem("Safe", "Save Props"); + MainMenu.AddItem("Move", sMoveDisplay); + MainMenu.AddItem("Physic", sPhysicDisplay); + MainMenu.AddItem("Reset", "Reset Props"); + MainMenu.AddItem("DeleteAll", "Delete All Props"); + + return MainMenu; +} + +Menu CreatePropMenu() +{ + //Prepare PropMenu + char sPath[PLATFORM_MAX_PATH]; + BuildPath(Path_SM, sPath, sizeof(sPath), "configs/props/props_list.txt"); //Get prop_list file + + KeyValues kv = new KeyValues("Props"); + + if (!kv.ImportFromFile(sPath)) + SetFailState("- Props - Unable to import: %s", sPath); + + if (!kv.GotoFirstSubKey()) + SetFailState(" - Props - Unable to read: %s", sPath); + + Menu PropMenu = new Menu(Handler_Props); + + PropMenu.SetTitle("Props"); + + do //Loop all kv keys + { + char sName[64]; + char sModel[PLATFORM_MAX_PATH]; + + kv.GetSectionName(sName, sizeof(sName)); + kv.GetString("model", sModel, sizeof(sModel)); + PropMenu.AddItem(sModel, sName); + } + while (kv.GotoNextKey()); + + delete kv; + + PropMenu.ExitBackButton = true; + + return PropMenu; +} + +Menu CreateEditMenu() +{ + //Prepare EditMenu + Menu EditMenu = new Menu(Handler_Edit); + + EditMenu.SetTitle("Edit"); + + EditMenu.AddItem("Alpha", "Set Transparency"); + EditMenu.AddItem("Color", "Set Color"); + EditMenu.AddItem("Life", "Set LifePoints"); + EditMenu.AddItem("Solid", "Set Consistency"); + EditMenu.AddItem("Size", "Set Size (Not working on all props)"); + EditMenu.AddItem("Physic", "Make Physic"); + EditMenu.AddItem("Rotate", "Rotate props"); + + EditMenu.ExitBackButton = true; + + return EditMenu; +} + +Menu CreateDeleteAllMenu() +{ + Menu DeleteAllMenu = new Menu(Handler_DeleteAll); + + DeleteAllMenu.SetTitle("Are you sure?"); + + DeleteAllMenu.AddItem("", "If you want to go back", ITEMDRAW_DISABLED); + DeleteAllMenu.AddItem("", "after you deleted the props", ITEMDRAW_DISABLED); + DeleteAllMenu.AddItem("", "press Reset Props and do NOT save the props!", ITEMDRAW_DISABLED); + DeleteAllMenu.AddItem("0", "NO"); + DeleteAllMenu.AddItem("1", "YES"); + + DeleteAllMenu.ExitBackButton = true; + return DeleteAllMenu; +} + +Menu CreateColorMenu() +{ + //Prepare ColorMenu + Menu ColorMenu = new Menu(Handler_Color); + + ColorMenu.SetTitle("Color"); + + ColorMenu.AddItem("Default", "Default"); + ColorMenu.AddItem("Red", "Red"); + ColorMenu.AddItem("Blue", "Blue"); + ColorMenu.AddItem("Green", "Green"); + ColorMenu.AddItem("Yellow", "Yellow"); + ColorMenu.AddItem("Pink", "Pink"); + ColorMenu.AddItem("Black", "Black"); + + ColorMenu.ExitBackButton = true; + + return ColorMenu; +} + +Menu CreateAlphaMenu() +{ + //Prepare AlphaMenu + Menu AlphaMenu = new Menu(Handler_Alpha); + + AlphaMenu.SetTitle("Trasparency"); + + AlphaMenu.AddItem("255", "Full Visible"); + AlphaMenu.AddItem("191", "75% Visible"); + AlphaMenu.AddItem("127", "Half Visible"); + AlphaMenu.AddItem("63", "25% Visible"); + AlphaMenu.AddItem("0", "Invisible"); + + AlphaMenu.ExitBackButton = true; + + return AlphaMenu; +} + +Menu CreateLifeMenu() +{ + //Prepare LifeMenu + Menu LifeMenu = new Menu(Handler_Life); + + LifeMenu.SetTitle("LifePoints"); + + LifeMenu.AddItem("0", "Unbreakable"); + LifeMenu.AddItem("50", "50HP"); + LifeMenu.AddItem("100", "100HP"); + LifeMenu.AddItem("200", "200HP"); + + LifeMenu.ExitBackButton = true; + + return LifeMenu; +} + +Menu CreateSolidMenu() +{ + Menu SolidMenu = new Menu(Handler_Solid); + + SolidMenu.SetTitle("Consistency"); + + SolidMenu.AddItem("6", "Solid"); + SolidMenu.AddItem("1", "Un-Solid"); + + SolidMenu.ExitBackButton = true; + + return SolidMenu; +} + +Menu CreateSizeMenu() +{ + Menu SizeMenu = new Menu(Handler_Size); + + SizeMenu.SetTitle("Size"); + + SizeMenu.AddItem("1.0", "Default"); + SizeMenu.AddItem("2.0", "Double"); + SizeMenu.AddItem("3.0", "Triple"); + SizeMenu.AddItem("4.0", "Quadruple"); + SizeMenu.AddItem("0.5", "Half"); + + SizeMenu.ExitBackButton = true; + + return SizeMenu; +} + +Menu CreateRotateMenu() +{ + Menu RotateXMenu = new Menu(Handler_RotateX); + + RotateXMenu.SetTitle("Rotation"); + + RotateXMenu.AddItem("Rotate X +45 Degrees", "Rotate X +45 Degrees"); + RotateXMenu.AddItem("Rotate Y +45 Degrees", "Rotate Y +45 Degrees"); + RotateXMenu.AddItem("Rotate Z +45 Degrees", "Rotate Z +45 Degrees"); + + RotateXMenu.ExitBackButton = true; + + return RotateXMenu; +} + + +//Menu Handlers +public int Handler_Main(Menu menu, MenuAction action, int param1, int param2) +{ + if (action == MenuAction_Select) + { + char info[64]; + menu.GetItem(param2, info, sizeof(info)); + + if (StrEqual(info, "Place")) + { + CreatePropMenu().DisplayAt(param1, param2, MENU_TIME_FOREVER); + } + else if(StrEqual(info, "Remove")) + { + if (RemoveProp(param1)) + { + PrintToChat(param1, "[HexProps] Prop successfully removed!"); + } + else + { + PrintToChat(param1, "[HexProps] Prop couldn't be found!"); + } + + CreateMainMenu(param1).Display(param1, MENU_TIME_FOREVER); + } + else if(StrEqual(info, "Edit")) + { + CreateEditMenu().Display(param1, MENU_TIME_FOREVER); + } + + + else if (StrEqual(info, "Move")) + { + //PrintToChatAll("param1 value: %N", param1); + if (CheckCommandAccess(param1, "generic_admin", ADMFLAG_GENERIC, false)) + { + bMoveProp[param1] = !bMoveProp[param1]; + PrintToChatAll("%N moving props!", param1); + } + CreateMainMenu(param1).Display(param1, MENU_TIME_FOREVER); + } + else if (StrEqual(info, "Physic")) + { + bPhysicProp[param1] = !bPhysicProp[param1]; + + CreateMainMenu(param1).Display(param1, MENU_TIME_FOREVER); + } + else if (StrEqual(info, "Safe")) + { + bool bSaved = SaveProps(); + if (bSaved) + { + PrintToChat(param1, "[HexProps] Props successfully saved!"); + } + else + { + PrintToChat(param1, "[HexProps] No props were saved!"); + } + CreateMainMenu(param1).Display(param1, MENU_TIME_FOREVER); + } + else if (StrEqual(info, "Reset")) + { + ResetProps(); + PrintToChat(param1, "[HexProps] Props successfully resetted!"); + CreateMainMenu(param1).Display(param1, MENU_TIME_FOREVER); + } + else + { + CreateDeleteAllMenu().Display(param1, 20); + } + } + else if (action == MenuAction_End) + { + delete menu; + } + return 1; +} + +public int Handler_Props(Menu menu, MenuAction action, int param1, int param2) +{ + if (action == MenuAction_Select) + { + char info[PLATFORM_MAX_PATH]; + menu.GetItem(param2, info, sizeof(info)); + + if (!IsModelPrecached(info)) + PrecacheModel(info); + + char sClass[64] = "prop_dynamic_override"; + if (bPhysicProp[param1]) + { + strcopy(sClass, sizeof(sClass), "prop_physics_multiplayer"); + } + + SpawnTempProp(param1, sClass, info); + CreatePropMenu().DisplayAt(param1, GetMenuSelectionPosition(), MENU_TIME_FOREVER); + } + else if (action == MenuAction_Cancel) + { + CreateMainMenu(param1).Display(param1, MENU_TIME_FOREVER); + } + else if (action == MenuAction_End) + { + delete menu; + } +} + +public int Handler_Edit(Menu menu, MenuAction action, int param1, int param2) +{ + if (action == MenuAction_Select) + { + char info[64]; + menu.GetItem(param2, info, sizeof(info)); + + if (StrEqual(info, "Alpha")) + { + CreateAlphaMenu().Display(param1, MENU_TIME_FOREVER); + } + else if (StrEqual(info, "Color")) + { + CreateColorMenu().Display(param1, MENU_TIME_FOREVER); + } + else if (StrEqual(info, "Life")) + { + CreateLifeMenu().Display(param1, MENU_TIME_FOREVER); + } + else if (StrEqual(info, "Solid")) + { + CreateSolidMenu().Display(param1, MENU_TIME_FOREVER); + } + else if (StrEqual(info, "Size")) + { + CreateSizeMenu().Display(param1, MENU_TIME_FOREVER); + } + else if (StrEqual(info, "Rotate")) + { + CreateRotateMenu().Display(param1, MENU_TIME_FOREVER); + } + else + { + MakePhysic(param1); + CreateEditMenu().Display(param1, MENU_TIME_FOREVER); + } + + } + else if (action == MenuAction_Cancel) + { + CreateMainMenu(param1).Display(param1, MENU_TIME_FOREVER); + } + else if (action == MenuAction_End) + { + delete menu; + } +} + +void MakePhysic(int client) +{ + int iEnt = GetAimEnt(client); + + if (iEnt == -1) + { + PrintToChat(client, "[HexProps] Prop couldn't be found"); + return; + } + + int iIndex = FindInArray(iEnt); + + if (!iIndex || iIndex == -1) + { + PrintToChat(client, "[HexProps] Prop couldn't be found"); + return; + } + + char sModel[PLATFORM_MAX_PATH]; + float vPos[3]; + GetEntityModel(iEnt, sModel); + GetEntityOrigin(iEnt, vPos); + + AcceptEntityInput(iEnt, "kill"); + PropsArray.Erase(iIndex); + + iEnt = -1; + iEnt = CreateEntityByName("prop_physics_multiplayer"); + + if (iEnt == -1) + { + PrintToChat(client, "[HexProps] Error occured while creating the physic prop!"); + return; + } + + DispatchKeyValue(iEnt, "Physics Mode", "1"); + SetEntityModel(iEnt, sModel); + DispatchSpawn(iEnt); + + TeleportEntity(iEnt, vPos, NULL_VECTOR, NULL_VECTOR); + + PropsArray.Push(EntIndexToEntRef(iEnt)); + +} +public int Handler_DeleteAll(Menu menu, MenuAction action, int param1, int param2) +{ + if (action == MenuAction_Select) + { + char info[64]; + menu.GetItem(param2, info, sizeof(info)); + bool bDelete = view_as(StringToInt(info)); + + if (bDelete) + { + if (!PropKv.GotoFirstSubKey()) + SetFailState("- HexProps - Failed to read: %s", sPropPath); + + do + { + PropKv.DeleteThis(); + } + while (PropKv.GotoNextKey()); + PropKv.Rewind(); + + for (int i = 0; i < PropsArray.Length; i++) + { + int iEnt = EntRefToEntIndex(PropsArray.Get(i)); + if (iEnt == INVALID_ENT_REFERENCE) + continue; + + AcceptEntityInput(iEnt, "kill"); + } + ReplyToCommand(param1, "[SM] Props deleted!"); + } + CreateMainMenu(param1).Display(param1, MENU_TIME_FOREVER); + } + else if (action == MenuAction_Cancel) + { + CreateEditMenu().Display(param1, MENU_TIME_FOREVER); + } + else if (action == MenuAction_End) + { + delete menu; + } +} + +public int Handler_Color(Menu menu, MenuAction action, int param1, int param2) +{ + if (action == MenuAction_Select) + { + int r, g, b; + char info[64]; + menu.GetItem(param2, info, sizeof(info)); + + if (StrEqual(info, "Red")) + { + r = 255; + } + else if (StrEqual(info, "Green")) + { + g = 255; + } + else if (StrEqual(info, "Blue")) + { + b = 255; + } + else if (StrEqual(info, "Pink")) + { + r = 255; + g = 102; + b = 178; + } + else if (StrEqual(info, "Yellow")) + { + r = 255; + g = 255; + } + else if (StrEqual(info, "Default")) + { + r = 255; + g = 255; + b = 255; + } + else{} //if black dont to anything + + int iAimEnt = GetAimEnt(param1); + + if (FindInArray(iAimEnt) != -1) + { + int r2, g2, b2, a; + + GetEntityRenderColor(iAimEnt, r2, g2, b2, a); + SetEntityRenderColor(iAimEnt, r, g, b, a); + } + else + { + PrintToChat(param1, "[HexProps] Prop couldn't be found"); + } + + CreateColorMenu().Display(param1, MENU_TIME_FOREVER); + + } + else if (action == MenuAction_Cancel) + { + CreateEditMenu().Display(param1, MENU_TIME_FOREVER); + } + else if (action == MenuAction_End) + { + delete menu; + } +} + +public int Handler_Alpha(Menu menu, MenuAction action, int param1, int param2) +{ + if (action == MenuAction_Select) + { + char info[64]; + menu.GetItem(param2, info, sizeof(info)); + + int iAimEnt = GetAimEnt(param1); + + if (FindInArray(iAimEnt) != -1) + { + int r, g, b, a; + SetEntityRenderMode(iAimEnt, RENDER_TRANSCOLOR); + GetEntityRenderColor(iAimEnt, r, g, b, a); + SetEntityRenderColor(iAimEnt, r, g, b, StringToInt(info)); + } + else + { + PrintToChat(param1, "[HexProps] Prop couldn't be found"); + } + + CreateAlphaMenu().Display(param1, MENU_TIME_FOREVER); + + } + else if (action == MenuAction_Cancel) + { + CreateEditMenu().Display(param1, MENU_TIME_FOREVER); + } + else if (action == MenuAction_End) + { + delete menu; + } +} + +public int Handler_Life(Menu menu, MenuAction action, int param1, int param2) +{ + if (action == MenuAction_Select) + { + char info[64]; + menu.GetItem(param2, info, sizeof(info)); + + int r, b, g, a; + int iLife; + + int iAimEnt = GetAimEnt(param1); + + if (FindInArray(iAimEnt) != -1) + { + GetEntityRenderColor(iAimEnt, r, g, b, a); + iLife = StringToInt(info); + + if (iLife) + { + iEntHP[iAimEnt] = iLife; + SetEntProp(iAimEnt, Prop_Data, "m_takedamage", 2); + SetEntProp(iAimEnt, Prop_Data, "m_iHealth", iLife); + } + } + else + { + PrintToChat(param1, "[HexProps] Prop couldn't be found"); + } + + CreateLifeMenu().Display(param1, MENU_TIME_FOREVER); + } + else if (action == MenuAction_Cancel) + { + CreateEditMenu().Display(param1, MENU_TIME_FOREVER); + } + else if (action == MenuAction_End) + { + delete menu; + } +} + +public int Handler_Solid(Menu menu, MenuAction action, int param1, int param2) +{ + if (action == MenuAction_Select) + { + char info[64]; + menu.GetItem(param2, info, sizeof(info)); + + int iAimEnt = GetAimEnt(param1); + + if (FindInArray(iAimEnt) != -1) + { + SetEntProp(iAimEnt, Prop_Send, "m_nSolidType", StringToInt(info)); + } + else + { + PrintToChat(param1, "[HexProps] Prop couldn't be found"); + } + + CreateSolidMenu().Display(param1, MENU_TIME_FOREVER); + } + else if (action == MenuAction_Cancel) + { + CreateEditMenu().Display(param1, MENU_TIME_FOREVER); + } + else if (action == MenuAction_End) + { + delete menu; + } +} + +public int Handler_Size(Menu menu, MenuAction action, int param1, int param2) +{ + if (action == MenuAction_Select) + { + char info[64]; + menu.GetItem(param2, info, sizeof(info)); + + int iAimEnt = GetAimEnt(param1); + + if (FindInArray(iAimEnt) != -1) + { + SetEntPropFloat(iAimEnt, Prop_Send, "m_flModelScale", StringToFloat(info)); + } + else + { + PrintToChat(param1, "[HexProps] Prop couldn't be found"); + } + + CreateSizeMenu().Display(param1, MENU_TIME_FOREVER); + } + else if (action == MenuAction_Cancel) + { + CreateEditMenu().Display(param1, MENU_TIME_FOREVER); + } + else if (action == MenuAction_End) + { + delete menu; + } +} + + +public int Handler_RotateX(Menu menu, MenuAction action, int param1, int param2) +{ + if (action == MenuAction_Select) + { + char info[64]; + char classname[64]; + float RotateVec[3]; + menu.GetItem(param2, info, sizeof(info)); + + int iAimEnt = GetAimEnt(param1); + + if (FindInArray(iAimEnt) != -1 && iAimEnt != -1) + { + GetEdictClassname(iAimEnt, classname, sizeof(classname)); + + if (StrEqual(classname, "prop_physics") || StrEqual(classname, "prop_physics_override") || StrEqual(classname, "prop_dynamic") || StrEqual(classname, "prop_dynamic_override") || StrEqual(classname, "prop_physics_multiplayer") || StrEqual(classname, "prop_dynamic_ornament") || StrEqual(classname, "prop_static")) + { + PrintToChat(param1, "%s", info); + GetEntPropVector(iAimEnt, Prop_Send, "m_angRotation", RotateVec); + if (StrContains(info, "X", false) >= 0) + { + RotateVec[0] = RotateVec[0] + 45.0; + } + else if (StrContains(info, "Y", false) >= 0) + { + RotateVec[1] = RotateVec[1] + 45.0; + } + else if (StrContains(info, "Z", false) >= 0) + { + RotateVec[2] = RotateVec[2] + 45.0; + } + TeleportEntity(iAimEnt, NULL_VECTOR, RotateVec, NULL_VECTOR); + AcceptEntityInput(iAimEnt, "TurnOn", iAimEnt, iAimEnt, 0); + AcceptEntityInput(iAimEnt, "EnableCollision"); + } + } + else + { + PrintToChat(param1, "[HexProps] Prop couldn't be found"); + } + + CreateRotateMenu().Display(param1, MENU_TIME_FOREVER); + } + else if (action == MenuAction_Cancel) + { + CreateEditMenu().Display(param1, MENU_TIME_FOREVER); + } + else if (action == MenuAction_End) + { + delete menu; + } +} + +//Functions +int SpawnProp(const char[] classname, const char[] model, float vPos[3], float vAng[3], int r, int g, int b, int a, bool solid, int iLife, float fSize) +{ + int iEnt = CreateEntityByName(classname); + //PrintToChatAll("classname: %s", classname); + if (iEnt == -1) + { + //PrintToChatAll("Failed iEnt = -1"); + return iEnt; + } + + if (!IsModelPrecached(model)) + PrecacheModel(model); + + SetEntityModel(iEnt, model); + SetEntityRenderMode(iEnt, RENDER_TRANSCOLOR); + SetEntityRenderColor(iEnt, r, b, g, a); + + SetEntProp(iEnt, Prop_Send, "m_nSolidType", 6); + if (!solid) + SetEntProp(iEnt, Prop_Send, "m_nSolidType", 1); + + if (iLife) + { + SetEntProp(iEnt, Prop_Data, "m_takedamage", 2); + iEntHP[iEnt] = iLife; + SetEntProp(iEnt, Prop_Data, "m_iHealth", iLife); + } + + SetEntPropFloat(iEnt, Prop_Send, "m_flModelScale", fSize); + + if (StrContains(classname, "physics") != -1) + { + DispatchKeyValue(iEnt, "Physics Mode", "1"); + DispatchSpawn(iEnt); + } + /* + PrintToChatAll("%i", view_as(solid)); + PrintToChatAll("vPos[0]: %f", vPos[0]); + PrintToChatAll("vPos[1]: %f", vPos[1]); + PrintToChatAll("vPos[2]: %f", vPos[2]); + PrintToChatAll("vAng[0]: %f", vAng[0]); + PrintToChatAll("vAng[1]: %f", vAng[1]); + PrintToChatAll("vAng[2]: %f", vAng[2]); + PrintToChatAll("fSize: %f", fSize); + PrintToChatAll("iLife: %i", iLife); + PrintToChatAll("model: %s", model); + for (int i = 1; i <= MaxClients; i++) + { + if (IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i)) + { + TeleportEntity(i, vPos, vAng, NULL_VECTOR); + } + } + */ + TeleportEntity(iEnt, vPos, vAng, NULL_VECTOR); + return iEnt; +} + +int SpawnTempProp(int client, const char[] classname, const char[] model) +{ + int iEnt = CreateEntityByName(classname); + + if (iEnt == -1) + { + CreatePropMenu().Display(client, MENU_TIME_FOREVER); + return -1; + } + + SetEntityModel(iEnt, model); + SetEntProp(iEnt, Prop_Send, "m_nSolidType", 6); + SetEntityRenderMode(iEnt, RENDER_TRANSCOLOR); + SetEntityRenderColor(iEnt); + + float vClientPos[3]; + float vClientAng[3]; + float vEndPoint[3]; + float vEndAng[3]; + + GetClientEyePosition(client, vClientPos); + GetClientEyeAngles(client, vClientAng); + + TR_TraceRayFilter(vClientPos, vClientAng, MASK_SOLID, RayType_Infinite, TraceRayDontHitPlayer, client); + + if (TR_DidHit()) + { + TR_GetEndPosition(vEndPoint); + TR_GetPlaneNormal(INVALID_HANDLE, vEndAng); + GetVectorAngles(vEndAng, vEndAng); + vEndAng[0] += 90.0; + } + else + { + CreatePropMenu().Display(client, MENU_TIME_FOREVER); + return -1; + } + + if (StrContains(classname, "physics") != -1) + { + DispatchKeyValue(iEnt, "Physics Mode", "1"); + DispatchSpawn(iEnt); + } + + TeleportEntity(iEnt, vEndPoint, vEndAng, NULL_VECTOR); + + int iIndex = PropsArray.Push(EntIndexToEntRef(iEnt)); + + SetEntityName(iEnt, "Prop_%i", iIndex); + + return iEnt; +} + +bool RemoveProp(int client) +{ + int iAimEnt = GetAimEnt(client); + int iIndex; + + if (iAimEnt == -1) + return false; + + iIndex = FindInArray(iAimEnt) != -1; + + if (!iIndex) + return false; + + AcceptEntityInput(iAimEnt, "kill"); + PropsArray.Erase(iIndex); + return true; +} + +bool SaveProps() +{ + ClearPropKv(); + + char sKey[8]; + int iCount; + bool bReturn = false; + + for (int i = 0; i < PropsArray.Length; i++) + { + PropKv.Rewind(); + IntToString(++iCount, sKey, sizeof(sKey)); + + if (PropKv.JumpToKey(sKey, true)) + { + int iEnt = EntRefToEntIndex(PropsArray.Get(i)); + + if (iEnt == INVALID_ENT_REFERENCE) + continue; + + char sClass[64]; + char sModel[PLATFORM_MAX_PATH]; + char sColor[16]; + float vPos[3]; + float vAng[3]; + int r, b, g, a; + + GetEntityClassname(iEnt, sClass, sizeof(sClass)); + GetEntityModel(iEnt, sModel); + GetEntityOrigin(iEnt, vPos); + GetEntityAngles(iEnt, vAng); + GetEntityRenderColor(iEnt, r, g, b, a); + bool solid = (GetEntProp(iEnt, Prop_Send, "m_nSolidType") == 6); + int iLife = iEntHP[iEnt]; + float fSize = GetEntPropFloat(iEnt, Prop_Send, "m_flModelScale"); + + ColorToString(sColor, sizeof(sColor), r, b, g, a); + + PropKv.SetString("classname", sClass); + PropKv.SetString("model", sModel); + PropKv.SetVector("position", vPos); + PropKv.SetVector("angles", vAng); + PropKv.SetString("color", sColor); + PropKv.SetNum("solid", solid); + PropKv.SetNum("life", iLife); + PropKv.SetFloat("size", fSize); + bReturn = true; + } + } + PropKv.Rewind(); + PropKv.ExportToFile(sPropPath); + return bReturn; +} + +void LoadProps() +{ + if (!PropKv.GotoFirstSubKey()) + return; + + PropsArray.Clear(); + //needs to edit this part to not rely on keyvalues + Handle l_hPropFile = INVALID_HANDLE; + char l_cReadLine[128]; + char sClass[64]; + char sModel[PLATFORM_MAX_PATH]; + float vPos[3]; + float vAng[3]; + char sColors[24]; + int r, g, b, a; + bool solid; + int iLife; + float fSize; + l_hPropFile = OpenFile(sPropPath, "r"); + while (!IsEndOfFile(l_hPropFile) && ReadFileLine(l_hPropFile, l_cReadLine, sizeof(l_cReadLine))) + { + ReplaceString(l_cReadLine, sizeof(l_cReadLine), "\"", "", true); + if (StrContains(l_cReadLine, "classname", false) > -1) + { + ReplaceString(l_cReadLine, sizeof(l_cReadLine), "classname", "", true); + Format(sClass, sizeof(sClass), l_cReadLine); + TrimString(sClass); + } + else if (StrContains(l_cReadLine, "model", false) > -1) + { + //trimming first part + strcopy(l_cReadLine, sizeof(l_cReadLine), l_cReadLine[7]); + Format(sModel, sizeof(sModel), l_cReadLine); + TrimString(sModel); + } + else if (StrContains(l_cReadLine, "position", false) > -1) + { + ReplaceString(l_cReadLine, sizeof(l_cReadLine), "position", "", true); + char sPart[3][64]; + //spliting on whitespace + ExplodeString(l_cReadLine, " ", sPart, 3, 64); + vPos[0] = StringToFloat(sPart[0]); + vPos[1] = StringToFloat(sPart[1]); + vPos[2] = StringToFloat(sPart[2]); + } + else if (StrContains(l_cReadLine, "angles", false) > -1) + { + ReplaceString(l_cReadLine, sizeof(l_cReadLine), "angles", "", true); + char sPart[3][64]; + //spliting on whitespace + ExplodeString(l_cReadLine, " ", sPart, 3, 64); + vAng[0] = StringToFloat(sPart[0]); + vAng[1] = StringToFloat(sPart[1]); + vAng[2] = StringToFloat(sPart[2]); + } + else if (StrContains(l_cReadLine, "color", false) > -1) + { + ReplaceString(l_cReadLine, sizeof(l_cReadLine), "color", "", true); + Format(sColors, sizeof(sColors), l_cReadLine); + } + else if (StrContains(l_cReadLine, "solid", false) > -1) + { + ReplaceString(l_cReadLine, sizeof(l_cReadLine), "solid", "", true); + TrimString(l_cReadLine); + solid = view_as(StringToInt(l_cReadLine)); + } + else if (StrContains(l_cReadLine, "life", false) > -1) + { + ReplaceString(l_cReadLine, sizeof(l_cReadLine), "life", "", true); + TrimString(l_cReadLine); + iLife = StringToInt(l_cReadLine); + } + else if (StrContains(l_cReadLine, "size", false) > -1) + { + ReplaceString(l_cReadLine, sizeof(l_cReadLine), "size", "", true); + TrimString(l_cReadLine); + fSize = StringToFloat(l_cReadLine); + StringToColor(sColors, r, g, b, a); + int iEnt = SpawnProp(sClass, sModel, vPos, vAng, r, g, b, a, solid, iLife, fSize); + if (iEnt != -1) + { + //still works good with reading from files + int iIndex = PropsArray.Push(EntIndexToEntRef(iEnt)); + SetEntityName(iEnt, "Prop_%i", iIndex); + //PrintToChatAll("iEnt: %i", iEnt); + } + } + } + delete l_hPropFile; + PropKv.Rewind(); +} + +void ResetProps() +{ + for (int i = 0; i < PropsArray.Length; i++) + { + int iEnt = EntRefToEntIndex(PropsArray.Get(i)); + + if (iEnt != INVALID_ENT_REFERENCE) + AcceptEntityInput(iEnt, "kill"); + } + PropsArray.Clear(); + + LoadProps(); +} + + + +//Trace +public bool TraceRayDontHitPlayer(int entity, int mask, any data) +{ + if(entity != data && entity > MaxClients) + { + return true; + } + return false; +} + +//Stocks +void ColorToString(char[] sColor, int maxlength, int r, int g, int b, int a) +{ + Format(sColor, maxlength, "%i %i %i %i", r, g, b, a); +} + +void StringToColor(char[] sColors, int &r, int &g, int &b, int &a) +{ + char sColorsL[4][64]; + //PrintToChatAll("sColors: %s", sColors); + ExplodeString(sColors, " ", sColorsL, sizeof(sColorsL), sizeof(sColorsL[])); + r = StringToInt(sColorsL[0]); + g = StringToInt(sColorsL[1]); + b = StringToInt(sColorsL[2]); + a = StringToInt(sColorsL[3]); +} + +void ClearPropKv() +{ + if (!PropKv.GotoFirstSubKey()) + return; + + do + { + PropKv.DeleteThis(); + } + while (PropKv.GotoNextKey()); + + PropKv.Rewind(); +} + +int FindInArray(int iEnt) +{ + if (iEnt == -1) + return 0; + + for (int i = 0; i < PropsArray.Length; i++) + { + int iSavedEnt = EntRefToEntIndex(PropsArray.Get(i)); + + if (iSavedEnt == INVALID_ENT_REFERENCE) + return 0; + + if (iSavedEnt == iEnt) + { + return i; + } + } + return 0; +} + +//Use this(instead of GetClientAimTarget) since we need to get non-solid entites too. +int GetAimEnt(int client) +{ + float vClientPos[3]; + float vClientAng[3]; + GetClientEyePosition(client, vClientPos); + GetClientEyeAngles(client, vClientAng); + TR_TraceRayFilter(vClientPos, vClientAng, MASK_ALL, RayType_Infinite, TraceRayDontHitPlayer, client); + int iEnt = TR_GetEntityIndex(); + //PrintToChatAll("IsValidEntity"); + + if (iEnt == 0) //if it hits nothing dont do anything man + { + iEnt = -1; + } + return iEnt; +} +public void OnClientDisconnect(int iClient) +{ + bMoveProp[iClient] = false; +} +public void OnClientPostAdminCheck(int iClient) +{ + bMoveProp[iClient] = false; +} + +//Natives +public int Native_IsEntProp(Handle plugin, int numParams) +{ + int iEnt = GetNativeCell(1); + + return (FindInArray(iEnt) == -1); +} \ No newline at end of file diff --git a/Plugins/hextags/scripting/hextags.sp b/Plugins/hextags/scripting/hextags.sp new file mode 100644 index 00000000..5921c991 --- /dev/null +++ b/Plugins/hextags/scripting/hextags.sp @@ -0,0 +1,1327 @@ +/* + * HexTags Plugin. + * by: Hexah + * https://github.com/Hexer10/HexTags + * + * Copyright (C) 2017 Mattia (Hexah|Hexer10|Papero) + * + * This file is part of the HexTags SourceMod Plugin. + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, version 3.0, as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include + +#undef REQUIRE_EXTENSIONS +#undef REQUIRE_PLUGIN +#include +#define REQUIRE_EXTENSIONS +#define REQUIRE_PLUGIN + +#define PLUGIN_AUTHOR "Hexah, changed by jenz" +#define PLUGIN_VERSION "1.208" + + +#pragma semicolon 1 +#pragma newdecls required + +Handle fTagsUpdated; + +bool bLate; + +//deffently needed for checking client pref +KeyValues g_hHextags; +KeyValues g_hIngame; + +static char g_sKVPATH[PLATFORM_MAX_PATH]; +static char g_sKVPATH1[PLATFORM_MAX_PATH]; +bool g_bHextags[MAXPLAYERS+1]; + +char clan[1024]; +char OriginalClan[512]; +char sTags[MAXPLAYERS + 1][eTags][128]; +char sNewName[MAXLENGTH_NAME]; +char sSecs[16]; + +int iPoints[MAXPLAYERS]; + +KeyValues kv; + + +//vip chattags +char ChatTagchat[MAXPLAYERS]; +int i_hasTag[MAXPLAYERS]; +//vip chatcolors +char ChatTagColor[MAXPLAYERS]; + +//token chattags +bool b_tokenTag[MAXPLAYERS+1]; +char c_storestats[MAXPLAYERS+1][MAX_NAME_LENGTH]; +char c_Chattagtoken[MAXPLAYERS+1][MAX_NAME_LENGTH]; + +//Plugin infos +public Plugin myinfo = +{ + name = "hextagsLevels", + author = PLUGIN_AUTHOR, + description = "Edit Tags & Colors! Modified by jenz", + version = PLUGIN_VERSION, + url = "https://forums.alliedmods.net/showthread.php?t=303671" +}; + +//Startup +public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) +{ + fTagsUpdated = CreateGlobalForward("HexTags_OnTagsUpdated", ET_Ignore, Param_Cell); + + //LateLoad + bLate = late; + return APLRes_Success; +} + +public void OnPluginStart() +{ + SQL_StartConnection(); + CreateConVar("sm_hextags_version", PLUGIN_VERSION, "HexTags plugin version", FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY); + + //Reg Cmds + RegAdminCmd("sm_reloadtags", Cmd_ReloadTags, ADMFLAG_BAN, "Reload HexTags plugin config"); + RegAdminCmd("sm_hexmysql", cmd_HexmySQL, ADMFLAG_BAN, "test mysql query result"); + RegAdminCmd("sm_chattag", cmd_ChatTag, ADMFLAG_CUSTOM1, "Select chat text"); + RegAdminCmd("sm_chatcolour", cmd_ChatColor, ADMFLAG_CUSTOM1, "Select chat colour"); + RegAdminCmd("sm_chatcolor", cmd_ChatColor, ADMFLAG_CUSTOM1, "Select chat color"); + + RegConsoleCmd("sm_getteam", Cmd_GetTeam, "Get current team name"); + RegConsoleCmd("sm_tokentag", Cmd_tokenTags, "Choose your tokentag"); + RegConsoleCmd("sm_tokentags", Cmd_tokenTags, "Choose your tokentag"); + RegConsoleCmd("sm_hextags", cmd_HexTags, "Restores clantag (reconnect maybe first)"); + + //storage of prefference + g_hHextags = new KeyValues("hexTags"); + BuildPath(Path_SM, g_sKVPATH, sizeof(g_sKVPATH), "data/playerprefs.hextags.txt"); + g_hHextags.ImportFromFile(g_sKVPATH); + + g_hIngame = new KeyValues("clanPrefs"); + BuildPath(Path_SM, g_sKVPATH1, sizeof(g_sKVPATH1), "data/playerprefs.ingame.txt"); + g_hIngame.ImportFromFile(g_sKVPATH1); + + + LoadKv(); + + //LateLoad + if (bLate) + { + + for (int i = 1; i <= MaxClients; i++)if (IsClientInGame(i)) + { + if(IsClientInGame(i) && IsClientAuthorized(i)) + { + // seems pretty good, only issue right now should be clan getting overwritten by new players + OnClientPostAdminCheck(i); + //check preferrence + static char sAuth[32]; + GetClientAuthId(i, AuthId_Steam2, sAuth, sizeof(sAuth)); + OnClientAuthorized(i, sAuth); + Frame_SetTag(GetClientUserId(i)); + } + } + + } +} + +public void OnPluginEnd() +{ + for(int client = 1; client <= MaxClients; client++) + { + if(IsClientInGame(client)) + OnClientDisconnect_Post(client); + } +} + + + +//Thanks to https://forums.alliedmods.net/showpost.php?p=2573907&postcount=6 +public Action OnClientCommandKeyValues(int client, KeyValues TagKv) +{ + char sKey[64]; + if (!TagKv.GetSectionName(sKey, sizeof(sKey))) + return Plugin_Continue; + + + if (StrEqual(sKey, "ClanTagChanged")) + { + Frame_SetTag(GetClientUserId(client)); + RequestFrame(Frame_SetTag, GetClientUserId(client)); + } + + return Plugin_Continue; +} + + +public void Frame_SetTag(any iUserID) +{ + int client = GetClientOfUserId(iUserID); + LoadTags(client); + + static char SID[32]; + GetClientAuthId(client, AuthId_Steam2, SID, sizeof(SID)); + + g_hHextags.Rewind(); + if(g_hHextags.JumpToKey(SID, true)) + { + int disabled = g_hHextags.GetNum("disabled", 0); + if(!disabled) + { + PrintToConsole(client, "disabled false"); + + + if (strlen(sTags[client][ScoreTag]) > 0 && IsCS()) + { + CS_SetClientClanTag(client, sTags[client][ScoreTag]); + } + } + } + else + { + PrintToConsole(client, "[SM]g_hHextags is false"); + } +} + + +//Commands + +public Action Cmd_ReloadTags(int client, int args) +{ + LoadKv(); + for (int i = 1; i <= MaxClients; i++)if (IsClientInGame(i))OnClientPostAdminCheck(i); + + ReplyToCommand(client, "[SM] Tags succesfully reloaded!"); + return Plugin_Handled; +} +public Action cmd_HexmySQL (int client, int args) +{ + ReplyToCommand(client, "[SM] Your iPoints are: %d", iPoints[client]); + PrintToConsole(client, "[SM] sSEC: %s", sSecs); + return Plugin_Handled; +} + + + +public Action cmd_ChatColor (int client, int args) +{ + if (!IsValidClient(client)) + { + return Plugin_Continue; + } + Menu menu = new Menu(ChatColorMenu_Handler); + if (CheckCommandAccess(client, "actual vip", ADMFLAG_CUSTOM1, true)) + { + menu.SetTitle("Chat Colors Menu"); + menu.AddItem("default", "default"); + menu.AddItem("teamcolor", "teamcolor"); + menu.AddItem("red", "red"); + menu.AddItem("lightred", "lightred"); + menu.AddItem("darkred", "darkred"); + menu.AddItem("bluegrey", "bluegrey"); + menu.AddItem("blue", "blue"); + menu.AddItem("darkblue", "darkblue"); + menu.AddItem("purple", "purple"); + menu.AddItem("orchid", "orchid"); + menu.AddItem("yellow", "yellow"); + menu.AddItem("gold", "gold"); + menu.AddItem("lightgreen", "lightgreen"); + menu.AddItem("green", "green"); + menu.AddItem("lime", "lime"); + menu.AddItem("grey", "grey"); + menu.AddItem("grey2", "grey2"); + + menu.Display(client, 0); + return Plugin_Handled; + } + if (b_tokenTag[client] == false) + { + PrintToChat(client, "Check !shop to gain access to !chatcolor"); + return Plugin_Handled; + } + if (StrContains(c_storestats[client], "l") >= 0) + { + menu.AddItem("teamcolor", "teamcolor"); + menu.AddItem("red", "red"); + menu.AddItem("lightred", "lightred"); + } + if (StrContains(c_storestats[client], "m") >= 0) + { + menu.AddItem("darkred", "darkred"); + menu.AddItem("bluegrey", "bluegrey"); + menu.AddItem("blue", "blue"); + } + if (StrContains(c_storestats[client], "n") >= 0) + { + menu.AddItem("darkblue", "darkblue"); + menu.AddItem("purple", "purple"); + menu.AddItem("orchid", "orchid"); + } + if (StrContains(c_storestats[client], "o") >= 0) + { + menu.AddItem("yellow", "yellow"); + } + if (StrContains(c_storestats[client], "p") >= 0) + { + menu.AddItem("gold", "gold"); + } + if (StrContains(c_storestats[client], "q") >= 0) + { + menu.AddItem("lightgreen", "lightgreen"); + } + if (StrContains(c_storestats[client], "r") >= 0) + { + menu.AddItem("green", "green"); + } + if (StrContains(c_storestats[client], "s") >= 0) + { + menu.AddItem("lime", "lime"); + } + if (StrContains(c_storestats[client], "t") >= 0) + { + menu.AddItem("grey", "grey"); + } + if (StrContains(c_storestats[client], "u") >= 0) + { + menu.AddItem("grey2", "grey2"); + } + menu.Display(client, 0); + return Plugin_Handled; +} + + +public int ChatColorMenu_Handler(Menu menu, MenuAction action, int client, int choice) +{ + if (action == MenuAction_Select) + { + char info[32]; + menu.GetItem(choice, info, sizeof(info)); + + static char SID[32]; + GetClientAuthId(client, AuthId_Steam2, SID, sizeof(SID)); + + if (StrEqual(info, "default", true)) + { + PrintToChat(client, "%N Selected Default Color.", client); + strcopy(ChatTagColor[client], sizeof(ChatTagColor), ""); + Format(ChatTagColor[client], sizeof(ChatTagColor), "default"); + chatcolorMYSQL(client, info); + return; + } + else if (StrEqual(info, "teamcolor", true)) + { + PrintToChat(client, "%N Selected teamcolor.", client); + strcopy(ChatTagColor[client], sizeof(ChatTagColor), ""); + Format(ChatTagColor[client], sizeof(ChatTagColor), "teamcolor"); + chatcolorMYSQL(client, info); + return; + } + else if (StrEqual(info, "red", true)) + { + PrintToChat(client, "%N Selected red Color.", client); + strcopy(ChatTagColor[client], sizeof(ChatTagColor), ""); + Format(ChatTagColor[client], sizeof(ChatTagColor), "red"); + chatcolorMYSQL(client, info); + + return; + } + else if (StrEqual(info, "lightred", true)) + { + PrintToChat(client, "%N Selected lightred Color.", client); + strcopy(ChatTagColor[client], sizeof(ChatTagColor), ""); + Format(ChatTagColor[client], sizeof(ChatTagColor), "lightred"); + chatcolorMYSQL(client, info); + + return; + } + else if (StrEqual(info, "darkred", true)) + { + PrintToChat(client, "%N Selected darkred Color.", client); + strcopy(ChatTagColor[client], sizeof(ChatTagColor), ""); + Format(ChatTagColor[client], sizeof(ChatTagColor), "darkred"); + chatcolorMYSQL(client, info); + + return; + } + else if (StrEqual(info, "bluegrey", true)) + { + PrintToChat(client, "%N Selected bluegrey Color.", client); + strcopy(ChatTagColor[client], sizeof(ChatTagColor), ""); + Format(ChatTagColor[client], sizeof(ChatTagColor), "bluegrey"); + chatcolorMYSQL(client, info); + + return; + } + else if (StrEqual(info, "blue", true)) + { + PrintToChat(client, "%N Selected blue Color.", client); + strcopy(ChatTagColor[client], sizeof(ChatTagColor), ""); + Format(ChatTagColor[client], sizeof(ChatTagColor), "blue"); + chatcolorMYSQL(client, info); + + return; + } + else if (StrEqual(info, "darkblue", true)) + { + PrintToChat(client, "%N Selected darkblue Color.", client); + strcopy(ChatTagColor[client], sizeof(ChatTagColor), ""); + Format(ChatTagColor[client], sizeof(ChatTagColor), "darkblue"); + chatcolorMYSQL(client, info); + + return; + } + else if (StrEqual(info, "purple", true)) + { + PrintToChat(client, "%N Selected purple Color.", client); + strcopy(ChatTagColor[client], sizeof(ChatTagColor), ""); + Format(ChatTagColor[client], sizeof(ChatTagColor), "purple"); + chatcolorMYSQL(client, info); + + return; + } + else if (StrEqual(info, "orchid", true)) + { + PrintToChat(client, "%N Selected orchid Color.", client); + strcopy(ChatTagColor[client], sizeof(ChatTagColor), ""); + Format(ChatTagColor[client], sizeof(ChatTagColor), "orchid"); + chatcolorMYSQL(client, info); + + return; + } + else if (StrEqual(info, "yellow", true)) + { + PrintToChat(client, "%N Selected yellow Color.", client); + strcopy(ChatTagColor[client], sizeof(ChatTagColor), ""); + Format(ChatTagColor[client], sizeof(ChatTagColor), "yellow"); + chatcolorMYSQL(client, info); + + return; + } + else if (StrEqual(info, "gold", true)) + { + PrintToChat(client, "%N Selected gold Color.", client); + strcopy(ChatTagColor[client], sizeof(ChatTagColor), ""); + Format(ChatTagColor[client], sizeof(ChatTagColor), "gold"); + chatcolorMYSQL(client, info); + return; + } + else if (StrEqual(info, "lightgreen", true)) + { + PrintToChat(client, "%N Selected lightgreen Color.", client); + strcopy(ChatTagColor[client], sizeof(ChatTagColor), ""); + Format(ChatTagColor[client], sizeof(ChatTagColor), "lightgreen"); + chatcolorMYSQL(client, info); + + return; + } + else if (StrEqual(info, "green", true)) + { + PrintToChat(client, "%N Selected green Color.", client); + strcopy(ChatTagColor[client], sizeof(ChatTagColor), ""); + Format(ChatTagColor[client], sizeof(ChatTagColor), "green"); + chatcolorMYSQL(client, info); + return; + } + else if (StrEqual(info, "lime", true)) + { + PrintToChat(client, "%N Selected lime Color.", client); + strcopy(ChatTagColor[client], sizeof(ChatTagColor), ""); + Format(ChatTagColor[client], sizeof(ChatTagColor), "lime"); + chatcolorMYSQL(client, info); + + return; + } + else if (StrEqual(info, "grey", true)) + { + PrintToChat(client, "%N Selected grey Color.", client); + strcopy(ChatTagColor[client], sizeof(ChatTagColor), ""); + Format(ChatTagColor[client], sizeof(ChatTagColor), "grey"); + chatcolorMYSQL(client, info); + + return; + } + else if (StrEqual(info, "grey2", true)) + { + PrintToChat(client, "%N Selected grey2 Color.", client); + strcopy(ChatTagColor[client], sizeof(ChatTagColor), ""); + Format(ChatTagColor[client], sizeof(ChatTagColor), "grey2"); + chatcolorMYSQL(client, info); + + return; + } + } +} + + +public Action cmd_ChatTag (int client, int args) +{ + char inputArgs[250]; + GetCmdArgString(inputArgs, sizeof(inputArgs)); + + if (StrContains(inputArgs, "'", false) >= 0) + { + PrintToChat(client, "[UNLOZE]' is invalid symbol"); + return Plugin_Handled; + } + if (StrContains(inputArgs, "reset", false) >= 0) + { + i_hasTag[client] = 0; + chattagMYSQL(client, inputArgs); + return Plugin_Handled; + } + i_hasTag[client] = 1; + ReplyToCommand(client, "Updated Chattag: %s", inputArgs); + + Format(ChatTagchat[client], sizeof(ChatTagchat), inputArgs); + chattagMYSQL(client, inputArgs); + return Plugin_Handled; +} + +public Action Cmd_tokenTags(int client, int args) +{ + if (b_tokenTag[client] == false) + { + PrintToChat(client, "Check !shop to gain access to !tokentag"); + return Plugin_Handled; + } + Menu menu = new Menu(MenuHandler1); + menu.SetTitle("Unloze Token Tags"); + if (StrContains(c_storestats[client], "l") >= 0) + { + menu.AddItem("Rookie", "Rookie"); + } + if (StrContains(c_storestats[client], "m") >= 0) + { + menu.AddItem("MEMBER", "MEMBER"); + } + if (StrContains(c_storestats[client], "n") >= 0) + { + menu.AddItem("SERBIAN", "SERBIAN"); + } + if (StrContains(c_storestats[client], "o") >= 0) + { + menu.AddItem("Overweight Vegetarian", "Overweight Vegetarian"); + } + if (StrContains(c_storestats[client], "p") >= 0) + { + menu.AddItem("русский", "русский"); + } + if (StrContains(c_storestats[client], "q") >= 0) + { + menu.AddItem("NIGGER elites", "NIGGER elites"); + } + if (StrContains(c_storestats[client], "r") >= 0) + { + menu.AddItem("BAGUETTE", "BAGUETTE"); + } + if (StrContains(c_storestats[client], "s") >= 0) + { + menu.AddItem("DANE", "DANE"); + } + if (StrContains(c_storestats[client], "t") >= 0) + { + menu.AddItem("WEEB", "WEEB"); + } + if (StrContains(c_storestats[client], "u") >= 0) + { + menu.AddItem("Nosteam Chad", "Nosteam Chad"); + } + + menu.AddItem("Reset", "Reset"); + menu.ExitButton = true; + menu.Display(client, 0); + return Plugin_Handled; +} + + +public int MenuHandler1(Menu menu, MenuAction action, int client, int choice) +{ + if (action == MenuAction_Select) + { + char info[32]; + menu.GetItem(choice, info, sizeof(info)); + if (StrEqual(info, "Rookie", true)) + { + Format(c_Chattagtoken[client], sizeof(c_Chattagtoken), "Rookie"); + } + else if (StrEqual(info, "MEMBER", true)) + { + Format(c_Chattagtoken[client], sizeof(c_Chattagtoken), "MEMBER"); + } + else if (StrEqual(info, "SERBIAN", true)) + { + Format(c_Chattagtoken[client], sizeof(c_Chattagtoken), "SERBIAN"); + } + else if (StrEqual(info, "Overweight Vegetarian", true)) + { + Format(c_Chattagtoken[client], sizeof(c_Chattagtoken), "Overweight Vegetarian"); + } + else if (StrEqual(info, "Reset", true)) + { + Format(c_Chattagtoken[client], sizeof(c_Chattagtoken), "Reset"); + } + PrintToChat(client, "Selected %s as Chattag", info); + chattagMYSQLTokens(client, info); + } +} + + +public Action Cmd_GetTeam(int client, int args) +{ + char sTeam[32]; + GetTeamName(GetClientTeam(client), sTeam, sizeof(sTeam)); + ReplyToCommand(client, "[SM] Current team name: %s", sTeam); + return Plugin_Handled; +} + +public Action cmd_HexTags(int client, int args) +{ + static char SID[32]; + GetClientAuthId(client, AuthId_Steam2, SID, sizeof(SID)); + + if (strlen(OriginalClan) >= 0) + { + g_hHextags.Rewind(); + if(g_hHextags.JumpToKey(SID, true)) + { + int disabled = g_hHextags.GetNum("disabled", 0); + if(!disabled) + { + //ReplyToCommand(client, "[HexTags] Saved entry for STEAMID({green}%s{default}) {green}successfully{default}.", SID); + g_hHextags.SetNum("disabled", 1); + g_hHextags.Rewind(); + g_hHextags.ExportToFile(g_sKVPATH); + + g_bHextags[client] = true; + ReplyToCommand(client, "[Hextags] Hextags disabled - entry saved."); + + g_hIngame.Rewind(); + if(g_hIngame.JumpToKey(SID, true)) + { + g_hIngame.GetString("clan", OriginalClan, sizeof(OriginalClan)); + } + + CS_SetClientClanTag(client, OriginalClan); + return Plugin_Handled; + } + else + { + //CPrintToChat(client, "[StopSound] Entry for STEAMID({green}%s{default}) {green}successfully deleted{default}.", SID); + g_hHextags.DeleteThis(); + g_hHextags.Rewind(); + g_hHextags.ExportToFile(g_sKVPATH); + + g_bHextags[client] = false; + ReplyToCommand(client, "[Hextags] Hextags enabled - entry deleted."); + + CS_SetClientClanTag(client, sTags[client][ScoreTag]); + return Plugin_Handled; + } + } + g_hHextags.Rewind(); + } + + + g_bHextags[client] = !g_bHextags[client]; + ReplyToCommand(client, "[Hextags FAILED?] Hextags %s.", g_bHextags[client] ? "disabled" : "enabled"); + return Plugin_Handled; +} + + +//Events + +public void OnClientAuthorized(int client, const char[] auth) +{ + if (IsFakeClient(client) == false) + { + //prevents OnClientAuthorized errors in sourcemod logs + iPoints[client] = CheckMYSQL(client); + CheckFlagsMYSQL(client); + TokentagMYSQL(client); + g_hHextags.Rewind(); + if(KvJumpToKey(g_hHextags, auth, false)) + { + int disabled = g_hHextags.GetNum("disabled", 0); + if (disabled) + g_bHextags[client] = true; + } + + g_hHextags.Rewind(); + } +} + +public void OnClientDisconnect_Post(int client) +{ + iPoints[client] = 0; + g_bHextags[client] = false; + Format(c_storestats[client], sizeof(c_storestats), ""); + g_hIngame.Rewind(); + g_hIngame.DeleteThis(); + g_hIngame.ExportToFile(g_sKVPATH1); + + Format(ChatTagColor[client], sizeof(ChatTagColor), "default"); + Format(c_Chattagtoken[client], sizeof(c_Chattagtoken), ""); +} + + +public void OnClientPostAdminCheck(int client) +{ + if (IsFakeClient(client) == true) + { + iPoints[client] = CheckMYSQL(client); + } + ReplaceString(sTags[client][ScoreTag], sizeof(sTags[][]), "{country}", "Dream bubbles and the furthest ring"); //sCountry + i_hasTag[client] = 0; + b_tokenTag[client] = false; + if (StrContains(c_storestats[client], "l") >= 0 || StrContains(c_storestats[client], "m") >= 0 || StrContains(c_storestats[client], "n") >= 0) + { + b_tokenTag[client] = true; + } + else if (StrContains(c_storestats[client], "o") >= 0 || StrContains(c_storestats[client], "p") >= 0 || StrContains(c_storestats[client], "q") >= 0) + { + b_tokenTag[client] = true; + } + else if (StrContains(c_storestats[client], "r") >= 0 || StrContains(c_storestats[client], "s") >= 0 || StrContains(c_storestats[client], "t") >= 0) + { + b_tokenTag[client] = true; + } + else if (StrContains(c_storestats[client], "u") >= 0) + { + b_tokenTag[client] = true; + } + sendMYSQL(client); +} + +public Action CP_OnChatMessage(int& author, ArrayList recipients, char[] flagstring, char[] name, char[] message, bool& processcolors, bool& removecolors) +{ + char sNewMessage[MAXLENGTH_MESSAGE]; + + for (int i = 0; i <= MaxClients; i++) + { + if (IsValidClient(i)) + { + if (i_hasTag[i] == 1 && (("%N", i) == ("%i", author))) + { + static char sAuth[32]; + GetClientAuthId(i, AuthId_Steam2, sAuth, sizeof(sAuth)); + strcopy(ChatTagchat[i], sizeof(ChatTagchat), ""); + strcopy(ChatTagColor[i], sizeof(ChatTagColor), ""); + + sendMYSQL(i); + + Format(sNewName, MAXLENGTH_NAME, "{%s}[%s] %s%s{default}", ChatTagColor[i], ChatTagchat[i], sTags[author][NameColor], name); + Format(sNewMessage, MAXLENGTH_MESSAGE, "%s%s", sTags[author][ChatColor], message); + strcopy(name, MAXLENGTH_NAME, sNewName); + strcopy(message, MAXLENGTH_MESSAGE, sNewMessage); + processcolors = true; + removecolors = false; + + return Plugin_Changed; + } + else if (IsValidClient(i) && i_hasTag[i] == 0 && i == author && b_tokenTag[i] == true && (StrContains(c_Chattagtoken[i], "reset", false) < 0)) + { + Format(sNewName, MAXLENGTH_NAME, "{%s}[%s] %s%s{default}", ChatTagColor[i], c_Chattagtoken[i], sTags[author][NameColor], name); + Format(sNewMessage, MAXLENGTH_MESSAGE, "%s%s", sTags[author][ChatColor], message); + strcopy(name, MAXLENGTH_NAME, sNewName); + strcopy(message, MAXLENGTH_MESSAGE, sNewMessage); + processcolors = true; + removecolors = false; + + return Plugin_Changed; + } + else if (IsValidClient(i) && i_hasTag[i] == 0 && i == author) + { + Format(sNewName, MAXLENGTH_NAME, "{default}[lvl: %s] %s%s{default}", sTags[author][Level], sTags[author][NameColor], name); + Format(sNewMessage, MAXLENGTH_MESSAGE, "%s%s", sTags[author][ChatColor], message); + strcopy(name, MAXLENGTH_NAME, sNewName); + strcopy(message, MAXLENGTH_MESSAGE, sNewMessage); + processcolors = true; + removecolors = false; + + return Plugin_Changed; + } + } + } + return Plugin_Changed; +} + + +//Functions +void LoadKv() +{ + char sConfig[PLATFORM_MAX_PATH]; + BuildPath(Path_SM, sConfig, sizeof(sConfig), "configs/hextags.cfg"); //Get cfg file + + if (OpenFile(sConfig, "rt") == null) + SetFailState("Couldn't find: \"%s\"", sConfig); //Check if cfg exist + + if (kv != null) + delete kv; + + kv = new KeyValues("HexTags"); //Create the kv + + + if (!kv.ImportFromFile(sConfig)) + SetFailState("Couldn't import: \"%s\"", sConfig); //Check if file was imported properly + + if (!kv.GotoFirstSubKey()) + LogMessage("No entries found in: \"%s\"", sConfig); //Notify that there aren't any entry +} + + + + + +void LoadTags(int client) +{ + //Clear the tags when re-checking + ResetTags(client); + + kv.Rewind(); + + //// GOOD PLACE FOR CS_GetClientClanTag + CS_GetClientClanTag(client, clan, sizeof(clan)); + g_hIngame.Rewind(); + static char SID[32]; + GetClientAuthId(client, AuthId_Steam2, SID, sizeof(SID)); + if(g_hIngame.JumpToKey(SID, true)) + { + g_hIngame.SetString("clan", clan); + } + + g_hIngame.ExportToFile(g_sKVPATH1); + //Check steamid checking + char steamid[32]; + + if (!GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid))) + return; + + if (kv.JumpToKey(steamid)) + { + Call_StartForward(fTagsUpdated); + Call_PushCell(client); + Call_Finish(); + GetTags(client); + return; + } + + steamid[6] = '0'; //Replace the STEAM_1 to STEAM_0 + + if (kv.JumpToKey(steamid)) //Check again with STEAM_0 + { + + GetTags(client); + Call_StartForward(fTagsUpdated); + Call_PushCell(client); + Call_Finish(); + return; + } + + //Start AdminGroups checking + AdminId admin = GetUserAdmin(client); + if (admin != INVALID_ADMIN_ID) + { + char sGroup[32]; + admin.GetGroup(0, sGroup, sizeof(sGroup)); + Format(sGroup, sizeof(sGroup), "@%s", sGroup); + + if (kv.JumpToKey(sGroup)) + { + GetTags(client); + Call_StartForward(fTagsUpdated); + Call_PushCell(client); + Call_Finish(); + return; + } + } + + //Start flags checking + char sFlags[21] = "abcdefghijklmnopqrstz"; + + for (int i = sizeof(sFlags) - 1; 0 <= i; i--) + { + char sFlag[1]; + sFlag[0] = sFlags[i]; + + if (ReadFlagString(sFlag) & GetUserFlagBits(client)) + { + if (kv.JumpToKey(sFlag)) + { + GetTags(client); + Call_StartForward(fTagsUpdated); + Call_PushCell(client); + Call_Finish(); + return; + } + } + } + + //start level checking + bool blvl = true; + if (blvl) + { + int iOldTime; + bool bReturn; + + if (!kv.GotoFirstSubKey()) + return; + do + { + + kv.GetSectionName(sSecs, sizeof(sSecs)); + + if(sSecs[0] != '#') //Check if it's a "level-format" + continue; + Format(sSecs, sizeof(sSecs), "%s", sSecs[1]); //Cut the '#' at the start + + if(iOldTime >= StringToInt(sSecs)) //Select only the higher time. + continue; + + if (StringToInt(sSecs) <= iPoints[client] / 1000) + { + GetTags(client); + iOldTime = StringToInt(sSecs); //Save the time + bReturn = true; + } + } + while (kv.GotoNextKey()); + + kv.Rewind(); + if (bReturn) + { + Call_StartForward(fTagsUpdated); + Call_PushCell(client); + Call_Finish(); + return; + } + } + + //Start team checking + char sTeam[32]; + int team = GetClientTeam(client); + GetTeamName(team, sTeam, sizeof(sTeam)); + + if (kv.JumpToKey(sTeam)) + { + GetTags(client); + return; + } + + //Check for 'All' entry + if (kv.JumpToKey("Default")) + GetTags(client); + + //Call the forward + Call_StartForward(fTagsUpdated); + Call_PushCell(client); + Call_Finish(); +} + +//Stocks +void GetTags(int client) +{ + kv.GetString("ScoreTag", sTags[client][ScoreTag], sizeof(sTags[][]), ""); + kv.GetString("ChatColor", sTags[client][ChatColor], sizeof(sTags[][]), ""); + kv.GetString("NameColor", sTags[client][NameColor], sizeof(sTags[][]), "{teamcolor}"); + kv.GetString("Level", sTags[client][Level], sizeof(sTags[][]), ""); +} + +void ResetTags(int client) +{ + strcopy(sTags[client][ScoreTag], sizeof(sTags[][]), ""); + strcopy(sTags[client][ChatColor], sizeof(sTags[][]), ""); + strcopy(sTags[client][NameColor], sizeof(sTags[][]), ""); + strcopy(sTags[client][Level], sizeof(sTags[][]), ""); +} + +bool IsCS() +{ + EngineVersion engine = GetEngineVersion(); + + return (engine == Engine_CSGO || engine == Engine_CSS); +} + +//API + +public int Native_SetClientTag(Handle plugin, int numParams) +{ + int client = GetNativeCell(1); + + if (client < 1 || client > MaxClients) + { + return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%d)", client); + } + if (!IsClientConnected(client)) + { + return ThrowNativeError(SP_ERROR_NATIVE, "Client %d is not connected", client); + } + + char sTag[32]; + eTags Tag = view_as(GetNativeCell(2)); + GetNativeString(3, sTag, sizeof(sTag)); + + strcopy(sTags[client][Tag], sizeof(sTags[][]), sTag); + return 0; +} + +public int Native_ResetClientTags(Handle plugin, int numParams) +{ + int client = GetNativeCell(1); + + if (client < 1 || client > MaxClients) + { + return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%d)", client); + } + if (!IsClientConnected(client)) + { + return ThrowNativeError(SP_ERROR_NATIVE, "Client %d is not connected", client); + } + + LoadTags(client); + return 0; +} + +stock bool IsValidClient(int client, bool alive = false, bool bots = false) +{ + if (client > 0 && client <= MaxClients && IsClientInGame(client) && (alive == false || IsPlayerAlive(client)) && (bots == false && !IsFakeClient(client))) + { + return true; + } + return false; +} + +stock void CheckCloseHandle(Handle handle) +{ + if (handle != INVALID_HANDLE) + { + CloseHandle(handle); + handle = INVALID_HANDLE; + } +} + + +/*neon idea */ +public int CheckMYSQL(int client) +{ + if (client < 1 || client > MaxClients) + { + return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%d)", client); + } + + + char error[255]; + Database db; + if (SQL_CheckConfig("stats")) + { + db = SQL_Connect("stats", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return -1; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + strcopy(sSID, sizeof(sSID), sSID[8]); //matching up with hlstats_PlayerUniqueIds + char sQuery[255]; + if (IsFakeClient(client) == false) + { + Format(sQuery, sizeof(sQuery), "SELECT skill from hlstats_Players JOIN hlstats_PlayerUniqueIds ON hlstats_Players.playerId = hlstats_PlayerUniqueIds.playerId WHERE uniqueId = '%s' AND hlstats_PlayerUniqueIds.game = 'csgo-ze'", sSID); + } + else + { + Format(sQuery, sizeof(sQuery), "SELECT skill FROM hlstats_Players WHERE playerId = '7715' "); + } + + DBResultSet rs; + + if ((rs = SQL_Query(db, sQuery)) == null) + { + //PrintToConsole(client, "[Unloze] Failed sQuery: %s", sQuery); + delete db; + delete rs; + return -1; + } + //PrintToConsole(client, "[Unloze] Success sQuery: %s", sQuery); + + + int iCollected; + + if (!(rs.RowCount > 0)) + { + iCollected = 0; + } + else + { + int iField; + rs.FetchRow(); + rs.FieldNameToNum("collected", iField); + iCollected = rs.FetchInt(iField); + if (IsFakeClient(client) == true) + { + char tag[64]; + Format(tag, sizeof(tag), "[LVL: %i]", (iCollected / 1000)); + CS_SetClientClanTag(client, tag); + } + } + delete rs; + delete db; + return iCollected; +} + + +public void sendMYSQL(int client) +{ + char error[255]; + Database db; + if (SQL_CheckConfig("unloze_chatcsgo")) + { + db = SQL_Connect("unloze_chatcsgo", true, error, sizeof(error)); + } + if (db == null) + { + CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + + char sQuery[255]; + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + Format(sQuery, sizeof(sQuery), "SELECT chattag, chatcolor FROM `unloze_csgochat` WHERE steam_id = '%s'", sSID); + DBResultSet rs; + + if ((rs = SQL_Query(db, sQuery)) == null) + { + + delete db; + delete rs; + return; + } + + Format(ChatTagColor[client], sizeof(ChatTagColor), "default"); + if (!(rs.RowCount > 0)) + { + Format(ChatTagchat[client], sizeof(ChatTagchat), "Place holder"); + } + else if (rs.FetchRow()) + { + rs.FetchString(0, ChatTagchat[client], MAX_NAME_LENGTH); + rs.FetchString(1, ChatTagColor[client], MAX_NAME_LENGTH); + if (CheckCommandAccess(client, "actual vip", ADMFLAG_CUSTOM1, true)) + { + i_hasTag[client] = 1; + } + else + { + i_hasTag[client] = 0; + } + if (StrContains(ChatTagchat[client], "reset", false) >= 0) + { + i_hasTag[client] = 0; + } + } + + delete rs; + delete db; + return; +} + +public void chatcolorMYSQL(int client, const char[] inputarg) +{ + char error[255]; + Database db; + if (SQL_CheckConfig("unloze_chatcsgo")) + { + db = SQL_Connect("unloze_chatcsgo", true, error, sizeof(error)); + } + if (db == null) + { + CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + + char sQuery[255]; + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_csgochat` (`steam_id`, `chatcolor`) VALUES ('%s','%s') ON DUPLICATE KEY UPDATE `chatcolor` = '%s'", sSID, inputarg, inputarg); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete db; +} + +public void chattagMYSQL(int client, const char[] inputarg) +{ + char error[255]; + Database db; + if (SQL_CheckConfig("unloze_chatcsgo")) + { + db = SQL_Connect("unloze_chatcsgo", true, error, sizeof(error)); + } + if (db == null) + { + CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + + char sQuery[255]; + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_csgochat` (`steam_id`, `chattag`) VALUES ('%s','%s') ON DUPLICATE KEY UPDATE `chattag` = '%s'", sSID, inputarg, inputarg); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete db; +} + +public void chattagMYSQLTokens(int client, const char[] info) +{ + char error[255]; + Database db; + if (SQL_CheckConfig("unloze_chatcsgo")) + { + db = SQL_Connect("unloze_chatcsgo", true, error, sizeof(error)); + } + if (db == null) + { + CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + + char sQuery[255]; + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_csgochattokens` (`steam_id`, `chattag`) VALUES ('%s','%s') ON DUPLICATE KEY UPDATE `chattag` = '%s'", sSID, info, info); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete db; +} + +public void SQL_StartConnection() +{ + char error[255]; + Database db; + if (SQL_CheckConfig("unloze_csgochat")) + { + db = SQL_Connect("unloze_csgochat", true, error, sizeof(error)); + } + if (db == null) + { + CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + //create tables + char sQuery[255]; + Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `unloze_csgochat` (`steam_id` VARCHAR(254) NOT NULL, `chattag` VARCHAR(254) NOT NULL, `chatcolor` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_id`))"); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + + Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `unloze_csgochattokens` (`steam_id` VARCHAR(254) NOT NULL, `chattag` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_id`))"); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + + delete db; +} + +public void CheckFlagsMYSQL(int client) +{ + char error[255]; + Database db; + //the points not related to hlstats are stored together with tracer prefferences but have + //their own table + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "SELECT storestats FROM `unloze_zonepoints` WHERE `steam_id` = '%s'", sSID); + + DBResultSet rs; + + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + return; + } + + if (rs.FetchRow()) + { + SQL_FetchString(rs, 0, c_storestats[client], MAX_NAME_LENGTH); + } + delete rs; + delete db; +} + + +public void TokentagMYSQL(int client) +{ + char error[255]; + Database db; + if (SQL_CheckConfig("unloze_chatcsgo")) + { + db = SQL_Connect("unloze_chatcsgo", true, error, sizeof(error)); + } + if (db == null) + { + CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "SELECT chattag FROM `unloze_csgochattokens` WHERE `steam_id` = '%s'", sSID); + + DBResultSet rs; + + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + return; + } + + if (rs.FetchRow()) + { + SQL_FetchString(rs, 0, c_Chattagtoken[client], MAX_NAME_LENGTH); + } + delete rs; + delete db; +} + +public void DummyCallbackSimple(Handle hOwner, Handle hChild, const char[] err, DataPack pack1) +{ + if (hOwner == null || hChild == null) + { + LogError("Query error. (%s)", err); + } +} \ No newline at end of file diff --git a/Plugins/meteorscsgo/scripting/meteors.sp/meteors.sp b/Plugins/meteorscsgo/scripting/meteors.sp/meteors.sp new file mode 100644 index 00000000..99c1c22c --- /dev/null +++ b/Plugins/meteorscsgo/scripting/meteors.sp/meteors.sp @@ -0,0 +1,446 @@ +#include +#include +#include +#include +#include +//#include +#pragma semicolon 1 +#pragma newdecls required + +public Plugin myinfo = +{ + name = "Meteors", + author = "Neon", + description = "", + version = "Meteors", + url = "https://steamcommunity.com/id/n3ontm" +} + +//ambient/explosions/explode_9.wav +//models/effects/vol_light128x512.mdl + +bool g_bEnabled = false; + +public void OnPluginStart() +{ + HookEvent("round_end", OnRoundEnding); + RegAdminCmd("sm_meteors", Command_Meteors, ADMFLAG_GENERIC); +} + +public void OnMapStart() +{ + g_bEnabled = false; + PrecacheModel("models/props/cs_office/vending_machine.mdl"); + + CreateTimer(5.0, MeteorMain, INVALID_HANDLE, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE); +} + +public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast) +{ + g_bEnabled = false; +} + +public Action Command_Meteors(int client, int args) +{ + if (g_bEnabled) + { + g_bEnabled = false; + CPrintToChatAll("{orchid}[Meteors] {Green}%N has disabled Meteors!", client); + } + else if (!(g_bEnabled)) + { + g_bEnabled = true; + CPrintToChatAll("{orchid}[Meteors] {Green}%N has enabled Meteors!", client); + } +} + +public Action MeteorMain(Handle timer) +{ + if (!(g_bEnabled)) + { + return; + } + int victimClient = GetTargetClient(); + + if (victimClient == -1) + { + return; + } + int indicator = SpawnIndicator(victimClient); + int model = SpawnMeteor2(victimClient); + int hurt = SpawnTriggerHurt(victimClient); + int move = SpawnMoveLinear(victimClient); + int explosion = SpawnExplosion(victimClient); + int sound = SpawnAmbientGeneric(victimClient); + int particle = SpawnParticle(victimClient); + int particle2 = SpawnParticle(victimClient); + + SetVariantString("!activator"); + AcceptEntityInput(model, "SetParent", move); + + SetVariantString("!activator"); + AcceptEntityInput(hurt, "SetParent", move); + + SetVariantString("!activator"); + AcceptEntityInput(particle, "SetParent", move); + + SetVariantString("!activator"); + AcceptEntityInput(particle2, "SetParent", move); + + AcceptEntityInput(move, "Open"); +} + +public Action SpawnParticle(int client) +{ + int Entity; + // Spawn dynamic prop entity + if ((Entity = CreateEntityByName("info_particle_system")) == INVALID_ENT_REFERENCE) + return -1; + + // Generate unique id for the entity + char StrEntityName[64]; + Format(StrEntityName, sizeof(StrEntityName), "info_particle_system_%i", Entity); + + // Setup entity + DispatchKeyValue(Entity, "targetname", "meteor_particle"); + DispatchKeyValue(Entity, "effect_name", "fire_large_01"); + //DispatchKeyValue(Entity, "effect_name", "burning_fx"); + DispatchSpawn(Entity); + ActivateEntity(Entity); + AcceptEntityInput(Entity, "start"); + + float fVector[3]; + float fAngles[3]; + GetClientAbsOrigin(client, fVector); + GetClientAbsAngles(client, fAngles); + + fVector[2] += 7000.0; + + TeleportEntity(Entity, fVector, NULL_VECTOR, NULL_VECTOR); + + return Entity; + +} + +public Action SpawnAmbientGeneric(int client) +{ + int Entity; + + // Spawn dynamic prop entity + if ((Entity = CreateEntityByName("ambient_generic")) == INVALID_ENT_REFERENCE) + return -1; + + // Generate unique id for the entity + char StrEntityName[64]; + Format(StrEntityName, sizeof(StrEntityName), "ambient_generic_%i", Entity); + + // Setup entity + DispatchKeyValue(Entity, "targetname", "meteor_sound"); + DispatchKeyValue(Entity, "spawnflags", "48"); + DispatchKeyValue(Entity, "SourceEntityName", "meteor_model2"); + DispatchKeyValue(Entity, "radius", "3050"); + DispatchKeyValue(Entity, "message", "ambient/explosions/explode_9.wav"); + DispatchKeyValue(Entity, "volume", "10"); + DispatchKeyValue(Entity, "health", "10"); + DispatchKeyValue(Entity, "preset", "0"); + DispatchKeyValue(Entity, "pitch", "100"); + DispatchKeyValue(Entity, "pitchstart", "100"); + DispatchSpawn(Entity); + ActivateEntity(Entity); + + return Entity; +} + +public Action SpawnTriggerHurt(int client) +{ + int Entity; + + // Spawn dynamic prop entity + if ((Entity = CreateEntityByName("trigger_hurt")) == INVALID_ENT_REFERENCE) + return -1; + + // Generate unique id for the entity + char StrEntityName[64]; + Format(StrEntityName, sizeof(StrEntityName), "trigger_hurt_%i", Entity); + + float fVector[3]; + float fAngles[3]; + GetClientAbsOrigin(client, fVector); + GetClientAbsAngles(client, fAngles); + + fVector[2] += 7000.0; + + + // Setup entity + DispatchKeyValue(Entity, "targetname", "meteor_hurt"); + DispatchKeyValue(Entity, "spawnflags", "1"); + DispatchKeyValue(Entity, "StartDisabled", "0"); + DispatchKeyValueVector(Entity, "origin", fVector); + DispatchKeyValue(Entity, "nodmgforce", "0"); + DispatchKeyValue(Entity, "damage", "80"); + //DispatchKeyValue(Entity, "damage", "320"); + DispatchKeyValue(Entity, "damagetype", "128"); + DispatchKeyValue(Entity, "damagemodel", "0"); + DispatchSpawn(Entity); + ActivateEntity(Entity); + + SetEntityModel(Entity, "models/props/cs_office/vending_machine.mdl"); + + float minbounds[3] = {-50.0, -50.0, -100.0}; + float maxbounds[3] = {50.0, 50.0, 100.0}; + SetEntPropVector(Entity, Prop_Send, "m_vecMins", minbounds); + SetEntPropVector(Entity, Prop_Send, "m_vecMaxs", maxbounds); + + SetEntProp(Entity, Prop_Send, "m_nSolidType", 2); + + int enteffects = GetEntProp(Entity, Prop_Send, "m_fEffects"); + enteffects |= 32; + SetEntProp(Entity, Prop_Send, "m_fEffects", enteffects); + + return Entity; +} + +public Action SpawnMeteor2(int client) +{ + int Entity; + // Spawn dynamic prop entity + if ((Entity = CreateEntityByName("prop_physics_multiplayer")) == INVALID_ENT_REFERENCE) + { + return -1; + } + // Generate unique id for the entity + char StrEntityName[512]; + Format(StrEntityName, sizeof(StrEntityName), "prop_physics_multiplayer_%i", Entity); + + // Setup entity + DispatchKeyValue(Entity, "targetname", "meteor_model2"); + DispatchKeyValue(Entity, "model", "models/props/cs_militia/militiarock05.mdl"); + DispatchKeyValue(Entity, "spawnflags", "8"); + DispatchKeyValue(Entity, "pressuredelay", "0"); + DispatchKeyValue(Entity, "physicsmode", "2"); + DispatchKeyValue(Entity, "physdamagescale", "0.1"); + DispatchKeyValue(Entity, "modelscale", "2.0"); + DispatchSpawn(Entity); + + float fVector[3]; + float fAngles[3]; + GetClientAbsOrigin(client, fVector); + GetClientAbsAngles(client, fAngles); + + fVector[2] += 7000.0; + //fVector[1] += 1000.0; + + TeleportEntity(Entity, fVector, NULL_VECTOR, NULL_VECTOR); + + return Entity; + +} +public Action SpawnExplosion(int client) +{ + int Entity; + // Spawn dynamic prop entity + if ((Entity = CreateEntityByName("env_explosion")) == INVALID_ENT_REFERENCE) + return -1; + + // Generate unique id for the entity + char StrEntityName[64]; + Format(StrEntityName, sizeof(StrEntityName), "env_explosion_%i", Entity); + + // Setup entity + DispatchKeyValue(Entity, "targetname", "meteor_explosion"); + DispatchKeyValue(Entity, "fireballsprite", "sprites/zerogxplode.spr"); + DispatchKeyValue(Entity, "rendermode", "5"); + DispatchKeyValue(Entity, "iMagnitude", "300"); + DispatchKeyValue(Entity, "iRadiusOverride", "70"); + + DispatchKeyValue(Entity, "spawnflags", "81"); + + DispatchSpawn(Entity); + + float fVector[3]; + float fAngles[3]; + GetClientAbsOrigin(client, fVector); + GetClientAbsAngles(client, fAngles); + + TeleportEntity(Entity, fVector, NULL_VECTOR, NULL_VECTOR); + + return Entity; + + +} + +public Action SpawnMeteor(int client) +{ + int Entity; + // Spawn dynamic prop entity + if ((Entity = CreateEntityByName("prop_dynamic")) == INVALID_ENT_REFERENCE) + return -1; + + // Generate unique id for the entity + char StrEntityName[64]; Format(StrEntityName, sizeof(StrEntityName), "prop_dynamic_%i", Entity); + + // Setup entity + DispatchKeyValue(Entity, "targetname", "meteor_model"); + DispatchKeyValue(Entity, "model", "models/props/cs_militia/militiarock05.mdl"); + DispatchKeyValue(Entity, "solid", "0"); + DispatchKeyValue(Entity, "modelscale", "1.0"); + DispatchKeyValue(Entity, "renderamt", "255"); + DispatchKeyValue(Entity, "rendercolor", "0 181 240"); + DispatchKeyValue(Entity, "renderfx", "0"); + DispatchKeyValue(Entity, "rendermode", "0"); + + DispatchSpawn(Entity); + + float fVector[3]; + float fAngles[3]; + GetClientAbsOrigin(client, fVector); + GetClientAbsAngles(client, fAngles); + + fVector[2] += 7000.0; + //fVector[1] += 1000.0; + + TeleportEntity(Entity, fVector, NULL_VECTOR, NULL_VECTOR); + + return Entity; + + +} + +public Action SpawnMoveLinear(int client) +{ + int Entity; + // Spawn dynamic prop entity + if ((Entity = CreateEntityByName("func_movelinear")) == INVALID_ENT_REFERENCE) + return -1; + + // Generate unique id for the entity + char StrEntityName[64]; Format(StrEntityName, sizeof(StrEntityName), "func_movelinear_%i", Entity); + + float fVectorClient[3]; + float fVectorStart[3]; + float fAngles[3]; + float fVectorCalculated[3]; + float fAnglesCalculated[3]; + GetClientAbsOrigin(client, fVectorClient); + GetClientAbsAngles(client, fAngles); + + fVectorStart = fVectorClient; + fVectorStart[2] += 7000.0; + + SubtractVectors(fVectorClient, fVectorStart, fVectorCalculated); + float distanceF = GetVectorLength(fVectorCalculated, false); + distanceF -= 128.0; + NormalizeVector(fVectorCalculated, fVectorCalculated); + GetVectorAngles(fVectorCalculated, fAnglesCalculated); + + // Setup entity + DispatchKeyValue(Entity, "targetname", "meteor_linear"); + DispatchKeyValueVector(Entity, "movedir", fAnglesCalculated); + DispatchKeyValueVector(Entity, "origin", fVectorStart); + DispatchKeyValue(Entity, "speed", "3000"); + DispatchKeyValueFloat(Entity, "movedistance", distanceF); + DispatchKeyValue(Entity, "spawnflags", "8"); + DispatchKeyValue(Entity, "rendermode", "3"); + DispatchKeyValue(Entity, "rendercolor", "136 0 0"); + DispatchKeyValue(Entity, "OnFullyOpen", "!self,KillHierarchy,,0.01,1"); + DispatchKeyValue(Entity, "OnFullyOpen", "meteor_indicator,Kill,,0,1"); + DispatchKeyValue(Entity, "OnFullyOpen", "meteor_explosion,Explode,,0,1"); + DispatchKeyValue(Entity, "OnFullyOpen", "meteor_explosion,Kill,,0.01,1"); + DispatchKeyValue(Entity, "OnFullyOpen", "meteor_sound,PlaySound,,0,1"); + DispatchKeyValue(Entity, "OnFullyOpen", "meteor_sound,Kill,,0.01,1"); + DispatchSpawn(Entity); + + return Entity; +} + + +public Action SpawnIndicator(int client) +{ + int Entity; + // Spawn dynamic prop entity + if ((Entity = CreateEntityByName("prop_dynamic")) == INVALID_ENT_REFERENCE) + return -1; + + // Generate unique id for the entity + char StrEntityName[64]; + Format(StrEntityName, sizeof(StrEntityName), "prop_dynamic_%i", Entity); + + // Setup entity + //this is problematic one + DispatchKeyValue(Entity, "targetname", "meteor_indicator"); + DispatchKeyValue(Entity, "model", "models/editor/spot_cone.mdl"); + DispatchKeyValue(Entity, "solid", "0"); + DispatchKeyValue(Entity, "modelscale", "5.5"); + DispatchKeyValue(Entity, "angles", "0 0 90"); + DispatchKeyValue(Entity, "renderamt", "255"); + DispatchKeyValue(Entity, "rendercolor", "255 0 0"); + DispatchKeyValue(Entity, "renderfx", "0"); + DispatchKeyValue(Entity, "rendermode", "0"); + + DispatchSpawn(Entity); + + float fVector[3]; + float fAngles[3]; + GetClientAbsOrigin(client, fVector); + GetClientAbsAngles(client, fAngles); + + fVector[2] += 35.0; + + TeleportEntity(Entity, fVector, NULL_VECTOR, NULL_VECTOR); + + return Entity; +} + +public int GetTargetClient() +{ + + int outsideClientCount = 0; + int[] outsideClients = new int[MaxClients]; + + for(int i = 1; i <= MaxClients; i++) + { + if(IsClientInGame(i) && IsPlayerAlive(i) && (ZR_IsClientHuman(i)) && (GetClientDistanceToCeiling(i) > 200.0)) + { + outsideClients[outsideClientCount] = i; + outsideClientCount += 1; + } + } + + if (outsideClientCount == 0) + return -1; + + int randomIndex = GetRandomInt(0, outsideClientCount - 1); + + return outsideClients[randomIndex]; + +} + +public float GetClientDistanceToCeiling(int client) +{ + float distanceF = 0.0; + + float fOrigin[3]; + float fCeiling[3]; + GetClientAbsOrigin(client, fOrigin); + + fOrigin[2] += 10.0; + + TR_TraceRayFilter(fOrigin, {-90.0,0.0,0.0}, MASK_PLAYERSOLID, RayType_Infinite, TraceRayNoPlayers, client); + if (TR_DidHit()) + { + TR_GetEndPosition(fCeiling); + fOrigin[2] -= 10.0; + distanceF = GetVectorDistance(fOrigin, fCeiling); + } + //PrintToChatAll("Client: %d - %f", client,distanceF); + return distanceF; +} + +public bool TraceRayNoPlayers(int entity, int mask, any data) +{ + if(entity == data || (entity >= 1 && entity <= MaxClients)) + { + return false; + } + return true; +} \ No newline at end of file diff --git a/Plugins/tags_colors/scripting/simple-chatprocessor.sp b/Plugins/tags_colors/scripting/simple-chatprocessor.sp new file mode 100644 index 00000000..5c2ffdc3 --- /dev/null +++ b/Plugins/tags_colors/scripting/simple-chatprocessor.sp @@ -0,0 +1,854 @@ +/************************************************************************ +************************************************************************* +Simple Chat Processor +Description: + Process chat and allows other plugins to manipulate chat. +************************************************************************* +************************************************************************* +This file is part of Simple Plugins project. + +This plugin is free software: you can redistribute +it and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the License, or +later version. + +This plugin is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this plugin. If not, see . +************************************************************************* +************************************************************************* +File Information +$Id$ +$Author$ +$Revision$ +$Date$ +$LastChangedBy$ +$LastChangedDate$ +$URL$ +$Copyright: (c) Simple Plugins 2008-2009$ +************************************************************************* +************************************************************************* +*/ + +#include +#undef REQUIRE_PLUGIN +#include + +#define PLUGIN_VERSION "2.0.3" +#define SENDER_WORLD 0 +#define MAXLENGTH_INPUT 128 // Inclues \0 and is the size of the chat input box. +#define MAXLENGTH_NAME 64 // This is backwords math to get compability. Sourcemod has it set at 32, but there is room for more. +#define MAXLENGTH_MESSAGE 256 // This is based upon the SDK and the length of the entire message, including tags, name, : etc. + +#define CHATFLAGS_INVALID 0 +#define CHATFLAGS_ALL (1 << 0) +#define CHATFLAGS_TEAM (1 << 1) +#define CHATFLAGS_SPEC (1 << 2) +#define CHATFLAGS_DEAD (1 << 3) + +#define ADDSTRING(%1) SetTrieValue(g_hChatFormats, %1, 1) + +#define UPDATE_URL "http://dl.dropboxusercontent.com/u/83581539/ChatProcessor/updater.txt" + +enum eMods +{ + GameType_Unknown, + GameType_AOC, + GameType_CSGO, + GameType_CSS, + GameType_DOD, + GameType_FF, + GameType_HIDDEN, + GameType_HL2DM, + GameType_INS, + GameType_L4D, + GameType_L4D2, + GameType_NEO, + GameType_SGTLS, + GameType_TF, + GameType_DM, + GameType_ZPS, +}; + +//new Handle:g_hDPArray = INVALID_HANDLE; + +new eMods:g_CurrentMod; +new String:g_sGameName[eMods][32] = +{ + "Unknown", + "Age of Chivalry", + "Counter-Strike: GO", + "Counter Strike", + "Day Of Defeat", + "Fortress Forever", + "Hidden: Source", + "Half Life 2: Deathmatch", + "Insurgency", + "Left 4 Dead", + "Left 4 Dead 2", + "Neotokyo", + "Stargate TLS", + "Team Fortress 2", + "Dark Messiah", + "Zombie Panic: Source" +}; + +new Handle:g_hChatFormats = INVALID_HANDLE; +new Handle:g_fwdOnChatMessage; + +new bool:g_bSayText2; +new bool:g_bAutoUpdate; + +new g_CurrentChatType = CHATFLAGS_INVALID; + +public Plugin:myinfo = +{ + name = "Simple Chat Processor (Redux)", + author = "Simple Plugins, Mini", + description = "Process chat and allows other plugins to manipulate chat.", + version = PLUGIN_VERSION, + url = "http://forums.alliedmods.net" +}; + +public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max) +{ + MarkNativeAsOptional("GetUserMessageType"); + CreateNative("GetMessageFlags", Native_GetMessageFlags); + RegPluginLibrary("scp"); + return APLRes_Success; +} + +public OnPluginStart() +{ + new Handle:conVar = CreateConVar("sm_scp_autoupdate", "1", "Is auto-update enabled?"); + g_bAutoUpdate = GetConVarBool(conVar); + HookConVarChange(conVar, OnAutoUpdateChange); + + g_CurrentMod = GetCurrentMod(); + g_hChatFormats = CreateTrie(); + LogMessage("[SCP] Recognized mod [%s].", g_sGameName[g_CurrentMod]); + + /** + Hook the usermessage or error out if the mod doesn't support saytext2 + */ + new UserMsg:umSayText2 = GetUserMessageId("SayText2"); + if (umSayText2 != INVALID_MESSAGE_ID) + { + g_bSayText2 = true; + HookUserMessage(umSayText2, OnSayText2, true); + } + else + { + new UserMsg:umSayText = GetUserMessageId("SayText"); + if (umSayText != INVALID_MESSAGE_ID) + { + if (g_CurrentMod != GameType_DOD) + { + SetFailState("Unsupported game"); + } + g_bSayText2 = false; + HookUserMessage(umSayText, OnSayText, true); + } + else + { + LogError("[SCP] This mod appears not to support SayText2 or SayText. Plugin disabled."); + SetFailState("Error hooking usermessage saytext2 and saytext"); + } + } + + /** + Get mod type and load the correct translation file + */ + if (g_bSayText2) + { + decl String:sGameDir[32]; + decl String:sTranslationFile[PLATFORM_MAX_PATH]; + decl String:sTranslationLocation[PLATFORM_MAX_PATH]; + GetGameFolderName(sGameDir, sizeof(sGameDir)); + Format(sTranslationFile, sizeof(sTranslationFile), "scp.%s.phrases", sGameDir); + BuildPath(Path_SM, sTranslationLocation, sizeof(sTranslationLocation), "translations/%s.txt", sTranslationFile); + if (FileExists(sTranslationLocation)) + { + LogMessage("[SCP] Loading translation file [%s].", sTranslationFile); + LoadTranslations(sTranslationFile); + if (!GetChatFormats(sTranslationLocation)) + { + LogError("[SCP] Could not parse the translation file"); + SetFailState("Could not parse the translation file"); + } + } + else + { + LogError("[SCP] Translation file is not present"); + SetFailState("Translation file is not present"); + } + } + + /** + Create the global forward for other plugins + */ + g_fwdOnChatMessage = CreateGlobalForward("OnChatMessage", ET_Hook, Param_CellByRef, Param_Cell, Param_String, Param_String); + + //g_hDPArray = CreateArray(); +} + +public OnAutoUpdateChange(Handle:conVar, const String:oldVal[], const String:newVal[]) +{ + g_bAutoUpdate = bool:StringToInt(newVal); +} + +/** + * + * Updater Stuff + * By Dr. McKay + * Edited by Mini + * + */ +public OnAllPluginsLoaded() +{ + new Handle:convar; + if (LibraryExists("updater")) + { + Updater_AddPlugin(UPDATE_URL); + decl String:newVersion[10]; + FormatEx(newVersion, sizeof(newVersion), "%sA", PLUGIN_VERSION); + convar = CreateConVar("scp_version", newVersion, "Plugin Version", FCVAR_DONTRECORD | FCVAR_NOTIFY | FCVAR_CHEAT); + } + else + { + convar = CreateConVar("scp_version", PLUGIN_VERSION, "Plugin Version", FCVAR_DONTRECORD | FCVAR_NOTIFY | FCVAR_CHEAT); + } + HookConVarChange(convar, Callback_VersionConVarChanged); +} + +public Callback_VersionConVarChanged(Handle:convar, const String:oldValue[], const String:newValue[]) +{ + ResetConVar(convar); +} + +public OnLibraryAdded(const String:name[]) +{ + if (!strcmp(name, "updater")) + { + Updater_AddPlugin(UPDATE_URL); + } +} + +public Action:Updater_OnPluginDownloading() +{ + if (!g_bAutoUpdate) + { + return Plugin_Handled; + } + return Plugin_Continue; +} + +public Updater_OnPluginUpdated() +{ + ReloadPlugin(); +} + +public Action:OnSayText2(UserMsg:msg_id, Handle:bf, const clients[], numClients, bool:reliable, bool:init) +{ + /** + Get the sender of the usermessage and bug out if it is not a player + */ + new bool:bProtobuf = (CanTestFeatures() && GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf); + new cpSender; + if (bProtobuf) + { + cpSender = PbReadInt(bf, "ent_idx"); + } + else + { + cpSender = BfReadByte(bf); + } + + if (cpSender == SENDER_WORLD) + { + return Plugin_Continue; + } + + /** + Get the chat bool. This determines if sent to console as well as chat + */ + new bool:bChat; + if (bProtobuf) + { + bChat = PbReadBool(bf, "chat"); + } + else + { + bChat = (BfReadByte(bf) ? true : false); + } + + /** + Make sure we have a default translation string for the message + This also determines the message type... + */ + decl String:cpTranslationName[32]; + new buffer; + if (bProtobuf) + { + PbReadString(bf, "msg_name", cpTranslationName, sizeof(cpTranslationName)); + } + else + { + BfReadString(bf, cpTranslationName, sizeof(cpTranslationName)); + } + + if (!GetTrieValue(g_hChatFormats, cpTranslationName, buffer)) + { + return Plugin_Continue; + } + else + { + if (StrContains(cpTranslationName, "all", false) != -1) + { + g_CurrentChatType = g_CurrentChatType | CHATFLAGS_ALL; + } + if (StrContains(cpTranslationName, "team", false) != -1 + || StrContains(cpTranslationName, "survivor", false) != -1 + || StrContains(cpTranslationName, "infected", false) != -1 + || StrContains(cpTranslationName, "Cstrike_Chat_CT", false) != -1 + || StrContains(cpTranslationName, "Cstrike_Chat_T", false) != -1) + { + g_CurrentChatType = g_CurrentChatType | CHATFLAGS_TEAM; + } + if (StrContains(cpTranslationName, "spec", false) != -1) + { + g_CurrentChatType = g_CurrentChatType | CHATFLAGS_SPEC; + } + if (StrContains(cpTranslationName, "dead", false) != -1) + { + g_CurrentChatType = g_CurrentChatType | CHATFLAGS_DEAD; + } + } + + /** + Get the senders name + */ + decl String:cpSender_Name[MAXLENGTH_NAME]; + if (bProtobuf) + { + PbReadString(bf, "params", cpSender_Name, sizeof(cpSender_Name), 0); + } + else if (BfGetNumBytesLeft(bf)) + { + BfReadString(bf, cpSender_Name, sizeof(cpSender_Name)); + } + + /** + Get the message + */ + decl String:cpMessage[MAXLENGTH_INPUT]; + if (bProtobuf) + { + PbReadString(bf, "params", cpMessage, sizeof(cpMessage), 1); + } + else if (BfGetNumBytesLeft(bf)) + { + BfReadString(bf, cpMessage, sizeof(cpMessage)); + } + + /** + Store the clients in an array so the call can manipulate it. + */ + new Handle:cpRecipients = CreateArray(); + for (new i = 0; i < numClients; i++) + { + PushArrayCell(cpRecipients, clients[i]); + } + + /** + Because the message could be changed but not the name + we need to compare the original name to the returned name. + We do this because we may have to add the team color code to the name, + where as the message doesn't get a color code by default. + */ + decl String:sOriginalName[MAXLENGTH_NAME]; + strcopy(sOriginalName, sizeof(sOriginalName), cpSender_Name); + + /** + Start the forward for other plugins + */ + new Action:fResult; + Call_StartForward(g_fwdOnChatMessage); + Call_PushCellRef(cpSender); + Call_PushCell(cpRecipients); + Call_PushStringEx(cpSender_Name, sizeof(cpSender_Name), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushStringEx(cpMessage, sizeof(cpMessage), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + new fError = Call_Finish(fResult); + + g_CurrentChatType = CHATFLAGS_INVALID; + + if (fError != SP_ERROR_NONE) + { + ThrowNativeError(fError, "Forward failed"); + CloseHandle(cpRecipients); + return Plugin_Continue; + } + else if (fResult == Plugin_Continue) + { + CloseHandle(cpRecipients); + return Plugin_Continue; + } + else if (fResult == Plugin_Stop) + { + CloseHandle(cpRecipients); + return Plugin_Handled; + } + + /** + This is the check for a name change. If it has not changed we add the team color code + */ + if (StrEqual(sOriginalName, cpSender_Name)) + { + Format(cpSender_Name, sizeof(cpSender_Name), "\x03%s", cpSender_Name); + } + + /** + Create a timer to print the message on the next gameframe + */ + new Handle:cpPack; + CreateDataTimer(0.0, RebuildMessage, cpPack); + + new numRecipients = GetArraySize(cpRecipients); + + WritePackCell(cpPack, cpSender); + + for (new i = 0; i < numRecipients; i++) + { + new x = GetArrayCell(cpRecipients, i); + if (!IsValidClient(x)) + { + numRecipients--; + RemoveFromArray(cpRecipients, i); + } + } + + WritePackCell(cpPack, numRecipients); + + for (new i = 0; i < numRecipients; i++) + { + new x = GetArrayCell(cpRecipients, i); + WritePackCell(cpPack, x); + } + + WritePackCell(cpPack, bChat); + WritePackString(cpPack, cpTranslationName); + WritePackString(cpPack, cpSender_Name); + WritePackString(cpPack, cpMessage); + //PushArrayCell(g_hDPArray, cpPack); + WritePackCell(cpPack, bProtobuf); + + CloseHandle(cpRecipients); + + /** + Stop the original message + */ + return Plugin_Handled; +} + +public Action:OnSayText(UserMsg:msg_id, Handle:bf, const clients[], numClients, bool:reliable, bool:init) +{ + /** + Get the sender of the usermessage and bug out if it is not a player + */ + new bool:bProtobuf = (CanTestFeatures() && GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf); + new cpSender; + if (bProtobuf) + { + cpSender = PbReadInt(bf, "ent_idx"); + } + else + { + cpSender = BfReadByte(bf); + } + + if (cpSender == SENDER_WORLD) + { + return Plugin_Continue; + } + + /** + Get the chat message + */ + decl String:message[MAXLENGTH_INPUT]; + if (bProtobuf) + { + PbReadString(bf, "text", message, sizeof(message)); + } + else + { + BfReadString(bf, message, sizeof(message)); + } + + /** + Get the chat bool. This determines if sent to console as well as chat + */ + if (!bProtobuf) + { + BfReadBool(bf); + } + + /** + Store the clients in an array so the call can manipulate it. + */ + new Handle:cpRecipients = CreateArray(); + for (new i = 0; i < numClients; i++) + { + PushArrayCell(cpRecipients, clients[i]); + } + + decl String:prefix[64], String:senderName[MAX_NAME_LENGTH], String:textMessage[MAXLENGTH_MESSAGE], String:buffer[MAXLENGTH_INPUT]; + GetClientName(cpSender, senderName, sizeof(senderName)); + Format(buffer, sizeof(buffer), "%s:", senderName); + new pos = StrContains(message, buffer); + + if (pos == 0) + { + prefix[0] = '\0'; + } + else + { + Format(prefix, pos + 1, "%s ", message); + } + + g_CurrentChatType = CHATFLAGS_INVALID; + + if (StrContains(prefix, "(Team)") != -1) + { + g_CurrentChatType |= CHATFLAGS_TEAM; + } + if (GetClientTeam(cpSender) <= 1) + { + g_CurrentChatType |= CHATFLAGS_SPEC; + } + if (StrContains(prefix, "(Dead)") != -1) + { + g_CurrentChatType |= CHATFLAGS_DEAD; + } + + if (g_CurrentChatType == CHATFLAGS_INVALID) + { + g_CurrentChatType = CHATFLAGS_ALL; + } + + ReplaceString(message, sizeof(message), "\n", ""); + strcopy(textMessage, sizeof(textMessage), message[pos + strlen(senderName) + 2]); + + /** + Start the forward for other plugins + */ + new Action:fResult; + Call_StartForward(g_fwdOnChatMessage); + Call_PushCellRef(cpSender); + Call_PushCell(cpRecipients); + Call_PushStringEx(senderName, sizeof(senderName), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushStringEx(textMessage, sizeof(textMessage), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + new fError = Call_Finish(fResult); + + g_CurrentChatType = CHATFLAGS_INVALID; + + if (fError != SP_ERROR_NONE) + { + ThrowNativeError(fError, "Forward failed"); + CloseHandle(cpRecipients); + return Plugin_Continue; + } + else if (fResult == Plugin_Continue) + { + CloseHandle(cpRecipients); + return Plugin_Continue; + } + else if (fResult >= Plugin_Handled) + { + CloseHandle(cpRecipients); + return Plugin_Handled; + } + + GetClientName(cpSender, buffer, sizeof(buffer)); + if (StrEqual(senderName, buffer)) + { + Format(senderName, sizeof(senderName), "\x03%s", senderName); + } + + /** + Create a timer to print the message on the next gameframe + */ + new Handle:cpPack; + CreateDataTimer(0.0, RebuildMessage, cpPack); + + new numRecipients = GetArraySize(cpRecipients); + + WritePackCell(cpPack, cpSender); + + for (new i = 0; i < numRecipients; i++) + { + new x = GetArrayCell(cpRecipients, i); + if (!IsValidClient(x)) + { + numRecipients--; + RemoveFromArray(cpRecipients, i); + } + } + + WritePackCell(cpPack, numRecipients); + + for (new i = 0; i < numRecipients; i++) + { + new x = GetArrayCell(cpRecipients, i); + WritePackCell(cpPack, x); + } + + WritePackString(cpPack, prefix); + WritePackString(cpPack, senderName); + WritePackString(cpPack, textMessage); + //PushArrayCell(g_hDPArray, cpPack); + WritePackCell(cpPack, bProtobuf); + + + CloseHandle(cpRecipients); + + /** + Stop the original message + */ + return Plugin_Handled; +} + +public Action:RebuildMessage(Handle:timer, Handle:pack) +{ + ResetPack(pack); + if (g_bSayText2) + { + new client = ReadPackCell(pack); + new numClientsStart = ReadPackCell(pack); + new numClientsFinish; + new clients[numClientsStart]; + + for (new x = 0; x < numClientsStart; x++) + { + new buffer = ReadPackCell(pack); + if (IsValidClient(buffer)) + { + clients[numClientsFinish++] = buffer; + } + } + + new bool:bChat = bool:ReadPackCell(pack); + decl String:sChatType[32]; + decl String:sSenderName[MAXLENGTH_NAME]; + decl String:sMessage[MAXLENGTH_INPUT]; + ReadPackString(pack, sChatType, sizeof(sChatType)); + ReadPackString(pack, sSenderName, sizeof(sSenderName)); + ReadPackString(pack, sMessage, sizeof(sMessage)); + + decl String:sTranslation[MAXLENGTH_MESSAGE]; + Format(sTranslation, sizeof(sTranslation), " %t", sChatType, sSenderName, sMessage); + + new Handle:bf = StartMessage("SayText2", clients, numClientsFinish, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS); + + if (ReadPackCell(pack)) + { + PbSetInt(bf, "ent_idx", client); + PbSetBool(bf, "chat", bChat); + + PbSetString(bf, "msg_name", sTranslation); + PbAddString(bf, "params", ""); + PbAddString(bf, "params", ""); + PbAddString(bf, "params", ""); + PbAddString(bf, "params", ""); + } + else + { + BfWriteByte(bf, client); + BfWriteByte(bf, bChat); + BfWriteString(bf, sTranslation); + } + EndMessage(); + } + else + { + new client = ReadPackCell(pack); + new numClientsStart = ReadPackCell(pack); + new numClientsFinish; + new clients[numClientsStart]; + + for (new x = 0; x < numClientsStart; x++) + { + new buffer = ReadPackCell(pack); + if (IsValidClient(buffer)) + { + clients[numClientsFinish++] = buffer; + } + } + + decl String:sPrefix[MAXLENGTH_NAME]; + decl String:sSenderName[MAXLENGTH_NAME]; + decl String:sMessage[MAXLENGTH_INPUT]; + ReadPackString(pack, sPrefix, sizeof(sPrefix)); + ReadPackString(pack, sSenderName, sizeof(sSenderName)); + ReadPackString(pack, sMessage, sizeof(sMessage)); + + decl String:message[MAXLENGTH_MESSAGE]; + + new teamColor; + switch (GetClientTeam(client)) + { + case 0, 1:teamColor = 0xCCCCCC; + case 2:teamColor = 0x4D7942; + case 3:teamColor = 0xFF4040; + } + + decl String:buffer[32]; + Format(buffer, sizeof(buffer), "\x07%06X", teamColor); + ReplaceString(sSenderName, sizeof(sSenderName), "\x03", buffer); + ReplaceString(sMessage, sizeof(sMessage), "\x03", buffer); + + Format(message, sizeof(message), "\x01%s%s\x01: %s", sPrefix, sSenderName, sMessage); + PrintToServer(message); + + for (new j = 0; j < numClientsFinish; j++) + { + PrintToChat(clients[j], "%s", message); + } + } + + //CloseHandle(pack); + + //RemoveFromArray(g_hDPArray, i); +} + +public Native_GetMessageFlags(Handle:plugin, numParams) +{ + return g_CurrentChatType; +} + +stock bool:IsValidClient(client, bool:nobots = true) +{ + if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client))) + { + return false; + } + return IsClientInGame(client); +} + +stock bool:GetChatFormats(const String:file[]) +{ + new Handle:hParser = SMC_CreateParser(); + new String:error[128]; + new line = 0; + new col = 0; + + SMC_SetReaders(hParser, Config_NewSection, Config_KeyValue, Config_EndSection); + SMC_SetParseEnd(hParser, Config_End); + new SMCError:result = SMC_ParseFile(hParser, file, line, col); + CloseHandle(hParser); + + if (result != SMCError_Okay) + { + SMC_GetErrorString(result, error, sizeof(error)); + LogError("%s on line %d, col %d of %s", error, line, col, file); + } + + return (result == SMCError_Okay); +} + +public SMCResult:Config_NewSection(Handle:parser, const String:section[], bool:quotes) +{ + if (StrEqual(section, "Phrases")) + { + return SMCParse_Continue; + } + ADDSTRING(section); + return SMCParse_Continue; +} + +public SMCResult:Config_KeyValue(Handle:parser, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes) +{ + return SMCParse_Continue; +} + +public SMCResult:Config_EndSection(Handle:parser) +{ + return SMCParse_Continue; +} + +public Config_End(Handle:parser, bool:halted, bool:failed) +{ + //nothing +} + +stock eMods:GetCurrentMod() +{ + decl String:sGameType[64]; + GetGameFolderName(sGameType, sizeof(sGameType)); + + if (StrEqual(sGameType, "aoc", false)) + { + return GameType_AOC; + } + if (StrEqual(sGameType, "csgo", false)) + { + return GameType_CSGO; + } + if (StrEqual(sGameType, "cstrike", false)) + { + return GameType_CSS; + } + if (StrEqual(sGameType, "dod", false)) + { + return GameType_DOD; + } + if (StrEqual(sGameType, "ff", false)) + { + return GameType_FF; + } + if (StrEqual(sGameType, "hidden", false)) + { + return GameType_HIDDEN; + } + if (StrEqual(sGameType, "hl2mp", false)) + { + return GameType_HL2DM; + } + if (StrEqual(sGameType, "insurgency", false) || StrEqual(sGameType, "ins", false)) + { + return GameType_INS; + } + if (StrEqual(sGameType, "left4dead", false) || StrEqual(sGameType, "l4d", false)) + { + return GameType_L4D; + } + if (StrEqual(sGameType, "left4dead2", false) || StrEqual(sGameType, "l4d2", false)) + { + return GameType_L4D2; + } + if (StrEqual(sGameType, "nts", false)) + { + return GameType_NEO; + } + if (StrEqual(sGameType, "sgtls", false)) + { + return GameType_SGTLS; + } + if (StrEqual(sGameType, "tf", false)) + { + return GameType_TF; + } + if (StrEqual(sGameType, "zps", false)) + { + return GameType_ZPS; + } + if (StrEqual(sGameType, "mmdarkmessiah", false)) + { + return GameType_DM; + } + LogMessage("Unknown Game Folder: %s", sGameType); + return GameType_Unknown; +} \ No newline at end of file diff --git a/Plugins/tags_colors/scripting/tags_colors.sp b/Plugins/tags_colors/scripting/tags_colors.sp new file mode 100644 index 00000000..0ae30ad8 --- /dev/null +++ b/Plugins/tags_colors/scripting/tags_colors.sp @@ -0,0 +1,384 @@ +#include +#include + +public Plugin myinfo = +{ + name = "Tags", + author = "Pan32", + description = "Saves text & color", + version = "3.1.0", + url = "" +} + +#define MAXTAGSIZE 20 +#define VIPFLAG ADMFLAG_RESERVATION + +Handle g_hDatabase = INVALID_HANDLE; +int g_iChatColor[MAXPLAYERS+1]; +int g_iNameColor[MAXPLAYERS+1]; + +char g_colortags[][] = {"{white}", "{darkred}", "{teamcolor}", "{green}", "{lightgreen}", "{lime}", "{red}", "{gray}", "{yellow}", "{clearblue}", "{lightblue}", "{blue}", "{cleargray}", "{purple}", "{darkorange}", "{orange}"}; +char g_colors[][] = {"\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x09", "\x0A", "\x0B", "\x0C", "\x0D", "\x0E", "\x0F", "\x10"}; +char g_colornames[][] = { "White/None", "Dark Red", "Teamcolor", "Green", "Light Green", "Lime", "Red", "Gray", "Yellow", "Clear Blue", "Light Blue", "Blue", "Clear Gray", "Purple", "Dark Orange", "Orange" }; +char g_tags[MAXPLAYERS+1][MAXTAGSIZE]; + + +public void OnPluginStart() +{ + LoadTranslations("common.phrases"); + SQL_TConnect(OnSQLConnect, "tags"); + + RegAdminCmd("sm_chatcolor", Command_ColorsMenu, VIPFLAG, "Brings up the colors menu"); + RegAdminCmd("sm_chatcolors", Command_ColorsMenu, VIPFLAG, "Brings up the colors menu"); + RegAdminCmd("sm_colors", Command_ColorsMenu, VIPFLAG, "Brings up the colors menu"); + RegAdminCmd("sm_namecolors", Command_NameColorsMenu, VIPFLAG, "Set name color"); + RegAdminCmd("sm_namecolor", Command_NameColorsMenu, VIPFLAG, "Set name color"); + RegAdminCmd("sm_settag", Command_SetTag, VIPFLAG, "Set tag"); + RegAdminCmd("sm_colortags", Command_ColorTags, VIPFLAG, "Displays all available color tags"); + + for (new i = 1; i < MAXPLAYERS+1; i++) + { + g_iChatColor[i] = 0; + g_iNameColor[i] = 2; + } +} + +public void OnClientPostAdminCheck(int client) +{ + if (!IsFakeClient(client)) + { + char query[512]; + char steamid[32]; + GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid)); + Format(query, sizeof(query), "SELECT * FROM csgo_tagsncolors WHERE steamid='%s';", steamid); + + Handle result = SQL_Query(g_hDatabase, query); + if (result == INVALID_HANDLE) + { + SetFailState("[Tags] Lost connection to database. Reconnecting on map change."); + } + else + { + if (SQL_MoreRows(result)) + { + if (SQL_FetchRow(result)) + { + g_iChatColor[client] = SQL_FetchInt(result, 1); + SQL_FetchString(result, 2, g_tags[client], MAXTAGSIZE); + g_iNameColor[client] = SQL_FetchInt(result, 3); + } + } + else + { + g_tags[client][0] = '\0'; + g_iChatColor[client] = 0; + g_iNameColor[client] = 2; + } + CloseHandle(result); + } + } +} + +public Action Command_SetTag(int client, int args) +{ + if (client == 0) + return Plugin_Handled; + + if (!args) + { + ReplyToCommand(client, " \x06[Unloze] \x01Check console for output"); + PrintSetTagInfo(client); + return Plugin_Handled; + } + + char argument[128]; + bool isEmpty = false; + GetCmdArgString(argument, sizeof(argument)); + + if (StrContains(argument, "%s", false) > -1) + ReplaceString(argument, sizeof(argument), "%s", "", false); + + if (StrEqual(argument, "none", false)) + { + Format(argument, sizeof(argument), ""); + isEmpty = true + } + + else + CFormat(argument, sizeof(argument)); + + Format(g_tags[client], MAXTAGSIZE, "%s", argument); + + char safetag[2 * MAXTAGSIZE + 1]; + char query[1024]; + char steamid[64]; + + SQL_EscapeString(g_hDatabase, g_tags[client], safetag, 2 * strlen(g_tags[client]) + 1); + GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid)); + + Format(query, sizeof(query), "INSERT INTO csgo_tagsncolors (steamid, tag) VALUES('%s', '%s') ON DUPLICATE KEY UPDATE tag='%s';", steamid, safetag, safetag); + SQL_Query(g_hDatabase, query); + + if (isEmpty) + PrintToChat(client, " \x06[Unloze] \x01You removed your tag."); + else + PrintToChat(client, " \x06[Unloze] \x01Your tag was set to \"%s\x01\".", g_tags[client]); + + return Plugin_Handled; +} + +public void CFormat(char[] tag, int maxlength) +{ + + for (new i = 0; i < sizeof(g_colortags); i++) + { + /* If tag not found - skip */ + if (StrContains(tag, g_colortags[i], false) == -1) + continue; + + else + ReplaceString(tag, maxlength, g_colortags[i], g_colors[i], false); + } +} + +public void InvCFormat(char[] tag, int maxlength) +{ + for (new i = 0; i < sizeof(g_colors); i++) + { + /* If tag not found - skip */ + if (StrContains(tag, g_colors[i], false) == -1) + continue; + + else + ReplaceString(tag, maxlength, g_colors[i], g_colortags[i], false); + } +} + +void PrintSetTagInfo(int client) +{ + char currenttag[128]; + char colorbuffer[256]; + strcopy(currenttag, sizeof(currenttag), g_tags[client]); + InvCFormat(currenttag, sizeof(currenttag)); + + for (new i = 0; i < sizeof(g_colortags); i++) + { + Format(colorbuffer, sizeof(colorbuffer), "%s%s ", colorbuffer, g_colortags[i]); + } + + PrintToConsole(client, "//////////////////////////////////////////////////////////////////////////"); + PrintToConsole(client, "Usage: sm_settag [arg]"); + PrintToConsole(client, "To disable the tag, type \"sm_settag none\""); + PrintToConsole(client, " "); + PrintToConsole(client, "Available colors: %s", colorbuffer); + PrintToConsole(client, "Type sm_colortags to see these tags on chat"); + PrintToConsole(client, " "); + PrintToConsole(client, "Your current tag is \"%s\"", currenttag); + PrintToConsole(client, "//////////////////////////////////////////////////////////////////////////"); +} + +public Action Command_ColorTags(int client, int args) +{ + char buffer[256]; + for (new i = 0; i < sizeof(g_colors); i++) + { + Format(buffer, sizeof(buffer), "%s%s%s ", buffer, g_colors[i], g_colortags[i]); + } + PrintToChat(client, " %s", buffer); +} + +public Action Command_ColorsMenu(int client, int args) +{ + if (client == 0) + return Plugin_Handled; + + SubColorsMenu(client); + return Plugin_Handled; +} + +public Action Command_NameColorsMenu(int client, int args) +{ + if (client == 0) + return Plugin_Handled; + + Menu menu = new Menu(NameColorsHandler); + menu.SetTitle("Select a color:\n"); + for (new i = 0; i < sizeof(g_colornames); i++) + { + if (i == g_iNameColor[client]) + { + char buffer[32]; + Format(buffer, sizeof(buffer), "%s (Current)", g_colornames[i]); + menu.AddItem("", buffer, ITEMDRAW_DISABLED); + } + else + menu.AddItem("", g_colornames[i]); + } + menu.ExitButton = true; + menu.Display(client, MENU_TIME_FOREVER); + return Plugin_Handled; +} + +public int NameColorsHandler(Handle menu, MenuAction action, int param1, int param2) +{ + if (action == MenuAction_Select) + { + char info[32]; + bool found = GetMenuItem(menu, param2, info, sizeof(info)); + if (found == true) + { + g_iNameColor[param1] = param2; + + char query[512]; + char steamid[32]; + GetClientAuthId(param1, AuthId_Steam2, steamid, sizeof(steamid)); + Format(query, sizeof(query), "SELECT * FROM csgo_tagsncolors WHERE steamid='%s';", steamid); + + Handle result = SQL_Query(g_hDatabase, query); + + if (result == INVALID_HANDLE) + { + SetFailState("[Tags] Lost connection to database. Reconnecting on map change."); + } + else + { + if (SQL_MoreRows(result)) // if it fetches the row, they are a supporter, grab their data and load it + { + Format(query, sizeof(query), "UPDATE csgo_tagsncolors SET namecolor=%d WHERE steamid='%s';", g_iNameColor[param1], steamid); + SQL_Query(g_hDatabase, query); + } + else // if not, add them + { + Format(query, sizeof(query), "INSERT INTO csgo_tagsncolors (steamid, namecolor) VALUES('%s', %d);", steamid, g_iNameColor[param1]); + SQL_Query(g_hDatabase, query); + } + CloseHandle(result); + } + + PrintToChat(param1, " \x06[Unloze] \x01Your name color was set to %s%s\x01.", g_colors[g_iNameColor[param1]], g_colornames[g_iNameColor[param1]]); + } + } + else if (action == MenuAction_End) + { + delete menu; + } +} + +public void SubColorsMenu(int client) +{ + Menu menu = new Menu(SubColorsHandler); + menu.SetTitle("Select a color:\n"); + for (new i = 0; i < sizeof(g_colornames); i++) + { + if (i == g_iChatColor[client]) + { + char buffer[32]; + Format(buffer, sizeof(buffer), "%s (Current)", g_colornames[i]); + menu.AddItem("", buffer, ITEMDRAW_DISABLED); + } + else + menu.AddItem("", g_colornames[i]); + } + menu.ExitButton = true; + menu.Display(client, MENU_TIME_FOREVER); +} + +public int SubColorsHandler(Handle menu, MenuAction action, int param1, int param2) +{ + if (action == MenuAction_Select) + { + char info[32]; + bool found = GetMenuItem(menu, param2, info, sizeof(info)); + if (found == true) + { + g_iChatColor[param1] = param2; + + char query[512]; + char steamid[32]; + GetClientAuthId(param1, AuthId_Steam2, steamid, sizeof(steamid)); + Format(query, sizeof(query), "SELECT * FROM csgo_tagsncolors WHERE steamid='%s';", steamid); + + Handle result = SQL_Query(g_hDatabase, query); + + if (result == INVALID_HANDLE) + { + SetFailState("[Tags] Lost connection to database. Reconnecting on map change."); + } + else + { + if (SQL_MoreRows(result)) // if it fetches the row, they are a supporter, grab their data and load it + { + Format(query, sizeof(query), "UPDATE csgo_tagsncolors SET color=%d WHERE steamid='%s';", g_iChatColor[param1], steamid); + SQL_Query(g_hDatabase, query); + } + else // if not, add them + { + Format(query, sizeof(query), "INSERT INTO csgo_tagsncolors (steamid, color) VALUES('%s', %d);", steamid, g_iChatColor[param1]); + SQL_Query(g_hDatabase, query); + } + CloseHandle(result); + } + + PrintToChat(param1, " \x06[Unloze] \x01Your chat color was set to %s%s\x01.", g_colors[g_iChatColor[param1]], g_colornames[g_iChatColor[param1]]); + } + } + else if (action == MenuAction_End) + { + delete menu; + } +} + +public Action OnChatMessage(int &client, Handle recipients, char[] name, char[] message) +{ + if (!CheckCommandAccess(client, "sm_colors", VIPFLAG)) + return Plugin_Continue; + + char namecopy[MAX_NAME_LENGTH]; + Format(namecopy, MAX_NAME_LENGTH, "%s%s", g_colors[g_iNameColor[client]], name); + + if (strlen(g_tags[client])) + { + Format(namecopy, MAX_NAME_LENGTH, "%s%s", g_tags[client], namecopy); + } + + strcopy(name, MAX_NAME_LENGTH, namecopy); + + if (g_iChatColor[client] >= 0) + { + char copy[MAXLENGTH_INPUT]; + copy = g_colors[g_iChatColor[client]]; + StrCat(copy, MAXLENGTH_INPUT, message); + strcopy(message, MAXLENGTH_INPUT, copy); + } + + return Plugin_Changed; +} + +public void OnSQLConnect(Handle owner, Handle hndl, const char[] error, any:data) +{ + if(hndl == INVALID_HANDLE || strlen(error) > 0) + { + SetFailState("[Tags] Lost connection to database. Reconnecting on map change. Error: %s", error); + } + + g_hDatabase = hndl; + + SQL_TQuery(g_hDatabase, SQL_DoNothing, "CREATE TABLE IF NOT EXISTS csgo_tagsncolors (steamid VARCHAR(32) PRIMARY KEY, color INTEGER DEFAULT '0', tag VARCHAR(32) DEFAULT '', namecolor INTEGER DEFAULT '2');"); + + for (new i = 1; i <= MaxClients; i++) + { + if (IsClientInGame(i) && IsClientAuthorized(i)) + { + OnClientPostAdminCheck(i); + } + } +} + +public void SQL_DoNothing(Handle owner, Handle hndl, const char[] error, any:data) +{ + if (hndl == INVALID_HANDLE || strlen(error) > 0) + { + SetFailState("[Tags] Lost connection to database. Reconnecting on map change. Error: %s", error); + } +} + diff --git a/Plugins/tags_colors/translations/scp.csgo.phrases.txt b/Plugins/tags_colors/translations/scp.csgo.phrases.txt new file mode 100644 index 00000000..d8ecbbfd --- /dev/null +++ b/Plugins/tags_colors/translations/scp.csgo.phrases.txt @@ -0,0 +1,53 @@ +"Phrases" +{ + "Cstrike_Chat_CT_Loc" + { + "#format" "{1:s},{2:s}" + "en" "(Counter-Terrorist) {1}: {2}" + } + "Cstrike_Chat_CT" + { + "#format" "{1:s},{2:s}" + "en" "(Counter-Terrorist) {1}: {2}" + } + "Cstrike_Chat_T_Loc" + { + "#format" "{1:s},{2:s}" + "en" "(Terrorist) {1}: {2}" + } + "Cstrike_Chat_T" + { + "#format" "{1:s},{2:s}" + "en" "(Terrorist) {1}: {2}" + } + "Cstrike_Chat_CT_Dead" + { + "#format" "{1:s},{2:s}" + "en" "*DEAD*(Counter-Terrorist) {1}: {2}" + } + "Cstrike_Chat_T_Dead" + { + "#format" "{1:s},{2:s}" + "en" "*DEAD*(Terrorist) {1}: {2}" + } + "Cstrike_Chat_Spec" + { + "#format" "{1:s},{2:s}" + "en" "(Spectator) {1}: {2}" + } + "Cstrike_Chat_All" + { + "#format" "{1:s},{2:s}" + "en" "{1}: {2}" + } + "Cstrike_Chat_AllDead" + { + "#format" "{1:s},{2:s}" + "en" "*DEAD* {1}: {2}" + } + "Cstrike_Chat_AllSpec" + { + "#format" "{1:s},{2:s}" + "en" "*SPEC* {1}: {2}" + } +} \ No newline at end of file diff --git a/Plugins/unloze_beams/scripting/unloze_beams.sp b/Plugins/unloze_beams/scripting/unloze_beams.sp new file mode 100644 index 00000000..c9d605db --- /dev/null +++ b/Plugins/unloze_beams/scripting/unloze_beams.sp @@ -0,0 +1,829 @@ +#pragma semicolon 1 + +#define DEBUG + +#define PLUGIN_AUTHOR "jenz" +#define PLUGIN_VERSION "1.00" + +#include +#include + +#pragma newdecls required + +//material +int g_iBeam = -1; + +//zonepoints +char c_storestats[MAXPLAYERS+1][1024]; + +//drawing +int b_beamcolor[MAXPLAYERS]; +float aimpos[MAXPLAYERS][3]; +float beamangle[MAXPLAYERS]; +float g_fClientDurationPref[MAXPLAYERS]; +int colorrainbow[MAXPLAYERS][4]; +int clientcolors[MAXPLAYERS][4]; +int g_iClients[MAXPLAYERS]; +int client_count; +bool b_beamhiding[MAXPLAYERS]; + +public Plugin myinfo = +{ + name = "unloze shop beams", + author = PLUGIN_AUTHOR, + description = "beams purchaseable in the shop", + version = PLUGIN_VERSION, + url = "www.unloze.com" +}; + +public void OnPluginStart() +{ + AddFileToDownloadsTable("materials/unloze_tracers/xbeam.vmt"); + AddFileToDownloadsTable("materials/unloze_tracers/xbeam.vtf"); + + RegConsoleCmd("sm_beamers", cmd_beamPoint, "Enables beams through shop"); + RegConsoleCmd("sm_beams", cmd_beamPoint, "Enables beams through shop"); + RegConsoleCmd("sm_beam", cmd_beamPoint, "Enables beams through shop"); + RegConsoleCmd("sm_hidebeam", cmd_beamPointHide, "Hides beams for the client"); + RegConsoleCmd("sm_beamsize", cmd_beamPointangle, "Changes the BeamSize"); + RegConsoleCmd("sm_beamtime", cmd_beamPointDuration, "Changes the BeamSize"); + + RegAdminCmd("sm_beammysql", cmd_beammysqltest, ADMFLAG_ROOT); + SQL_StartConnection(); + + //0.1 is not good enough + //CreateTimer(0.1, beamTesendDelay, INVALID_HANDLE, TIMER_REPEAT); +} + + +public Action cmd_beammysqltest(int client, int args) +{ + CheckbeamprefHideMYSQL(client); +} + +public Action cmd_beamPointDuration(int client, int args) +{ + char number[5]; + float check; + GetCmdArg(args, number, sizeof(number)); + check = StringToFloat(number); + if (check > 5.0 || check < 0.1) + { + PrintToChat(client, "Input Range 0.1 - 5.0"); + return Plugin_Handled; + } + g_fClientDurationPref[client] = check; + PrintToChat(client, "beamDuration value: %f", g_fClientDurationPref[client]); + MySQLStoreBeamDurationPref(client, check); + return Plugin_Handled; +} + +public Action cmd_beamPointangle(int client, int args) +{ + char number[5]; + float check; + GetCmdArg(args, number, sizeof(number)); + check = StringToFloat(number); + if (check > 20.0 || check < 0.1) + { + PrintToChat(client, "Input Range 0.1 - 20.0"); + return Plugin_Handled; + } + beamangle[client] = check; + PrintToChat(client, "beamangle value: %f", beamangle[client]); + MySQLStoreBeamSizePref(client, check); + return Plugin_Handled; +} + +public Action cmd_beamPointHide( int client, int args ) +{ + if (!b_beamhiding[client]) + { + mysqlentryhidebeam(client, 1); + PrintToChat(client, "[UNLOZE] Disabled beams!"); + b_beamhiding[client] = true; + } + else + { + mysqlentryhidebeam(client, 0); + PrintToChat(client, "[UNLOZE] Enabled beams!"); + b_beamhiding[client] = false; + } + ClientCount(); + return Plugin_Handled; +} + +public Action cmd_beamPoint( int client, int args ) +{ + Menu menu = new Menu(MenuHandler1); + menu.SetTitle("UNLOZE Beams are unlocked through !shop"); + menu.AddItem("Disable", "Disable"); + if (StrContains(c_storestats[client], "w") >= 0) + { + menu.AddItem("Rainbow Beam", "Rainbow Beam"); + } + if (StrContains(c_storestats[client], "v") >= 0) + { + menu.AddItem("Blue Beam", "Blue Beam"); + } + if (StrContains(c_storestats[client], "x") >= 0) + { + menu.AddItem("Green Beam", "Green Beam"); + } + if (StrContains(c_storestats[client], "y") >= 0) + { + menu.AddItem("Red Beam", "Red Beam"); + } + if (StrContains(c_storestats[client], "z") >= 0) + { + menu.AddItem("Gold Beam", "Gold Beam"); + } + if (StrContains(c_storestats[client], "3") >= 0) + { + menu.AddItem("Black Beam", "Black Beam"); + } + if (StrContains(c_storestats[client], "4") >= 0) + { + menu.AddItem("Cyan Beam", "Cyan Beam"); + } + if (StrContains(c_storestats[client], "5") >= 0) + { + menu.AddItem("Turquoise Beam", "Turquoise Beam"); + } + if (StrContains(c_storestats[client], "6") >= 0) + { + menu.AddItem("Yellow Beam", "Yellow Beam"); + } + if (StrContains(c_storestats[client], "7") >= 0) + { + menu.AddItem("Pink Beam", "Pink Beam"); + } + if (StrContains(c_storestats[client], "8") >= 0) + { + menu.AddItem("Purple Beam", "Purple Beam"); + } + if (StrContains(c_storestats[client], "9") >= 0) + { + menu.AddItem("gray Beam", "gray Beam"); + } + menu.ExitButton = true; + menu.Display(client, 0); + return Plugin_Handled; +} + + +public int MenuHandler1(Menu menu, MenuAction action, int param1, int choice) +{ + /* If the menu was cancelled, print a message to the server about it. */ + if (action == MenuAction_Cancel) + { + PrintToServer("Client %d's menu was cancelled. Reason: %d", param1, choice); + } + /* If the menu has ended, destroy it */ + else if (action == MenuAction_End) + { + delete menu; + } + else if (action == MenuAction_Select) + { + char info[32]; + menu.GetItem(choice, info, sizeof(info)); + if (StrEqual(info, "Blue Beam", true)) + { + PrintToChat(param1, "Selected Blue Beam!"); + b_beamcolor[param1] = 1; + } + else if (StrEqual(info, "Red Beam", true)) + { + PrintToChat(param1, "Selected Red Beam!"); + b_beamcolor[param1] = 2; + } + else if (StrEqual(info, "Green Beam", true)) + { + PrintToChat(param1, "Selected Green Beam!"); + b_beamcolor[param1] = 3; + } + else if (StrEqual(info, "Gold Beam", true)) + { + PrintToChat(param1, "Selected Gold Beam!"); + b_beamcolor[param1] = 4; + } + else if (StrEqual(info, "Black Beam", true)) + { + PrintToChat(param1, "Selected Black Beam!"); + b_beamcolor[param1] = 5; + } + else if (StrEqual(info, "Cyan Beam", true)) + { + PrintToChat(param1, "Selected Cyan Beam!"); + b_beamcolor[param1] = 6; + } + else if (StrEqual(info, "Turquoise Beam", true)) + { + PrintToChat(param1, "Selected Turquoise Beam!"); + b_beamcolor[param1] = 7; + } + else if (StrEqual(info, "Yellow Beam", true)) + { + PrintToChat(param1, "Selected Yellow Beam!"); + b_beamcolor[param1] = 8; + } + else if (StrEqual(info, "Pink Beam", true)) + { + PrintToChat(param1, "Selected Pink Beam!"); + b_beamcolor[param1] = 9; + } + else if (StrEqual(info, "Purple Beam", true)) + { + PrintToChat(param1, "Selected Purple Beam!"); + b_beamcolor[param1] = 10; + } + else if (StrEqual(info, "gray Beam", true)) + { + PrintToChat(param1, "Selected gray Beam!"); + b_beamcolor[param1] = 11; + } + else if (StrEqual(info, "Rainbow Beam", true)) + { + PrintToChat(param1, "Selected Rainbow Beam!"); + b_beamcolor[param1] = 12; + } + else if (StrEqual(info, "Disable", true)) + { + PrintToChat(param1, "Disabled Beam!"); + b_beamcolor[param1] = 0; + } + InsertbeamprefMYSQL(param1, b_beamcolor[param1]); + } +} + +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]) +{ + if (!IsValidClient(client) || !IsPlayerAlive(client) || client_count < 1) + { + return Plugin_Continue; + } + if (b_beamcolor[client] == 0) + { + return Plugin_Continue; + } + //blue + if (b_beamcolor[client] == 1) + { + clientcolors[client][0] = 0; + clientcolors[client][1] = 0; + clientcolors[client][2] = 255; + } + //red + else if (b_beamcolor[client] == 2) + { + clientcolors[client][0] = 255; + clientcolors[client][1] = 0; + clientcolors[client][2] = 0; + } + //green + else if (b_beamcolor[client] == 3) + { + clientcolors[client][0] = 0; + clientcolors[client][1] = 255; + clientcolors[client][2] = 0; + } + //gold + else if (b_beamcolor[client] == 4) + { + clientcolors[client][0] = 255; + clientcolors[client][1] = 215; + clientcolors[client][2] = 0; + } + //black + else if (b_beamcolor[client] == 5) + { + clientcolors[client][0] = 0; + clientcolors[client][1] = 0; + clientcolors[client][2] = 0; + } + //cyan + else if (b_beamcolor[client] == 6) + { + clientcolors[client][0] = 0; + clientcolors[client][1] = 255; + clientcolors[client][2] = 255; + } + //turqouise + else if (b_beamcolor[client] == 7) + { + clientcolors[client][0] = 64; + clientcolors[client][1] = 224; + clientcolors[client][2] = 208; + } + //yellow + else if (b_beamcolor[client] == 8) + { + clientcolors[client][0] = 255; + clientcolors[client][1] = 255; + clientcolors[client][2] = 0; + } + //pink + else if (b_beamcolor[client] == 9) + { + clientcolors[client][0] = 255; + clientcolors[client][1] = 105; + clientcolors[client][2] = 180; + } + //purple + else if (b_beamcolor[client] == 10) + { + clientcolors[client][0] = 128; + clientcolors[client][1] = 0; + clientcolors[client][2] = 128; + } + //gray + else if (b_beamcolor[client] == 11) + { + clientcolors[client][0] = 128; + clientcolors[client][1] = 128; + clientcolors[client][2] = 128; + } + //rainbow + else if (b_beamcolor[client] == 12) + { + int ran; + ran = GetRandomInt(0, 2); + colorrainbow[client][ran] -= 1; + if (colorrainbow[client][0] < 1) + { + colorrainbow[client][0] = 255; + } + if (colorrainbow[client][1] < 1) + { + colorrainbow[client][1] = 255; + } + if (colorrainbow[client][2] < 1) + { + colorrainbow[client][2] = 255; + } + } + float otherhalf; + otherhalf -= beamangle[client]; + GetClientAbsOrigin(client, aimpos[client]); + if (b_beamcolor[client] == 12) + { + Circle(aimpos[client], beamangle[client], g_iBeam, client, colorrainbow[client]); + Circle(aimpos[client], otherhalf, g_iBeam, client, colorrainbow[client]); + } + else + { + Circle(aimpos[client], beamangle[client], g_iBeam, client, clientcolors[client]); + Circle(aimpos[client], otherhalf, g_iBeam, client, clientcolors[client]); + } + return Plugin_Continue; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: Mapstart +//---------------------------------------------------------------------------------------------------- +public void OnMapStart() +{ + g_iBeam = PrecacheModel("materials/unloze_tracers/xbeam.vmt"); +} + +public void OnClientDisconnect_Post(int client) +{ + ClientCount(); +} + +//actually used on each mapchange according to mitchell +public void OnClientDisconnect (int client) +{ + Format(c_storestats[client], sizeof(c_storestats), ""); + beamangle[client] = 0.0; + b_beamcolor[client] = 0; + aimpos[client][0] = 0.0; + aimpos[client][1] = 0.0; + aimpos[client][2] = 0.0; + colorrainbow[client][0] = 255; + colorrainbow[client][1] = 255; + colorrainbow[client][2] = 255; + colorrainbow[client][3] = 255; + + clientcolors[client][0] = 255; + clientcolors[client][1] = 255; + clientcolors[client][2] = 255; + clientcolors[client][3] = 255; + b_beamhiding[client] = false; + g_fClientDurationPref[client] = 1.0; + //IsClientConnected(client) && IsClientInGame(client) would be true here +} + + +public void OnClientPostAdminCheck(int client) +{ + beamangle[client] = 5.0; + b_beamhiding[client] = false; + aimpos[client][0] = 0.0; + aimpos[client][1] = 0.0; + aimpos[client][2] = 0.0; + b_beamcolor[client] = 0; + colorrainbow[client][0] = 255; + colorrainbow[client][1] = 255; + colorrainbow[client][2] = 255; + colorrainbow[client][3] = 255; + clientcolors[client][0] = 255; + clientcolors[client][1] = 255; + clientcolors[client][2] = 255; + clientcolors[client][3] = 255; + g_fClientDurationPref[client] = 1.0; + CheckbeamSizeMYSQL(client); + CheckBeamDurationMYSQL(client); + CheckFlagsMYSQL(client); + CheckbeamprefMYSQL(client); + CheckbeamprefHideMYSQL(client); +} + + +stock void ClientCount() +{ + client_count = 0; + for (int i = 1; i <= MaxClients; i++) + { + if (IsValidClient(i) && !b_beamhiding[i]) + { + g_iClients[client_count++] = i; + } + } +} + +public void MySQLStoreBeamDurationPref(int client, float check) +{ + char error[255]; + Database db; + //the points not related to hlstats are stored together with tracer prefferences but have + //their own table + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_beampref2` (`steam_id`, `Duration`) VALUES ('%s','%f') ON DUPLICATE KEY UPDATE `Duration` = '%f'", sSID, check, check); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete db; +} + +public void MySQLStoreBeamSizePref(int client, float check) +{ + char error[255]; + Database db; + //the points not related to hlstats are stored together with tracer prefferences but have + //their own table + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_beampref2` (`steam_id`, `size`) VALUES ('%s','%f') ON DUPLICATE KEY UPDATE `size` = '%f'", sSID, check, check); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete db; +} + +public void CheckBeamDurationMYSQL(int client) +{ + char error[255]; + Database db; + //the points not related to hlstats are stored together with tracer prefferences but have + //their own table + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "SELECT Duration FROM `unloze_beampref2` WHERE `steam_id` = '%s'", sSID); + + DBResultSet rs; + + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + return; + } + + if (rs.RowCount > 0 && rs.FetchRow()) + { + char l_cSize[4]; + SQL_FetchString(rs, 0, l_cSize, sizeof(l_cSize)); + g_fClientDurationPref[client] = StringToFloat(l_cSize); + if (g_fClientDurationPref[client] == 0.0) + { + g_fClientDurationPref[client] = 1.0; + } + } + delete rs; + delete db; +} + +public void CheckbeamSizeMYSQL(int client) +{ + char error[255]; + Database db; + //the points not related to hlstats are stored together with tracer prefferences but have + //their own table + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "SELECT size FROM `unloze_beampref2` WHERE `steam_id` = '%s'", sSID); + + DBResultSet rs; + + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + return; + } + + if (rs.RowCount > 0 && rs.FetchRow()) + { + char l_cSize[4]; + SQL_FetchString(rs, 0, l_cSize, sizeof(l_cSize)); + beamangle[client] = StringToFloat(l_cSize); + } + delete rs; + delete db; +} + +public void CheckFlagsMYSQL(int client) +{ + char error[255]; + Database db; + //the points not related to hlstats are stored together with tracer prefferences but have + //their own table + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "SELECT storestats FROM `unloze_zonepoints` WHERE `steam_id` = '%s'", sSID); + + DBResultSet rs; + + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + return; + } + + if (rs.RowCount > 0 && rs.FetchRow()) + { + SQL_FetchString(rs, 0, c_storestats[client], sizeof(c_storestats)); + } + delete rs; + delete db; +} + +public void CheckbeamprefHideMYSQL(int client) +{ + char error[255]; + Database db; + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB CheckbeamprefHideMYSQL!"); + delete db; + return; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "SELECT hide FROM `unloze_beamprefhide` WHERE `steam_id` = '%s'", sSID); + + DBResultSet rs1; + + if ((rs1 = SQL_Query(db, sQuery)) == null) + { + //PrintToChatAll("Failed, null result"); + delete db; + delete rs1; + return; + } + + if (rs1.RowCount > 0 && rs1.FetchRow()) + { + //PrintToChatAll("Has Entry"); + int translate; + translate = SQL_FetchInt(rs1, 0); + if (translate == 1) + { + b_beamhiding[client] = true; + delete db; + delete rs1; + return; + } + } + ClientCount(); + delete rs1; + delete db; +} + +public void CheckbeamprefMYSQL(int client) +{ + char error[255]; + Database db; + //the points not related to hlstats are stored together with tracer prefferences but have + //their own table + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "SELECT beam FROM `unloze_beampref` WHERE `steam_id` = '%s'", sSID); + DBResultSet rs; + + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + return; + } + if (rs.RowCount > 0 && rs.FetchRow()) + { + char translate[124]; + SQL_FetchString(rs, 0, translate[client], MAX_NAME_LENGTH); + b_beamcolor[client] = StringToInt(translate[client]); + } + delete rs; + delete db; +} + + +public void InsertbeamprefMYSQL(int client, int colornumber) +{ + char error[255]; + Database db; + //the points not related to hlstats are stored together with tracer prefferences but have + //their own table + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_beampref` (`steam_id`, `beam`) VALUES ('%s','%i') ON DUPLICATE KEY UPDATE `beam` = '%i'", sSID, colornumber, colornumber); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete db; +} + + +public void mysqlentryhidebeam(int client, int hide) +{ + char error[255]; + Database db; + //the points not related to hlstats are stored together with tracer prefferences but have + //their own table + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_beamprefhide` (`steam_id`, `hide`) VALUES ('%s','%i') ON DUPLICATE KEY UPDATE `hide` = '%i'", sSID, hide, hide); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete db; +} + + +public void SQL_StartConnection() +{ + char error[255]; + Database db; + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + //create tables + char sQuery[255]; + Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `unloze_beampref` (`steam_id` VARCHAR(254) NOT NULL, `beam` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_id`))"); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `unloze_beamprefhide` (`steam_id` VARCHAR(254) NOT NULL, `hide` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_id`))"); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `unloze_beampref2` (`steam_id` VARCHAR(254) NOT NULL, `size` VARCHAR(254) NOT NULL, `Duration` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_id`))"); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + + delete db; +} + +//old mitch coderino https://forums.alliedmods.net/showthread.php?t=141518&page=2 +public void Circle(float vecLocation[3], float radius, int material, int client, const int colors[4]) +{ + float pos2[4][3]; + + //Create the start position for the first part of the beam + pos2[0][0] = vecLocation[0]; + pos2[1][0] = vecLocation[0] + radius; + pos2[2][0] = vecLocation[0] + (radius*DegToRad(90.0)); + pos2[3][0] = vecLocation[0] + (radius*DegToRad(45.0)); + pos2[0][1] = vecLocation[1] + radius; + pos2[1][1] = vecLocation[1]; + pos2[2][1] = vecLocation[1] + (radius*DegToRad(90.0)); + pos2[3][1] = vecLocation[1] - (radius*DegToRad(45.0)); + pos2[0][2] = vecLocation[2]; + pos2[1][2] = vecLocation[2]; + pos2[2][2] = vecLocation[2]; + pos2[3][2] = vecLocation[2]; + + TE_SetupBeamPoints(pos2[0], vecLocation, material, 0, 0, 0, g_fClientDurationPref[client], 5.0, 5.0, 5, 0.0, colors, 3); + TE_Send(g_iClients, client_count); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: stocks +//---------------------------------------------------------------------------------------------------- +stock bool IsValidClient(int client, bool alive = true, bool bots = false) +{ + if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client)) + { + return true; + } + return false; +} + +public void DummyCallbackSimple(Handle hOwner, Handle hChild, const char[] err, DataPack pack1) +{ + if (hOwner == null || hChild == null) + { + LogError("Query error. (%s)", err); + } +} \ No newline at end of file diff --git a/Plugins/unloze_eventScheduler/scripting/unloze_eventScheduler.sp b/Plugins/unloze_eventScheduler/scripting/unloze_eventScheduler.sp new file mode 100644 index 00000000..b6afa6aa --- /dev/null +++ b/Plugins/unloze_eventScheduler/scripting/unloze_eventScheduler.sp @@ -0,0 +1,361 @@ +#pragma semicolon 1 + +#define DEBUG + +#define PLUGIN_AUTHOR "jenz" +#define PLUGIN_VERSION "1.00" + +#include +#include +#include + +#pragma newdecls required + +static char g_sEventURL[PLATFORM_MAX_PATH]; +char c_EventContent[526][526]; +bool b_eventLink[MAXPLAYERS]; + + +public Plugin myinfo = +{ + name = "unloze_EventScheduler", + author = PLUGIN_AUTHOR, + description = "Ingame Event Notifier", + version = PLUGIN_VERSION, + url = "www.unloze.com" +}; + +//---------------------------------------------------------------------------------------------------- +// Purpose: pluginstart/ mapstart +//---------------------------------------------------------------------------------------------------- + +public void OnPluginStart() +{ + //commands + RegConsoleCmd("say", Cmd_Say); + RegAdminCmd("sm_event", Cmd_EventNotifier, ADMFLAG_GENERIC); + RegAdminCmd("sm_mapstartevent", Cmd_CheckEventInfo, ADMFLAG_ROOT); + + //FilePath + BuildPath(Path_SM, g_sEventURL, sizeof(g_sEventURL), "configs/EventURL.txt"); +} + +public void OnMapStart() +{ + EventInfo(); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: timer notifications +//---------------------------------------------------------------------------------------------------- + +public Action EventCountDown(Handle timer) +{ + //PrintToChatAll("c_EventContent[1]: %s", c_EventContent[1]); + //PrintToChatAll("c_EventContent[2]: %s", c_EventContent[2]); + CalculateTimeToNextEvent(c_EventContent[1], c_EventContent[2]); + return Plugin_Handled; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: CalculateTimeToNextEvent +//---------------------------------------------------------------------------------------------------- +public void CalculateTimeToNextEvent(char[] content, char[] content1) +{ + char sPart[2][526]; + char sMonth[24]; + char sDay[24]; + char sHour[24]; + char sMinute[24]; + int i_Month; + int i_Day; + int i_Hour; + int i_Minute; + int months; + int days; + int hours; + int minutes; + FormatTime(sMonth, sizeof(sMonth), "%m"); + FormatTime(sDay, sizeof(sDay), "%d"); + FormatTime(sHour, sizeof(sHour), "%H"); + FormatTime(sMinute, sizeof(sMinute), "%M"); + TrimString(content); + TrimString(content1); + ExplodeString(content, "/", sPart, 2, 526); + //update we apperently need to know month + i_Day = StringToInt(sDay); + days = StringToInt(sPart[0]); + i_Month = StringToInt(sMonth); + ExplodeString(sPart[1], "/", sPart, 2, 526); + months = StringToInt(sPart[0]); + i_Hour = StringToInt(sHour); + hours = StringToInt(content1); + //PrintToChatAll("hours: %i", hours); + i_Minute = StringToInt(sMinute); + if (days >= i_Day || months > i_Month) + { + ///SHIIIET + if (days >= i_Day) + { + days -= i_Day; + } + else if (i_Month == 1 || i_Month == 3 || i_Month == 5 || i_Month == 7 || i_Month == 8 || i_Month == 10 || i_Month == 12) + { + days += (31 - i_Day); + } + else if (i_Month == 2) + { + days += (28 - i_Day); + } + else + { + days += (30 - i_Day); + } + + //from 12 to 24 or from 7 to 19 etc etc + hours += 12; + if (i_Hour > hours) + { + days -= 1; + hours = 24 - (i_Hour - hours); + //PrintToChatAll("if statement hours: %i", hours); + } + else + { + hours -= i_Hour; + //PrintToChatAll("else statement: hours: %i", hours); + } + //should solve one hour delay + if (hours != 0) + { + hours -= 1; + } + + minutes = 60 - i_Minute; + PrintToChatAll("\x06[UNLOZE]\x03 Next Event is: Event# %s", c_EventContent[0]); + PrintToChatAll("\x06[UNLOZE]\x03 Taking Place in: %i Days, %i Hours, %i Minutes", days, hours, minutes); + PrintToChatAll("\x06[UNLOZE]\x03 Rewards: %s VIP", c_EventContent[3]); + } + else + { + //PrintToChatAll("days: %i \ni_Day: %i", days, i_Day); + //PrintToChatAll("months: %i \ni_Month: %i", months, i_Month); + PrintToChatAll("[UNLOZE] Waiting for next Event to be Scheduled..."); + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: EventInfo +//---------------------------------------------------------------------------------------------------- +public void EventInfo() +{ + //manual check if map event is read correctly on mapstart + Handle zonefile = INVALID_HANDLE; + char line[526]; + //PrintToChatAll("g_sEventURL: %s", g_sEventURL); + zonefile = OpenFile(g_sEventURL, "r"); + if (zonefile == INVALID_HANDLE) + { + //PrintToChatAll("Invalid handle"); + return; + } + ReadFileLine(zonefile, line, sizeof(line)); + //reading the link on every mapstart + ReplaceString(line, sizeof(line), "\"", "", false); + //PrintToChatAll("line: %s", line); + System2HTTPRequest httpRequest = new System2HTTPRequest(HttpResponseCallback, line); + httpRequest.GET(); + delete httpRequest; + delete zonefile; + //5 minutes just + CreateTimer(300.0, EventCountDown, INVALID_HANDLE, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: cmds & menus +//---------------------------------------------------------------------------------------------------- +public Action Cmd_CheckEventInfo(int client, any args) +{ + EventInfo(); + return Plugin_Handled; +} + +public Action Cmd_EventNotifier(int client, any args) +{ + EventNotifierMenu(client); + return Plugin_Handled; +} + +static void EventNotifierMenu(int client) +{ + char c_local[526]; + Format(c_local, sizeof(c_local), "Next Event: %s", c_EventContent[0]); + Menu EventMenu = CreateMenu(Event_Menu); + EventMenu.SetTitle("UNLOZE Event Scheduler"); + EventMenu.AddItem("nothing here", c_local, ITEMDRAW_DISABLED); + EventMenu.AddItem("nothing here", "Link an Event"); + EventMenu.ExitButton = true; + EventMenu.ExitBackButton = true; + EventMenu.Display(client, 30); +} + +public int Event_Menu(Menu menu, MenuAction action, int client, int choice) +{ + if (action == MenuAction_Select) + { + if (choice == 1) + { + PrintToChat(client, "Copy the Event link Into the chat!"); + b_eventLink[client] = true; + } + else if (action == MenuAction_End) + { + delete(menu); + } + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: simple say hook +//---------------------------------------------------------------------------------------------------- +public Action Cmd_Say(int client, int args) +{ + if (b_eventLink[client]) + { + char arg[526]; + GetCmdArgString(arg, sizeof(arg)); + PrintToChat(client, "arg: %s", arg); + ReplaceString(arg, sizeof(arg), "\"", "", false); + System2HTTPRequest httpRequest = new System2HTTPRequest(HttpResponseCallback, arg); + httpRequest.GET(); + delete httpRequest; + b_eventLink[client] = false; + + Handle zonefile = INVALID_HANDLE; + zonefile = OpenFile(g_sEventURL, "w"); + //one would think storing c_EventContent[0] could be better ohwell + WriteFileLine(zonefile, arg); + delete zonefile; + return Plugin_Handled; + } + return Plugin_Continue; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: http callbacks +//---------------------------------------------------------------------------------------------------- +public void HttpResponseCallback(bool success, const char[] error, System2HTTPRequest request, System2HTTPResponse response, HTTPRequestMethod method) +{ + if (success) + { + //PrintToChatAll("Success"); + char content[526]; + char content1[1080]; + //for some horrifying reason this is inconsistent + for (int found = 0; found < response.ContentLength;) + { + found += response.GetContent(content, sizeof(content), found); + FindRelevantData(content); + } + for (int found = 0; found < response.ContentLength;) + { + found += response.GetContent(content1, sizeof(content1), found); + FindRelevantDataRewards(content1); + } + + ReplaceString(c_EventContent[0], sizeof(c_EventContent), "", "", false); + ReplaceString(c_EventContent[0], sizeof(c_EventContent), "| UNLOZE", "", false); + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: Finds relevant data like event title, hours & days left, event rewards +//---------------------------------------------------------------------------------------------------- +public void FindRelevantDataRewards(char[] content) +{ + if (StrContains(content, "Prize :", false) > -1) + { + //this is fragile as fuck + char sPart[2][526]; + //PrintToChatAll("Prize content: %s", content); + ExplodeString(content, "Prize :", sPart, 2, 526); + //PrintToChatAll("sPart[1]: %s", sPart[1]); + //PrintToChatAll("sPart[0]: %s", sPart[0]); + c_EventContent[3] = sPart[1]; + ExplodeString(c_EventContent[3], "VIP", sPart, 2, 526); + c_EventContent[3] = sPart[0]; + ReplaceString(c_EventContent[3], sizeof(c_EventContent), "</span></b>", ""); + PrintToChatAll("c_EventContent[3]: %s", c_EventContent[3]); + } +} +public void FindRelevantData(char[] content) +{ + if (StrContains(content, "content=\"Event#", true) > -1) + { + char sPart[2][526]; + //PrintToChatAll("content: %s", content); + //if event managers change formatting heads will roll + ExplodeString(content, "content=\"Event#", sPart, 2, 526); + //PrintToChatAll("sPart[0]: %s", sPart[0]); + //PrintToChatAll("sPart[1]: %s", sPart[1]); + c_EventContent[0] = sPart[1]; + ExplodeString(c_EventContent[0], "\"/>", sPart, 2, 526); + //PrintToChatAll("POST sPart[0]: %s", sPart[0]); + c_EventContent[0] = sPart[0]; + ReplaceString(c_EventContent[0], sizeof(c_EventContent), "amp;", "", false); + + } + if (StrContains(content, "Date :", true) > -1) + { + //PrintToChatAll("StrContains Date :%s", content); + char sPart[2][526]; + char c_localfix[526]; + //PrintToChatAll("c_EventContent[1] Pre: %s", c_EventContent[1]); + //THIS IS FIIIINE + ExplodeString(content, "Date :", sPart, 2, 526); + c_localfix = sPart[1]; + //PrintToChatAll("Date c_localfix: %s", c_localfix); + ExplodeString(c_localfix, "</span><br/>", sPart, 2, 526); + c_localfix = sPart[0]; + TrimString(c_localfix); + if (StrContains(c_localfix, "'\">") > -1) + { + ExplodeString(c_localfix, "'\">", sPart, 2, 526); + } + else if (StrContains(c_localfix, "</b></span>") > -1) + { + ExplodeString(c_localfix, "</b></span>", sPart, 2, 526); + } + //PrintToChatAll("</span><br/> c_localfix: %s", c_localfix); + //PrintToChatAll("POST Day sPart[0]: %s", sPart[0]); + c_EventContent[1] = sPart[1]; + ReplaceString(c_EventContent[1], sizeof(c_EventContent), "</span></span>", ""); + PrintToChatAll("c_EventContent[1]: %s", c_EventContent[1]); + } + if (StrContains(content, "Time :", true) > -1) + { + char sPart[2][526]; + //if event managers change formatting heads will roll + SplitString(content, " pm GMT+2", c_EventContent[2], sizeof(c_EventContent)); + //THIS IS FIIIINE + ExplodeString(c_EventContent[2], "pm GMT+1", sPart, 2, 526); + //PrintToChatAll("hour sPart[0]: %s", sPart[0]); + c_EventContent[2] = sPart[1]; + ReplaceString(c_EventContent[2], sizeof(c_EventContent), "/", "", false); + TrimString(c_EventContent[2]); + PrintToChatAll("c_EventContent[2]: %s", c_EventContent[2]); + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: OnClientPostAdminCheck && disconnect +//---------------------------------------------------------------------------------------------------- +public void OnClientPostAdminCheck(int client) +{ + b_eventLink[client] = false; +} + +public void OnClientDisconnect(int client) +{ + b_eventLink[client] = false; +} diff --git a/Plugins/unloze_ingamePoll/scripting/unloze_ingamePoll.sp b/Plugins/unloze_ingamePoll/scripting/unloze_ingamePoll.sp new file mode 100644 index 00000000..a6d2e1aa --- /dev/null +++ b/Plugins/unloze_ingamePoll/scripting/unloze_ingamePoll.sp @@ -0,0 +1,833 @@ +#pragma semicolon 1 +#define DEBUG +#define PLUGIN_AUTHOR "jenz" +#define PLUGIN_VERSION "2.00" + +#include <sourcemod> +#include <sdktools> + +#pragma newdecls required +char g_cPollText[256][512]; +char g_cPollVotes[256][512]; +char g_cPollIRunOutOfNames[256][512]; +char g_cPollTextClient[256]; +char g_cPollVotesCvar[256]; +char g_cPollCommands[512]; +int g_iPollVoteWithHigestResult; +int g_iPollVotesCvar; +int g_iPollIndex; +int g_iAdminSay[MAXPLAYERS]; +int g_iAdminVoteOptions[MAXPLAYERS]; +Handle g_hTimer; + +public Plugin myinfo = +{ + name = "Unloze ingame polls", + author = PLUGIN_AUTHOR, + description = "ingame polls", + version = PLUGIN_VERSION, + url = "www.unloze.com" +}; + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnPluginStart() +{ + //Reg Cmds + RegConsoleCmd("sm_poll", Cmd_Polls, "Vote on ongoing polls"); + RegConsoleCmd("sm_polls", Cmd_Polls, "Vote on ongoing polls"); + RegConsoleCmd("say", Cmd_Say); + + //mysql + SQL_StartConnection(); + + //admin cmds + RegAdminCmd("sm_pollmenu", Cmd_pollAdminMenu, ADMFLAG_GENERIC); +} + +public void OnMapStart() +{ + MySQLSelectPollTitles(); + CreateTimer(1.0, evaluatedelayAll, INVALID_HANDLE); + g_hTimer = CreateTimer(260.0, pollNotifier, INVALID_HANDLE, TIMER_REPEAT); + //change to 260.0 again for main server +} + +public void OnMapEnd() +{ + if (g_hTimer != INVALID_HANDLE) + { + KillTimer(g_hTimer); + g_hTimer = INVALID_HANDLE; + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void InitializeQueries(char[] PollText) +{ + int l_iPollVoteOptions; + int l_iMax; + int i_lCounter; + //for loop here to count votes for each option of the specified poll + //needs state 0 to only count active votes + l_iPollVoteOptions = MySQLSelectPollVotes(PollText, 0); + for (int j = 0; j <= l_iPollVoteOptions; j++) + { + l_iMax = MySQLQueryVotes(PollText, j); + if (l_iMax > i_lCounter) + { + //index 4 is wrong should be 3 + g_iPollVoteWithHigestResult = j; + i_lCounter = l_iMax; + } + } +} + +public Action ExecuteVoteCommand(char[] command, bool mapstart) +{ + if (StrContains(command, "mp_", true) == -1 && StrContains(command, "sv_", true) == -1 && StrContains(command, "plugins", true) == -1) + { + ServerCommand(command); + } + else if (mapstart) + { + ServerCommand(command); + } + //PrintToChatAll("command: %s", command); + return Plugin_Handled; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Action evaluatedelay(Handle timer) +{ + char command[512]; + InitializeQueries(g_cPollTextClient); + MySQLSelectHighestVoteForPoll(g_cPollText[g_iPollVotesCvar][256], g_iPollVoteWithHigestResult); + Format(command, sizeof(command), g_cPollCommands); + ExecuteVoteCommand(command, false); +} + +//experimental to launch all on mapstart +public Action evaluatedelayAll(Handle timer) +{ + int l_iIndex; + char command[512]; + //should correctly itterate through all + //[numberOfStrings][lengthOfLongestString] + while (g_cPollText[l_iIndex][256] != '\0') + { + InitializeQueries(g_cPollText[l_iIndex][256]); + MySQLSelectHighestVoteForPoll(g_cPollText[l_iIndex][256], g_iPollVoteWithHigestResult); + Format(command, sizeof(command), g_cPollCommands); + ExecuteVoteCommand(command, true); + l_iIndex++; + } +} +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Action pollNotifier(Handle timer) +{ + int l_iIndex; + //edited + while (g_cPollText[l_iIndex][256] != '\0') + { + PrintToChatAll("\x06[UNLOZE]\x07 Current Polls: %s", g_cPollText[l_iIndex][256]); + l_iIndex++; + } + PrintToChatAll("\x06[UNLOZE]\x07 Type !poll to vote"); +} + +public Action Cmd_pollAdminMenu(int client, int args) +{ + EditPollAdminMenu(client); +} + +public Action EditPollAdminMenu(int client) +{ + Menu menu1 = new Menu(Menu_PollAdminMenu); + menu1.SetTitle("[UNLOZE] Admin menu to edit polls"); + menu1.AddItem("nuffin here", "Create new Poll"); + menu1.AddItem("nuffin here", "Edit poll"); + menu1.Display(client, MENU_TIME_FOREVER); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Action Cmd_Say(int client, int args) +{ + int l_iIndex; + + if (g_iAdminSay[client] == 1) + { + //edited to dimensional array + while (g_cPollText[l_iIndex][256] != '\0') + { + l_iIndex++; + } + GetCmdArgString(g_cPollText[l_iIndex][256], sizeof(g_cPollText)); + ReplaceString(g_cPollText[l_iIndex][256], sizeof(g_cPollText), "\"", ""); + PrintToChat(client, "Creating new PollTitle: %s", g_cPollText[l_iIndex][256]); + //sends a new poll title to DB as a COLUMN + sendMYSQLPollTextCOLUMN(g_cPollText[l_iIndex][256]); + } + else if (g_iAdminSay[client] == 2) + { + //edited to dimensional array + char l_cArgStringUpdate[256]; + GetCmdArgString(l_cArgStringUpdate, sizeof(l_cArgStringUpdate)); + ReplaceString(l_cArgStringUpdate, sizeof(l_cArgStringUpdate), "\"", ""); + PrintToChat(client, "Updating PollTitle to: %s", l_cArgStringUpdate); + //update the coloumn title if somebody wants to rename poll + //g_iPollIndex stores what POll an admin choose to edit + MySQLUpdateTextCOLUMN(g_cPollText[g_iPollIndex][256], l_cArgStringUpdate); + } + if (g_iAdminVoteOptions[client] == 1) + { + char l_cDummy[1]; + GetCmdArgString(g_cPollVotes[client][256], sizeof(g_cPollVotes)); + ReplaceString(g_cPollVotes[client][256], sizeof(g_cPollVotes), "\"", ""); + PrintToChat(client, "Made %s an Vote Option", g_cPollVotes[client][256]); + PrintToChat(client, "Give the Vote Option a COMMAND BEFORE MAKING NEXT VOTE OPTION"); + + //After each vote option its cvar has to be set before next vote option can be made + mysqlStoreVoteOption(0, l_cDummy[0], client); + } + else if (g_iAdminVoteOptions[client] == 2) + { + char l_cPollcommands[256][512]; + GetCmdArgString(l_cPollcommands[0][256], sizeof(l_cPollcommands)); + ReplaceString(l_cPollcommands[0][256], sizeof(l_cPollcommands), "\"", ""); + PrintToChat(client, "\x06Added %s as a cvar/command to vote option: %s", l_cPollcommands[0][256], g_cPollVotesCvar); + PrintToChat(client, "You can now add another vote option to the poll"); + //After each vote option its cvar has to be set before next vote option can be made + mysqlStoreVoteOption(1, l_cPollcommands[0][256], client); + } + //Updating all polltitles + MySQLSelectPollTitles(); + g_iAdminSay[client] = 0; + g_iAdminVoteOptions[client] = 0; + return Plugin_Continue; +} + +public Action Cmd_Polls(int client, int args) +{ + //select what poll to vote on + pollMenu(client, 0); + return Plugin_Handled; +} + +public void pollMenu(int client, int state) +{ + char c_activePoll1[512][512]; + Menu menu1; + if (state == 0) + { + menu1 = new Menu(Menu_onGoingPolls); + } + else + { + menu1 = new Menu(Menu_EditonGoingPolls); + menu1.AddItem("Go Back", "Go Back"); + } + int i; + menu1.SetTitle("Active Polls:"); + while (g_cPollText[i][256] != '\0') + { + Format(c_activePoll1[i][256], sizeof(c_activePoll1), g_cPollText[i][256]); + menu1.AddItem("nuffin here", c_activePoll1[i][256]); + i++; + } + if (i < 1) + { + PrintToChat(client, "There are currently no Active polls to vote on"); + return; + } + //display votes count for each vote here + menu1.Display(client, MENU_TIME_FOREVER); +} + +public void pollSubSection(int client, int selection) +{ + char l_cActivePoll[512]; + char l_cPollIRunOutOfNames[256][512]; + int l_iPollVoteOptions; + int l_iMax; + //selection here is the poll index that is voted on + g_iPollVotesCvar = selection; + Format(l_cActivePoll, sizeof(l_cActivePoll), g_cPollText[selection][256]); + Format(g_cPollTextClient, sizeof(g_cPollTextClient), l_cActivePoll); + Menu menu = new Menu(Menu_IndividualPoll); + //needs state 1 to select all vote options, aka not voted for yet + l_iPollVoteOptions = MySQLSelectPollVotes(l_cActivePoll, 1); + menu.SetTitle("Poll to vote on: %s", l_cActivePoll); + menu.AddItem("Go Back", "Go Back"); + //for loop here to take care of all vote options for each pollText + for (int j = 0; j < l_iPollVoteOptions; j++) + { + menu.AddItem(g_cPollIRunOutOfNames[j][256], g_cPollIRunOutOfNames[j][256]); + } + for (int i = 0; i < l_iPollVoteOptions; i++) + { + //should be correct with searching for polltext + l_iMax = MySQLQueryVotes(g_cPollText[selection][256], i); + Format(l_cPollIRunOutOfNames[i][256], sizeof(l_cPollIRunOutOfNames), "%s = VOTES %i", g_cPollIRunOutOfNames[i][256], l_iMax); + menu.AddItem("", l_cPollIRunOutOfNames[i][256], ITEMDRAW_DISABLED); + } + menu.Display(client, MENU_TIME_FOREVER); +} + +public int Menu_EditonGoingPolls(Menu menu, MenuAction action, int client, int selection) +{ + if (action == MenuAction_Select) + { + char info[32]; + menu.GetItem(selection, info, sizeof(info)); + if (StrContains(info, "Go Back", true) > -1) + { + EditPollAdminMenu(client); + } + else + { + //storing selection + char l_cAtivePoll[512]; + Format(l_cAtivePoll, sizeof(l_cAtivePoll), g_cPollText[selection][256]); + //get selected poll to edit down here so the cmd_say knows which index to update + g_cPollVotes[client][256] = selection; + g_iPollIndex = selection; + Menu menu1 = new Menu(Menu_EditSelectedPoll); + menu1.SetTitle("Selected Poll to Edit: %s", l_cAtivePoll); + menu1.AddItem("", "Rename Poll Title"); + menu1.AddItem("", "add vote options"); + menu1.AddItem("", "Add cvar or command to execute for each vote option"); + menu1.AddItem("", "Delete poll"); + menu1.Display(client, MENU_TIME_FOREVER); + } + } + else if (action == MenuAction_End) + { + delete menu; + } +} + +public int Menu_EditSelectedPoll(Menu menu, MenuAction action, int client, int selection) +{ + if (action == MenuAction_Select) + { + if (selection == 0) + { + g_iAdminSay[client] = 2; + PrintToChat(client, "Enter the poll Title into the chat to update it!"); + } + else if (selection == 1) + { + //display menu here to list the polls current vote options + //and ability to add new one + int l_iPollVoteOptions; + char c_activePoll[512]; + Format(c_activePoll, sizeof(c_activePoll), g_cPollText[g_iPollIndex][256]); + //needs state 1 to select all possible vote options + l_iPollVoteOptions = MySQLSelectPollVotes(c_activePoll, 1); + + //gets c_activePoll correctly now ingame + Menu menu1 = new Menu(Menu_pollSpecificVoteOptions); + menu1.SetTitle("Selected Poll %s has Vote Options:", c_activePoll); + + //gets these correctly now + for (int j = 0; j < l_iPollVoteOptions; j++) + { + menu1.AddItem(g_cPollIRunOutOfNames[j][256], g_cPollIRunOutOfNames[j][256], ITEMDRAW_DISABLED); + } + + menu1.AddItem("AddVote Option", "AddVote Option"); + menu1.Display(client, MENU_TIME_FOREVER); + } + else if (selection == 2) + { + //menu displaying vote options here + int l_iPollVoteOptions; + char c_activePoll[512]; + Format(c_activePoll, sizeof(c_activePoll), g_cPollText[g_iPollIndex][256]); + //needs state 1 to select all possible vote options + l_iPollVoteOptions = MySQLSelectPollVotes(c_activePoll, 1); + Menu menu1 = new Menu(Menu_PollAdminCvartoVote); + menu1.SetTitle("[UNLOZE] Select what vote Option to Give a cvar/command"); + for (int j = 0; j < l_iPollVoteOptions; j++) + { + menu1.AddItem(g_cPollIRunOutOfNames[j][256], g_cPollIRunOutOfNames[j][256]); + } + if (l_iPollVoteOptions > 0) + { + menu1.Display(client, MENU_TIME_FOREVER); + } + else + { + PrintToChat(client, "There currently aren´t any Vote options, add one to give it a cvar"); + } + } + else if (selection == 3) + { + //add option to delete poll here + char c_activePoll[512]; + Format(c_activePoll, sizeof(c_activePoll), g_cPollText[g_iPollIndex][256]); + MySQLDeletePoll(c_activePoll); + //Updating all polltitles + MySQLSelectPollTitles(); + } + } + else if (action == MenuAction_End) + { + delete menu; + } +} + +public int Menu_pollSpecificVoteOptions(Menu menu, MenuAction action, int client, int selection) +{ + if (action == MenuAction_Select) + { + char info[32]; + menu.GetItem(selection, info, sizeof(info)); + if (StrContains(info, "AddVote Option", true) > -1) + { + //Does insert part correctly with mysql query on mywebsql + g_iAdminVoteOptions[client] = 1; + PrintToChat(client, "Enter the vote option into the chat!"); + } + } + else if (action == MenuAction_End) + { + delete menu; + } +} + +public int Menu_PollAdminCvartoVote(Menu menu, MenuAction action, int client, int selection) +{ + if (action == MenuAction_Select) + { + //storing which vote option to edit + char info[256]; + menu.GetItem(selection, info, sizeof(info)); + g_cPollVotesCvar = info; + //PrintToChatAll("g_cPollVotesCvar: %s", g_cPollVotesCvar); + g_iAdminVoteOptions[client] = 2; + PrintToChat(client, "Enter the cvar/command related to the vote into the chat"); + } + else if (action == MenuAction_End) + { + delete menu; + } +} + +public int Menu_onGoingPolls(Menu menu, MenuAction action, int client, int selection) +{ + if (action == MenuAction_Select) + { + //VoteOption from the Poll to vote on + pollSubSection(client, selection); + } + else if (action == MenuAction_End) + { + delete menu; + } +} + +public int Menu_IndividualPoll(Menu menu, MenuAction action, int client, int selection) +{ + if (action == MenuAction_Select) + { + char info[32]; + menu.GetItem(selection, info, sizeof(info)); + if (StrContains(info, "Go Back", true) > -1) + { + pollMenu(client, 0); + } + else + { + char VOTE[256]; + menu.GetItem(selection, VOTE, sizeof(VOTE)); + PrintToChat(client, "You voted %s", VOTE); + MYSQLInsertVotes(client, g_cPollTextClient, VOTE); + CreateTimer(1.0, evaluatedelay, INVALID_HANDLE); + } + } + else if (action == MenuAction_End) + { + delete menu; + } +} + +public int Menu_PollAdminMenu(Menu menu, MenuAction action, int client, int selection) +{ + if (action == MenuAction_Select) + { + if (selection == 0) + { + g_iAdminSay[client] = 1; + PrintToChat(client, "Enter the poll text into the chat!"); + } + else if (selection == 1) + { + //select what poll to edit + pollMenu(client, 1); + } + } + else if (action == MenuAction_End) + { + delete menu; + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnClientDisconnect (int client) +{ + g_iAdminSay[client] = 0; + g_iAdminVoteOptions[client] = 0; +} + +public void OnClientPostAdminCheck(int client) +{ + g_iAdminSay[client] = 0; + g_iAdminVoteOptions[client] = 0; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: MYSQL queries +//---------------------------------------------------------------------------------------------------- + +public void SQL_StartConnection() +{ + char error[255]; + Database db; + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + //create tables + char sQuery[255]; + Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `unloze_pollvotes` (`steam_id` VARCHAR(64) NOT NULL, PRIMARY KEY (`steam_id`))"); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `unloze_pollVoteCvars` (`command` VARCHAR(256) NOT NULL, PRIMARY KEY (`command`))"); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete db; +} + +public void MySQLUpdateTextCOLUMN(char[] CurrentPollText, char[] NewPollText) +{ + char error[255]; + char sQuery[512]; + Database db; + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + Format(sQuery, sizeof(sQuery), "ALTER TABLE `unloze_pollvotes` CHANGE `%s` `%s` VARCHAR(256) NOT NULL;", CurrentPollText, NewPollText); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + Format(sQuery, sizeof(sQuery), "ALTER TABLE `unloze_pollVoteCvars` CHANGE `%s` `%s` VARCHAR(256) NOT NULL;", CurrentPollText, NewPollText); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete db; +} + +public void sendMYSQLPollTextCOLUMN(char[] pollText) +{ + char error[255]; + char sQuery[512]; + Database db; + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + Format(sQuery, sizeof(sQuery), "ALTER TABLE `unloze_pollvotes` ADD COLUMN `%s` VARCHAR(256) NOT NULL;", pollText); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + Format(sQuery, sizeof(sQuery), "ALTER TABLE `unloze_pollVoteCvars` ADD COLUMN `%s` VARCHAR(256) NOT NULL;", pollText); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete db; +} + +public void MYSQLInsertVotes(int client, char[] pollText, char[] VOTE) +{ + char error[255]; + char sQuery[512]; + char sSID[64]; + Database db; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_pollvotes` (`steam_id`,`%s`) VALUES ('%s', '%s') ON DUPLICATE KEY UPDATE `%s` = '%s'", pollText, sSID, VOTE, pollText, VOTE); + //PrintToChatAll("MYSQLInsertVotes sQuery: %s", sQuery); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete db; +} + +public void mysqlStoreVoteOption(int state, char[] Command, int client) +{ + char error[255]; + Database db; + + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + delete db; + return; + } + + char sQuery[512]; + if (state == 1) + { + Format(sQuery, sizeof(sQuery), "UPDATE `unloze_pollVoteCvars` SET `command`= '%s' WHERE `%s`= '%s'", Command, g_cPollText[g_iPollIndex][256], g_cPollVotesCvar); + //PrintToChatAll("VoteOption Squery: %s", sQuery); + } + else + { + Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_pollVoteCvars` (`%s`) VALUES ('%s') ON DUPLICATE KEY UPDATE `%s` = '%s'", g_cPollText[g_iPollIndex][256], g_cPollVotes[client][256], g_cPollText[g_iPollIndex][256], g_cPollVotes[client][256]); + //PrintToChatAll("VoteOption Squery: %s", sQuery); + } + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete db; +} + +public void MySQLDeletePoll(char[] PollText) +{ + char error[255]; + Database db; + + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + delete db; + return; + } + + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "ALTER TABLE unloze_pollvotes DROP COLUMN `%s`", PollText); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + Format(sQuery, sizeof(sQuery), "ALTER TABLE unloze_pollVoteCvars DROP COLUMN `%s`", PollText); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete db; +} + +public int MySQLQueryVotes(char[] PollText, int indexJ) +{ + char sQuery[512]; + char error[255]; + int l_iCounter; + Database db; + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + delete db; + return 0; + } + DBResultSet rs; + Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM unloze_pollvotes WHERE `%s` = '%s'", PollText, g_cPollIRunOutOfNames[indexJ][256]); + + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + return 0; + } + //PrintToChatAll("success: %s", sQuery); + if (rs.RowCount > 0 && rs.FetchRow()) + { + char l_cPollVoteCounter[512]; + SQL_FetchString(rs, 0, l_cPollVoteCounter, sizeof(l_cPollVoteCounter)); + //PrintToChatAll("l_cPollVoteCounter: %s", l_cPollVoteCounter); + //counting votes + l_iCounter = StringToInt(l_cPollVoteCounter); + } + delete rs; + delete db; + return l_iCounter; +} + +public void MySQLSelectPollTitles() +{ + char error[255]; + Database db; + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + delete db; + return; + } + char sQuery[512]; + //Collects the column_names requires + Format(sQuery, sizeof(sQuery), "SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME = 'unloze_pollvotes'"); + + DBResultSet rs; + + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + Format(g_cPollText[0][256], sizeof(g_cPollText), "No Active polls"); + return; + } + int index; + if (rs.RowCount > 0) + { + //should skip steam_id + rs.FetchRow(); + while (rs.FetchRow()) + { + //should be 0 + SQL_FetchString(rs, 0, g_cPollText[index][256], sizeof(g_cPollText)); + index++; + } + } + delete rs; + delete db; +} + +public int MySQLSelectPollVotes(char[] PollText, int state) +{ + char error[255]; + Database db; + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + delete db; + return 0; + } + char sQuery[512]; + if (state == 1) + { + Format(sQuery, sizeof(sQuery), "SELECT `%s` FROM unloze_pollVoteCvars", PollText); + } + else + { + Format(sQuery, sizeof(sQuery), "SELECT `%s` FROM unloze_pollvotes", PollText); + } + //PrintToChatAll("Query i want: %s", sQuery); + DBResultSet rs; + + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + Format(g_cPollIRunOutOfNames[0][256], sizeof(g_cPollIRunOutOfNames), "No Active Votes available for the poll"); + return 0; + } + int index; + char l_cLocalFix[256][512]; + //regardless of state 1/0 it should need this to allocate it slightly more effectively + if (rs.RowCount > 0) + { + while (rs.FetchRow()) + { + //preventing empty fields + SQL_FetchString(rs, 0, l_cLocalFix[index][256], sizeof(l_cLocalFix)); + if (l_cLocalFix[index][256] != '\0') + { + Format(g_cPollIRunOutOfNames[index][256], sizeof(g_cPollIRunOutOfNames), l_cLocalFix[index][256]); + //PrintToChatAll("SUCCESS g_cPollIRunOutOfNames[index][256]: %s", g_cPollIRunOutOfNames[index][256]); + index++; + } + } + } + delete rs; + delete db; + return index; +} + +public void MySQLSelectHighestVoteForPoll(char[] PollText, int index) +{ + char error[255]; + Database db; + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + delete db; + return; + } + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "SELECT command FROM unloze_pollVoteCvars WHERE `%s` = '%s'", PollText, g_cPollIRunOutOfNames[index][256]); + //PrintToChatAll("MySQLSelectHighestVoteForPoll: %s",sQuery); + DBResultSet rs; + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + + return; + } + if (rs.RowCount > 0 && rs.FetchRow()) + { + SQL_FetchString(rs, 0, g_cPollCommands, sizeof(g_cPollCommands)); + } + delete rs; + delete db; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +stock bool IsValidClient(int client) +{ + if (client > 0 && client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client)) + { + return true; + } + return false; +} + +public void DummyCallbackSimple(Handle hOwner, Handle hChild, const char[] err, DataPack pack1) +{ + if (hOwner == null || hChild == null) + { + LogError("Query error. (%s)", err); + } +} \ No newline at end of file diff --git a/Plugins/unloze_maptimer/scripting/unloze_maptimer.sp b/Plugins/unloze_maptimer/scripting/unloze_maptimer.sp new file mode 100644 index 00000000..f27c7822 --- /dev/null +++ b/Plugins/unloze_maptimer/scripting/unloze_maptimer.sp @@ -0,0 +1,809 @@ +#pragma semicolon 1 +#pragma newdecls required +#define DEBUG + +#define PLUGIN_AUTHOR "jenz" +#define PLUGIN_VERSION "6.20" +#define ZONE_PREFIX_RACE "ZONE_PREFIX_RACE" + +#include <sourcemod> +#include <sdktools> +#include <sdkhooks> +#include <unloze_zones> +#include <colorvariables> +#include <regex> +#include <zombiereloaded> + +bool g_bMessage[MAXPLAYERS]; +bool g_bStopTimer[MAXPLAYERS]; +bool g_bRoundend; +bool g_bSmap; +bool g_bRmap; +char g_cMapname[512]; +float g_fEngineRoundtimeSurf[MAXPLAYERS]; +float g_fEngineSecondsSurf[MAXPLAYERS]; +float g_fPlayertimes[MAXPLAYERS]; +float g_fEngineRoundtime; +float g_fEngineSeconds; +int g_iEngine_minutesSurf[MAXPLAYERS]; +int g_iCurrentS[MAXPLAYERS]; +int g_iSurf[MAXPLAYERS]; +int g_iEngine_minutes; +Handle g_hSurfTimer[MAXPLAYERS]; + +public Plugin myinfo = +{ + name = "Unloze Map Timer", + author = PLUGIN_AUTHOR, + description = "Timers for Race Maps", + version = PLUGIN_VERSION, + url = "" +}; + +//---------------------------------------------------------------------------------------------------- +// Purpose: Pluginstart/mapstart +//---------------------------------------------------------------------------------------------------- + +public void OnPluginStart() +{ + SQL_StartConnection(); + RegConsoleCmd("sm_toptime", cmd_timerCheck, "checking"); + + RegConsoleCmd("sm_s1", cmd_timerCheckS1, "checking"); + RegConsoleCmd("sm_s2", cmd_timerCheckS2, "checking 2"); + RegConsoleCmd("sm_s3", cmd_timerCheckS3, "checking 3"); + RegConsoleCmd("sm_s4", cmd_timerCheckS4, "checking 4"); + RegConsoleCmd("sm_s5", cmd_timerCheckS5, "checking 5"); + RegConsoleCmd("sm_s6", cmd_timerCheckS6, "checking 6"); + RegConsoleCmd("sm_s7", cmd_timerCheckS7, "checking 7"); + RegConsoleCmd("sm_s8", cmd_timerCheckS8, "checking 8"); + RegConsoleCmd("sm_s9", cmd_timerCheckS9, "checking 9"); + RegConsoleCmd("sm_s10", cmd_timerCheckS010, "checking 10"); + HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy); + HookEvent("round_end", Event_RoundEnd); +} + +public void OnMapStart() +{ + GetCurrentMap(g_cMapname, sizeof(g_cMapname)); + g_bSmap = false; + g_bRmap = false; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: mysql queries/callbacks +//---------------------------------------------------------------------------------------------------- + +public void SQL_SelectTop_Callback(Database db, DBResultSet results, const char[] error, any data) +{ + if (results == null) + { + //LogError("[SS] Selecting players error. Reason: %s", error); + return; + } + + int client = GetClientFromSerial(data); + if (client == 0) + { + LogError("[SS] Client is not valid. Reason: %s", error); + return; + } + + Menu menu = new Menu(MenuHandler1); + if (g_iSurf[client] != 0) + { + menu.SetTitle("Maptimer: %s_S%i", g_cMapname, g_iSurf[client]); + } + else + { + menu.SetTitle("Maptimer: %s", g_cMapname); + } + + + int iS_Count = 0; + char gS_MenuContent[524]; + + while (results.FetchRow()) + { + float oldTime = 0.0; + int engine_cMin = 0; + float engine_cSec = 0.0; + iS_Count++; + + //Player Name + char[] gS_PlayerName = new char[MAX_NAME_LENGTH]; + results.FetchString(0, gS_PlayerName, MAX_NAME_LENGTH); + oldTime = results.FetchFloat(1); + engine_cMin = RoundToFloor(oldTime / 60); + engine_cSec = oldTime - (engine_cMin * 60); + + Format(gS_MenuContent, sizeof(gS_MenuContent), "Position: %i Time: %i:%f - %s", iS_Count, engine_cMin, engine_cSec, gS_PlayerName); + + menu.AddItem("-1", gS_MenuContent, ITEMDRAW_DISABLED); + } + + if (!iS_Count) + { + menu.AddItem("-1", "No results.", ITEMDRAW_DISABLED); + } + + //menu.AddItem("no", "No", ITEMDRAW_DISABLED); + menu.ExitButton = true; + menu.Display(client, 20); + + +//////message////// + + char sQuery[564]; + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + + if (g_iSurf[client] != 0) + { + Format(sQuery, sizeof(sQuery), "SELECT name, `%sS%i` FROM `zetimer_tableSurf` WHERE steam_auth = '%s'", g_cMapname, g_iSurf[client], sSID); + } + else + { + Format(sQuery, sizeof(sQuery), "SELECT name, `%s` FROM `zetimer_table` WHERE steam_auth = '%s'", g_cMapname, sSID); + } + DBResultSet rs; + + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + return; + } + + char gS_MessageContent[524]; + if (rs.FetchRow()) + { + float oldTime = 0.0; + int engine_cMin = 0; + float engine_cSec = 0.0; + + //Player Name + char[] gS_PlayerName = new char[MAX_NAME_LENGTH]; + rs.FetchString(0, gS_PlayerName, MAX_NAME_LENGTH); + oldTime = rs.FetchFloat(1); + engine_cMin = RoundToFloor(oldTime / 60); + engine_cSec = oldTime - (engine_cMin * 60); + + Format(gS_MessageContent, sizeof(gS_MessageContent), "%i:%f - %s", engine_cMin, engine_cSec, gS_PlayerName); + if (g_iSurf[client] != 0) + { + CPrintToChat(client, "Your best time Stage %i: %s", g_iSurf[client], gS_MessageContent); + } + else + { + CPrintToChat(client, "Your best time: %s", gS_MessageContent); + } + } + delete db; + delete rs; +} + +public float receiveMYSQL(int client, float f_playerTime) +{ + //variables + float iCollected; + char sQuery[255]; + char sSID[64]; + char error[255]; + DBResultSet rs; + Database db; + + if (SQL_CheckConfig("zetimer")) + { + db = SQL_Connect("zetimer", true, error, sizeof(error)); + } + if (db == null) + { + CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!"); + delete db; + } + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + Format(sQuery, sizeof(sQuery), "SELECT `%s` FROM `zetimer_table` WHERE steam_auth = '%s'", g_cMapname, sSID); + //PrintToChatAll("receiveMYSQL sQuery: %s", sQuery); + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + return 0.0; + } + + if(SQL_FetchRow(rs)) + { + iCollected = SQL_FetchFloat(rs, 0); + } + + delete rs; + delete db; + return iCollected; +} + +public void sendMYSQLSurf(int client, float f_playerTime, int Entry) +{ + char error[255]; + Database db; + if (SQL_CheckConfig("zetimer")) + { + db = SQL_Connect("zetimer", true, error, sizeof(error)); + } + if (db == null) + { + CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[255]; + //Format(sQuery, sizeof(sQuery), "SELECT `%sS1` FROM `zetimer_tableSurf` LIMIT 10", g_cMapname); + Format(sQuery, sizeof(sQuery), "SELECT `%sS%i` FROM `zetimer_tableSurf` LIMIT 10", g_cMapname, Entry); + //PrintToChatAll("sendMYSQLSurf sQuery: %s", sQuery); + DBResultSet rs; + if ((rs = SQL_Query(db, sQuery)) == null) + { + Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_tableSurf` ADD COLUMN `%sS%i` DECIMAL(13,3) NOT NULL", g_cMapname, Entry); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + PrintToChat(client, "Sorry but the time was not counted since the Table had to be created first EKSDEE- jenz"); + } + else + { + char l_cName[256]; + SQL_FetchClientName(client, db, l_cName, sizeof(l_cName)); + Format(sQuery, sizeof(sQuery), "INSERT INTO `zetimer_tableSurf` (`steam_auth`, `name`, `%sS%i`) VALUES ('%s', '%s', '%f') ON DUPLICATE KEY UPDATE `name` = '%s', `%sS%i` = '%f'", g_cMapname, Entry, sSID, l_cName, f_playerTime, l_cName, g_cMapname, Entry, f_playerTime); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + } + delete db; + delete rs; + //CPrintToChatAll("reaching end, query is: %s", sQuery); +} + +public void sendMYSQL(int client, float f_playerTime) +{ + char error[255]; + Database db; + if (SQL_CheckConfig("zetimer")) + { + db = SQL_Connect("zetimer", true, error, sizeof(error)); + } + if (db == null) + { + CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!"); + delete db; + } + + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[255]; + Format(sQuery, sizeof(sQuery), "SELECT `%s` FROM `zetimer_table` LIMIT 10", g_cMapname); + + DBResultSet rs; + if ((rs = SQL_Query(db, sQuery)) == null) + { + Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table` ADD COLUMN `%s` DECIMAL(13,3) NOT NULL", g_cMapname); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + PrintToChat(client, "Sorry but the time was not counted since the Table had to be created first EKSDEE- jenz"); + } + else + { + Format(sQuery, sizeof(sQuery), "INSERT INTO `zetimer_table` (`steam_auth`, `name`, `%s`) VALUES ('%s', '%N', '%f') ON DUPLICATE KEY UPDATE `name` = '%N', `%s` = '%f'", g_cMapname, sSID, client, f_playerTime, client, g_cMapname, f_playerTime); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + } + + delete db; + delete rs; + //CPrintToChatAll("reaching end, query is: %s", sQuery); +} + +public void SQL_StartConnection() +{ + char error[255]; + Database db; + if (SQL_CheckConfig("zetimer")) + { + db = SQL_Connect("zetimer", true, error, sizeof(error)); + } + if (db == null) + { + CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + } + + //create tables + char sQuery[255]; + Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `zetimer_table` (`steam_auth` VARCHAR(254) NOT NULL, `name` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_auth`))"); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `zetimer_tableSurf` (`steam_auth` VARCHAR(254) NOT NULL, `name` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_auth`))"); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete db; +} + +public float receiveMYSQLSurf(int client, float f_playerTime, int i_zoneEndIndex) +{ + //variables + float iCollected; + char sQuery[255]; + char sSID[64]; + char error[255]; + DBResultSet rs; + Database db; + + if (SQL_CheckConfig("zetimer")) + { + db = SQL_Connect("zetimer", true, error, sizeof(error)); + } + if (db == null) + { + CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!"); + delete db; + } + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + Format(sQuery, sizeof(sQuery), "SELECT `%sS%i` FROM `zetimer_tableSurf` WHERE steam_auth = '%s'", g_cMapname, i_zoneEndIndex, sSID); + //PrintToChatAll("receiveMYSQLSurf sQuery: %s", sQuery); + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + return 0.0; + } + + if (SQL_FetchRow(rs)) + { + iCollected = SQL_FetchFloat(rs, 0); + } + + delete rs; + delete db; + return iCollected; +} + +public void mysqlLoadNames(int client) +{ + char error[255]; + char sQuery[255]; + char sSID[64]; + Database db; + DBResultSet rs; + + if (SQL_CheckConfig("zetimer")) + { + db = SQL_Connect("zetimer", true, error, sizeof(error)); + } + if (db == null) + { + CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + } + + char cClient[250]; + Format(cClient, sizeof(cClient), "%N", client); + + if (StrContains(cClient, "'") >= 0) + { + ReplaceString(cClient, sizeof(cClient), "'", "", false); + } + + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + Format(sQuery, sizeof(sQuery), "UPDATE `zetimer_table` SET `name`= '%s' WHERE `steam_auth` = '%s'", cClient, sSID); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + Format(sQuery, sizeof(sQuery), "UPDATE `zetimer_tableSurf` SET `name`= '%s' WHERE `steam_auth` = '%s'", cClient, sSID); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete rs; + delete db; +} + +public Action MysqlCheckSurfStage(int client, int count) +{ + if (g_bSmap == false) + { + CPrintToChat(client, "[UNLOZE] Does not support Surf zones"); + return Plugin_Handled; + } + + Database db; + char sQuery[512]; + char error[255]; + + if (SQL_CheckConfig("zetimer")) + { + db = SQL_Connect("zetimer", true, error, sizeof(error)); + } + if (db == null) + { + CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!"); + delete db; + } + Format(sQuery, sizeof(sQuery), "SELECT name, %sS%i FROM `zetimer_tableSurf` WHERE %sS%i > 0.000 ORDER BY %sS%i ASC LIMIT 10", g_cMapname, count, g_cMapname, count, g_cMapname, count); + db.Query(SQL_SelectTop_Callback, sQuery, GetClientSerial(client), DBPrio_Normal); + //CPrintToChat(client, " "); + delete db; + return Plugin_Handled; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: Chat Command for Race timer +//---------------------------------------------------------------------------------------------------- + +public Action cmd_timerCheck(int client, int args) +{ + if (g_bRmap == false) + { + CPrintToChat(client, "[UNLOZE] Does not support race zones"); + return Plugin_Handled; + } + Database db; + char sQuery[512]; + char error[555]; + + if (SQL_CheckConfig("zetimer")) + { + db = SQL_Connect("zetimer", true, error, sizeof(error)); + } + if (db == null) + { + CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!"); + delete db; + } + g_iSurf[client] = 0; + Format(sQuery, sizeof(sQuery), "SELECT name, %s FROM `zetimer_table` WHERE %s > 0.000 ORDER BY %s ASC LIMIT 10", g_cMapname, g_cMapname, g_cMapname); + db.Query(SQL_SelectTop_Callback, sQuery, GetClientSerial(client), DBPrio_Normal); + + delete db; + return Plugin_Handled; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: Chat Command for Surf timer +//---------------------------------------------------------------------------------------------------- + +public Action cmd_timerCheckS1(int client, int args) +{ + g_iSurf[client] = 1; + MysqlCheckSurfStage(client, g_iSurf[client]); + return Plugin_Handled; +} + +public Action cmd_timerCheckS2(int client, int args) +{ + g_iSurf[client] = 2; + MysqlCheckSurfStage(client, g_iSurf[client]); + return Plugin_Handled; +} + +public Action cmd_timerCheckS3(int client, int args) +{ + g_iSurf[client] = 3; + MysqlCheckSurfStage(client, g_iSurf[client]); + return Plugin_Handled; +} + +public Action cmd_timerCheckS4(int client, int args) +{ + g_iSurf[client] = 4; + MysqlCheckSurfStage(client, g_iSurf[client]); + return Plugin_Handled; +} + +public Action cmd_timerCheckS5(int client, int args) +{ + g_iSurf[client] = 5; + MysqlCheckSurfStage(client, g_iSurf[client]); + return Plugin_Handled; +} + +public Action cmd_timerCheckS6(int client, int args) +{ + g_iSurf[client] = 6; + MysqlCheckSurfStage(client, g_iSurf[client]); + return Plugin_Handled; +} + +public Action cmd_timerCheckS7(int client, int args) +{ + g_iSurf[client] = 7; + MysqlCheckSurfStage(client, g_iSurf[client]); + return Plugin_Handled; +} + +public Action cmd_timerCheckS8(int client, int args) +{ + g_iSurf[client] = 8; + MysqlCheckSurfStage(client, g_iSurf[client]); + return Plugin_Handled; +} + +public Action cmd_timerCheckS9(int client, int args) +{ + g_iSurf[client] = 9; + MysqlCheckSurfStage(client, g_iSurf[client]); + return Plugin_Handled; +} + +public Action cmd_timerCheckS010(int client, int args) +{ + g_iSurf[client] = 10; + MysqlCheckSurfStage(client, g_iSurf[client]); + return Plugin_Handled; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: Menus +//---------------------------------------------------------------------------------------------------- +public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2) +{ + + /* If the menu was cancelled, print a message to the server about it. */ + if (action == MenuAction_Cancel) + { + PrintToServer("Client %d's menu was cancelled. Reason: %d", param1, param2); + } + /* If the menu has ended, destroy it */ + else if (action == MenuAction_End) + { + delete menu; + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: Roundstart/roundend, Postadmincheck, disconnect +//---------------------------------------------------------------------------------------------------- + +public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast) +{ + for (int i = 1; i < MaxClients; i++) + { + if (IsValidClient(i)) + { + g_fPlayertimes[i] = 0.0; + g_bMessage[i] = false; + g_fEngineRoundtimeSurf[i] = 0.0; + g_fEngineSecondsSurf[i] = 0.0; + g_iEngine_minutesSurf[i] = 0; + + g_iCurrentS[i] = -1; + g_iSurf[i] = 0; + } + } + g_fEngineRoundtime = 0.0; + g_iEngine_minutes = 0; + g_fEngineSeconds = 0.0; + CreateTimer(0.1, Timer_CountdownRace, _, TIMER_REPEAT); + g_bRoundend = false; +} + +public void Event_RoundEnd(Handle event, const char[] name, bool dontBroadcast) +{ + g_bRoundend = true; +} +public void OnClientDisconnect(int client) +{ + //disconnect is triggered on each map switch + g_bMessage[client] = false; + g_fPlayertimes[client] = 0.0; + g_fEngineRoundtimeSurf[client] = 0.0; + g_fEngineSecondsSurf[client] = 0.0; + g_iEngine_minutesSurf[client] = 0; + g_iCurrentS[client] = 0; + g_iSurf[client] = 0; + g_bStopTimer[client] = false; +} + +public void OnClientPostAdminCheck(int client) +{ + g_bMessage[client] = false; + g_fPlayertimes[client] = 0.0; + g_fEngineRoundtimeSurf[client] = 0.0; + g_fEngineSecondsSurf[client] = 0.0; + g_iEngine_minutesSurf[client] = 0; + g_iCurrentS[client] = 0; + g_iSurf[client] = 0; + g_bStopTimer[client] = true; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: Counting maptime functions +//---------------------------------------------------------------------------------------------------- + +//Callback for timer +public Action Timer_CountdownRace(Handle timer, any data) +{ + if (g_bRoundend) + { + return Plugin_Stop; + } + + g_fEngineRoundtime += 0.1; + g_fEngineSeconds += 0.1; + if (g_fEngineSeconds >= 60.0) + { + g_iEngine_minutes += 1; + g_fEngineSeconds = 0.0; + } + + return Plugin_Changed; +} + + +public Action Timer_CountdownSurf(Handle timer, int client) +{ + if (g_iCurrentS[client] == -1 || !g_bStopTimer[client]) + { + if (g_hSurfTimer[client] != INVALID_HANDLE) + { + delete g_hSurfTimer[client]; + } + return Plugin_Stop; + } + //PrintToChatAll("g_fEngineRoundtimeSurf: %f", g_fEngineRoundtimeSurf[client]); + //PrintToChatAll("g_fEngineSecondsSurf: %f", g_fEngineSecondsSurf[client]); + g_fEngineRoundtimeSurf[client] += 0.1; + g_fEngineSecondsSurf[client] += 0.1; + if (g_fEngineSecondsSurf[client] >= 60.0) + { + g_iEngine_minutesSurf[client] += 1; + g_fEngineSecondsSurf[client] = 0.0; + } + + return Plugin_Changed; +} + +public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn) +{ + g_iCurrentS[client] = -1; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: zone forwards +//---------------------------------------------------------------------------------------------------- +public void unloze_zoneLeave(int client, char [] zone) +{ + if (IsValidClient(client) && GetClientTeam(client) == 3 && StrContains(zone, "ZONE_PREFIX_SURF_S", false) >= 0) + { + //PrintToChatAll("unloze_zoneLeave succesfull: %s", zone); + g_fEngineRoundtimeSurf[client] = 0.0; + g_fEngineSecondsSurf[client] = 0.0; + g_iEngine_minutesSurf[client] = 0; + g_iCurrentS[client] = -1; + + //createtime only one per player + g_hSurfTimer[client] = CreateTimer(0.1, Timer_CountdownSurf, client, TIMER_REPEAT); + g_iCurrentS[client] = 0; + } +} +public void unloze_zoneEntry(int client, char[] zone) +{ + float oldTime[MAXPLAYERS]; + //ZONE_PREFIX_RACE + + if (IsValidClient(client) && GetClientTeam(client) == 3 && StrContains(zone, ZONE_PREFIX_RACE, false) >= 0) + { + g_bRmap = true; + + g_fPlayertimes[client] = g_fEngineRoundtime; + + if (g_bMessage[client] == true) + { + return; + } + + CPrintToChat(client, "{green}[Unloze] Client: %N \nTime: %i:%f", client, g_iEngine_minutes, g_fEngineSeconds); + oldTime[client] = receiveMYSQL(client, g_fPlayertimes[client]); + + int engine_cMin = 0; + float engine_cSec = 0.0; + engine_cMin = RoundToFloor(oldTime[client] / 60); + engine_cSec = oldTime[client] - (engine_cMin * 60); + CPrintToChat(client, "Your record: 0%i:%f \n Command: !toptime", engine_cMin, engine_cSec); + + if (g_fPlayertimes[client] < oldTime[client] || oldTime[client] == -1.000000 || oldTime[client] == 0.000000) + { + sendMYSQL(client, g_fPlayertimes[client]); + CPrintToChat(client, "Updated timer"); + } + g_bMessage[client] = true; + return; + } + + + //everything below here is only for ZONE_PREFIX_SURF + + if (StrContains(zone, "ZONE_PREFIX_SURF_S", false) >= 0) + { + //When the first client enters the surf gets unlocked + //else do nothing with surf start zoneEntry + g_bSmap = true; + return; + } + + if (StrContains(zone, "ZONE_PREFIX_SURF_E", false) < 0) + { + //if client entered non surf end zone stop + return; + } + + char out[64]; + //stops timer unsafe? + g_iCurrentS[client] = -1; + + + if (StrContains(zone, "10", false) < 0) + { + Regexmatcher(zone, out, sizeof(out)); + } + else + { + Format(out, sizeof(out), "10"); + } + if (GetClientTeam(client) != 3) + { + return; + } + int i_zoneEndIndex; + int engine_cMinS1 = 0; + float engine_cSecS1 = 0.0; + //PrintToChatAll("zone: %s", zone); + //PrintToChatAll("out: %s", out); + i_zoneEndIndex = StringToInt(out); + + + g_fPlayertimes[client] = g_fEngineRoundtimeSurf[client]; + oldTime[client] = receiveMYSQLSurf(client, g_fPlayertimes[client], i_zoneEndIndex); + //CPrintToChat(client, "oldTime[%N] ZONE_PREFIX_SURF: %f", client, oldTime[client]); + + CPrintToChat(client, "{green}[UNLOZE] Client: %N \nTime: %i:%f", client, g_iEngine_minutesSurf[client], g_fEngineSecondsSurf[client]); + + engine_cMinS1 = RoundToFloor(oldTime[client] / 60); + engine_cSecS1 = oldTime[client] - (engine_cMinS1 * 60); + + CPrintToChat(client, "Your record Stage %i: 0%i:%f \n Command: !s%i", i_zoneEndIndex, engine_cMinS1, engine_cSecS1, i_zoneEndIndex); + + if (g_fPlayertimes[client] < oldTime[client] || oldTime[client] <= 0.000000) + { + sendMYSQLSurf(client, g_fPlayertimes[client], i_zoneEndIndex); + CPrintToChat(client, "Updated surftimer"); + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: stocks +//---------------------------------------------------------------------------------------------------- +stock bool IsValidClient(int client) +{ + if (client > 0 && client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client) && IsPlayerAlive(client)) + { + return true; + } + return false; +} + +stock void Regexmatcher(const char[] message, char[] out, int maxlen) +{ + Regex regex = CompileRegex("[0-9]"); + //the match is needed for getsubstring apperently + regex.Match(message); + regex.GetSubString(0, out, maxlen); +} + +public void DummyCallbackSimple(Handle hOwner, Handle hChild, const char[] err, DataPack pack1) +{ + if (hOwner == null || hChild == null) + { + LogError("Query error. (%s)", err); + } +} + +stock void SQL_FetchClientName(int client, Database database, char[] buffer, int size) +{ + char sName[MAX_NAME_LENGTH]; + GetClientName(client, sName, sizeof(sName)); + + int size2 = 2 * strlen(sName) + 1; + char[] sEscapedName = new char[size2 + 1]; + SQL_EscapeString(database, sName, sEscapedName, size2 + 1); + + strcopy(buffer, size, sEscapedName); +} \ No newline at end of file diff --git a/Plugins/unloze_spraytracers/scripting/unloze_spraytracers.sp b/Plugins/unloze_spraytracers/scripting/unloze_spraytracers.sp new file mode 100644 index 00000000..85cfbd8e --- /dev/null +++ b/Plugins/unloze_spraytracers/scripting/unloze_spraytracers.sp @@ -0,0 +1,974 @@ +#pragma semicolon 1 + +#define DEBUG + +#define PLUGIN_AUTHOR "jenz" +#define PLUGIN_VERSION "2.00" + +#define MAX_DEFINED_COLORS 128 +#define MAX_DEFINED_MATERIALS 128 + +//taser +#define TASER "weapon_tracers_taser" +#define GLOW "weapon_taser_glow_impact" +#define SOUND_IMPACT "weapons/taser/taser_hit.wav" +#define SOUND_SHOOT "weapons/taser/taser_shoot.wav" + +#include <sourcemod> +#include <sdktools> +#include <csgocolors> +#include <sdkhooks> +#include <clientprefs> +#include <emitsoundany> + +#undef REQUIRE_EXTENSIONS +#tryinclude <dhooks> +#define REQUIRE_EXTENSIONS + +#pragma newdecls required +//potentially 1024 bits +char g_cStorestats[MAXPLAYERS][526]; +bool g_bZeusOwner[MAXPLAYERS]; +float g_fLastAngles[MAXPLAYERS + 1][3]; +int g_iTracerpref[MAXPLAYERS]; +int g_iPlayerRank[MAXPLAYERS + 1]; +int g_iPlayerPoints[MAXPLAYERS + 1]; +int g_iTEsends[MAXPLAYERS]; +int g_iBeam = -1; +int g_iPlayerCount; +int g_iPlayerCountTop10; +int g_iPlayerArrayTop10[MAXPLAYERS]; +int g_iPlayerArray[MAXPLAYERS]; +int g_iStoreColors[MAXPLAYERS][3]; +bool g_bStoreColorbool[MAXPLAYERS]; + +public Plugin myinfo = +{ + name = "Unloze Tracers based on zeustracers", + author = PLUGIN_AUTHOR, + description = "Grants sprayTracers based on clients ranking", + version = PLUGIN_VERSION, + url = "https://forums.alliedmods.net/showthread.php?p=2501632" +}; + +//Startup +public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) +{ + return APLRes_Success; +} + +public void OnPluginStart() +{ + //Reg Cmds + RegConsoleCmd("sm_tracers", Cmd_Tracer, "enable/ disable tracers"); + + //mysql + SQL_StartConnection(); + + AddTempEntHook("Shotgun Shot", Hook_BulletShot); + HookEvent("bullet_impact", Event_OnBulletImpact); + HookEvent("round_start", Event_RoundStart); +} + +public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast) +{ + for (int i = 0; i < MaxClients; i++) + { + if (IsValidClient(i) && IsPlayerAlive(i)) + { + g_iTEsends[i] = 0; + } + } +} + +public void OnMapStart() +{ + g_iBeam = PrecacheModel("materials/unloze_tracers/xbeam.vmt"); + AddFileToDownloadsTable("materials/unloze_tracers/xbeam.vmt"); + AddFileToDownloadsTable("materials/unloze_tracers/xbeam.vtf"); + PrecacheEffect("ParticleEffect"); + PrecacheParticleEffect(TASER); + PrecacheParticleEffect(GLOW); + PrecacheSound(SOUND_IMPACT); + PrecacheSound(SOUND_SHOOT); +} + +void PrecacheEffect(const char[] sEffectName) +{ + static int table = INVALID_STRING_TABLE; + + if (table == INVALID_STRING_TABLE) + table = FindStringTable("EffectDispatch"); + + bool save = LockStringTables(false); + AddToStringTable(table, sEffectName); + LockStringTables(save); +} + +void PrecacheParticleEffect(const char[] sEffectName) +{ + static int table = INVALID_STRING_TABLE; + + if (table == INVALID_STRING_TABLE) + table = FindStringTable("ParticleEffectNames"); + + bool save = LockStringTables(false); + AddToStringTable(table, sEffectName); + LockStringTables(save); +} + +public Action Cmd_Tracer(int client, int args) +{ + Menu menu = new Menu(MenuHandler1); + menu.SetTitle("UNLOZE tracers are unlocked through !shop"); + menu.AddItem("", "Toggle Tracer Visibility"); + if (StrContains(g_cStorestats[client], "k") >= 0) + { + menu.AddItem("", "Zeus tracers"); + } + if (StrContains(g_cStorestats[client], "§") >= 0) + { + menu.AddItem("255 255 0", "Yellow Tracers"); + } + if (StrContains(g_cStorestats[client], "@") >= 0) + { + menu.AddItem("0 0 255", "Blue Tracers"); + } + if (StrContains(g_cStorestats[client], "£") >= 0) + { + menu.AddItem("0 255 0", "Green Tracers"); + } + if (StrContains(g_cStorestats[client], "$") >= 0) + { + menu.AddItem("255 0 0", "Red Tracers"); + } + if (StrContains(g_cStorestats[client], "€") >= 0) + { + menu.AddItem("255 215 0", "Gold Tracers"); + } + if (StrContains(g_cStorestats[client], "(") >= 0) + { + menu.AddItem("0 255 255", "cyan Tracers"); + } + menu.ExitButton = true; + menu.Display(client, 0); + return Plugin_Handled; +} + + +public int MenuHandler1(Menu menu, MenuAction action, int param1, int choice) +{ + char info[256]; + menu.GetItem(choice, info, sizeof(info)); + if (action == MenuAction_Cancel) + { + //PrintToServer("Client %d's menu was cancelled. Reason: %d", param1, choice); + } + + else if (action == MenuAction_End) + { + delete menu; + } + else if (action == MenuAction_Select) + { + if (choice == 0) + { + g_bZeusOwner[param1] = false; + g_bStoreColorbool[param1] = false; + static char SID[32]; + GetClientAuthId(param1, AuthId_Steam2, SID, sizeof(SID)); + if (g_iTracerpref[param1] == 0) + { + g_iTracerpref[param1] = 1; + PrintToChat(param1, "Disabled tracers"); + } + else + { + g_iTracerpref[param1] = 0; + PrintToChat(param1, "Enabled tracers"); + } + ClientCount(); + tracerprefMYSQL(param1); + return 0; + } + else if (choice == 1) + { + g_bZeusOwner[param1] = true; + g_bStoreColorbool[param1] = false; + } + else if (choice > 1) + { + char l_cColorPref[256]; + g_bStoreColorbool[param1] = true; + g_bZeusOwner[param1] = false; + Format(l_cColorPref, sizeof(l_cColorPref), info); + char sPart[3][526]; + ExplodeString(l_cColorPref, " ", sPart, 3, 526); + g_iStoreColors[param1][0] = StringToInt(sPart[0]); + g_iStoreColors[param1][1] = StringToInt(sPart[1]); + g_iStoreColors[param1][2] = StringToInt(sPart[2]); + InsertTracerPrefMYSQL(param1, l_cColorPref); + } + } + ClientCount(); + return 0; +} + + +public Action Event_OnBulletImpact(Event event, const char[] name, bool dontBroadcast) +{ + int client = GetClientOfUserId(event.GetInt("userid")); + //unnecesary checks but eh + if (!IsClientInGame(client) || IsFakeClient(client) || g_iPlayerArray[0] == '\0' || g_iPlayerCount < 1) + { + return Plugin_Handled; + } + if (g_iTracerpref[client] == 1) + { + return Plugin_Handled; + } + //bought tracers for 25000 tokens in the shop if true + if (!g_bZeusOwner[client] && !g_bStoreColorbool[client]) + { + //making sure if not bought from shop that atleast rank 32 and 5000 points + if (g_iPlayerRank[client] > 32 || g_iPlayerPoints[client] < 5000) + { + //PrintToChatAll("g_cStorestats client %N: %s", client, g_cStorestats[client]); + return Plugin_Handled; + } + } + ++g_iTEsends[client]; + if (g_iTEsends[client] < 2) + { + return Plugin_Handled; + } + g_iTEsends[client] = 0; + + float impact_pos[3]; + float fPosition[3], fImpact[3], fDifference[3]; + float muzzle_pos[3], camera_pos[3]; + float pov_pos[3]; + int l_iStoreColors[3]; + + GetClientEyePosition(client, fPosition); + impact_pos[0] = event.GetFloat("x"); + impact_pos[1] = event.GetFloat("y"); + impact_pos[2] = event.GetFloat("z"); + fImpact[0] = GetEventFloat (event, "x"); + fImpact[1] = GetEventFloat (event, "y"); + fImpact[2] = GetEventFloat (event, "z"); + + GetWeaponAttachmentPosition(client, "muzzle_flash", muzzle_pos); + GetWeaponAttachmentPosition(client, "camera_buymenu", camera_pos); + + //Create an offset for first person + pov_pos[0] = muzzle_pos[0] - camera_pos[0]; + pov_pos[1] = muzzle_pos[1] - camera_pos[1]; + pov_pos[2] = muzzle_pos[2] - camera_pos[2] + 0.1; + ScaleVector(pov_pos, 0.4); + SubtractVectors(muzzle_pos, pov_pos, pov_pos); + + //Move the beam a bit forward so it isn't too close for first person + float distance = GetVectorDistance(pov_pos, impact_pos); + float percentage = 0.2 / (distance / 100); + pov_pos[0] = pov_pos[0] + ((impact_pos[0] - pov_pos[0]) * percentage); + pov_pos[1] = pov_pos[1] + ((impact_pos[1] - pov_pos[1]) * percentage); + pov_pos[2] = pov_pos[2] + ((impact_pos[2] - pov_pos[2]) * percentage); + + + float fDistance = GetVectorDistance(fPosition, fImpact); + float fPercent = (0.4 / (fDistance / 100.0)); + + fDifference[0] = fPosition[0] + ((fImpact[0] - fPosition[0]) * fPercent); + fDifference[1] = fPosition[1] + ((fImpact[1] - fPosition[1]) * fPercent) - 0.08; + fDifference[2] = fPosition[2] + ((fImpact[2] - fPosition[2]) * fPercent); + + //MASK_SOLID_BRUSHONLY + Handle trace = TR_TraceRayFilterEx(fDifference, fImpact, MASK_SHOT, RayType_EndPoint, Bool_TraceFilterPlayers); + TR_GetEndPosition(fImpact, trace); + CloseHandle(trace); + + if (g_bZeusOwner[client]) + { + if (g_iPlayerArrayTop10[0] == '\0' || g_iPlayerCountTop10 < 1) + { + return Plugin_Handled; + } + TE_DispatchEffect(TASER, impact_pos, pov_pos, g_fLastAngles[client]); + TE_Send(g_iPlayerArrayTop10, g_iPlayerCountTop10); + + //Display the particle to everyone else under the normal position + TE_DispatchEffect(TASER, impact_pos, muzzle_pos, g_fLastAngles[client]); + TE_Send(g_iPlayerArray, g_iPlayerCount); + + //Move the impact glow a bit out so it doesn't clip the wall + impact_pos[0] = impact_pos[0] + ((pov_pos[0] - impact_pos[0]) * percentage); + impact_pos[1] = impact_pos[1] + ((pov_pos[1] - impact_pos[1]) * percentage); + impact_pos[2] = impact_pos[2] + ((pov_pos[2] - impact_pos[2]) * percentage); + + TE_DispatchEffect(GLOW, impact_pos, impact_pos); + TE_Send(g_iPlayerArrayTop10, g_iPlayerCountTop10); + + TE_DispatchEffect(GLOW, impact_pos, impact_pos); + TE_Send(g_iPlayerArray, g_iPlayerCount); + + //play taser sounds to clients + EmitSound(g_iPlayerArrayTop10, g_iPlayerCountTop10, SOUND_SHOOT, client, SNDCHAN_WEAPON, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.15, SNDPITCH_NORMAL); + EmitSound(g_iPlayerArrayTop10, g_iPlayerCountTop10, SOUND_IMPACT, client, SNDCHAN_WEAPON, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.15, SNDPITCH_NORMAL); + EmitSoundToClient(client, SOUND_SHOOT, client, SNDCHAN_WEAPON, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.15, SNDPITCH_NORMAL); + EmitSoundToClient(client, SOUND_IMPACT, client, SNDCHAN_WEAPON, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.15, SNDPITCH_NORMAL); + return Plugin_Handled; + } + else if (g_bStoreColorbool[client]) + { + l_iStoreColors[0] = g_iStoreColors[client][0]; + l_iStoreColors[1] = g_iStoreColors[client][1]; + l_iStoreColors[2] = g_iStoreColors[client][2]; + } + if (g_iPlayerRank[client] > 32) + { + TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {192, 192, 192, 105}, 1); + TE_Send(g_iPlayerArray, g_iPlayerCount); + return Plugin_Handled; + } + //red + else if (g_iPlayerRank[client] > 29 || colorIndex(l_iStoreColors, 255, 0, 0)) + { + TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {255, 0, 0, 105}, 1); + TE_Send(g_iPlayerArray, g_iPlayerCount); + return Plugin_Handled; + } + else if (g_iPlayerRank[client] > 27) + { + TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {255, 77, 0, 105}, 1); + TE_Send(g_iPlayerArray, g_iPlayerCount); + return Plugin_Handled; + } + //yellow + else if (g_iPlayerRank[client] > 25 || colorIndex(l_iStoreColors, 255, 255, 0)) + { + TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {255, 255, 0, 105}, 1); + TE_Send(g_iPlayerArray, g_iPlayerCount); + return Plugin_Handled; + } + //blue + else if (colorIndex(l_iStoreColors, 0, 0, 255)) + { + TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {0, 0, 255, 105}, 1); + TE_Send(g_iPlayerArray, g_iPlayerCount); + return Plugin_Handled; + } + //gold + else if (colorIndex(l_iStoreColors, 255, 215, 0)) + { + TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {255, 215, 0, 105}, 1); + TE_Send(g_iPlayerArray, g_iPlayerCount); + return Plugin_Handled; + } + //cyan 0 255 255 + else if (colorIndex(l_iStoreColors, 0, 255, 255)) + { + TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {0, 255, 255, 105}, 1); + TE_Send(g_iPlayerArray, g_iPlayerCount); + return Plugin_Handled; + } + else if (g_iPlayerRank[client] > 23) + { + TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {35, 142, 35, 105}, 1); + TE_Send(g_iPlayerArray, g_iPlayerCount); + return Plugin_Handled; + } + else if (g_iPlayerRank[client] > 21) + { + TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {128, 128, 0, 105}, 1); + TE_Send(g_iPlayerArray, g_iPlayerCount); + return Plugin_Handled; + } + else if (g_iPlayerRank[client] > 18) + { + TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {64, 224, 208, 105}, 1); + TE_Send(g_iPlayerArray, g_iPlayerCount); + return Plugin_Handled; + } + else if (g_iPlayerRank[client] > 15) + { + TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {0, 128, 128, 105}, 1); + TE_Send(g_iPlayerArray, g_iPlayerCount); + return Plugin_Handled; + } + else if (g_iPlayerRank[client] > 13) + { + TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {240, 248, 255, 105}, 1); + TE_Send(g_iPlayerArray, g_iPlayerCount); + return Plugin_Handled; + } + else if (g_iPlayerRank[client] > 12) + { + TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {128, 0, 128, 105}, 1); + TE_Send(g_iPlayerArray, g_iPlayerCount); + return Plugin_Handled; + } + else if (g_iPlayerRank[client] > 9) + { + TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {148, 0, 211, 105}, 1); + TE_Send(g_iPlayerArray, g_iPlayerCount); + return Plugin_Handled; + } + //green + else if (g_iPlayerRank[client] > 6 || colorIndex(l_iStoreColors, 255, 255, 0)) + { + TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {0, 255, 0, 105}, 1); + TE_Send(g_iPlayerArray, g_iPlayerCount); + return Plugin_Handled; + } + else if (g_iPlayerRank[client] > 3) + { + TE_SetupBeamPoints(fDifference, fImpact, g_iBeam, 0, 0, 0, 0.6, 4.0, 4.0, 1, 1.1, {218, 112, 214, 105}, 1); + TE_Send(g_iPlayerArray, g_iPlayerCount); + return Plugin_Handled; + } + else if (g_iPlayerRank[client] >= 0) + { + //Display the particle to first person + TE_DispatchEffect(TASER, impact_pos, pov_pos, g_fLastAngles[client]); + TE_Send(g_iPlayerArrayTop10, g_iPlayerCountTop10); + + //Display the particle to everyone else under the normal position + TE_DispatchEffect(TASER, impact_pos, muzzle_pos, g_fLastAngles[client]); + TE_Send(g_iPlayerArray, g_iPlayerCount); + + //Move the impact glow a bit out so it doesn't clip the wall + impact_pos[0] = impact_pos[0] + ((pov_pos[0] - impact_pos[0]) * percentage); + impact_pos[1] = impact_pos[1] + ((pov_pos[1] - impact_pos[1]) * percentage); + impact_pos[2] = impact_pos[2] + ((pov_pos[2] - impact_pos[2]) * percentage); + + TE_DispatchEffect(GLOW, impact_pos, impact_pos); + TE_Send(g_iPlayerArrayTop10, g_iPlayerCountTop10); + TE_DispatchEffect(GLOW, impact_pos, impact_pos); + TE_Send(g_iPlayerArray, g_iPlayerCount); + + //play taser sounds to clients SNDCHAN_STATIC + EmitSound(g_iPlayerArrayTop10, g_iPlayerCountTop10, SOUND_SHOOT, client, SNDCHAN_WEAPON, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.15, SNDPITCH_NORMAL); + EmitSound(g_iPlayerArrayTop10, g_iPlayerCountTop10, SOUND_IMPACT, client, SNDCHAN_WEAPON, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.15, SNDPITCH_NORMAL); + EmitSoundToClient(client, SOUND_SHOOT, client, SNDCHAN_WEAPON, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.15, SNDPITCH_NORMAL); + EmitSoundToClient(client, SOUND_IMPACT, client, SNDCHAN_WEAPON, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.15, SNDPITCH_NORMAL); + return Plugin_Handled; + } + return Plugin_Handled; +} + + +public Action Hook_BulletShot(const char[] te_name, const int[] Players, int numClients, float delay) +{ + + int client = TE_ReadNum("m_iPlayer") + 1; + + float origin[3]; + TE_ReadVector("m_vecOrigin", origin); + g_fLastAngles[client][0] = TE_ReadFloat("m_vecAngles[0]"); + g_fLastAngles[client][1] = TE_ReadFloat("m_vecAngles[1]"); + g_fLastAngles[client][2] = 0.0; + + float impact_pos[3]; + Handle trace = TR_TraceRayFilterEx(origin, g_fLastAngles[client], MASK_SHOT, RayType_Infinite, TR_DontHitSelf, client); + if (TR_DidHit(trace)) + { + TR_GetEndPosition(impact_pos, trace); + } + delete trace; + return Plugin_Continue; +} + +public bool TR_DontHitSelf(int entity, int mask, any data) +{ + if (entity == data) + return false; + return true; +} + +void GetWeaponAttachmentPosition(int client, const char[] attachment, float pos[3]) +{ + if (!attachment[0]) + return; + + int entity = CreateEntityByName("info_target"); + DispatchSpawn(entity); + + int weapon; + + if ((weapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon")) == -1) + return; + + if ((weapon = GetEntPropEnt(weapon, Prop_Send, "m_hWeaponWorldModel")) == -1) + return; + + SetVariantString("!activator"); + AcceptEntityInput(entity, "SetParent", weapon, entity, 0); + + SetVariantString(attachment); + AcceptEntityInput(entity, "SetParentAttachment", weapon, entity, 0); + + TeleportEntity(entity, NULL_VECTOR, NULL_VECTOR, NULL_VECTOR); + GetEntPropVector(entity, Prop_Data, "m_vecAbsOrigin", pos); + AcceptEntityInput(entity, "kill"); +} + +void TE_DispatchEffect(const char[] particle, const float pos[3], const float endpos[3], const float angles[3] = NULL_VECTOR) +{ + TE_Start("EffectDispatch"); + TE_WriteFloatArray("m_vStart.x", pos, 3); + TE_WriteFloatArray("m_vOrigin.x", endpos, 3); + TE_WriteVector("m_vAngles", angles); + TE_WriteNum("m_nHitBox", GetParticleEffectIndex(particle)); + TE_WriteNum("m_iEffectName", GetEffectIndex("ParticleEffect")); +} + + +int GetParticleEffectIndex(const char[] sEffectName) +{ + static int table = INVALID_STRING_TABLE; + + if (table == INVALID_STRING_TABLE) + table = FindStringTable("ParticleEffectNames"); + + int iIndex = FindStringIndex(table, sEffectName); + + if (iIndex != INVALID_STRING_INDEX) + return iIndex; + + return 0; +} + + +int GetEffectIndex(const char[] sEffectName) +{ + static int table = INVALID_STRING_TABLE; + + if (table == INVALID_STRING_TABLE) + table = FindStringTable("EffectDispatch"); + + int iIndex = FindStringIndex(table, sEffectName); + + if (iIndex != INVALID_STRING_INDEX) + return iIndex; + + return 0; +} + +public void OnClientPostAdminCheck(int client) +{ + if (client > 0 && client <= MaxClients && IsClientInGame(client)) + { + g_bStoreColorbool[client] = false; + CheckFlagsMYSQL(client); + tracerprefMYSQLpostadmin(client); + CheckMYSQLTracerColorPref(client); + g_iPlayerRank[client] = CheckMYSQL(client); + g_iPlayerPoints[client] = CheckMYSQLPoints(client); + g_iTEsends[client] = 0; + g_bZeusOwner[client] = false; + if (StrContains(g_cStorestats[client], "k") >= 0 && !g_bStoreColorbool[client]) + { + g_bZeusOwner[client] = true; + } + ClientCount(); + } +} + +public void OnClientDisconnect_Post(int client) +{ + ClientCount(); +} + +public void OnClientDisconnect (int client) +{ + Format(g_cStorestats[client], sizeof(g_cStorestats), ""); + g_iPlayerRank[client] = 0; + g_iPlayerPoints[client] = 0; + g_iTEsends[client] = 0; + g_bZeusOwner[client] = false; + g_bStoreColorbool[client] = false; + g_iTracerpref[client] = 0; + g_iStoreColors[client][0] = 0; + g_iStoreColors[client][1] = 0; + g_iStoreColors[client][2] = 0; +} + +public bool Bool_TraceFilterPlayers(int entity, int contentsMask, any client) +{ + return !entity || entity > MaxClients; +} + +public int CheckMYSQL(int client) +{ + if (client < 1 || client > MaxClients) + { + return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%d)", client); + } + if (!IsClientConnected(client)) + { + return ThrowNativeError(SP_ERROR_NATIVE, "Client %d is not connected", client); + } + + char error[255]; + Database db; + if (SQL_CheckConfig("stats")) + { + db = SQL_Connect("stats", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return -1; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + + strcopy(sSID, sizeof(sSID), sSID[8]); //matching up with hlstats_PlayerUniqueIds + Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) AS rank FROM hlstats_Players WHERE hlstats_Players.game = 'csgo-ze' AND hideranking = 0 AND skill > (SELECT skill from hlstats_Players JOIN hlstats_PlayerUniqueIds ON hlstats_Players.playerId = hlstats_PlayerUniqueIds.playerId WHERE uniqueId = '%s' AND hlstats_PlayerUniqueIds.game = 'csgo-ze')", sSID); + + DBResultSet rs; + + if ((rs = SQL_Query(db, sQuery)) == null) + { + + delete db; + delete rs; + return -1; + } + + + int iCollected; + + if (!(rs.RowCount > 0)) + { + iCollected = 0; + } + else + { + int iField; + rs.FetchRow(); + rs.FieldNameToNum("collected", iField); + iCollected = rs.FetchInt(iField); + } + delete rs; + delete db; + return iCollected; +} + + +public void InsertTracerPrefMYSQL(int client, char[] colornumber) +{ + char error[255]; + Database db; + //the points not related to hlstats are stored together with tracer prefferences but have + //their own table + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_tracerprefColor` (`steam_id`, `Color`) VALUES ('%s','%s') ON DUPLICATE KEY UPDATE `Color` = '%s'", sSID, colornumber, colornumber); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete db; +} + + +/*neon idea */ +public int CheckMYSQLPoints (int client) +{ + if (client < 1 || client > MaxClients) + { + return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%d)", client); + } + if (!IsClientConnected(client)) + { + return ThrowNativeError(SP_ERROR_NATIVE, "Client %d is not connected", client); + } + + + char error[255]; + Database db; + if (SQL_CheckConfig("levels")) + { + db = SQL_Connect("levels", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return -1; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + strcopy(sSID, sizeof(sSID), sSID[8]); //matching up with hlstats_PlayerUniqueIds + char sQuery[255]; + Format(sQuery, sizeof(sQuery), "SELECT skill from hlstats_Players JOIN hlstats_PlayerUniqueIds ON hlstats_Players.playerId = hlstats_PlayerUniqueIds.playerId WHERE uniqueId = '%s' AND hlstats_PlayerUniqueIds.game = 'csgo-ze'", sSID); + + DBResultSet rs; + + if ((rs = SQL_Query(db, sQuery)) == null) + { + //PrintToConsole(client, "[Unloze] Failed sQuery: %s", sQuery); + delete db; + delete rs; + return -1; + } + //PrintToConsole(client, "[Unloze] Success sQuery: %s", sQuery); + + + int iCollected; + + if (!(rs.RowCount > 0)) + { + iCollected = 0; + } + else + { + int iField; + rs.FetchRow(); + rs.FieldNameToNum("collected", iField); + iCollected = rs.FetchInt(iField); + } + delete rs; + delete db; + return iCollected; +} + +public void SQL_StartConnection() +{ + char error[255]; + Database db; + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + //create tables + char sQuery[255]; + Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `unloze_tracerpref` (`steam_id` VARCHAR(254) NOT NULL, `disabled` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_id`))"); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `unloze_tracerprefColor` (`steam_id` VARCHAR(254) NOT NULL, `Color` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_id`))"); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + + delete db; +} + +public void tracerprefMYSQL(int client) +{ + char error[255]; + Database db; + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + //create tables + char sQuery[255]; + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + if (g_iTracerpref[client] == 1) + { + Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_tracerpref` (`steam_id`, `disabled`) VALUES ('%s','1') ON DUPLICATE KEY UPDATE `disabled` = '1'", sSID); + } + else if (g_iTracerpref[client] == 0) + { + Format(sQuery, sizeof(sQuery), "DELETE FROM unloze_tracerpref WHERE `steam_id` = '%s'", sSID); + } + SQL_TQuery(db, DummyCallbackSimple, sQuery); + + delete db; +} + + +public void CheckMYSQLTracerColorPref(int client) +{ + char error[255]; + Database db; + //the points not related to hlstats are stored together with tracer prefferences but have + //their own table + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "SELECT Color FROM `unloze_tracerprefColor` WHERE `steam_id` = '%s'", sSID); + DBResultSet rs; + + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + return; + } + if (rs.RowCount > 0 && rs.FetchRow()) + { + char translate[124]; + char sPart[3][526]; + SQL_FetchString(rs, 0, translate, MAX_NAME_LENGTH); + ExplodeString(translate, " ", sPart, 3, 526); + g_iStoreColors[client][0] = StringToInt(sPart[0]); + g_iStoreColors[client][1] = StringToInt(sPart[1]); + g_iStoreColors[client][2] = StringToInt(sPart[2]); + g_bStoreColorbool[client] = true; + delete rs; + delete db; + return; + } + g_iStoreColors[client][0] = 0; + g_iStoreColors[client][1] = 0; + g_iStoreColors[client][2] = 0; + delete rs; + delete db; +} + +public void tracerprefMYSQLpostadmin(int client) +{ + char error[255]; + Database db; + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + //create tables + char sQuery[255]; + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + Format(sQuery, sizeof(sQuery), "SELECT disabled FROM `unloze_tracerpref` WHERE `steam_id` = '%s'", sSID); + + DBResultSet rs; + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + return; + } + + if (!(rs.RowCount > 0)) + { + g_iTracerpref[client] = 0; + } + else + { + g_iTracerpref[client] = 1; + } + delete rs; + delete db; +} + +public void CheckFlagsMYSQL(int client) +{ + char error[255]; + Database db; + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "SELECT storestats FROM `unloze_zonepoints` WHERE `steam_id` = '%s'", sSID); + + DBResultSet rs; + + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + return; + } + + if (rs.FetchRow()) + { + SQL_FetchString(rs, 0, g_cStorestats[client], sizeof(g_cStorestats)); + } + delete rs; + delete db; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: stocks +//---------------------------------------------------------------------------------------------------- + +public void DummyCallbackSimple(Handle hOwner, Handle hChild, const char[] err, DataPack pack1) +{ + if (hOwner == null || hChild == null) + { + LogError("Query error. (%s)", err); + } +} + +stock bool IsValidClient(int client) +{ + if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && !IsFakeClient(client)) + { + return true; + } + return false; +} + +stock void ClientCount() +{ + g_iPlayerCount = 0; + g_iPlayerCountTop10 = 0; + for (int i = 1; i <= MaxClients; i++) + { + if (IsValidClient(i) && g_iTracerpref[i] == 0) + { + if (g_iPlayerRank[i] < 4 || g_bZeusOwner[i]) + { + g_iPlayerArrayTop10[g_iPlayerCountTop10++] = i; + } + g_iPlayerArray[g_iPlayerCount++] = i; + } + } +} + +stock bool colorIndex(int colors[3], int a, int g, int b) +{ + if (colors[0] == a && colors[1] == g && colors[2] == b) + { + return true; + } + return false; +} \ No newline at end of file diff --git a/Plugins/unloze_zones/scripting/include/unloze_zones.inc b/Plugins/unloze_zones/scripting/include/unloze_zones.inc new file mode 100644 index 00000000..7d5e886d --- /dev/null +++ b/Plugins/unloze_zones/scripting/include/unloze_zones.inc @@ -0,0 +1,34 @@ +/** Double-include prevention */ +#if defined _unloze_zones_included_ + #endinput +#endif +#define _unloze_zones_included_ + +/** + * Called when client Enters a zone + * + * @int Client entering zone. + * @char name of the zone. + */ + +forward void unloze_zoneEntry(int client, char[] zone); + +/** + * Called when client Leaves a zone + * + * @int Client leaving zone. + * @char name of the zone. + */ + +forward void unloze_zoneLeave(int client, char[] zone); + +/** + * @int zone index + * @char modifies the zone indexes name + */ +native void ZoneNameBasedOnIndex(int index, char[] callbackresult); + +/** +* @returns total count of zones +*/ +native int unloze_zoneCount(); \ No newline at end of file diff --git a/Plugins/unloze_zones/scripting/unloze_zones.sp b/Plugins/unloze_zones/scripting/unloze_zones.sp new file mode 100644 index 00000000..bb0c0d77 --- /dev/null +++ b/Plugins/unloze_zones/scripting/unloze_zones.sp @@ -0,0 +1,1167 @@ +#pragma semicolon 1 +#define DEBUG +#define PLUGIN_AUTHOR "jenz, thx to zuff for help" +#define PLUGIN_VERSION "1.00" +#define MAXZONES 64 +#define ZONENAMELENGTH 256 +#include <sourcemod> +#include <sdktools> +#include <sdkhooks> +#pragma newdecls required +//---------------------------------------------------------------------------------------------------- +// Purpose: Global variables +//---------------------------------------------------------------------------------------------------- +//forwards +static char g_sConfigzones[PLATFORM_MAX_PATH]; +static Handle g_hForwardedZonesEnter; +static Handle g_hForwardedZonesLeaver; +//material +int g_iBeam = -1; +//creating new zones based on shavit/blaacky stuff +char g_cZones[MAXZONES][ZONENAMELENGTH]; +char g_cZoneIndexName[MAXZONES][ZONENAMELENGTH]; +float f_startPos[MAXZONES][3]; +float f_endpos[MAXZONES][3]; +int i_admindrawing[MAXPLAYERS]; +int ZONE_INDEX[MAXPLAYERS]; +//experimental int? +int i_renameRefference[MAXPLAYERS]; +int i_zoneRefference; +//counting zones +int i_zoneCount; +//making zone names +bool b_zonenaming[MAXPLAYERS]; +//deleting zones +int i_adminSelectOption[MAXPLAYERS]; +//entity refference +int i_zoneEntRef[MAXZONES]; +//mapname +char mapname[125]; +//---------------------------------------------------------------------------------------------------- +// Purpose: description +//---------------------------------------------------------------------------------------------------- +public Plugin myinfo = +{ + name = "Unloze zones", + author = PLUGIN_AUTHOR, + description = "Zones to use for zonerewards", + version = PLUGIN_VERSION, + url = "www.unloze.com" +}; +//---------------------------------------------------------------------------------------------------- +// Purpose: pluginstart/end/askpluginload +//---------------------------------------------------------------------------------------------------- +public void OnPluginStart() +{ + //hooks + HookEvent("round_start", Event_roundStart, EventHookMode_Post); + //commands + RegConsoleCmd("say", Cmd_Say); + RegAdminCmd("sm_zones", Cmd_Zones, ADMFLAG_GENERIC); + RegAdminCmd("sm_zone", Cmd_Zones, ADMFLAG_GENERIC); + RegAdminCmd("sm_zonetest", Cmd_Zonetest, ADMFLAG_ROOT); + + RegAdminCmd("sm_showzones", Cmd_ZoneDisplay, ADMFLAG_CUSTOM1); + RegAdminCmd("sm_showzone", Cmd_ZoneDisplay, ADMFLAG_CUSTOM1); +} +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnPluginEnd() +{ + CloseHandle(g_hForwardedZonesEnter); + CloseHandle(g_hForwardedZonesLeaver); +} +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public APLRes AskPluginLoad2(Handle myself, bool late, char [] error, int err_max) +{ + //global forwards + g_hForwardedZonesEnter = CreateGlobalForward("unloze_zoneEntry", ET_Ignore, Param_Cell, Param_String); + g_hForwardedZonesLeaver = CreateGlobalForward("unloze_zoneLeave", ET_Ignore, Param_Cell, Param_String); + CreateNative("unloze_zoneCount", Native_zoneCount); + CreateNative("ZoneNameBasedOnIndex", Native_ZoneNameBasedOnIndex); + return APLRes_Success; +} +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public int Native_zoneCount(Handle handler, int numParams) +{ + return i_zoneCount; +} +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public int Native_ZoneNameBasedOnIndex(Handle handler, int numParams) +{ + int i = GetNativeCell(1); + SetNativeString(2, g_cZones[i][ZONENAMELENGTH -1], sizeof(g_cZones), true); +} +//---------------------------------------------------------------------------------------------------- +// Purpose: Displayes zones +//---------------------------------------------------------------------------------------------------- +public Action Cmd_ZoneDisplay(int client, int args) +{ + displayzones(client); +} +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void displayzones(int client) +{ + if (i_admindrawing[client] == 0) + { + i_admindrawing[client] = -1; + PrintToChat(client, "Activated zone display"); + } + else if (i_admindrawing[client] <= -1) + { + i_admindrawing[client] = 0; + PrintToChat(client, "De-Activated zone display"); + } +} +//---------------------------------------------------------------------------------------------------- +// Purpose: commands && menus +//---------------------------------------------------------------------------------------------------- +public Action Cmd_Zonetest(int client, int args) +{ + ReadZoneFile(); + return Plugin_Handled; +} +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Action Cmd_Zones(int client, int args) +{ + Menu menu = new Menu(MenuHandler1); + menu.SetTitle("UNLOZE Zones menu!"); + menu.AddItem("Create new Zone", "Create new Zone"); + menu.AddItem("Rename Zones", "Rename Zones"); + menu.AddItem("Show/hide Zones", "Show/hide Zones"); + menu.AddItem("Delete Zone", "Delete Zone"); + menu.AddItem("Goto Zone", "Goto Zone"); + menu.AddItem("Editing Zone", "Editing Zone"); + menu.ExitButton = true; + menu.Display(client, 0); + return Plugin_Handled; +} +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public int MenuHandler1(Menu menu, MenuAction action, int param1, int choice) +{ + /* If the menu was cancelled, print a message to the server about it. */ + if (action == MenuAction_Cancel) + { + PrintToServer("Client %d's menu was cancelled. Reason: %d", param1, choice); + } + /* If the menu has ended, destroy it */ + else if (action == MenuAction_End) + { + delete menu; + } + else if (action == MenuAction_Select) + { + char info[32]; + menu.GetItem(choice, info, sizeof(info)); + if (StrEqual(info, "Create new Zone", true)) + { + PrintToChat(param1, "Creating new zone"); + GetClientAbsOrigin(param1, f_startPos[ZONE_INDEX[param1]]); + i_admindrawing[param1] = 1; + cmd_menuFinishZone(param1, 0); + } + else if (StrEqual(info, "Rename Zones", true)) + { + //make menu to select zone + i_adminSelectOption[param1] = 7; + cmd_menuZoneCounter(param1); + } + else if (StrEqual(info, "Show/hide Zones", true)) + { + i_adminSelectOption[param1] = 6; + cmd_menuZoneCounter(param1); + } + else if (StrEqual(info, "Delete Zone", true)) + { + i_adminSelectOption[param1] = 1; + cmd_menuZoneCounter(param1); + } + else if (StrEqual(info, "Goto Zone", true)) + { + i_adminSelectOption[param1] = 2; + cmd_menuZoneCounter(param1); + } + else if (StrEqual(info, "Editing Zone", true)) + { + i_adminSelectOption[param1] = 5; + cmd_menuZoneCounter(param1); + } + + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: simple say hook +//---------------------------------------------------------------------------------------------------- +public Action Cmd_Say(int client, int args) +{ + if (b_zonenaming[client]) + { + GetCmdArgString(g_cZones[ZONE_INDEX[client]], sizeof(g_cZones)); + chattrim(g_cZones[ZONE_INDEX[client]]); + PrintToChat(client, "Updated zone name to: %s", g_cZones[ZONE_INDEX[client]]); + //renaming zones + i_adminSelectOption[client] = 3; + + //PrintToChatAll("i_renameRefference value: %i", i_renameRefference[client]); + KillMultiple(i_renameRefference[client]); + + CreateZones(f_startPos[i_renameRefference[client]], f_endpos[i_renameRefference[client]], g_cZones[ZONE_INDEX[client]], i_renameRefference[client]); + writetofile(f_startPos[i_renameRefference[client]], f_endpos[i_renameRefference[client]], g_cZones[ZONE_INDEX[client]], i_renameRefference[client], client); + i_renameRefference[client] = 0; + b_zonenaming[client] = false; + } +} + +public void chattrim(char[] message) +{ + for (int i = 0; i < strlen(message); i++) + { + if (StrContains(message[i], "}", false) >= 0) + { + strcopy(message, strlen(message), message[i]); + } + } + ReplaceString(message, strlen(message), "\"", "", true); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: Creatingzonepoints and displaying them +//---------------------------------------------------------------------------------------------------- + +// https://forums.alliedmods.net/showthread.php?p=2030793 +/* +* Generates all 8 points of a zone given just 2 of its points +*/ +public void CreateZonePoints(float point[8][3]) +{ + for (int i = 1; i < 7; i++) + { + for (int j = 0; j < 3; j++) + { + point[i][j] = point[((i >> (2 - j)) & 1) * 7][j]; + } + } +} + +/* +* Graphically draws a zone +* if client == 0, it draws it for all players in the game +* if client index is between 0 and MaxClients+1, it draws for the specified client +*/ +public Action DrawZone(int client, float array[8][3], int beamsprite, int halosprite, color[4], float life) +{ + //shavit idea + static int pairs[][] = + { + { 0, 2 }, + { 2, 6 }, + { 6, 4 }, + { 4, 0 }, + { 0, 1 }, + { 3, 1 }, + { 3, 2 }, + { 3, 7 }, + { 5, 1 }, + { 5, 4 }, + { 6, 7 }, + { 7, 5 } + }; + for (int i = 0; i < 12; i++) + { + TE_SetupBeamPoints(array[pairs[i][0]], array[pairs[i][1]], beamsprite, halosprite, 0, 0, life, 5.0, 5.0, 1, 1.1, color, 1); + TE_SendToClient(client, 0.0); + } + return Plugin_Handled; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: menus +//---------------------------------------------------------------------------------------------------- +public Action cmd_menuZoneCounter(int client) +{ + if (i_zoneCount < 1) + { + PrintToChat(client, "No active zones!"); + return Plugin_Handled; + } + char c_nameCompare[MAXZONES][256]; + Menu menu = new Menu(MenuHandler2); + menu.SetTitle("Select which zone to Rename, Display, Delete, Edit or Goto "); + //PrintToChatAll("i_zoneCount: %i", i_zoneCount); + for (int i = 0; i < i_zoneCount; i++) + { + if (MenuZoneindex(i)) + { + //PrintToChat(client, "MenuZoneindex true"); + Format(c_nameCompare[i], sizeof(c_nameCompare), g_cZoneIndexName[ZONE_INDEX[i]]); + char toChar[64]; + IntToString(i, toChar, sizeof(toChar)); + Format(toChar, sizeof(toChar), "_%s", toChar); + StrCat(g_cZoneIndexName[ZONE_INDEX[i]], sizeof(c_nameCompare), toChar); + //PrintToChatAll("MenuZoneindex true %s", g_cZoneIndexName[ZONE_INDEX[i]]); + menu.AddItem(g_cZoneIndexName[ZONE_INDEX[i]], g_cZoneIndexName[ZONE_INDEX[i]]); + } + } + menu.ExitButton = true; + menu.Display(client, 0); + return Plugin_Handled; +} +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public int CheckEntryKeys() +{ + //openfile here and find it mannualy in a really autistic way + int i_counter[MAXPLAYERS]; + int i_zoneTempCount; + Handle zonefile = INVALID_HANDLE; + char line[128]; + zonefile = OpenFile(g_sConfigzones, "r"); + while (!IsEndOfFile(zonefile) && ReadFileLine(zonefile, line, sizeof(line))) + { + int temp; + temp = strlen(line); + if (temp == 5) + { + TrimString(line); + ReplaceString(line, sizeof(line), "\"", "", false); + i_counter[i_zoneTempCount] = StringToInt(line); + //PrintToChatAll("i_counter[i_zoneTempCount]: %i", i_counter[i_zoneTempCount]); + ++i_zoneTempCount; + //PrintToChatAll("i_zoneTempCount: %i", i_zoneTempCount); + } + } + + int i_Upper; + for (int i = 0; i < i_zoneTempCount; i++) + { + if (i_counter[i] > i_Upper) + { + i_Upper = i_counter[i]; + } + } + i_Upper++; + CloseHandle(zonefile); + return i_Upper; +} + + +public int Keychecker(int i_zoneKeylocal) +{ + //openfile here and find it mannualy in a really autistic way + int i_zoneTempCount; + Handle zonefile = INVALID_HANDLE; + char line[128]; + zonefile = OpenFile(g_sConfigzones, "r"); + while (!IsEndOfFile(zonefile) && ReadFileLine(zonefile, line, sizeof(line))) + { + int temp; + temp = strlen(line); + if (temp == 5) + { + if (i_zoneTempCount == i_zoneKeylocal) + { + //PrintToChatAll("Success %s", line); + //PrintToChatAll("temp: %i", temp); + TrimString(line); + ReplaceString(line, sizeof(line), "\"", "", false); + i_zoneTempCount = StringToInt(line); + //PrintToChatAll("i_zoneTempCount: %i", i_zoneTempCount); + CloseHandle(zonefile); + return i_zoneTempCount; + } + i_zoneTempCount++; + } + } + CloseHandle(zonefile); + //PrintToChatAll("Failed finding zone entry key"); + return 0; +} + +public bool MenuZoneindex(int ZoneKey) +{ + int i_zoneKeylocal; + i_zoneKeylocal = Keychecker(ZoneKey); + char c_entry[64]; + IntToString(i_zoneKeylocal, c_entry, sizeof(c_entry)); + //PrintToChatAll("c_entry: %s", c_entry); + KeyValues kv_zoneentries = new KeyValues("Zones"); + if (kv_zoneentries.ImportFromFile(g_sConfigzones)) + { + //PrintToChatAll("Success import from: %s", g_sConfigzones); + } + else + { + //PrintToChatAll("Failed import from: %s", g_sConfigzones); + delete kv_zoneentries; + return false; + } + + if (kv_zoneentries.GotoFirstSubKey()) + { + //kinda super important + kv_zoneentries.Rewind(); + if (kv_zoneentries.JumpToKey(c_entry, false)) + { + //alternatively ZoneKey here + KvGetString(kv_zoneentries, "name", g_cZoneIndexName[ZONE_INDEX[i_zoneKeylocal]], ZONENAMELENGTH); + //PrintToChatAll("SUCCESS JumpToKey GotoFirstSubKey: zoneIndexName %s", g_cZoneIndexName[ZONE_INDEX[i_zoneKeylocal]]); + //PrintToChatAll("c_entry: %s", c_entry); + delete kv_zoneentries; + return true; + } + } + //PrintToChatAll("Finished GotoNextKey"); + delete kv_zoneentries; + return false; +} + +public Action cmd_menuFinishZone1(int client, int args) +{ + Menu menu = new Menu(MenuHandler3); + menu.SetTitle("UNLOZE Editing zone: %s", g_cZoneIndexName[ZONE_INDEX[i_zoneRefference]]); + menu.AddItem("Finish Zone", "Finish Zone"); + menu.AddItem("Restart Zone", "Restart Zone"); + menu.ExitButton = true; + menu.Display(client, 0); + return Plugin_Handled; +} + +public Action cmd_menuFinishZone(int client, int args) +{ + Menu menu = new Menu(MenuHandler2); + menu.SetTitle("UNLOZE Zones menu!"); + menu.AddItem("Finish new Zone", "Finish new Zone"); + menu.AddItem("Restart Zone", "Restart Zone"); + menu.ExitButton = true; + menu.Display(client, 0); + return Plugin_Handled; +} +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public int MenuHandler2(Menu menu, MenuAction action, int param1, int choice) +{ + //PrintToChat(param1, "Disabled Admin drawing"); + /* If the menu was cancelled, print a message to the server about it. */ + if (action == MenuAction_Cancel) + { + i_admindrawing[param1] = 0; + i_adminSelectOption[param1] = 0; + //PrintToServer("Client %d's menu was cancelled. Reason: %d", param1, choice); + return 0; + } + else if (action == MenuAction_Select) + { + char info[32]; + menu.GetItem(choice, info, sizeof(info)); + if (StrEqual(info, "Finish new Zone", true)) + { + PrintToChat(param1, "Finished creating zone!"); + i_admindrawing[param1] = 0; + Format(g_cZones[ZONE_INDEX[i_zoneCount]], sizeof(g_cZones), "UNASSIGNED NAME"); + i_adminSelectOption[param1] = 4; + i_zoneCount++; + CreateZones(f_startPos[ZONE_INDEX[param1]], f_endpos[ZONE_INDEX[param1]], g_cZones[ZONE_INDEX[i_zoneCount]], i_zoneCount); + writetofile(f_startPos[ZONE_INDEX[param1]], f_endpos[ZONE_INDEX[param1]], g_cZones[ZONE_INDEX[i_zoneCount]], i_zoneCount, param1); + //Updating file + ReadZoneFile(); + return 0; + } + else if (StrEqual(info, "Restart Zone", true)) + { + i_admindrawing[param1] = 0; + Cmd_Zones(param1, 0); + return 0; + } + else + { + DisplayMenuAtItem(menu, param1, GetMenuSelectionPosition(), 0); + //Deleting Entries + if (i_zoneCount >= 1) + { + //PrintToChatAll("i_zoneCount: %i", i_zoneCount); + if (i_adminSelectOption[param1] == 1) + { + //i_adminSelectOption[param1] = 0; + for (int i = 0; i < i_zoneCount; i++) + { + if (choice == i) + { + if (deleteFromFile(i, param1)) + { + //ZONE_INDEX[param1] = i; + PrintToChat(param1, "Deleting %s ", g_cZoneIndexName[ZONE_INDEX[i]]); + i_zoneCount -= 1; + //potential crashes? + KillMultiple(i); + } + //only one zone to delete + break; + } + } + } + //teleporting to zones + else if (i_adminSelectOption[param1] == 2) + { + //PrintToChatAll("i_adminSelectOption == 2"); + //i_adminSelectOption[param1] = 0; + float f_middle[MAXZONES][3]; + float f_min1[MAXZONES][3], f_max1[MAXZONES][3]; + for (int i = 0; i < i_zoneCount; i++) + { + if (choice == i) + { + PrintToChat(param1, "Teleported to: %s", g_cZones[i]); + //PrintToChat(param1, "Teleported to: %s", g_cZoneIndexName[i]); + f_min1[i][0] = f_startPos[i][0]; + f_min1[i][1] = f_startPos[i][1]; + f_min1[i][2] = f_startPos[i][2]; + f_max1[i][0] = f_endpos[i][0]; + f_max1[i][1] = f_endpos[i][1]; + f_max1[i][2] = f_endpos[i][2]; + //update local variable instead of global + GetMiddleOfABox(f_min1[i], f_max1[i], f_middle[i]); + TeleportEntity(param1, f_middle[i], NULL_VECTOR, NULL_VECTOR); + //only one zone to teleport to + break; + } + } + } + //Editing zones + else if (i_adminSelectOption[param1] == 5) + { + //i_adminSelectOption[param1] = 0; + for (int i = 0; i < i_zoneCount; i++) + { + if (choice == i) + { + //alternatively g_cZoneIndexName[i] + i_zoneRefference = i; + Menu menu1 = new Menu(MenuHandler3); + menu1.SetTitle("UNLOZE Editing zone: %s", g_cZoneIndexName[ZONE_INDEX[i]]); + menu1.AddItem("Redo Zone", "Redo Zone"); + menu1.AddItem("move Zone up", "move Zone up"); + menu1.AddItem("move Zone down", "move Zone down"); + menu1.AddItem("move Zone left", "move Zone left"); + menu1.AddItem("move Zone right", "move Zone right"); + menu1.AddItem("move Zone forwards", "move Zone forwards"); + menu1.AddItem("move Zone backwards", "move Zone backwards"); + menu1.ExitButton = true; + menu1.Display(param1, 0); + break; + } + } + } + //displaying zone + if (i_adminSelectOption[param1] == 6) + { + displayzones(param1); + } + //renaming zones + else if (i_adminSelectOption[param1] == 7) + { + for (int i = 0; i < i_zoneCount; i++) + { + if (choice == i) + { + i_renameRefference[param1] = i; + b_zonenaming[param1] = true; + PrintToChat(param1, "Enter the name of the zone into the chat"); + //only one zone to update + break; + } + } + } + } + else + { + PrintToChat(param1, "No zones available"); + } + } + } + return 0; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: MenuHandler3 +//---------------------------------------------------------------------------------------------------- + +public int MenuHandler3(Menu menu, MenuAction action, int param1, int choice) +{ + //i_admindrawing[param1] = 0; + /* If the menu was cancelled, print a message to the server about it. */ + if (action == MenuAction_Cancel) + { + PrintToServer("Client %d's menu was cancelled. Reason: %d", param1, choice); + } + + /* If the menu has ended, destroy it */ + /* + else if (action == MenuAction_End) + { + delete menu; + } + */ + else if (action == MenuAction_Select) + { + DisplayMenuAtItem(menu, param1, GetMenuSelectionPosition(), 0); + char info[32]; + float f_moveStartPos[MAXZONES][3], f_moveEndPos[MAXZONES][3]; + f_moveStartPos[i_zoneRefference] = f_startPos[i_zoneRefference]; + f_moveEndPos[i_zoneRefference] = f_endpos[i_zoneRefference]; + menu.GetItem(choice, info, sizeof(info)); + if (StrEqual(info, "Redo Zone", true)) + { + GetClientAbsOrigin(param1, f_startPos[ZONE_INDEX[param1]]); + i_admindrawing[param1] = 1; + cmd_menuFinishZone1(param1, 0); + } + else if (StrEqual(info, "move Zone up", true)) + { + f_moveStartPos[i_zoneRefference][2] += 15.0; + } + else if (StrEqual(info, "move Zone down", true)) + { + f_moveEndPos[i_zoneRefference][2] -= 15.0; + } + else if (StrEqual(info, "move Zone left", true)) + { + f_moveStartPos[i_zoneRefference][1] += 15.0; + } + else if (StrEqual(info, "move Zone right", true)) + { + f_moveEndPos[i_zoneRefference][1] -= 15.0; + } + else if (StrEqual(info, "move Zone forwards", true)) + { + f_moveStartPos[i_zoneRefference][0] -= 15.0; + } + else if (StrEqual(info, "move Zone backwards", true)) + { + f_moveEndPos[i_zoneRefference][0] += 15.0; + } + //redoing coordinates but keep same name somehow + else if (StrEqual(info, "Finish Zone", true)) + { + i_admindrawing[param1] = 0; + i_adminSelectOption[param1] = 4; + TrimString(g_cZones[ZONE_INDEX[i_zoneRefference]]); + CreateZones(f_startPos[ZONE_INDEX[param1]], f_endpos[ZONE_INDEX[param1]], g_cZones[ZONE_INDEX[i_zoneRefference]], i_zoneRefference); + writetofile(f_startPos[ZONE_INDEX[param1]], f_endpos[ZONE_INDEX[param1]], g_cZones[ZONE_INDEX[i_zoneRefference]], i_zoneRefference, param1); + //experimental + ReadZoneFile(); + } + else if (StrEqual(info, "Restart Zone", true)) + { + GetClientAbsOrigin(param1, f_startPos[ZONE_INDEX[param1]]); + i_admindrawing[param1] = 1; + cmd_menuFinishZone1(param1, 0); + } + if (!StrEqual(info, "Restart Zone", true) && !StrEqual(info, "Redo Zone", true) && !StrEqual(info, "Finish Zone", true)) + { + i_adminSelectOption[param1] = 3; + TrimString(g_cZones[ZONE_INDEX[i_zoneRefference]]); + //PrintToChatAll("writetofile after moving zone somewhere"); + CreateZones(f_moveStartPos[i_zoneRefference], f_moveEndPos[i_zoneRefference], g_cZones[ZONE_INDEX[i_zoneRefference]], i_zoneRefference); + writetofile(f_moveStartPos[i_zoneRefference], f_moveEndPos[i_zoneRefference], g_cZones[ZONE_INDEX[i_zoneRefference]], i_zoneRefference, param1); + //experimental for updating in real time + ReadZoneFile(); + } + + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: Writing to File +//---------------------------------------------------------------------------------------------------- + +public void writetofile(float[3] startpos, float[3] endpos, char[] zones, int EntryValue, int client) +{ + char c_entryCount[64]; + KeyValues kv_zoneentries = CreateKeyValues("Zones"); + int i_zoneKeylocal; + //PrintToChatAll("EntryValue: %i", EntryValue); + if (i_adminSelectOption[client] == 3) + { + i_zoneKeylocal = Keychecker(EntryValue); + //PrintToChatAll("i_zoneKeylocal: %i", i_zoneKeylocal); + IntToString(i_zoneKeylocal, c_entryCount, sizeof(c_entryCount)); + } + else if (i_adminSelectOption[client] == 4|| i_adminSelectOption[client] == 5) + { + i_zoneKeylocal = CheckEntryKeys(); + IntToString(i_zoneKeylocal, c_entryCount, sizeof(c_entryCount)); + } + float f_min1[3], f_max1[3]; + f_min1[0] = startpos[0]; + f_min1[1] = startpos[1]; + f_min1[2] = startpos[2]; + f_max1[0] = endpos[0]; + f_max1[1] = endpos[1]; + f_max1[2] = endpos[2]; + if (kv_zoneentries.ImportFromFile(g_sConfigzones)) + { + //PrintToChatAll("Success import from: %s", g_sConfigzones); + } + else + { + //PrintToChatAll("Failed import from: %s", g_sConfigzones); + delete kv_zoneentries; + i_adminSelectOption[client] = 0; + return; + } + kv_zoneentries.Rewind(); + + if (i_adminSelectOption[client] == 4) + { + if (kv_zoneentries.JumpToKey(c_entryCount, true)) + { + KvSetString(kv_zoneentries, "name", zones); + KvSetVector(kv_zoneentries, "cordinate_a", f_min1); + KvSetVector(kv_zoneentries, "cordinate_b", f_max1); + PrintToChat(client, "Added zone: %s", c_entryCount); + } + } + + //renaming zone parts + else if (i_adminSelectOption[client] == 3) + { + //c_entryCount starts as 0 and goes to i_zounecount + if (kv_zoneentries.JumpToKey(c_entryCount, false)) + { + KvSetString(kv_zoneentries, "name", zones); + KvSetVector(kv_zoneentries, "cordinate_a", f_min1); + KvSetVector(kv_zoneentries, "cordinate_b", f_max1); + /* + PrintToChat(client, "f_min1 %f", f_min1); + PrintToChat(client, "f_max1 %f", f_max1); + PrintToChat(client, "Success zonekeys %s!", c_entryCount); + */ + PrintToChat(client, "Coordinate_a: %f", f_min1); + PrintToChat(client, "Coordinate_b: %f", f_max1); + } + /* + else + { + PrintToChat(client, "Failed %s", c_entryCount); + } + */ + } + + i_adminSelectOption[client] = 0; + kv_zoneentries.Rewind(); + kv_zoneentries.ExportToFile(g_sConfigzones); + delete kv_zoneentries; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: Deleting entries +//---------------------------------------------------------------------------------------------------- +public bool deleteFromFile(int EntryValue, int client) +{ + int i_zoneKeylocal; + i_zoneKeylocal = Keychecker(EntryValue); + //big question here + //PrintToChatAll("deleteFromFile EntryValue: %i", EntryValue); + char c_entryCount[128]; + KeyValues kv_zoneentries = CreateKeyValues("Zones"); + IntToString(i_zoneKeylocal, c_entryCount, sizeof(c_entryCount)); + if (kv_zoneentries.ImportFromFile(g_sConfigzones)) + { + //PrintToChatAll("Success import from: %s", g_sConfigzones); + } + else + { + //PrintToChatAll("Failed import from: %s", g_sConfigzones); + delete kv_zoneentries; + return false; + } + kv_zoneentries.Rewind(); + if (kv_zoneentries.JumpToKey(c_entryCount, false)) + { + //PrintToChat(client, "Success JumpToKey Deleting: %s", c_entryCount); + kv_zoneentries.DeleteThis(); + kv_zoneentries.Rewind(); + kv_zoneentries.ExportToFile(g_sConfigzones); + delete kv_zoneentries; + return true; + } + delete kv_zoneentries; + return false; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: PlayerRun +//---------------------------------------------------------------------------------------------------- + +public void OnPlayerRunCmdPost(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]) +{ + //admin is drawing a new zone + if (i_admindrawing[client] >= 1) + { + i_admindrawing[client]++; + + //add delay to prevent client- crash from te_setupbeampoints + if (i_admindrawing[client] >= 15) + { + //PrintToChatAll(">= 15"); + i_admindrawing[client] = 1; + + f_endpos[ZONE_INDEX[client]] = GetAimPosition(client); + float points[8][3]; + points[0] = f_startPos[ZONE_INDEX[client]]; + points[7] = f_endpos[ZONE_INDEX[client]]; + + CreateZonePoints(points); + DrawZone(client, points, g_iBeam, 0, { 255, 255, 255, 255 }, 0.5); + } + } + //people with custom flag 1 that want to see zones + else if (i_admindrawing[client] <= -1) + { + i_admindrawing[client] -= 1; + //add delay to prevent client- crash from te_setupbeampoints + if (i_admindrawing[client] <= -15) + { + i_admindrawing[client] = -1; + + //PrintToChatAll("i_zoneCount: %i", i_zoneCount); + float points[8][3]; + for (int i = 0; i < i_zoneCount; i++) + { + points[0] = f_startPos[i]; + points[7] = f_endpos[i]; + //fills all other points than [0] and [7] + CreateZonePoints(points); + DrawZone(client, points, g_iBeam, 0, { 255, 255, 255, 255 }, 1.0); + } + } + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: GetAimPosition for zone end drawing +//---------------------------------------------------------------------------------------------------- + +float[] GetAimPosition(int client) +{ + float pos[3]; + GetClientEyePosition(client, pos); + + float angles[3]; + GetClientEyeAngles(client, angles); + + TR_TraceRayFilter(pos, angles, MASK_SHOT, RayType_Infinite, TraceFilter_NoClients, client); + + if (TR_DidHit()) + { + float end[3]; + TR_GetEndPosition(end); + + return end; + } + + return pos; +} + +public bool TraceFilter_NoClients(int entity, int contentsMask, any data) +{ + return (entity != data && 1 <= data <= MaxClients || !IsClientInGame(data)); +} + + +//---------------------------------------------------------------------------------------------------- +// Purpose: Mapstart +//---------------------------------------------------------------------------------------------------- +public void OnMapStart() +{ + GetCurrentMap(mapname, sizeof(mapname)); + PrecacheModel("models/props/cs_office/vending_machine.mdl"); + g_iBeam = PrecacheModel("materials/unloze_tracers/xbeam.vmt"); + AddFileToDownloadsTable("materials/unloze_tracers/xbeam.vmt"); + AddFileToDownloadsTable("materials/unloze_tracers/xbeam.vtf"); + ReadZoneFile(); +} + + +//---------------------------------------------------------------------------------------------------- +// Purpose: Reads from file +//---------------------------------------------------------------------------------------------------- +public Action ReadZoneFile() +{ + //loading zone file + int i_zoneTemp; + Handle zonefile = INVALID_HANDLE; + char line[128]; + BuildPath(Path_SM, g_sConfigzones, sizeof(g_sConfigzones), "configs/unloze_zones/%s.zones.txt", mapname); + zonefile = OpenFile(g_sConfigzones, "r"); + if (zonefile == INVALID_HANDLE) + { + Handle kv = CreateKeyValues("Zones"); + KeyValuesToFile(kv, g_sConfigzones); + CloseHandle(kv); + //PrintToChatAll("Cannot read file %s ! Creating...", g_sConfigzones); + delete zonefile; + return Plugin_Handled; + } + while (!IsEndOfFile(zonefile) && ReadFileLine(zonefile, line, sizeof(line))) + { + if (StrContains(line, "name", false) >= 0) + { + ReplaceString(line, sizeof(line), "\"", "", true); + ReplaceString(line, sizeof(line), "name", "", true); + Format(g_cZones[i_zoneTemp], sizeof(g_cZones), line); + } + + //are cordinate_a and cordinate_b 3 vectors or only one to assign? + if (StrContains(line, "cordinate_a", false) >= 0) + { + ReplaceString(line, sizeof(line), "\"", "", true); + ReplaceString(line, sizeof(line), "cordinate_a", "", true); + //PrintToChatAll("line CoordA: %s", line); + + char sPart[4][32]; + ExplodeString(line, " ", sPart, 4, 32); + + f_startPos[i_zoneTemp][0] = StringToFloat(sPart[0]); + //PrintToChatAll("f_startPos[i_zoneTemp][0] value: %f", f_startPos[i_zoneTemp][0]); + + f_startPos[i_zoneTemp][1] = StringToFloat(sPart[1]);//reading second vector + //PrintToChatAll("f_startPos[i_zoneTemp][1] value: %f", f_startPos[i_zoneTemp][1]); + + f_startPos[i_zoneTemp][2] = StringToFloat(sPart[2]);//reading third vector + //PrintToChatAll("f_startPos[i_zoneTemp][2] value: %f", f_startPos[i_zoneTemp][2]); + } + if (StrContains(line, "cordinate_b", false) >= 0) + { + ReplaceString(line, sizeof(line), "\"", "", true); + ReplaceString(line, sizeof(line), "cordinate_b", "", true); + //PrintToChatAll("line CoordB: %s", line); + + char sPart[4][32]; + ExplodeString(line, " ", sPart, 4, 32); + + f_endpos[i_zoneTemp][0] = StringToFloat(sPart[0]); + //PrintToChatAll("f_endpos[i_zoneTemp][0] value: %f", f_endpos[i_zoneTemp][0]); + + f_endpos[i_zoneTemp][1] = StringToFloat(sPart[1]);//reading second vector + //PrintToChatAll("f_endpos[i_zoneTemp][1] value: %f", f_endpos[i_zoneTemp][1]); + + f_endpos[i_zoneTemp][2] = StringToFloat(sPart[2]);//reading third vector + //PrintToChatAll("f_endpos[i_zoneTemp][2] value: %f", f_endpos[i_zoneTemp][2]); + i_zoneTemp++; + } + } + i_zoneCount = i_zoneTemp; + delete zonefile; + return Plugin_Handled; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: OnClientPostAdminCheck && disconnect +//---------------------------------------------------------------------------------------------------- +public void OnClientPostAdminCheck(int client) +{ + ZONE_INDEX[client] = 0; + i_renameRefference[client] = 0; + i_adminSelectOption[client] = 0; + i_admindrawing[client] = 0; + b_zonenaming[client] = false; +} + +public void OnClientDisconnect(int client) +{ + ZONE_INDEX[client] = 0; + i_renameRefference[client] = 0; + i_adminSelectOption[client] = 0; + i_admindrawing[client] = 0; + b_zonenaming[client] = false; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: Hook roundstart +//---------------------------------------------------------------------------------------------------- +public void Event_roundStart(Handle event, const char[] name, bool dontBroadcast) +{ + ReadZoneFile(); + for (int i = 0; i < i_zoneCount; i++) + { + CreateZones(f_startPos[i], f_endpos[i], g_cZones[i], i); + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: Destroys trigger_multiple in current round +//---------------------------------------------------------------------------------------------------- +public void KillMultiple(int zone) +{ + int zoneEntity[MAXZONES]; + //entref here + zoneEntity[zone] = EntRefToEntIndex(i_zoneEntRef[zone]); + if (IsValidEntRef(zoneEntity[zone])) + { + SDKUnhook(zoneEntity[zone], SDKHook_StartTouchPost, OnStartTouch); + SDKUnhook(zoneEntity[zone], SDKHook_EndTouchPost, OnEndTouch); + AcceptEntityInput(zoneEntity[zone], "Kill"); + //PrintToChatAll("Destroyed trigger multiple"); + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: Zone loading https://forums.alliedmods.net/showthread.php?p=2585082 +//---------------------------------------------------------------------------------------------------- +public void CreateZones(float f_min[3], float f_max[3], char[] sZoneName, int zoneCount) +{ + char c_nameZoneName[128]; + Format(c_nameZoneName, sizeof(c_nameZoneName), sZoneName); + int entindex = CreateEntityByName("trigger_multiple"); + if (entindex != -1) + { + // According to a mysterious source: + // Spawnflags: 1 - only a player can trigger this by touch, makes it so a NPC cannot fire a trigger_multiple + // 2 - Won't fire unless triggering ent's view angles are within 45 degrees of trigger's angles (in addition to any other conditions), so if you want the player to only be able to fire the entity at a 90 degree angle you would do ",angles,0 90 0," into your spawnstring. + // 4 - Won't fire unless player is in it and pressing use button (in addition to any other conditions), you must make a bounding box,(max\mins) for this to work. + // 8 - Won't fire unless player/NPC is in it and pressing fire button, you must make a bounding box,(max\mins) for this to work. + // 16 - only non-player NPCs can trigger this by touch + // 128 - Start off, has to be activated by a target_activate to be touchable/usable + // 256 - multiple players can trigger the entity at the same time + + //targetname seems not to update in real time when using sdkhooks + //maybe make a local char here to take parameter instead? + DispatchKeyValue(entindex, "targetname", c_nameZoneName); + DispatchKeyValue(entindex, "spawnflags", "257"); + SetEntityModel(entindex, "models/props/cs_office/vending_machine.mdl"); + } + DispatchSpawn(entindex); + ActivateEntity(entindex); + + //we need to copy it over to local floats or else parameter gets updated and the origin is fucked + float f_middle[3]; + float f_min1[3], f_max1[3]; + f_min1[0] = f_min[0]; + f_min1[1] = f_min[1]; + f_min1[2] = f_min[2]; + f_max1[0] = f_max[0]; + f_max1[1] = f_max[1]; + f_max1[2] = f_max[2]; + GetMiddleOfABox(f_min1, f_max1, f_middle); + //PrintToChatAll("f_middle: %f", f_middle); + TeleportEntity(entindex, f_middle, NULL_VECTOR, NULL_VECTOR); + + + // Have the mins always be negative + for (int i = 0; i < 3; i++) + { + f_min1[i] = f_min1[i] - f_middle[i]; + if (f_min1[i] > 0.0) + { + f_min1[i] *= -1.0; + } + } + // And the maxs always be positive + for (int i = 0; i < 3; i++) + { + f_max1[i] = f_max1[i] - f_middle[i]; + if (f_max1[i] < 0.0) + { + f_max1[i] *= -1.0; + } + } + SetEntPropVector(entindex, Prop_Send, "m_vecMins", f_min1); + SetEntPropVector(entindex, Prop_Send, "m_vecMaxs", f_max1); + SetEntProp(entindex, Prop_Send, "m_nSolidType", 2); + + int enteffects = GetEntProp(entindex, Prop_Send, "m_fEffects"); + enteffects |= 32; + SetEntProp(entindex, Prop_Send, "m_fEffects", enteffects); + SDKHook(entindex, SDKHook_StartTouchPost, OnStartTouch); + SDKHook(entindex, SDKHook_EndTouchPost, OnEndTouch); + i_zoneEntRef[zoneCount] = EntIndexToEntRef(entindex); +} + + + +//---------------------------------------------------------------------------------------------------- +// Purpose: Entity Output Handlers +//---------------------------------------------------------------------------------------------------- +public void OnStartTouch(int entindex, int other) +{ + if (IsValidClient(other)) + { + char zoneName[64]; + GetEntPropString(entindex, Prop_Data, "m_iName", zoneName, sizeof(zoneName)); + //PrintToChatAll("zoneName: %s", zoneName); + + //forward + Call_StartForward(g_hForwardedZonesEnter); + Call_PushCell(other); + Call_PushString(zoneName); + Call_Finish(); + } +} + +public void OnEndTouch(int entindex, int other) +{ + if (IsValidClient(other)) + { + char zoneName[64]; + GetEntPropString(entindex, Prop_Data, "m_iName", zoneName, sizeof(zoneName)); + //PrintToChatAll("zoneName: %s", zoneName); + + //forward + Call_StartForward(g_hForwardedZonesLeaver); + Call_PushCell(other); + Call_PushString(zoneName); + Call_Finish(); + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: stocks +//---------------------------------------------------------------------------------------------------- +stock bool IsValidClient(int client) +{ + if (client > 0 && client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client) && IsPlayerAlive(client)) + { + return true; + } + return false; +} + +stock void GetMiddleOfABox(const float vec1[3], const float vec2[3], float buffer[3]) +{ + float mid[3]; + MakeVectorFromPoints(vec1, vec2, mid); + mid[0] = mid[0] / 2.0; + mid[1] = mid[1] / 2.0; + mid[2] = mid[2] / 2.0; + AddVectors(vec1, mid, buffer); +} + +stock bool IsValidEntRef(int entity) +{ + if (entity && EntRefToEntIndex(entity) != INVALID_ENT_REFERENCE) + { + return true; + } + return false; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- diff --git a/Plugins/zonerewards/scripting/zoneRewards.sp b/Plugins/zonerewards/scripting/zoneRewards.sp new file mode 100644 index 00000000..245f40f6 --- /dev/null +++ b/Plugins/zonerewards/scripting/zoneRewards.sp @@ -0,0 +1,1973 @@ +#pragma semicolon 1 + +#define DEBUG + +#define PLUGIN_AUTHOR "jenz" +#define PLUGIN_VERSION "1.10" +#define ZONE_PREFIX_CT "ZONE_PREFIX_CT" + + +#include <sourcemod> +#include <sdktools> +#include <sdkhooks> +#include <unloze_zones> +#include <admingroups> +#include <zombiereloaded> + +//map prefferences +KeyValues g_kZoneStats; +static char g_sKVPATH[PLATFORM_MAX_PATH]; + +//token scaler +float f_tokenscaler; + +//sets players health +int g_iclientSpawn[MAXPLAYERS+1]; +//set score +int g_iClientScore[MAXPLAYERS+1]; + +//damage +float i_bDmgScale[MAXPLAYERS+1]; + +//zonepoints +int i_points[MAXPLAYERS+1]; +char c_storestats[MAXPLAYERS+1][1024]; +float f_2kdmgPoints[MAXPLAYERS+1]; + + +//convars +ConVar G_hCvar_Points_Humans = null; + +bool g_bClientFilter[MAXPLAYERS+1]; +bool g_bDmgScale[MAXPLAYERS+1]; +bool g_bDmgOutput[MAXPLAYERS+1]; + + +public Plugin myinfo = +{ + name = "end Zones", + author = PLUGIN_AUTHOR, + description = "end zones in maps", + version = PLUGIN_VERSION, + url = "https://forums.alliedmods.net/showthread.php?t=224839" +}; + + +public void OnPluginStart() +{ + // Events. + HookEvent("round_end", Event_RoundEnd); + HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy); + + //mysql + SQL_StartConnection(); + + //translations + LoadTranslations("common.phrases"); + + //commands + RegConsoleCmd("sm_dmgscale", cmd_dmgScaleOutput, "Enables output for damage"); + RegConsoleCmd("sm_store", cmd_shopmenu, "Shop for Unloze Tokens"); + RegConsoleCmd("sm_shop", cmd_shopmenu, "Shop for Unloze Tokens"); + RegConsoleCmd("sm_transfertoken", cmd_transfertoken, "transfers token from player to player"); + RegConsoleCmd("sm_transfertokens", cmd_transfertoken, "transfers token from player to player"); + RegAdminCmd("sm_zoneDataDel", Cmd_zoneDataDel, ADMFLAG_ROOT); + RegAdminCmd("sm_mysqlpoints", Cmd_mysqltokens, ADMFLAG_ROOT); + RegAdminCmd("sm_givetokens", Cmd_givetokens, ADMFLAG_ROOT); + + //prefference for reconnect + g_kZoneStats = new KeyValues("zoneStats"); + BuildPath(Path_SM, g_sKVPATH, sizeof(g_sKVPATH), "data/playerprefs.zoneStats.txt"); + g_kZoneStats.ImportFromFile(g_sKVPATH); + + //convars + G_hCvar_Points_Humans = CreateConVar("hlx_roundpoints_humans", "250", "The amount of points to reward to humans for winning a round."); + +} + +public void OnAllPluginsLoaded() +{ + AdminGroups_CreateAdminGroup("Token-1"); + AdminGroups_CreateAdminGroup("Token-1-VIP"); + AdminGroups_CreateAdminGroup("Token-2"); + AdminGroups_CreateAdminGroup("Token-2-VIP"); + AdminGroups_CreateAdminGroup("Token-3"); + AdminGroups_CreateAdminGroup("Token-3-VIP"); + AdminGroups_CreateAdminGroup("Token-4"); + AdminGroups_CreateAdminGroup("Token-4-VIP"); + AdminGroups_CreateAdminGroup("Token-5"); + AdminGroups_CreateAdminGroup("Token-5-VIP"); + AdminGroups_CreateAdminGroup("Token-6"); + AdminGroups_CreateAdminGroup("Token-6-VIP"); + AdminGroups_CreateAdminGroup("Token-7"); + AdminGroups_CreateAdminGroup("Token-7-VIP"); + AdminGroups_CreateAdminGroup("Token-8"); + AdminGroups_CreateAdminGroup("Token-8-VIP"); + AdminGroups_CreateAdminGroup("Token-9"); + AdminGroups_CreateAdminGroup("Token-9-VIP"); +} + + +//---------------------------------------------------------------------------------------------------- +// Purpose: cmds +//---------------------------------------------------------------------------------------------------- +public Action Cmd_zoneDataDel(int client, int args) +{ + DeleteAll(g_kZoneStats); +} + +public Action Cmd_mysqltokens(int client, int args) +{ + PrintToChat(client, "c_storestats value: %s", c_storestats[client]); + return Plugin_Handled; +} + + + +public Action cmd_transfertoken(int client, int args) +{ + if (args < 2) + { + ReplyToCommand(client, "[SM] Usage: sm_transfertoken <#userid|name> <value>"); + return Plugin_Handled; + } + char sArgs[65]; + char sArgs2[20]; + GetCmdArg(1, sArgs, sizeof(sArgs)); + GetCmdArg(2, sArgs2, sizeof(sArgs2)); + + int amount = clamp(StringToInt(sArgs2), 1, 0x7FFFFFFF); + + if (amount == 1) + { + PrintToChat(client, "Invalid amount"); + return Plugin_Handled; + } + else if (i_points[client] < amount) + { + PrintToChat(client, "Not enough Tokens: %i", i_points[client]); + return Plugin_Handled; + } + + //PrintToChat(client, "amount value: %i", amount); + //PrintToChat(client, "sArgs value: %s", sArgs); + + int i = FindTarget(client, sArgs, true, false); + if (i == -1) + { + PrintToChat(client, "Invalid target"); + return Plugin_Handled; + } + + if (IsValidClient1(i)) + { + //PrintToChatAll("i %N", i); + //PrintToChatAll("Client %N", client); + i_points[client] -= amount; + sendMYSQL(client); + PrintToChat(client, "You send %i Tokens to %N, your total amount: %i", amount, i, i_points[client]); + i_points[i] += amount; + sendMYSQL(i); + PrintToChat(i, "You received %i Tokens from %N, your total amount: %i", amount, client, i_points[i]); + } + return Plugin_Handled; +} + + +public Action Cmd_givetokens(int client, int args) +{ + i_points[client] += 2500; + sendMYSQL(client); + PrintToChat(client, "You received 2500 Tokens, your total amount: %i", i_points[client]); + return Plugin_Handled; +} + +public Action cmd_dmgScaleOutput(int client, int args) +{ + if (!(g_bDmgOutput[client])) + { + g_bDmgOutput[client] = true; + ReplyToCommand(client, "Enabled output for Damage Scaler"); + } + else + { + g_bDmgOutput[client] = false; + ReplyToCommand(client, "Disabled output for Damage Scaler"); + } +} + +public Action cmd_shopmenu(int client, int args) +{ + Menu menu = new Menu(ShopMenu_Handler, MenuAction_Display|MenuAction_Select|MenuAction_Cancel); + menu.SetTitle("Unloze Shop | Your Tokens: %i", i_points[client]); + menu.AddItem("Playermodels CT", "Playermodels CT"); + menu.AddItem("Playermodels ZM", "Playermodels ZM"); + menu.AddItem("Paint", "Paint"); + menu.AddItem("Tracers", "Tracers"); + menu.AddItem("Chat Tags", "Chat Tags"); + menu.AddItem("Beams", "Beams"); + menu.Display(client, 0); + // ?? return Plugin_Handled; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: shop menu handlers +//---------------------------------------------------------------------------------------------------- + +public int ShopMenu_Handler(Menu menu, MenuAction action, int client, int choice) +{ + switch (action) + { + case MenuAction_Select: + { + Menu menu1 = new Menu(PlayermodelMenu_Handler, MenuAction_Display|MenuAction_Select|MenuAction_Cancel); + menu1.AddItem("Back", "Back"); + char info[32]; + menu.GetItem(choice, info, sizeof(info)); + static char SID[32]; + GetClientAuthId(client, AuthId_Steam2, SID, sizeof(SID)); + if (StrEqual(info, "Playermodels CT", true)) + { + menu1.SetTitle("Unloze Playermodels CT | Command: !zclass | Your Tokens: %i", i_points[client]); + menu1.AddItem("Lightning [120 Tokens]", "Lightning [120 Tokens]"); + menu1.AddItem("Batman [500 Tokens]", "Batman [500 Tokens]"); + menu1.AddItem("Connor [3000 Tokens]", "Connor [3000 Tokens]"); + menu1.AddItem("Samus [3000 Tokens]", "Samus [3000 Tokens]"); + menu1.AddItem("Duke Nukem [4000 Tokens]", "Duke Nukem [4000 Tokens]"); + menu1.AddItem("Back", "Back"); + menu1.AddItem("Trevor [15000 Tokens]", "Trevor [15000 Tokens]"); + menu1.Display(client, 0); + + return -1; + } + else if (StrEqual(info, "Playermodels ZM", true)) + { + menu1.SetTitle("Unloze Playermodels ZM | Command: !zclass | Your Tokens: %i", i_points[client]); + menu1.AddItem("Stalker [200 Tokens]", "Stalker [200 Tokens]"); + menu1.AddItem("Xeno [600 Tokens]", "Xeno [600 Tokens]"); + menu1.AddItem("Grunt [3000 Tokens]", "Grunt [3000 Tokens]"); + + menu1.Display(client, 0); + return -1; + } + else if (StrEqual(info, "Paint", true)) + { + Menu menu2 = new Menu(PaintMenu_Handler); + menu2.SetTitle("UNLOZE Paint | Commands: !paint !paintcolor !paintsize | Your Tokens: %i", i_points[client]); + menu2.AddItem("Back", "Back"); + menu2.AddItem("Unlock paint [4000 Tokens]", "Unlock paint [4000 Tokens]"); + menu2.AddItem("Unlock size [4500 Tokens]", "Unlock size [4500 Tokens]"); + menu2.AddItem("Unlock colour [5000 Tokens]", "Unlock colour [5000 Tokens]"); + menu2.Display(client, 0); + return -1; + } + else if (StrEqual(info, "Tracers", true)) + { + Menu menu2 = new Menu(TracersMenu_Handler); + menu2.SetTitle("UNLOZE Tracers | Command: !tracers | Your Tokens: %i", i_points[client]); + menu2.AddItem("Back", "Back"); + menu2.AddItem("ZEUS Tracers [25000 Tokens]", "ZEUS Tracers [25000 Tokens]"); + menu2.AddItem("Yellow Tracers [7500 Tokens]", "Yellow Tracers [7500 Tokens]"); + menu2.AddItem("Blue Tracers [7500 Tokens]", "Blue Tracers [7500 Tokens]"); + menu2.AddItem("Green Tracers [7500 Tokens]", "Green Tracers [7500 Tokens]"); + menu2.AddItem("Red Tracers [7500 Tokens]", "Red Tracers [7500 Tokens]"); + menu2.AddItem("Gold Tracers [7500 Tokens]", "Gold Tracers [7500 Tokens]"); + menu2.AddItem("Cyan Tracers [7500 Tokens]", "Cyan Tracers [7500 Tokens]"); + menu2.Display(client, 0); + return -1; + } + else if (StrEqual(info, "Chat Tags", true)) + { + Menu menu2 = new Menu(ChatTagsMenu_Handler); + menu2.SetTitle("UNLOZE ChatTags | Commands: !tokentags !chatcolor | Your Tokens: %i", i_points[client]); + menu2.AddItem("Back", "Back"); + menu2.AddItem("Rookie [1500 Tokens]", "Rookie [1500 Tokens]"); + menu2.AddItem("Member [2400 Tokens]", "Member [2400 Tokens]"); + menu2.AddItem("Overweight Vegetarian [3000 Tokens]", "Overweight Vegetarian [3000 Tokens]"); + menu2.AddItem("русский [3800 Tokens]", "русский [3800 Tokens]"); + menu2.AddItem("SERBIAN [5000 Tokens]", "SERBIAN [5000 Tokens]"); + menu2.AddItem("Back", "Back"); + menu2.AddItem("WEEB [6000 Tokens]", "WEEB [6000 Tokens]"); + menu2.AddItem("BAGUETTE [7000 Tokens]", "BAGUETTE [7000 Tokens]"); + menu2.AddItem("NIGGER elites [11377 Tokens]", "NIGGER elites [11377 Tokens]"); + menu2.AddItem("DANE [15000 Tokens]", "DANE [15000 Tokens]"); + menu2.AddItem("Nosteam Chad [20000 Tokens]", "Nosteam Chad [20000 Tokens]"); + menu2.Display(client, 0); + return -1; + } + else if (StrEqual(info, "Beams", true)) + { + Menu menu2 = new Menu(BeamMenu_Handler); + menu2.SetTitle("UNLOZE Beams | Commands: !beams !hidebeam| Your Tokens: %i", i_points[client]); + menu2.AddItem("Back", "Back"); + menu2.AddItem("Rainbow beam [15500 Tokens]", "Rainbow beam [15500 Tokens]"); + menu2.AddItem("Blue beam [1500 Tokens]", "Blue beam [1500 Tokens]"); + menu2.AddItem("Green beam [1500 Tokens]", "Green beam [1500 Tokens]"); + menu2.AddItem("Red beam [1500 Tokens]", "Red beam [1500 Tokens]"); + menu2.AddItem("Gold beam [1500 Tokens]", "Gold beam [1500 Tokens]"); + menu2.AddItem("Back", "Back"); + menu2.AddItem("Black beam [1500 Tokens]", "Black beam [1500 Tokens]"); + menu2.AddItem("Cyan beam [1500 Tokens]", "Cyan beam [1500 Tokens]"); + menu2.AddItem("Turquoise beam [1500 Tokens]", "Turquoise beam [1500 Tokens]"); + menu2.AddItem("Yellow beam [1500 Tokens]", "Yellow beam [1500 Tokens]"); + menu2.AddItem("Pink beam [1500 Tokens]", "Pink beam [1500 Tokens]"); + menu2.AddItem("Back", "Back"); + menu2.AddItem("Purple beam [1500 Tokens]", "Purple beam [1500 Tokens]"); + menu2.AddItem("gray beam [1500 Tokens]", "gray beam [1500 Tokens]"); + menu2.Display(client, 0); + return -1; + } + } + } + return -1; +} + +public int PlayermodelMenu_Handler(Menu menu, MenuAction action, int client, int choice) +{ + if (action == MenuAction_Select) + { + char purchaseEntry[64]; + char info[32]; + menu.GetItem(choice, info, sizeof(info)); + + static char SID[32]; + GetClientAuthId(client, AuthId_Steam2, SID, sizeof(SID)); + + if (StrEqual(info, "Lightning [120 Tokens]", true)) + { + if (i_points[client] >= 120 && (StrContains(c_storestats[client], "1") < 0)) + { + if (CheckCommandAccess(client, "sm_store_vip", ADMFLAG_CUSTOM1)) + { + AdminGroups_GrantAdminGroup(client, "Token-4-VIP"); + } + else + { + AdminGroups_GrantAdminGroup(client, "Token-4"); + } + strcopy(purchaseEntry, sizeof(purchaseEntry), "1"); + i_points[client] -= 120; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Lightning playermodel for 120 UNLOZE tokens!"); + PrintToChat(client, "Check !zclass for your new playermodel!"); + } + else if (StrContains(c_storestats[client], "1") >= 0) + { + PrintToChat(client, "You already purchased Lightning!"); + } + else if (i_points[client] <= 120) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Stalker [200 Tokens]", true)) + { + if (i_points[client] >= 200 && (StrContains(c_storestats[client], "a") < 0)) + { + if (CheckCommandAccess(client, "sm_store_vip", ADMFLAG_CUSTOM1)) + { + AdminGroups_GrantAdminGroup(client, "Token-1-VIP"); + } + else + { + AdminGroups_GrantAdminGroup(client, "Token-1"); + } + strcopy(purchaseEntry, sizeof(purchaseEntry), "a"); + i_points[client] -= 200; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Stalker playermodel for 200 UNLOZE tokens!"); + PrintToChat(client, "Check !zclass for your new playermodel!"); + } + else if (StrContains(c_storestats[client], "a") >= 0) + { + PrintToChat(client, "You already purchased Stalker!"); + } + else if (i_points[client] <= 200) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Batman [500 Tokens]", true)) + { + if (i_points[client] >= 500 && (StrContains(c_storestats[client], "2") < 0)) + { + if (CheckCommandAccess(client, "sm_store_vip", ADMFLAG_CUSTOM1)) + { + AdminGroups_GrantAdminGroup(client, "Token-5-VIP"); + } + else + { + AdminGroups_GrantAdminGroup(client, "Token-5"); + } + strcopy(purchaseEntry, sizeof(purchaseEntry), "2"); + i_points[client] -= 500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Batman playermodel for 500 UNLOZE tokens!"); + PrintToChat(client, "Check !zclass for your new playermodel!"); + } + else if (StrContains(c_storestats[client], "2") >= 0) + { + PrintToChat(client, "You already purchased Batman!"); + } + else if (i_points[client] <= 500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Xeno [600 Tokens]", true)) + { + if (i_points[client] >= 600 && (StrContains(c_storestats[client], "c") < 0)) + { + if (CheckCommandAccess(client, "sm_store_vip", ADMFLAG_CUSTOM1)) + { + AdminGroups_GrantAdminGroup(client, "Token-3-VIP"); + } + else + { + AdminGroups_GrantAdminGroup(client, "Token-3"); + } + strcopy(purchaseEntry, sizeof(purchaseEntry), "c"); + i_points[client] -= 600; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Xeno playermodel for 600 UNLOZE tokens!"); + PrintToChat(client, "Check !zclass for your new playermodel!"); + } + else if (StrContains(c_storestats[client], "c") >= 0) + { + PrintToChat(client, "You already purchased Xeno!"); + } + else if (i_points[client] <= 600) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Connor [3000 Tokens]", true)) + { + if (i_points[client] >= 3000 && (StrContains(c_storestats[client], "f") < 0)) + { + if (CheckCommandAccess(client, "sm_store_vip", ADMFLAG_CUSTOM1)) + { + AdminGroups_GrantAdminGroup(client, "Token-6-VIP"); + } + else + { + AdminGroups_GrantAdminGroup(client, "Token-6"); + } + strcopy(purchaseEntry, sizeof(purchaseEntry), "f"); + i_points[client] -= 3000; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Connor playermodel for 3000 UNLOZE tokens!"); + PrintToChat(client, "Check !zclass for your new playermodel!"); + } + else if (StrContains(c_storestats[client], "f") >= 0) + { + PrintToChat(client, "You already purchased Connor!"); + } + else if (i_points[client] <= 3000) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Duke Nukem [4000 Tokens]", true)) + { + if (i_points[client] >= 4000 && (StrContains(c_storestats[client], "g") < 0)) + { + if (CheckCommandAccess(client, "sm_store_vip", ADMFLAG_CUSTOM1)) + { + AdminGroups_GrantAdminGroup(client, "Token-7-VIP"); + } + else + { + AdminGroups_GrantAdminGroup(client, "Token-7"); + } + strcopy(purchaseEntry, sizeof(purchaseEntry), "g"); + i_points[client] -= 4000; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Duke playermodel for 4000 UNLOZE tokens!"); + PrintToChat(client, "Check !zclass for your new playermodel!"); + } + else if (StrContains(c_storestats[client], "g") >= 0) + { + PrintToChat(client, "You already purchased Duke!"); + } + else if (i_points[client] <= 4000) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Samus [3000 Tokens]", true)) + { + if (i_points[client] >= 3000 && (StrContains(c_storestats[client], "h") < 0)) + { + if (CheckCommandAccess(client, "sm_store_vip", ADMFLAG_CUSTOM1)) + { + AdminGroups_GrantAdminGroup(client, "Token-8-VIP"); + } + else + { + AdminGroups_GrantAdminGroup(client, "Token-8"); + } + strcopy(purchaseEntry, sizeof(purchaseEntry), "h"); + i_points[client] -= 3000; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Samus playermodel for 3000 UNLOZE tokens!"); + PrintToChat(client, "Check !zclass for your new playermodel!"); + } + else if (StrContains(c_storestats[client], "h") >= 0) + { + PrintToChat(client, "You already purchased Samus!"); + } + else if (i_points[client] <= 3000) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Trevor [15000 Tokens]", true)) + { + if (i_points[client] >= 15000 && (StrContains(c_storestats[client], "i") < 0)) + { + if (CheckCommandAccess(client, "sm_store_vip", ADMFLAG_CUSTOM1)) + { + AdminGroups_GrantAdminGroup(client, "Token-9-VIP"); + } + else + { + AdminGroups_GrantAdminGroup(client, "Token-9"); + } + strcopy(purchaseEntry, sizeof(purchaseEntry), "i"); + i_points[client] -= 15000; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Trevor playermodel for 15000 UNLOZE tokens!"); + PrintToChat(client, "Check !zclass for your new playermodel!"); + } + else if (StrContains(c_storestats[client], "i") >= 0) + { + PrintToChat(client, "You already purchased Trevor!"); + } + else if (i_points[client] <= 15000) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Back", true)) + { + cmd_shopmenu(client, 0); + return -1; + } + else if (StrEqual(info, "Grunt [3000 Tokens]", true)) + { + if (i_points[client] >= 3000 && (StrContains(c_storestats[client], "j") < 0)) + { + if (CheckCommandAccess(client, "sm_store_vip", ADMFLAG_CUSTOM1)) + { + AdminGroups_GrantAdminGroup(client, "Token-2-VIP"); + } + else + { + AdminGroups_GrantAdminGroup(client, "Token-2"); + } + strcopy(purchaseEntry, sizeof(purchaseEntry), "j"); + i_points[client] -= 3000; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Grunt playermodel for 3000 UNLOZE tokens!"); + PrintToChat(client, "Check !zclass for your new playermodel!"); + } + else if (StrContains(c_storestats[client], "j") >= 0) + { + PrintToChat(client, "You already purchased Grunt!"); + } + else if (i_points[client] <= 3000) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + } + return -1; +} + + +public int TracersMenu_Handler(Menu menu, MenuAction action, int client, int choice) +{ + if (action == MenuAction_Select) + { + char purchaseEntry[64]; + char info[32]; + menu.GetItem(choice, info, sizeof(info)); + + static char SID[32]; + GetClientAuthId(client, AuthId_Steam2, SID, sizeof(SID)); + + if (StrEqual(info, "ZEUS Tracers [25000 Tokens]", true)) + { + if (i_points[client] >= 25000 && (StrContains(c_storestats[client], "k") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "k"); + i_points[client] -= 25000; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased ZEUS Tracers for 25000 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server to use !tracers to select feature!"); + } + else if (StrContains(c_storestats[client], "k") >= 0) + { + PrintToChat(client, "You already purchased ZEUS tracers!"); + } + else if (i_points[client] <= 25000) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Yellow Tracers [7500 Tokens]")) + { + if (i_points[client] >= 7500 && (StrContains(c_storestats[client], "§") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "§"); + i_points[client] -= 7500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Yellow Tracers for 7500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server to use !tracers to select feature!"); + } + else if (StrContains(c_storestats[client], "§") >= 0) + { + PrintToChat(client, "You already purchased Yellow tracers!"); + } + else if (i_points[client] <= 7500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Blue Tracers [7500 Tokens]")) + { + if (i_points[client] >= 7500 && (StrContains(c_storestats[client], "@") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "@"); + i_points[client] -= 7500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Blue Tracers for 7500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server to use !tracers to select feature!"); + } + else if (StrContains(c_storestats[client], "@") >= 0) + { + PrintToChat(client, "You already purchased Blue tracers!"); + } + else if (i_points[client] <= 7500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Green Tracers [7500 Tokens]")) + { + if (i_points[client] >= 7500 && (StrContains(c_storestats[client], "£") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "£"); + i_points[client] -= 7500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Green Tracers for 7500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server to use !tracers to select feature!"); + } + else if (StrContains(c_storestats[client], "£") >= 0) + { + PrintToChat(client, "You already purchased Green tracers!"); + } + else if (i_points[client] <= 7500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Red Tracers [7500 Tokens]")) + { + if (i_points[client] >= 7500 && (StrContains(c_storestats[client], "$") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "$"); + i_points[client] -= 7500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Red Tracers for 7500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server to use !tracers to select feature!"); + } + else if (StrContains(c_storestats[client], "$") >= 0) + { + PrintToChat(client, "You already purchased Red tracers!"); + } + else if (i_points[client] <= 7500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Gold Tracers [7500 Tokens]")) + { + if (i_points[client] >= 7500 && (StrContains(c_storestats[client], "€") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "€"); + i_points[client] -= 7500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Gold Tracers for 7500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server to use !tracers to select feature!"); + } + else if (StrContains(c_storestats[client], "€") >= 0) + { + PrintToChat(client, "You already purchased Gold tracers!"); + } + else if (i_points[client] <= 7500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Cyan Tracers [7500 Tokens]")) + { + if (i_points[client] >= 7500 && (StrContains(c_storestats[client], "(") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "("); + i_points[client] -= 7500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Cyan Tracers for 7500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server to use !tracers to select feature!"); + } + else if (StrContains(c_storestats[client], "(") >= 0) + { + PrintToChat(client, "You already purchased Cyan tracers!"); + } + else if (i_points[client] <= 7500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Back", true)) + { + cmd_shopmenu(client, 0); + } + } + return -1; +} + + +public int BeamMenu_Handler(Menu menu, MenuAction action, int client, int choice) +{ + if (action == MenuAction_Select) + { + char purchaseEntry[64]; + char info[32]; + menu.GetItem(choice, info, sizeof(info)); + + if (StrEqual(info, "Back", true)) + { + cmd_shopmenu(client, 0); + } + else if (StrEqual(info, "Blue beam [1500 Tokens]")) + { + if (i_points[client] >= 1500 && (StrContains(c_storestats[client], "v") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "v"); + i_points[client] -= 1500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Blue beamers for 1500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server and use !beams to enable/disable!"); + } + else if (StrContains(c_storestats[client], "v") >= 0) + { + PrintToChat(client, "You already purchased Blue Beamers!"); + } + else if (i_points[client] <= 1500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Green beam [1500 Tokens]")) + { + if (i_points[client] >= 1500 && (StrContains(c_storestats[client], "x") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "x"); + i_points[client] -= 1500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Green beamers for 1500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server and use !beams to enable/disable!"); + } + else if (StrContains(c_storestats[client], "x") >= 0) + { + PrintToChat(client, "You already purchased Green Beamers!"); + } + else if (i_points[client] <= 1500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Red beam [1500 Tokens]")) + { + if (i_points[client] >= 1500 && (StrContains(c_storestats[client], "y") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "y"); + i_points[client] -= 1500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Red beamers for 1500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server and use !beams to enable/disable!"); + } + else if (StrContains(c_storestats[client], "y") >= 0) + { + PrintToChat(client, "You already purchased Red Beamers!"); + } + else if (i_points[client] <= 1500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Gold beam [1500 Tokens]")) + { + if (i_points[client] >= 1500 && (StrContains(c_storestats[client], "z") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "z"); + i_points[client] -= 1500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Gold beamers for 1500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server and use !beams to enable/disable!"); + } + else if (StrContains(c_storestats[client], "z") >= 0) + { + PrintToChat(client, "You already purchased Gold Beamers!"); + } + else if (i_points[client] <= 1500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Black beam [1500 Tokens]")) + { + if (i_points[client] >= 1500 && (StrContains(c_storestats[client], "3") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "3"); + i_points[client] -= 1500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Black beamers for 1500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server and use !beams to enable/disable!"); + } + else if (StrContains(c_storestats[client], "3") >= 0) + { + PrintToChat(client, "You already purchased Black Beamers!"); + } + else if (i_points[client] <= 1500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Cyan beam [1500 Tokens]")) + { + if (i_points[client] >= 1500 && (StrContains(c_storestats[client], "4") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "4"); + i_points[client] -= 1500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Cyan beamers for 1500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server and use !beams to enable/disable!"); + } + else if (StrContains(c_storestats[client], "4") >= 0) + { + PrintToChat(client, "You already purchased Cyan Beamers!"); + } + else if (i_points[client] <= 1500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Turquoise beam [1500 Tokens]")) + { + if (i_points[client] >= 1500 && (StrContains(c_storestats[client], "5") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "5"); + i_points[client] -= 1500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Turquoise beamers for 1500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server and use !beams to enable/disable!"); + } + else if (StrContains(c_storestats[client], "5") >= 0) + { + PrintToChat(client, "You already purchased Turquoise Beamers!"); + } + else if (i_points[client] <= 1500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Yellow beam [1500 Tokens]")) + { + if (i_points[client] >= 1500 && (StrContains(c_storestats[client], "6") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "6"); + i_points[client] -= 1500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Yellow beamers for 1500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server and use !beams to enable/disable!"); + } + else if (StrContains(c_storestats[client], "6") >= 0) + { + PrintToChat(client, "You already purchased Yellow Beamers!"); + } + else if (i_points[client] <= 1500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Pink beam [1500 Tokens]")) + { + if (i_points[client] >= 1500 && (StrContains(c_storestats[client], "7") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "7"); + i_points[client] -= 1500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Pink beamers for 1500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server and use !beams to enable/disable!"); + } + else if (StrContains(c_storestats[client], "7") >= 0) + { + PrintToChat(client, "You already purchased Pink Beamers!"); + } + else if (i_points[client] <= 1500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Purple beam [1500 Tokens]")) + { + if (i_points[client] >= 1500 && (StrContains(c_storestats[client], "8") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "8"); + i_points[client] -= 1500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Purple beamers for 1500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server and use !beams to enable/disable!"); + } + else if (StrContains(c_storestats[client], "8") >= 0) + { + PrintToChat(client, "You already purchased Purple Beamers!"); + } + else if (i_points[client] <= 1500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "gray beam [1500 Tokens]")) + { + if (i_points[client] >= 1500 && (StrContains(c_storestats[client], "9") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "9"); + i_points[client] -= 1500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased gray beamers for 1500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server and use !beams to enable/disable!"); + } + else if (StrContains(c_storestats[client], "9") >= 0) + { + PrintToChat(client, "You already purchased gray Beamers!"); + } + else if (i_points[client] <= 1500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Rainbow beam [15500 Tokens]")) + { + if (i_points[client] >= 15500 && (StrContains(c_storestats[client], "w") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "w"); + i_points[client] -= 15500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Rainbow beamers for 15500 UNLOZE tokens!"); + PrintToChat(client, "Rejoin the server and use !beams to enable/disable!"); + } + else if (StrContains(c_storestats[client], "w") >= 0) + { + PrintToChat(client, "You already purchased Rainbow Beamers!"); + } + else if (i_points[client] <= 15500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + } +} + +public int ChatTagsMenu_Handler(Menu menu, MenuAction action, int client, int choice) +{ + if (action == MenuAction_Select) + { + char purchaseEntry[64]; + char info[32]; + menu.GetItem(choice, info, sizeof(info)); + + if (StrEqual(info, "Rookie [1500 Tokens]", true)) + { + if (i_points[client] >= 1500 && (StrContains(c_storestats[client], "l") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "l"); + i_points[client] -= 1500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Rookie Tag for 1500 UNLOZE tokens!"); + PrintToChat(client, "Reconnect to the server to use !tokentag!"); + } + else if (StrContains(c_storestats[client], "l") >= 0) + { + PrintToChat(client, "You already purchased Rookie Tag! Use !tokentag to select your tag!"); + } + else if (i_points[client] <= 1500) + { + PrintToChat(client, "You only have %i UNLOZE tokens, your legit broke nigga", i_points[client]); + } + } + else if (StrEqual(info, "Member [2400 Tokens]", true)) + { + if (i_points[client] >= 2400 && (StrContains(c_storestats[client], "m") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "m"); + i_points[client] -= 2400; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased MEMBER Tag for 2400 UNLOZE tokens!"); + PrintToChat(client, "Reconnect to the server to use !tokentag!"); + } + else if (StrContains(c_storestats[client], "m") >= 0) + { + PrintToChat(client, "You already purchased MEMBER Tag! Use !tokentag to select your tag!"); + } + else if (i_points[client] <= 2400) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "SERBIAN [5000 Tokens]", true)) + { + if (i_points[client] >= 5000 && (StrContains(c_storestats[client], "n") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "n"); + i_points[client] -= 5000; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased SERBIAN Tag for 5000 UNLOZE tokens!"); + PrintToChat(client, "Reconnect to the server to use !tokentag!"); + } + else if (StrContains(c_storestats[client], "n") >= 0) + { + PrintToChat(client, "You already purchased SERBIAN Tag! Use !tokentag to select your tag!"); + } + else if (i_points[client] <= 5000) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Overweight Vegetarian [3000 Tokens]", true)) + { + if (i_points[client] >= 3000 && (StrContains(c_storestats[client], "o") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "o"); + i_points[client] -= 3000; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Overweight Vegetarian Tag for 3000 UNLOZE tokens!"); + PrintToChat(client, "Reconnect to the server to use !tokentag!"); + } + else if (StrContains(c_storestats[client], "o") >= 0) + { + PrintToChat(client, "You already purchased Overweight Vegetarian Tag! Use !tokentag to select your tag!"); + } + else if (i_points[client] <= 3000) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "русский [3800 Tokens]", true)) + { + if (i_points[client] >= 3800 && (StrContains(c_storestats[client], "p") < 0)) + { + Format(purchaseEntry, sizeof(purchaseEntry), "p"); + i_points[client] -= 3800; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased русский Tag for 3800 UNLOZE tokens!"); + PrintToChat(client, "Reconnect to the server to use !tokentag!"); + } + else if (StrContains(c_storestats[client], "p") >= 0) + { + PrintToChat(client, "You already purchased русский Tag! Use !tokentag to select your tag!"); + } + else if (i_points[client] <= 3800) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "NIGGER elites [11377 Tokens]", true)) + { + if (i_points[client] >= 11377 && (StrContains(c_storestats[client], "q") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "q"); + i_points[client] -= 11377; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased NIGGER elites Tag for 11377 UNLOZE tokens!"); + PrintToChat(client, "Reconnect to the server to use !tokentag!"); + } + else if (StrContains(c_storestats[client], "q") >= 0) + { + PrintToChat(client, "You already purchased NIGGER elites Tag! Use !tokentag to select your tag!"); + } + else if (i_points[client] <= 11377) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "BAGUETTE [7000 Tokens]", true)) + { + if (i_points[client] >= 7000 && (StrContains(c_storestats[client], "r") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "r"); + i_points[client] -= 7000; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased BAGUETTE Tag for 7000 UNLOZE tokens!"); + PrintToChat(client, "Reconnect to the server to use !tokentag!"); + } + else if (StrContains(c_storestats[client], "r") >= 0) + { + PrintToChat(client, "You already purchased BAGUETTE Tag! Use !tokentag to select your tag!"); + } + else if (i_points[client] <= 7000) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "DANE [15000 Tokens]", true)) + { + if (i_points[client] >= 15000 && (StrContains(c_storestats[client], "s") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "s"); + i_points[client] -= 15000; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased DANE Tag for 15000 UNLOZE tokens!"); + PrintToChat(client, "Reconnect to the server to use !tokentag!"); + } + else if (StrContains(c_storestats[client], "s") >= 0) + { + PrintToChat(client, "You already purchased DANE Tag! Use !tokentag to select your tag!"); + } + else if (i_points[client] <= 15000) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "WEEB [6000 Tokens]", true)) + { + if (i_points[client] >= 6000 && (StrContains(c_storestats[client], "t") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "t"); + i_points[client] -= 6000; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased WEEB Tag for 6000 UNLOZE tokens!"); + PrintToChat(client, "Reconnect to the server to use !tokentag!"); + } + else if (StrContains(c_storestats[client], "t") >= 0) + { + PrintToChat(client, "You already purchased WEEB Tag! Use !tokentag to select your tag!"); + } + else if (i_points[client] <= 6000) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Nosteam Chad [20000 Tokens]", true)) + { + if (i_points[client] >= 20000 && (StrContains(c_storestats[client], "u") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "u"); + i_points[client] -= 20000; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Nosteam Chad Tag for 20000 UNLOZE tokens!"); + PrintToChat(client, "Reconnect to the server to use !tokentag!"); + } + else if (StrContains(c_storestats[client], "u") >= 0) + { + PrintToChat(client, "You already purchased Nosteam Chad Tag! Use !tokentag to select your tag!"); + } + else if (i_points[client] <= 20000) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Back", true)) + { + cmd_shopmenu(client, 0); + } + } + return -1; +} + +public int PaintMenu_Handler(Menu menu, MenuAction action, int client, int choice) +{ + if (action == MenuAction_Select) + { + char purchaseEntry [64]; + char info[32]; + menu.GetItem(choice, info, sizeof(info)); + + + if (StrEqual(info, "Unlock size [4500 Tokens]", true)) + { + if (i_points[client] >= 4500 && (StrContains(c_storestats[client], "b") < 0)) + { + //this one does thank god not need an group on sourceban + strcopy(purchaseEntry, sizeof(purchaseEntry), "b"); + i_points[client] -= 4500; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased Paintsize feature for 4500 UNLOZE tokens!"); + PrintToChat(client, "use !paintsize to change paint size!"); + } + else if (StrContains(c_storestats[client], "b") >= 0) + { + PrintToChat(client, "You already purchased Paintsize!"); + } + else if (i_points[client] <= 4500) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Unlock paint [4000 Tokens]", true)) + { + if (i_points[client] >= 4000 && (StrContains(c_storestats[client], "d") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "d"); + i_points[client] -= 4000; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased paint feature for 4000 UNLOZE tokens!"); + PrintToChat(client, "Reconnect to the server and use !paint to enable the feature!"); + } + else if (StrContains(c_storestats[client], "d") >= 0) + { + PrintToChat(client, "You already purchased the paint feature!"); + } + else if (i_points[client] <= 4000) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Unlock colour [5000 Tokens]", true)) + { + if (i_points[client] >= 5000 && (StrContains(c_storestats[client], "e") < 0)) + { + strcopy(purchaseEntry, sizeof(purchaseEntry), "e"); + i_points[client] -= 5000; + sendMYSQL(client); + storeEntryMYSQL(client, purchaseEntry); + PrintToChat(client, "Purchased paintcolour feature for 5000 UNLOZE tokens!"); + PrintToChat(client, "Reconnect to the server and use !paintcolour to enable the feature!"); + } + else if (StrContains(c_storestats[client], "e") >= 0) + { + PrintToChat(client, "You already purchased the paintcolour feature!"); + } + else if (i_points[client] <= 5000) + { + PrintToChat(client, "You only have %i UNLOZE tokens", i_points[client]); + } + } + else if (StrEqual(info, "Back", true)) + { + cmd_shopmenu(client, 0); + } + } + return -1; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: verifications onmapstart/end/disconnect/connect/auth +//---------------------------------------------------------------------------------------------------- + +public void OnMapStart() +{ + DeleteAll(g_kZoneStats); + DeleteAll(g_kZoneStats); +} + +public void OnMapEnd() +{ + DeleteAll(g_kZoneStats); + DeleteAll(g_kZoneStats); +} + +public void OnClientDisconnect(int iClient) +{ + f_2kdmgPoints[iClient] = 0.0; + if (!IsFakeClient(iClient)) + { + f_tokenscaler -= 100.0; + } + Format(c_storestats[iClient], sizeof(c_storestats), ""); + i_points[iClient] = 0; + g_iclientSpawn[iClient] = 0; + g_bClientFilter[iClient] = false; + g_bDmgScale[iClient] = false; + g_bDmgOutput[iClient] = false; + g_iClientScore[iClient] = 0; + i_bDmgScale[iClient] = 0.0; +} + +public void OnClientPostAdminCheck(int client) +{ + f_2kdmgPoints[client] = 0.0; + if (!IsFakeClient(client) && f_tokenscaler < 2000.0) + { + f_tokenscaler += 100.0; + } + i_points[client] = 0; + CreateTimer(2.0, points_delay, client, TIMER_FLAG_NO_MAPCHANGE); +} + +public Action points_delay(Handle timer, int client) +{ + receiveMYSQL(client); +} + +public Action roundsettings(Handle timer, any data) +{ + for (int i = 1; i < MaxClients; i++) + { + if (IsValidClient(i)) + { + g_kZoneStats.Rewind(); + static char SID[32]; + GetClientAuthId(i, AuthId_Steam2, SID, sizeof(SID)); + if (KvJumpToKey(g_kZoneStats, SID, false)) + { + int disabled = g_kZoneStats.GetNum("disabled", 0); + if (!disabled) + { + return; + } + i_bDmgScale[i] = disabled * 1.0; + g_iclientSpawn[i] = disabled * 10; + g_iClientScore[i] = disabled * 25; + g_bDmgScale[i] = true; + SetEntityHealth(i, GetClientHealth(i) + g_iclientSpawn[i]); + SetEntProp(i, Prop_Data, "m_iFrags", g_iClientScore[i]); + } + g_bClientFilter[i] = false; + } + } +} + +public void OnClientPostAdminFilter(int i) +{ + if (StrContains(c_storestats[i], "1") >= 0) + { + if (CheckCommandAccess(i, "sm_store_vip", ADMFLAG_CUSTOM1)) + AdminGroups_GrantAdminGroup(i, "Token-4-VIP"); + else + AdminGroups_GrantAdminGroup(i, "Token-4"); + } + if (StrContains(c_storestats[i], "a") >= 0) + { + if (CheckCommandAccess(i, "sm_store_vip", ADMFLAG_CUSTOM1)) + AdminGroups_GrantAdminGroup(i, "Token-1-VIP"); + else + AdminGroups_GrantAdminGroup(i, "Token-1"); + } + if (StrContains(c_storestats[i], "2") >= 0) + { + if (CheckCommandAccess(i, "sm_store_vip", ADMFLAG_CUSTOM1)) + AdminGroups_GrantAdminGroup(i, "Token-5-VIP"); + else + AdminGroups_GrantAdminGroup(i, "Token-5"); + } + if (StrContains(c_storestats[i], "c") >= 0) + { + if (CheckCommandAccess(i, "sm_store_vip", ADMFLAG_CUSTOM1)) + AdminGroups_GrantAdminGroup(i, "Token-3-VIP"); + else + AdminGroups_GrantAdminGroup(i, "Token-3"); + } + if (StrContains(c_storestats[i], "f") >= 0) + { + if (CheckCommandAccess(i, "sm_store_vip", ADMFLAG_CUSTOM1)) + AdminGroups_GrantAdminGroup(i, "Token-6-VIP"); + else + AdminGroups_GrantAdminGroup(i, "Token-6"); + } + if (StrContains(c_storestats[i], "g") >= 0) + { + if (CheckCommandAccess(i, "sm_store_vip", ADMFLAG_CUSTOM1)) + AdminGroups_GrantAdminGroup(i, "Token-7-VIP"); + else + AdminGroups_GrantAdminGroup(i, "Token-7"); + } + if (StrContains(c_storestats[i], "h") >= 0) + { + if (CheckCommandAccess(i, "sm_store_vip", ADMFLAG_CUSTOM1)) + AdminGroups_GrantAdminGroup(i, "Token-8-VIP"); + else + AdminGroups_GrantAdminGroup(i, "Token-8"); + } + if (StrContains(c_storestats[i], "i") >= 0) + { + if (CheckCommandAccess(i, "sm_store_vip", ADMFLAG_CUSTOM1)) + AdminGroups_GrantAdminGroup(i, "Token-9-VIP"); + else + AdminGroups_GrantAdminGroup(i, "Token-9"); + } + if (StrContains(c_storestats[i], "j") >= 0) + { + if (CheckCommandAccess(i, "sm_store_vip", ADMFLAG_CUSTOM1)) + AdminGroups_GrantAdminGroup(i, "Token-2-VIP"); + else + AdminGroups_GrantAdminGroup(i, "Token-2"); + } +} + +public void OnClientAuthorized(int client, const char[] auth) +{ + if (!IsFakeClient(client)) + { + //does not take time should be do able in postadmincheck + CheckFlagsMYSQL(client); + + g_kZoneStats.Rewind(); + if (KvJumpToKey(g_kZoneStats, auth, false)) + { + int disabled = g_kZoneStats.GetNum("disabled", 0); + if (!disabled) + { + return; + } + i_bDmgScale[client] = disabled * 1.0; + g_iclientSpawn[client] = disabled * 10; + g_iClientScore[client] = disabled * 25; + g_bDmgScale[client] = true; + } + } +} + +public OnClientPutInServer(int client) +{ + SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamagePre); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: zones +//---------------------------------------------------------------------------------------------------- +//Zone_OnClientEntry +//void unloze_zoneEntry +public void unloze_zoneEntry(int client, char[] zone) +{ + if (IsValidClient(client) && (GetClientTeam(client) == 3)) + { + if (StrContains(zone, "ZONE_PREFIX_CT", false) >= 0) + { + //add filter on player + //PrintToChatAll("ZoneRewards: zone: %s", zone); + g_bClientFilter[client] = true; + return; + } + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: hooks +//---------------------------------------------------------------------------------------------------- + +public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast) +{ + CreateTimer(5.0, roundsettings, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE); + + //check if under 8 players, if so we assign 4x value + f_tokenscaler = 0.0; + for (int i = 0; i < MaxClients; i++) + { + if (i > 0 && i <= MaxClients && IsClientInGame(i) && !IsFakeClient(i)) + { + f_tokenscaler += 100.0; + } + } + if (f_tokenscaler > 2000.0) + { + f_tokenscaler = 2000.0; + } +} + + +public void Event_RoundEnd(Handle event, const char[] name, bool dontBroadcast) +{ + int winner = GetEventInt(event, "winner"); + int g_iWinnerAmount = 0; + + if ((winner == 3)) + { + for (int i = 0; i < MaxClients; i++) + { + if(IsValidClient(i) && g_bClientFilter[i]) //put filter here + { + g_iWinnerAmount += 1; + int extrahealth = 10; + int extraScore = 25 + ((GetClientFrags(i)) - g_iClientScore[i]); + g_iclientSpawn[i] += extrahealth; + + i_bDmgScale[i] += 1.0; + g_bDmgScale[i] = true; + + //kills + GetClientFrags(iClient) + g_iClientScore[i] += extraScore; + i_points[i] += 20; + sendMYSQL(i); + PrintToChat(i, "Won stage. Upgraded Stats!"); + PrintToChat(i, "Health: %i", g_iclientSpawn[i]); + //PrintToChat(i, "Damage: %f", i_bDmgScale{i} * 7.0); + PrintToChat(i, "Clientscore: %i", g_iClientScore[i]); + PrintToChat(i, "Earned 20 Unloze Tokens! Your amount: %i", i_points[i]); + + static char SID[32]; + GetClientAuthId(i, AuthId_Steam2, SID, sizeof(SID)); + + g_kZoneStats.Rewind(); + + if(g_kZoneStats.JumpToKey(SID, true)) + { + int disabled = g_kZoneStats.GetNum("disabled", 0); + if(!disabled) + { + g_kZoneStats.SetNum("disabled", 1); + } + else if (disabled == 1) + { + g_kZoneStats.SetNum("disabled", 2); + } + else if (disabled == 2) + { + g_kZoneStats.SetNum("disabled", 3); + } + else if (disabled == 3) + { + g_kZoneStats.SetNum("disabled", 4); + } + else if (disabled == 4) + { + g_kZoneStats.SetNum("disabled", 5); + } + else if (disabled == 5) + { + g_kZoneStats.SetNum("disabled", 6); + } + else if (disabled == 6) + { + g_kZoneStats.SetNum("disabled", 7); + } + else if (disabled == 7) + { + g_kZoneStats.SetNum("disabled", 8); + } + else if (disabled == 8) + { + g_kZoneStats.SetNum("disabled", 9); + } + else if (disabled == 9) + { + g_kZoneStats.SetNum("disabled", 10); + } + else if (disabled == 10) + { + g_kZoneStats.SetNum("disabled", 11); + } + + g_kZoneStats.Rewind(); + g_kZoneStats.ExportToFile(g_sKVPATH); + } + } + } + + + for (int i = 0; i < MaxClients; i++) + { + if (IsValidClient(i) && g_bClientFilter[i] && g_iWinnerAmount < 2) + { + PrintToChatAll("Solo Won stage. Upgraded Stats and extra points added %i", GetConVarInt(G_hCvar_Points_Humans)); + //PrintToChatAll("g_iWinnerAmount: %d", g_iWinnerAmount); + char sAuthID[64]; + i_points[i] += 60; + sendMYSQL(i); + PrintToChatAll("%N Earned 60 Unloze Tokens for solo win! Their amount: %i", i, i_points[i]); + if (!GetClientAuthId(i, AuthId_Steam2, sAuthID, sizeof(sAuthID))) + { + Format(sAuthID, sizeof(sAuthID), "UNKNOWN"); + } + LogToGame("\"%N<%d><%s><%s>\" triggered \"human_win_%i\"", i, GetClientUserId(i), sAuthID, "CT", GetConVarInt(G_hCvar_Points_Humans)); + } + else if (IsValidClient(i) && g_bClientFilter[i] && g_iWinnerAmount < 3) + { + PrintToChatAll("Duo Won stage. Upgraded Stats and extra points added %i", GetConVarInt(G_hCvar_Points_Humans)); + //PrintToChatAll("g_iWinnerAmount: %d", g_iWinnerAmount); + char sAuthID[64]; + i_points[i] += 35; + sendMYSQL(i); + PrintToChatAll("%N Earned 35 Unloze Tokens for Duo win! Their amount: %i", i, i_points[i]); + if (!GetClientAuthId(i, AuthId_Steam2, sAuthID, sizeof(sAuthID))) + { + Format(sAuthID, sizeof(sAuthID), "UNKNOWN"); + } + LogToGame("\"%N<%d><%s><%s>\" triggered \"human_win_%i\"", i, GetClientUserId(i), sAuthID, "CT", GetConVarInt(G_hCvar_Points_Humans) / 2); + } + else if (IsValidClient(i) && g_bClientFilter[i] && g_iWinnerAmount < 4) + { + PrintToChatAll("Trio Won stage. Upgraded Stats and extra points added %i", GetConVarInt(G_hCvar_Points_Humans)); + //PrintToChatAll("g_iWinnerAmount: %d", g_iWinnerAmount); + char sAuthID[64]; + i_points[i] += 20; + sendMYSQL(i); + PrintToChatAll("%N Earned 20 Unloze Tokens for Duo win! Their amount: %i", i, i_points[i]); + if (!GetClientAuthId(i, AuthId_Steam2, sAuthID, sizeof(sAuthID))) + { + Format(sAuthID, sizeof(sAuthID), "UNKNOWN"); + } + LogToGame("\"%N<%d><%s><%s>\" triggered \"human_win_%i\"", i, GetClientUserId(i), sAuthID, "CT", GetConVarInt(G_hCvar_Points_Humans) / 3); + } + } + g_iWinnerAmount = 0; + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: damageHook +//---------------------------------------------------------------------------------------------------- + +public Action OnTakeDamagePre(victim, &attacker, &inflictor, &Float:damage, &damagetype) +{ + if(IsValidClient(attacker) && IsValidClient(victim)) + { + if (victim > 0 && attacker <= MAXPLAYERS && GetClientTeam(victim) != GetClientTeam(attacker)) + { + if (f_2kdmgPoints[attacker] >= f_tokenscaler) + { + f_2kdmgPoints[attacker] = 0.0; + PrintToChat(attacker, "You earned 1 UNLOZE token for %f Damage on Zombies!", f_tokenscaler); + i_points[attacker] += 1; + sendMYSQL(attacker); + } + if (g_bDmgScale[attacker]) + { + if (g_bDmgOutput[attacker]) + { + PrintToChat(attacker, "Client %N ORIGINAL Damage: %f", attacker, damage); + } + damage += i_bDmgScale[attacker] * 7.0; + f_2kdmgPoints[attacker] += damage; + if (g_bDmgOutput[attacker]) + { + PrintToChat(attacker, "Client %N POST Damage: %f", attacker, damage); + PrintToChat(attacker, "Client %N i_bDmgScale: %i", attacker, i_bDmgScale[attacker]); + } + return Plugin_Changed; + } + else + { + f_2kdmgPoints[attacker] += damage; + return Plugin_Changed; + } + } + } + return Plugin_Continue; +} + + //---------------------------------------------------------------------------------------------------- +// Purpose: stock & clean keyvalues just MISC +//---------------------------------------------------------------------------------------------------- + +stock bool IsValidClient(int client) +{ + if (client > 0 && client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client) && IsPlayerAlive(client)) + { + return true; + } + return false; +} + +stock bool IsValidClient1(int client) +{ + if (client > 0 && client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client)) + { + return true; + } + return false; +} + +public void DeleteAll (KeyValues kv) +{ + kv.Rewind(); + if (kv.GotoFirstSubKey()) + { + //PrintToChatAll("Reached first subkey"); + kv.DeleteThis(); + while (KvGotoNextKey(kv)) + { + kv.DeleteThis(); + //PrintToChatAll("Deletes something?"); + } + kv.DeleteThis(); + } + kv.Rewind(); + kv.ExportToFile(g_sKVPATH); + //PrintToChatAll("End?"); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: MYSQL queries +//---------------------------------------------------------------------------------------------------- + +public void SQL_StartConnection() +{ + char error[255]; + Database db; + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + //create tables + char sQuery[255]; + Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `unloze_zonepoints` (`steam_id` VARCHAR(254) NOT NULL, `points` VARCHAR(254) NOT NULL, `storestats` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_id`))"); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + + delete db; +} + + +public void receiveMYSQL(int client) +{ + if (IsValidClient1(client)) + { + char error[255]; + Database db; + //the points not related to hlstats are stored together with tracer prefferences but have + //their own table + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "SELECT points FROM `unloze_zonepoints`WHERE `steam_id` = '%s'", sSID); + + DBResultSet rs; + + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + return; + } + + if (rs.RowCount > 0 && rs.FetchRow()) + { + char points[512]; + SQL_FetchString(rs, 0, points, sizeof(points)); + i_points[client] = StringToInt(points); + //PrintToChat(client, "Fetched row!"); + //PrintToChat(client, "%i", i_points[client]); + } + delete rs; + delete db; + } +} + +public void sendMYSQL(int client) +{ + if (IsValidClient1(client)) + { + char error[255]; + Database db; + //the points not related to hlstats are stored together with tracer prefferences but have + //their own table + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "INSERT INTO `unloze_zonepoints` (`steam_id`,`points`) VALUES ('%s','%i') ON DUPLICATE KEY UPDATE `points` = '%i'", sSID, i_points[client], i_points[client]); + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete db; + } +} + + +public Action storeEntryMYSQL(int client, char[] purchaseEntry) +{ + //without delay it seems to cause crashes + Handle h_Datapack; + CreateDataTimer(1.0, storestats_delay, h_Datapack); + WritePackCell(h_Datapack, client); + WritePackString(h_Datapack, purchaseEntry); +} + +public Action storestats_delay(Handle timer, Handle h_Datapack) +{ + int client; + char purchaseEntry[128]; + ResetPack(h_Datapack); + client = ReadPackCell(h_Datapack); + ReadPackString(h_Datapack, purchaseEntry, sizeof(purchaseEntry)); + + char error[255]; + Database db; + //the points not related to hlstats are stored together with tracer prefferences but have + //their own table + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return Plugin_Handled; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + //predefined statements cant be corrupted since players dont know the char of each item + Format(sQuery, sizeof(sQuery), "UPDATE unloze_zonepoints SET storestats = CONCAT(storestats, '%s') WHERE `steam_id` = '%s'", purchaseEntry, sSID); + DBResultSet rs; + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + return Plugin_Handled; + } + SQL_TQuery(db, DummyCallbackSimple, sQuery); + delete rs; + delete db; + StrCat(c_storestats[client], sizeof(c_storestats), purchaseEntry); + return Plugin_Handled; +} + +public void CheckFlagsMYSQL(int client) +{ + char error[255]; + Database db; + //the points not related to hlstats are stored together with tracer prefferences but have + //their own table + if (SQL_CheckConfig("unloze_tracerpref")) + { + db = SQL_Connect("unloze_tracerpref", true, error, sizeof(error)); + } + if (db == null) + { + PrintToChat(client, "{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!"); + delete db; + return; + } + char sSID[64]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "SELECT storestats FROM `unloze_zonepoints` WHERE `steam_id` = '%s'", sSID); + + DBResultSet rs; + + if ((rs = SQL_Query(db, sQuery)) == null) + { + delete db; + delete rs; + return; + } + + if (rs.RowCount > 0 && rs.FetchRow()) + { + SQL_FetchString(rs, 0, c_storestats[client], sizeof(c_storestats)); + } + delete rs; + delete db; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: stock by zacade, stock by botox & MYSQL callback +//---------------------------------------------------------------------------------------------------- +stock void ApplyGroupFlags(int client, const char[] group) +{ + AdminId AdmID; + GroupId GrpID; + + if ((AdmID = GetUserAdmin(client)) == INVALID_ADMIN_ID) + { + //PrintToChatAll("Creating new user for %L", client); + + AdmID = CreateAdmin(""); + SetUserAdmin(client, AdmID, true); + } + + if ((GrpID = FindAdmGroup(group)) != INVALID_GROUP_ID) + { + if (AdminInheritGroup(AdmID, GrpID)) + { + //PrintToChat(client, "%L added to group %s", client, group); + } + } + else + { + //PrintToChatAll("%L group not found %s", client, group); + } +} + +public void DummyCallbackSimple(Handle hOwner, Handle hChild, const char[] err, DataPack pack1) +{ + if (hOwner == null || hChild == null) + { + LogError("Query error. (%s)", err); + } +} + +stock any clamp(any input, any min, any max) +{ + any retval = input < min ? min : input; + + return retval > max ? max : retval; +} \ No newline at end of file