CCVar@ g_pHideChat;
CCVar@ g_pSilence;
CCVar@ g_pTrailSize;
CCVar@ g_pTrailDuration;
CCVar@ g_pTrailAlpha;
CScheduledFunction@ g_pThinkFunc = null;
dictionary g_PlayerTrails;
array<string> g_PlayerIDInfo;
int g_TrailSpriteIndex;
int oldTrailSize;
float oldTrailDuration;
int oldTrailAlpha;
void PluginInit()
{
g_Module.ScriptInfo.SetAuthor("Zode");
g_Module.ScriptInfo.SetContactInfo("Zodemon @ Svencoop forums");
g_Hooks.RegisterHook(Hooks::Player::ClientSay, @ClientSay);
g_Hooks.RegisterHook( Hooks::Player::ClientDisconnect, @ClientDisconnect );
@g_pHideChat = CCVar("hidechat", false, "Hide player chat when executing trail command", ConCommandFlag::AdminOnly);
@g_pSilence = CCVar("silence", false, "Silent plugin - only print to user instead of everybody", ConCommandFlag::AdminOnly);
@g_pTrailSize = CCVar("trailsize", 8, "(1-255) trail size", ConCommandFlag::AdminOnly);
@g_pTrailDuration = CCVar("trailduration", 4.0f, "(float 0.1-25.5) trail duration (in seconds)", ConCommandFlag::AdminOnly);
@g_pTrailAlpha = CCVar("trailalpha", 200, "(1-255) trail alpha", ConCommandFlag::AdminOnly);
}
void TrailSizeCheck()
{
if(g_pTrailSize.GetInt() <= 0)
{
g_pTrailSize.SetInt(1);
g_Game.AlertMessage( at_console, "Trail size cant be less than 1, setting cvar to 1");
}
if(g_pTrailSize.GetInt() > 255)
{
g_pTrailSize.SetInt(255);
g_Game.AlertMessage( at_console, "Trail size cant be more than 255, setting cvar to 255");
}
if(oldTrailSize != g_pTrailSize.GetInt())
{
resetTrails();
oldTrailSize = g_pTrailSize.GetInt();
}
}
void TrailDurationCheck()
{
if(g_pTrailDuration.GetFloat() <= 0.0f )
{
g_pTrailDuration.SetFloat(0.1f);
g_Game.AlertMessage( at_console, "Trail duration cant be less than 0.1, setting cvar to 0.1");
}
if(g_pTrailDuration.GetFloat() > 25.5f)
{
g_pTrailDuration.SetFloat(25.5f);
g_Game.AlertMessage( at_console, "Trail duration cant be more than 25.5, setting cvar to 25.5");
}
if(oldTrailDuration != g_pTrailDuration.GetFloat())
{
resetTrails();
oldTrailDuration = g_pTrailDuration.GetFloat();
}
}
void TrailAlphaCheck()
{
if(g_pTrailAlpha.GetInt() <= 0)
{
g_pTrailAlpha.SetInt(1);
g_Game.AlertMessage( at_console, "Trail alpha cant be less than 1, setting cvar to 1");
}
if(g_pTrailAlpha.GetInt() > 255)
{
g_pTrailAlpha.SetInt(255);
g_Game.AlertMessage( at_console, "Trail alpha cant be more than 255, setting cvar to 255");
}
if(oldTrailAlpha != g_pTrailAlpha.GetInt())
{
resetTrails();
oldTrailAlpha = g_pTrailAlpha.GetInt();
}
}
class PlayerTrailData
{
int id;
Vector color;
bool restart;
}
void MapInit()
{
g_TrailSpriteIndex = g_Game.PrecacheModel("sprites/zbeam3.spr");
g_PlayerTrails.deleteAll();
g_PlayerIDInfo.resize(0); // clear up array, thanks solokiller!
if(g_pThinkFunc !is null) { g_Scheduler.RemoveTimer(g_pThinkFunc); }
@g_pThinkFunc = g_Scheduler.SetInterval("trailThink", 0.3f);
//lmao couldnt figure out callbacks for ccvars
TrailSizeCheck();
TrailDurationCheck();
TrailAlphaCheck();
}
HookReturnCode ClientSay(SayParameters@ pParams)
{
CBasePlayer@ pPlayer = pParams.GetPlayer();
const CCommand@ pArguments = pParams.GetArguments();
bool bSilent = g_pSilence.GetBool();
int iTrailSize = g_pTrailSize.GetInt();
int iTrailDuration = int(g_pTrailDuration.GetFloat()*10);
int iTrailAlpha = g_pTrailAlpha.GetInt();
//lmao couldnt figure out callbacks for ccvars
TrailSizeCheck();
TrailDurationCheck();
TrailAlphaCheck();
if(pArguments.ArgC() >=2)
{
if(pArguments.Arg(0) == "trail")
{
pParams.ShouldHide = g_pHideChat.GetBool();
if(pArguments.Arg(1) == "off") // turn off trail
{
if(bSilent)
{
g_PlayerFuncs.ClientPrint(pPlayer, HUD_PRINTTALK, "[Trail] You no longer have a trail.");
}else{
g_PlayerFuncs.ClientPrintAll(HUD_PRINTTALK, "[Trail] " + pPlayer.pev.netname + " no longer has a trail.");
}
removeTrail(pPlayer);
}else{ // handle colors
// ewww elseif nest
if(pArguments.Arg(1) == "red")
{
if(bSilent)
{
g_PlayerFuncs.ClientPrint(pPlayer, HUD_PRINTTALK, "[Trail] You now have a red trail.");
}else{
g_PlayerFuncs.ClientPrintAll(HUD_PRINTTALK, "[Trail] " + pPlayer.pev.netname + " now has a red trail.");
}
addTrail(pPlayer, iTrailSize, iTrailDuration, iTrailAlpha, Vector(255,0,0));
}else if(pArguments.Arg(1) == "orange")
{
if(bSilent)
{
g_PlayerFuncs.ClientPrint(pPlayer, HUD_PRINTTALK, "[Trail] You now have an orange trail.");
}else{
g_PlayerFuncs.ClientPrintAll(HUD_PRINTTALK, "[Trail] " + pPlayer.pev.netname + " now has an orange trail.");
}
addTrail(pPlayer, iTrailSize, iTrailDuration, iTrailAlpha, Vector(255,128,0));
}else if(pArguments.Arg(1) == "yellow")
{
if(bSilent)
{
g_PlayerFuncs.ClientPrint(pPlayer, HUD_PRINTTALK, "[Trail] You now have an yellow trail.");
}else{
g_PlayerFuncs.ClientPrintAll(HUD_PRINTTALK, "[Trail] " + pPlayer.pev.netname + " now has an yellow trail.");
}
addTrail(pPlayer, iTrailSize, iTrailDuration, iTrailAlpha, Vector(255,255,0));
}else if(pArguments.Arg(1) == "lime")
{
if(bSilent)
{
g_PlayerFuncs.ClientPrint(pPlayer, HUD_PRINTTALK, "[Trail] You now have a lime trail.");
}else{
g_PlayerFuncs.ClientPrintAll(HUD_PRINTTALK, "[Trail] " + pPlayer.pev.netname + " now has a lime trail.");
}
addTrail(pPlayer, iTrailSize, iTrailDuration, iTrailAlpha, Vector(128,255,0));
}else if(pArguments.Arg(1) == "green")
{
if(bSilent)
{
g_PlayerFuncs.ClientPrint(pPlayer, HUD_PRINTTALK, "[Trail] You now have a green trail.");
}else{
g_PlayerFuncs.ClientPrintAll(HUD_PRINTTALK, "[Trail] " + pPlayer.pev.netname + " now has a green trail.");
}
addTrail(pPlayer, iTrailSize, iTrailDuration, iTrailAlpha, Vector(0,255,0));
}else if(pArguments.Arg(1) == "turquoise")
{
if(bSilent)
{
g_PlayerFuncs.ClientPrint(pPlayer, HUD_PRINTTALK, "[Trail] You now have a turquoise trail.");
}else{
g_PlayerFuncs.ClientPrintAll(HUD_PRINTTALK, "[Trail] " + pPlayer.pev.netname + " now has a turquoise trail.");
}
addTrail(pPlayer, iTrailSize, iTrailDuration, iTrailAlpha, Vector(0,255,200));
}else if(pArguments.Arg(1) == "cyan")
{
if(bSilent)
{
g_PlayerFuncs.ClientPrint(pPlayer, HUD_PRINTTALK, "[Trail] You now have a cyan trail.");
}else{
g_PlayerFuncs.ClientPrintAll(HUD_PRINTTALK, "[Trail] " + pPlayer.pev.netname + " now has a cyan trail.");
}
addTrail(pPlayer, iTrailSize, iTrailDuration, iTrailAlpha, Vector(0,128,255));
}else if(pArguments.Arg(1) == "blue")
{
if(bSilent)
{
g_PlayerFuncs.ClientPrint(pPlayer, HUD_PRINTTALK, "[Trail] You now have a blue trail.");
}else{
g_PlayerFuncs.ClientPrintAll(HUD_PRINTTALK, "[Trail] " + pPlayer.pev.netname + " now has a blue trail.");
}
addTrail(pPlayer, iTrailSize, iTrailDuration, iTrailAlpha, Vector(0,0,255));
}else if(pArguments.Arg(1) == "purple")
{
if(bSilent)
{
g_PlayerFuncs.ClientPrint(pPlayer, HUD_PRINTTALK, "[Trail] You now have a purple trail.");
}else{
g_PlayerFuncs.ClientPrintAll(HUD_PRINTTALK, "[Trail] " + pPlayer.pev.netname + " now has a purple trail.");
}
addTrail(pPlayer, iTrailSize, iTrailDuration, iTrailAlpha, Vector(128,0,255));
}else if(pArguments.Arg(1) == "pink")
{
if(bSilent)
{
g_PlayerFuncs.ClientPrint(pPlayer, HUD_PRINTTALK, "[Trail] You now have a pink trail.");
}else{
g_PlayerFuncs.ClientPrintAll(HUD_PRINTTALK, "[Trail] " + pPlayer.pev.netname + " now has a pink trail.");
}
addTrail(pPlayer, iTrailSize, iTrailDuration, iTrailAlpha, Vector(255,0,255));
}else if(pArguments.Arg(1) == "white")
{
if(bSilent)
{
g_PlayerFuncs.ClientPrint(pPlayer, HUD_PRINTTALK, "[Trail] You now have a white trail.");
}else{
g_PlayerFuncs.ClientPrintAll(HUD_PRINTTALK, "[Trail] " + pPlayer.pev.netname + " now has a white trail.");
}
addTrail(pPlayer, iTrailSize, iTrailDuration, iTrailAlpha, Vector(255,255,255));
}else{
if(bSilent)
{
g_PlayerFuncs.ClientPrint(pPlayer, HUD_PRINTTALK, "[Trail] No such color.");
}else{
if(g_pHideChat.GetBool() == false)
{
g_PlayerFuncs.ClientPrintAll(HUD_PRINTTALK, "[Trail] No such color.");
}else{
g_PlayerFuncs.ClientPrint(pPlayer, HUD_PRINTTALK, "[Trail] No such color.");
}
}
}
}
return HOOK_HANDLED;
}
}
return HOOK_CONTINUE;
}
HookReturnCode ClientDisconnect(CBasePlayer@ pPlayer)
{
string szSteamId = g_EngineFuncs.GetPlayerAuthId( pPlayer.edict() );
if(g_PlayerTrails.exists(szSteamId))
{
g_PlayerTrails.delete(szSteamId);
g_PlayerIDInfo.removeAt(g_PlayerIDInfo.find(szSteamId));
}
return HOOK_CONTINUE;
}
void trailThink()
{
//lmao couldnt figure out callbacks for ccvars
TrailSizeCheck();
TrailDurationCheck();
TrailAlphaCheck();
// check vel difference
for(uint i = 0; i < g_PlayerIDInfo.length(); i++)
{
PlayerTrailData@ data = cast<PlayerTrailData@>(g_PlayerTrails[g_PlayerIDInfo[i]]);
CBasePlayer@ pPlayer = g_PlayerFuncs.FindPlayerByIndex(data.id);
Vector tempVel = pPlayer.pev.velocity;
bool tempBool = false;
if(tempVel.x == 0 && tempVel.y == 0 && tempVel.z == 0) { data.restart = true; }
if(data.restart)
{
if(tempVel.x >= 2) { tempBool = true; }
if(tempVel.y >= 2) { tempBool = true; }
if(tempVel.z >= 2) { tempBool = true; }
}
if(tempBool)
{
data.restart = false;
int pID = g_EntityFuncs.EntIndex(pPlayer.edict());
killMsg(pID);
trailMsg(pPlayer, g_pTrailSize.GetInt(), int(g_pTrailDuration.GetFloat()*10), g_pTrailAlpha.GetInt(), data.color);
}
}
}
void resetTrails()
{
for(uint i = 0; i < g_PlayerIDInfo.length(); i++)
{
PlayerTrailData@ data = cast<PlayerTrailData@>(g_PlayerTrails[g_PlayerIDInfo[i]]);
CBasePlayer@ pPlayer = g_PlayerFuncs.FindPlayerByIndex(data.id);
killMsg(data.id);
trailMsg(pPlayer, g_pTrailSize.GetInt(), int(g_pTrailDuration.GetFloat()*10), g_pTrailAlpha.GetInt(), data.color);
}
}
void addTrail(CBasePlayer@ pPlayer, int trailSize, int trailDuration, int trailAlpha, Vector color)
{
string szSteamId = g_EngineFuncs.GetPlayerAuthId( pPlayer.edict() );
if(g_PlayerTrails.exists(szSteamId))
{
PlayerTrailData@ data = cast<PlayerTrailData@>(g_PlayerTrails[szSteamId]);
int pID = g_EntityFuncs.EntIndex(pPlayer.edict());
data.color = color;
data.restart = false;
killMsg(pID); // set trail
trailMsg(pPlayer, trailSize, trailDuration, trailAlpha, color);
}else{
PlayerTrailData data; // add trail
data.id = g_EntityFuncs.EntIndex(pPlayer.edict());
data.color = color;
data.restart = false;
g_PlayerIDInfo.insertLast(szSteamId);
g_PlayerTrails[szSteamId] = data;
trailMsg(pPlayer, trailSize, trailDuration, trailAlpha, color);
}
}
void trailMsg(CBasePlayer@ pPlayer, int trailSize, int trailDuration, int trailAlpha, Vector color)
{
int pID = g_EntityFuncs.EntIndex(pPlayer.edict());
// send trail message
NetworkMessage message(MSG_BROADCAST, NetworkMessages::SVC_TEMPENTITY, null);
message.WriteByte(TE_BEAMFOLLOW);
message.WriteShort(pID);
message.WriteShort(g_TrailSpriteIndex);
message.WriteByte(trailDuration);
message.WriteByte(trailSize);
message.WriteByte(int(color.x));
message.WriteByte(int(color.y));
message.WriteByte(int(color.z));
message.WriteByte(trailAlpha);
message.End();
}
void removeTrail(CBasePlayer@ pPlayer)
{
string szSteamId = g_EngineFuncs.GetPlayerAuthId( pPlayer.edict() );
g_PlayerTrails.delete(szSteamId);
g_PlayerIDInfo.removeAt(g_PlayerIDInfo.find(szSteamId));
int pID = g_EntityFuncs.EntIndex(pPlayer.edict());
killMsg(pID);
}
void killMsg(int id)
{
// send kill trail message
NetworkMessage message(MSG_BROADCAST, NetworkMessages::SVC_TEMPENTITY, null);
message.WriteByte(TE_KILLBEAM);
message.WriteShort(id);
message.End();
}