#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <vip_core>
#include <clientprefs>
public Plugin myinfo =
{
name = "[VIP] AURA",
author = "R1KO & Pheonix (˙·٠●Феникс●٠·˙) & Dragokas",
version = "1.0.1",
url = ""
};
/*
Fork by Dragokas
1.0.1
- Added new aura.
- Added different colors, including random and changeful color.
- updated to new syntax and metodmaps.
- updated for using with newest VIP_core, added missing 'GetRGBAFromString'.
- added translation into English.
- made alpha level unnecessary to specify in config file.
- made menu restore currently selected page.
*/
#define VIP_AURA_M "AURA_M"
#define VIP_AURA "AURA"
int g_clientColor[MAXPLAYERS+1][4];
VIP_ToggleState g_bHasAura[MAXPLAYERS+1];
Handle g_hTimer[MAXPLAYERS+1], g_hCookie;
KeyValues g_hKv;
Menu g_hmenu;
int g_iBeamSprite, g_iHaloSprite;
int g_iBeamSprite2;
bool g_bBeamRandomColor[MAXPLAYERS+1];
float g_iBeamLifeTime = 0.7;
int g_iAlphaColor = 128;
public void OnPluginStart()
{
LoadTranslations("Aura_Pulse.phrases");
if(VIP_IsVIPLoaded())
{
VIP_OnVIPLoaded();
}
if (g_hKv != INVALID_HANDLE) delete g_hKv;
g_hKv = new KeyValues("Aura_Colors");
char buffer[PLATFORM_MAX_PATH];
BuildPath(Path_SM, buffer, sizeof(buffer), "data/vip/modules/aura_colors.ini");
if (!g_hKv.ImportFromFile(buffer)) SetFailState("Couldn't parse file %s", buffer);
g_hCookie = RegClientCookie("VIP_AURA", "VIP_AURA", CookieAccess_Public);
}
public void OnPluginEnd()
{
if(CanTestFeatures() && GetFeatureStatus(FeatureType_Native, "VIP_UnregisterFeature") == FeatureStatus_Available)
{
VIP_UnregisterFeature(VIP_AURA_M);
VIP_UnregisterFeature(VIP_AURA);
}
}
public void OnMapStart()
{
g_iBeamSprite = PrecacheModel("materials/sprites/laser.vmt");
g_iBeamSprite2 = PrecacheModel("materials/sprites/blueflare1.vmt");
g_iHaloSprite = PrecacheModel("materials/sprites/glow08.vmt");
}
public void VIP_OnVIPLoaded()
{
VIP_RegisterFeature(VIP_AURA_M, _, SELECTABLE, Open_aura, OnDisplayItem, OnDrawItem);
VIP_RegisterFeature(VIP_AURA, BOOL, _, ToggleItemCallback, OnDisplayItem_f);
}
public void VIP_OnVIPClientLoaded(int client)
{
if(VIP_IsClientFeatureUse(client, VIP_AURA))
{
g_bHasAura[client] = ENABLED;
char sInfo[64];
GetClientCookie(client, g_hCookie, sInfo, 64);
if(sInfo[0])
{
GetRGBAFromString(sInfo, g_clientColor[client]);
AdjustColor(client);
return;
}
else {
g_bBeamRandomColor[client] = false;
g_clientColor[client][0] = 0;
g_clientColor[client][1] = 0;
g_clientColor[client][2] = 255;
g_clientColor[client][3] = g_iAlphaColor;
return;
}
}
for(int i=0; i < 4; i++) g_clientColor[client][i] = 255;
}
void GetRGBAFromString(const char[] sInfo, int color[4])
{
char sColors[4][4];
ExplodeString(sInfo, " ", sColors, sizeof(sColors), sizeof(sColors[]));
color[0] = StringToInt(sColors[0]);
color[1] = StringToInt(sColors[1]);
color[2] = StringToInt(sColors[2]);
if (sColors[3][0] != '\0' && !StrEqual(sColors[3][0], "0")) {
color[3] = StringToInt(sColors[3]); // alpha
}
else {
color[3] = g_iAlphaColor;
}
}
public bool Open_aura(int client, const char[] sFeatureName)
{
char buffer[50], sColor[50];
g_hmenu = new Menu(AuraMenuHandler);
g_hmenu.ExitBackButton = true;
g_hmenu.SetTitle("%T\n ", "Choose_Aura", client);
g_hKv.Rewind();
if (g_hKv.GotoFirstSubKey())
{
do
{
if (g_hKv.GetSectionName(buffer, 256))
{
Format(sColor, sizeof(sColor), "%T", buffer, client);
g_hmenu.AddItem(buffer, sColor);
}
}
while (g_hKv.GotoNextKey());
}
g_hKv.Rewind();
g_hmenu.Display(client, MENU_TIME_FOREVER);
return false;
}
public int AuraMenuHandler(Menu hMenu, MenuAction action, int client, int Item)
{
switch(action)
{
case MenuAction_Cancel:
{
if(Item == MenuCancel_ExitBack) VIP_SendClientVIPMenu(client);
}
case MenuAction_Select:
{
char sInfo[64];
hMenu.GetItem(Item, sInfo, 64);
g_hKv.Rewind();
if (g_hKv.JumpToKey(sInfo, false))
{
g_hKv.GetColor("color", g_clientColor[client][0], g_clientColor[client][1], g_clientColor[client][2], g_clientColor[client][3]);
g_hKv.Rewind();
PrintToChat(client, "\x03%t \x04%t", "Aura_changed", sInfo);
FormatEx(sInfo, 64, "%i %i %i %i", g_clientColor[client][0], g_clientColor[client][1], g_clientColor[client][2], g_clientColor[client][3]);
if (g_clientColor[client][3] == 0)
g_clientColor[client][3] = g_iAlphaColor;
SetClientCookie(client, g_hCookie, sInfo);
AdjustColor(client);
}
else PrintToChat(client, "Failed to use \"%s\"!.", sInfo);
g_hmenu.DisplayAt(client, hMenu.Selection, MENU_TIME_FOREVER);
}
}
}
void AdjustColor(int client)
{
g_bBeamRandomColor[client] = false;
if (g_clientColor[client][0] == 0 && g_clientColor[client][1] == 0 && g_clientColor[client][2] == 0) {
SetBeamRandomColor(client);
}
else if (g_clientColor[client][0] == 1 && g_clientColor[client][1] == 1 && g_clientColor[client][2] == 1) {
SetBeamRandomColor(client);
g_bBeamRandomColor[client] = true;
}
}
public int OnDrawItem(int client, const char[] sMenuOptionName, int style)
{
return VIP_GetClientFeatureStatus(client, VIP_AURA) != ENABLED ? ITEMDRAW_DISABLED : style;
}
public bool OnDisplayItem(int client, const char[] sFeatureName, char[] sDisplay, int maxlen)
{
FormatEx(sDisplay, maxlen, "%T", "Aura_Color", client);
return true;
}
public Action ToggleItemCallback(int client, const char[] sFeatureName, VIP_ToggleState OldStatus, VIP_ToggleState &NewStatus)
{
g_bHasAura[client] = NewStatus;
if(NewStatus == ENABLED) SetClientAura(client);
return Plugin_Continue;
}
public bool OnDisplayItem_f(int client, const char[] sFeatureName, char[] sDisplay, int maxlen)
{
FormatEx(sDisplay, maxlen, "%T [%T]", "Aura", client, VIP_IsClientFeatureUse(client, VIP_AURA) ? "Enabled": "Disabled", client);
return true;
}
public void OnClientDisconnect(int client)
{
g_bHasAura[client] = DISABLED;
g_hTimer[client] = INVALID_HANDLE;
}
public void VIP_OnPlayerSpawn(int client, int iTeam, bool bIsVIP)
{
if(bIsVIP && g_bHasAura[client])
{
SetClientAura(client);
}
}
void SetClientAura(int client)
{
if(g_hTimer[client] == INVALID_HANDLE) {
g_hTimer[client] = CreateTimer(g_iBeamLifeTime, Timer_SetAura, client, TIMER_REPEAT);
}
}
public Action Timer_SetAura(Handle timer, int client)
{
if (g_bBeamRandomColor[client]) SetBeamRandomColor(client);
if(IsClientInGame(client) && IsPlayerAlive(client) && g_bHasAura[client] == ENABLED)
{
float g_AuraVec[3];
GetClientAbsOrigin(client, g_AuraVec);
g_AuraVec[2] += 10.0;
TE_SetupBeamRingPoint(g_AuraVec, GetRandomFloat(0.0, 20.0), GetRandomFloat(40.0, 55.0), GetRandomInt(0, 1) == 0 ? g_iBeamSprite : g_iBeamSprite2, g_iHaloSprite, 0, 15, GetRandomFloat(0.5, 1.2), 15.0, 1.0, g_clientColor[client], 1, 0);
TE_SendToAll();
return Plugin_Continue;
}
else {
g_hTimer[client] = INVALID_HANDLE;
}
return Plugin_Stop;
}
void SetBeamRandomColor(int client)
{
g_clientColor[client][0] = GetRandomInt(0, 255);
g_clientColor[client][1] = GetRandomInt(0, 255);
g_clientColor[client][2] = GetRandomInt(0, 255);
}