Skip to content

Commit

Permalink
Warden: Glow #299
Browse files Browse the repository at this point in the history
sm_warden_glow_enable", "1", "0 - disabled, 1 - enable warden glow
  • Loading branch information
shanapu committed Jul 27, 2018
1 parent 2ea188f commit 2257167
Show file tree
Hide file tree
Showing 3 changed files with 253 additions and 5 deletions.
10 changes: 8 additions & 2 deletions addons/sourcemod/scripting/MyJailbreak/Modules/Warden/deputy.sp
Expand Up @@ -346,14 +346,18 @@ public void Deputy_Event_RoundStart(Event event, const char[] name, bool dontBro
Forward_OnDeputyRemoved(g_iDeputy);
g_iLastDeputy = g_iDeputy;
g_iDeputy = -1;

}
}
}

if (g_iDeputy != -1)
{
if (gc_bModelDeputy.BoolValue) SetEntityModel(g_iDeputy, g_sModelPathDeputy);
if (gc_bModelDeputy.BoolValue)
{
SetEntityModel(g_iDeputy, g_sModelPathDeputy);
}

Glow_OnDeputyCreation(g_iDeputy);
}
}

Expand Down Expand Up @@ -665,6 +669,7 @@ void Forward_OnDeputyCreated(int client)

Color_OnDeputyCreation(client);
HandCuffs_OnDeputyCreation(client);
Glow_OnDeputyCreation(client);
}

// Deputy was removed (will fire all time - *BySelf *ByAdmin *Death ...)
Expand All @@ -676,4 +681,5 @@ void Forward_OnDeputyRemoved(int client)

Color_OnDeputyRemoved(client);
HandCuffs_OnDeputyRemoved(client);
Glow_OnDeputyRemoved(client);
}
222 changes: 222 additions & 0 deletions addons/sourcemod/scripting/MyJailbreak/Modules/Warden/glow.sp
@@ -0,0 +1,222 @@
/*
* MyJailbreak - Warden - Glow Warden Module.
* by: shanapu
* https://github.com/shanapu/MyJailbreak/
*
* Copyright (C) 2018 Thomas Schmidt (shanapu)
*
* This file is part of the MyJailbreak 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 <http://www.gnu.org/licenses/>.
*/

/******************************************************************************
STARTUP
******************************************************************************/

// Includes
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>
#include <autoexecconfig>
#include <warden>
#include <myjbwarden>
#include <mystocks>

// Optional Plugins
#undef REQUIRE_PLUGIN
#include <CustomPlayerSkins>
#define REQUIRE_PLUGIN

// Compiler Options
#pragma semicolon 1
#pragma newdecls required

// Console Variables
ConVar gc_bGlow;
ConVar gc_iWardenGlowRed;
ConVar gc_iWardenGlowGreen;
ConVar gc_iWardenGlowBlue;
ConVar gc_iDeputyGlowRed;
ConVar gc_iDeputyGlowGreen;
ConVar gc_iDeputyGlowBlue;
ConVar gc_bWardenGlowRandom;

// Info
public void Glow_OnPluginStart()
{
// AutoExecConfig
gc_bGlow = AutoExecConfig_CreateConVar("sm_warden_glow_enable", "1", "0 - disabled, 1 - enable warden glow", _, true, 0.0, true, 1.0);
gc_bWardenGlowRandom = AutoExecConfig_CreateConVar("sm_warden_glow_random", "0", "0 - disabled, 1 - enable warden random glow everytime / ignores RGB values", _, true, 0.0, true, 1.0);
gc_iWardenGlowRed = AutoExecConfig_CreateConVar("sm_warden_glow_red", "0", "What glow to turn the warden into (set R, G and B values to 255 to disable) (Rgb): x - red value", _, true, 0.0, true, 255.0);
gc_iWardenGlowGreen = AutoExecConfig_CreateConVar("sm_warden_glow_green", "0", "What glow to turn the warden into (rGb): x - green value", _, true, 0.0, true, 255.0);
gc_iWardenGlowBlue = AutoExecConfig_CreateConVar("sm_warden_glow_blue", "255", "What glow to turn the warden into (rgB): x - blue value", _, true, 0.0, true, 255.0);
gc_iDeputyGlowRed = AutoExecConfig_CreateConVar("sm_warden_glow_red_deputy", "0", "What glow to turn the deputy into (set R, G and B values to 255 to disable) (Rgb): x - red value", _, true, 0.0, true, 255.0);
gc_iDeputyGlowGreen = AutoExecConfig_CreateConVar("sm_warden_glow_green_deputy", "155", "What glow to turn the deputy into (rGb): x - green value", _, true, 0.0, true, 255.0);
gc_iDeputyGlowBlue = AutoExecConfig_CreateConVar("sm_warden_glow_blue_deputy", "255", "What glow to turn the deputy into (rgB): x - blue value", _, true, 0.0, true, 255.0);
}

/******************************************************************************
FORWARDS LISTEN
******************************************************************************/

void Glow_OnWardenCreation(int client)
{
RequestFrame(NextFrame_WardenGlow, GetClientUserId(client));
}

void Glow_OnWardenRemoved(int client)
{
RequestFrame(NextFrame_WardenRemoveGlow, GetClientUserId(client));
}

void Glow_OnDeputyCreation(int client)
{
RequestFrame(NextFrame_WardenGlow, GetClientUserId(client));
}

void Glow_OnDeputyRemoved(int client)
{
RequestFrame(NextFrame_WardenRemoveGlow, GetClientUserId(client));
}

/******************************************************************************
TIMER
******************************************************************************/


void NextFrame_WardenGlow(int userid)
{
if (!gc_bPlugin.BoolValue || !gc_bGlow.BoolValue || !g_bEnabled || !gp_bCustomPlayerSkins)
return;

int client = GetClientOfUserId(userid);

if (!IsValidClient(client, true, false))
return;

if (!IsClientWarden(client) && !IsClientDeputy(client))
return;

SetupGlowSkin(client);
}

void NextFrame_WardenRemoveGlow(int userid)
{
if (!gc_bPlugin.BoolValue || !gc_bGlow.BoolValue || !g_bEnabled || !gp_bCustomPlayerSkins)
return;

int client = GetClientOfUserId(userid);

if (!IsValidClient(client, true, false))
return;

UnhookGlow(client);
}

// Perpare client for glow
void SetupGlowSkin(int client)
{
char sModel[PLATFORM_MAX_PATH];
GetClientModel(client, sModel, sizeof(sModel));

int iSkin = CPS_SetSkin(client, sModel, CPS_RENDER);
if (iSkin == -1)
return;

if (SDKHookEx(iSkin, SDKHook_SetTransmit, OnSetTransmit_GlowSkin))
{
GlowSkin(iSkin, client);
}
}

// set client glow
void GlowSkin(int iSkin, int client)
{
int iOffset;

if ((iOffset = GetEntSendPropOffs(iSkin, "m_clrGlow")) == -1)
return;

SetEntProp(iSkin, Prop_Send, "m_bShouldGlow", true, true);
SetEntProp(iSkin, Prop_Send, "m_nGlowStyle", 1);
SetEntPropFloat(iSkin, Prop_Send, "m_flGlowMaxDist", 10000000.0);

int iRed;
int iGreen;
int iBlue;

if (gc_bWardenGlowRandom.BoolValue)
{
int i = GetRandomInt(1, 7);
iRed = g_iColors[i][0];
iGreen = g_iColors[i][1];
iBlue = g_iColors[i][2];

}
else if (IsClientWarden(client))
{
iRed = gc_iWardenGlowRed.IntValue;
iGreen = gc_iWardenGlowGreen.IntValue;
iBlue = gc_iWardenGlowBlue.IntValue;
}
else
{
iRed = gc_iDeputyGlowRed.IntValue;
iGreen = gc_iDeputyGlowGreen.IntValue;
iBlue = gc_iDeputyGlowBlue.IntValue;
}

SetEntData(iSkin, iOffset, iRed, _, true);
SetEntData(iSkin, iOffset + 1, iGreen, _, true);
SetEntData(iSkin, iOffset + 2, iBlue, _, true);
SetEntData(iSkin, iOffset + 3, 255, _, true);
}

// Who can see the glow if vaild
public Action OnSetTransmit_GlowSkin(int iSkin, int client)
{
if (!IsPlayerAlive(client))
return Plugin_Handled;

for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i))
continue;

if (!CPS_HasSkin(i))
continue;

if (EntRefToEntIndex(CPS_GetSkin(i)) != iSkin)
continue;

return Plugin_Continue;
}

return Plugin_Handled;
}

// remove glow
void UnhookGlow(int client)
{
if (!IsValidClient(client, true, true))
return;

int iSkin = CPS_GetSkin(client);
if (iSkin == INVALID_ENT_REFERENCE)
return;

SetEntProp(iSkin, Prop_Send, "m_bShouldGlow", false, true);
SDKUnhook(iSkin, SDKHook_SetTransmit, OnSetTransmit_GlowSkin);
}
26 changes: 23 additions & 3 deletions addons/sourcemod/scripting/MyJailbreak/warden.sp
Expand Up @@ -48,6 +48,7 @@
#include <voiceannounce_ex>
#include <chat-processor>
#include <scp>
#include <CustomPlayerSkins>
#define REQUIRE_PLUGIN

#include <mystocks>
Expand Down Expand Up @@ -99,6 +100,7 @@ bool gp_bChatProcessor = false;
bool gp_bSimpleChatProcessor = false;
bool gp_bBasecomm = false;
bool gp_bSourceComms = false;
bool gp_bCustomPlayerSkins = false;

// Integers
int g_iCMDCoolDown[MAXPLAYERS+1] = 0;
Expand Down Expand Up @@ -174,6 +176,7 @@ char g_sRestrictedSound[32] = "buttons/button11.wav";
#include "MyJailbreak/Modules/Warden/orders.sp"
#include "MyJailbreak/Modules/Warden/freedays.sp"
#include "MyJailbreak/Modules/Warden/withheldLR.sp"
#include "MyJailbreak/Modules/Warden/glow.sp"

// Compiler Options
#pragma semicolon 1
Expand Down Expand Up @@ -262,6 +265,7 @@ public void OnPluginStart()
Orders_OnPluginStart();
Freedays_OnPluginStart();
NoLR_OnPluginStart();
Glow_OnPluginStart();

// AutoExecConfig
AutoExecConfig_ExecuteFile();
Expand Down Expand Up @@ -470,6 +474,7 @@ public void OnAllPluginsLoaded()
gp_bChatProcessor = LibraryExists("chat-processor");
gp_bBasecomm = LibraryExists("basecomm");
gp_bSourceComms = LibraryExists("sourcecomms");
gp_bCustomPlayerSkins = LibraryExists("CustomPlayerSkins");
}

public void OnLibraryRemoved(const char[] name)
Expand Down Expand Up @@ -506,6 +511,10 @@ public void OnLibraryRemoved(const char[] name)
{
gp_bSourceComms = false;
}
else if (StrEqual(name, "CustomPlayerSkins"))
{
gp_bCustomPlayerSkins = false;
}
}

public void OnLibraryAdded(const char[] name)
Expand Down Expand Up @@ -542,6 +551,10 @@ public void OnLibraryAdded(const char[] name)
{
gp_bSourceComms = true;
}
else if (StrEqual(name, "CustomPlayerSkins"))
{
gp_bCustomPlayerSkins = true;
}
}

/******************************************************************************
Expand Down Expand Up @@ -932,8 +945,13 @@ public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
}
else // stay warden
{
if (gc_bModel.BoolValue) SetEntityModel(g_iWarden, g_sModelPathWarden);
if (gc_bModel.BoolValue)
{
SetEntityModel(g_iWarden, g_sModelPathWarden);
}

SetLimit(g_iWarden, GetLimit(g_iWarden)+1);
Glow_OnWardenCreation(g_iWarden);
}
}

Expand Down Expand Up @@ -1244,7 +1262,7 @@ int GetLimit(int client)
int limit;

GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid));

if (!GetTrieValue(g_hLimit, steamid, limit))
{
limit = 0;
Expand Down Expand Up @@ -1297,7 +1315,7 @@ void CheckWardenCoolDowns()
SetCoolDown(i, 0);
}

CPrintToChatAll("%s %s", g_sPrefix, "The warden cooldown for all guards has been reseted");
CPrintToChatAll("%s %s", g_sPrefix, "The warden cooldown for all guards has been reseted"); //ToDo Translate
}

/******************************************************************************
Expand Down Expand Up @@ -1662,6 +1680,7 @@ void Forward_OnWardenRemoved(int client)
Laser_OnWardenRemoved(client);
Painter_OnWardenRemoved(client);
HandCuffs_OnWardenRemoved(client);
Glow_OnWardenRemoved(client);
}

// Warden was removed (will only fire on ByAdmin)
Expand Down Expand Up @@ -1705,4 +1724,5 @@ void OnWardenCreation(int client)
Color_OnWardenCreation(client);
Laser_OnWardenCreation(client);
HandCuffs_OnWardenCreation(client);
Glow_OnWardenCreation(client);
}

0 comments on commit 2257167

Please sign in to comment.