Raised This Month: $51 Target: $400
 12% 

[TF2] Glow Plugin Rebuild Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KiRRA
Senior Member
Join Date: Nov 2012
Old 12-30-2012 , 13:21   [TF2] Glow Plugin Rebuild Help
Reply With Quote #1

G'day. I am looking to get some help in rebuilding an old plugin someone created for our servers a few years ago. The author isn't very active and thus can't provide any support in future changes to our servers.

I am looking to get the dependency of the menu removed as well as a double check on coding accuracy. We were not provided the source code for compiling it ourselves so all I can provide is a badly decompiled version of the source. This was decompiled using the Lysis online decompiler and thus might have errors. I have tried editing the code myself (only removing the requirement of the donatormenu.smx) and it seems decompiling it just produced too many issues. Is there anyone who could help me clean this code up as this is a gorgeous glow plugin and I'm sure others could benefit from it if it was cleaned up. I have my own menu I am looking to add this command into but without the old menu dependency being removed, am unable to do so.

Below is the coding after being decompiled.

Code:
public PlVers:__version =
{
 version = 5,
 filevers = "1.2.1-dev",
 date = "09/12/2009",
 time = "19:20:01"
};
new Float:NULL_VECTOR[3];
new String:NULL_STRING[1];
public Extension:__ext_core =
{
 name = "Core",
 file = "core",
 autoload = 0,
 required = 0,
};
new MaxClients;
public Extension:__ext_tf2 =
{
 name = "TF2 Tools",
 file = "game.tf2.ext",
 autoload = 1,
 required = 1,
};
public Extension:__ext_sdktools =
{
 name = "SDKTools",
 file = "sdktools.ext",
 autoload = 1,
 required = 1,
};
new String:TFResourceNames[18][0];
public Extension:__ext_topmenus =
{
 name = "TopMenus",
 file = "topmenus.ext",
 autoload = 1,
 required = 1,
};
public Plugin:myinfo =
{
 name = "Donator Plugin: Glow",
 description = "Grants donators glow effect",
 author = "Wazz",
 version = "1.0.0.0",
 url = ""
};
new clientList[65];
new clientEnt[65];
new Handle:db;
public __ext_core_SetNTVOptional()
{
 VerifyCoreVersion();
 return 0;
}
Float:operator+(Float:,_:)(Float:oper1, oper2)
{
 return oper1 + float(oper2);
}
bool:StrEqual(String:str1[], String:str2[], bool:caseSensitive)
{
 return strcmp(str1, str2, caseSensitive) == 0;
}
GetEntSendPropOffs(ent, String:prop[], bool:actual)
{
 decl String:cls[64];
 if (!GetEntityNetClass(ent, cls, 64))
 {
  return -1;
 }
 if (actual)
 {
  return FindSendPropInfo(cls, prop, 0, 0, 0);
 }
 return FindSendPropOffs(cls, prop);
}
SetEntityRenderMode(entity, RenderMode:mode)
{
 static bool:gotconfig;
 static String:prop[8];
 if (!gotconfig)
 {
  new Handle:gc = LoadGameConfigFile("core.games");
  new bool:exists = GameConfGetKeyValue(gc, "m_nRenderMode", "", 32);
  CloseHandle(gc);
  if (!exists)
  {
   strcopy("", 32, "m_nRenderMode");
  }
  gotconfig = 1;
 }
 SetEntProp(entity, PropType:0, "", mode, 1);
 return 0;
}
SetEntityRenderColor(entity, r, g, b, a)
{
 static bool:gotconfig;
 static String:prop[8];
 if (!gotconfig)
 {
  new Handle:gc = LoadGameConfigFile("core.games");
  new bool:exists = GameConfGetKeyValue(gc, "m_clrRender", "", 32);
  CloseHandle(gc);
  if (!exists)
  {
   strcopy("", 32, "m_clrRender");
  }
  gotconfig = 1;
 }
 new offset = GetEntSendPropOffs(entity, "", false);
 if (0 >= offset)
 {
  ThrowError("SetEntityRenderColor not supported by this mod");
 }
 SetEntData(entity, offset, r, 1, true);
 SetEntData(entity, offset + 1, g, 1, true);
 SetEntData(entity, offset + 2, b, 1, true);
 SetEntData(entity, offset + 3, a, 1, true);
 return 0;
}
TFClassType:TF2_GetPlayerClass(client)
{
 return GetEntProp(client, PropType:0, TFResourceNames, 4);
}
bool:isDonator(Client)
{
 new AdminId:adminId = GetUserAdmin(Client);
 if (GetAdminFlag(adminId, AdminFlag:15, AdmAccessMode:1))
 {
  return true;
 }
 return false;
}
public DB_OnPluginStart()
{
 CreateDBConnection();
 CreateDBTables();
 return 0;
}
SaveSetting(Client)
{
 decl String:query[128];
 decl String:ConUsrSteamID[60];
 GetClientAuthString(Client, ConUsrSteamID, 60);
 if (clientList[Client][0][0])
 {
  var1 = 1;
 }
 else
 {
  var1 = 0;
 }
 Format(query, 128, "UPDATE Glow SET ONOFF = %i WHERE STEAMID = '%s'", var1, ConUsrSteamID);
 SQL_TQuery(db, SQLErrorCheckCallback, query, any:0, DBPriority:1);
 return 0;
}
GetSavedSetting(Client)
{
 decl String:ConUsrSteamID[60];
 decl String:query[128];
 GetClientAuthString(Client, ConUsrSteamID, 60);
 Format(query, 128, "SELECT ONOFF FROM `Glow` WHERE STEAMID = '%s'", ConUsrSteamID);
 SQL_TQuery(db, T_GetSavedColor, query, Client, DBPriority:1);
 return 0;
}
public T_GetSavedColor(Handle:owner, Handle:hndl, String:error[], Client)
{
 if (!IsClientInGame(Client))
 {
  return 0;
 }
 if (hndl)
 {
  while (SQL_FetchRow(hndl))
  {
   clientList[Client] = SQL_FetchInt(hndl, 0, 0);
  }
 }
 else
 {
  LogError("Query failed [#002]! %s", error);
 }
 return 0;
}
CreateDBConnection()
{
 if (SQL_CheckConfig("donator"))
 {
  decl String:error[256];
  db = SQL_Connect("donator", true, error, 256);
  if (db)
  {
   LogMessage("DatabaseInit (CONNECTED) with donator config");
   decl String:query[256];
   Format(query, 256, "SET NAMES 'utf8'");
   if (!SQL_FastQuery(db, query, -1))
   {
    LogError("Can't select character set (%s)", query);
   }
  }
  else
  {
   SetFailState("Failed to connect: %s", error);
  }
 }
 else
 {
  if (SQL_CheckConfig("default"))
  {
   decl String:error[256];
   db = SQL_Connect("default", true, error, 256);
   if (db)
   {
    LogMessage("DatabaseInit (CONNECTED) with default config");
    decl String:query[256];
    Format(query, 256, "SET NAMES 'utf8'");
    if (!SQL_FastQuery(db, query, -1))
    {
     LogError("Can't select character set (%s)", query);
    }
   }
   else
   {
    SetFailState("Failed to connect: %s", error);
   }
  }
  SetFailState("Failed to connect: Cannot find any configuration in databases.cfg");
 }
 return 0;
}
CreateDBTables()
{
 new len = 0;
 decl String:query[192];
 len = Format(query[len], 192 - len, "CREATE TABLE IF NOT EXISTS `Data`") + len;
 len = Format(query[len], 192 - len, "(`name` TEXT, `datatxt` TEXT, `dataint` INTEGER);") + len;
 SQL_TQuery(db, T_CheckDBUptodate1, query, any:0, DBPriority:1);
 return 0;
}
public T_CheckDBUptodate1(Handle:owner, Handle:hndl, String:error[], data)
{
 if (hndl)
 {
  decl String:buffer[64];
  Format(buffer, 64, "SELECT dataint FROM `Data` where `name` = 'dbversion'");
  SQL_TQuery(db, T_CheckDBUptodate2, buffer, any:0, DBPriority:1);
 }
 else
 {
  LogError("Query failed [#007]! %s", error);
 }
 return 0;
}
public T_CheckDBUptodate2(Handle:owner, Handle:hndl, String:error[], data)
{
 if (hndl)
 {
  CreateDBGlow();
  if (!SQL_GetRowCount(hndl))
  {
   decl String:buffer[96];
   Format(buffer, 96, "INSERT INTO Data (`name`,`dataint`) VALUES ('dbversion', %i)", 10);
   SQL_TQuery(db, SQLErrorCheckCallback, buffer, any:0, DBPriority:1);
  }
  new Client = 1;
  while (Client <= MaxClients)
  {
   if (IsClientInGame(Client))
   {
    InitializeClientOnDB(Client);
    Client++;
   }
   Client++;
  }
 }
 else
 {
  LogError("Query failed [#008]! %s", error);
 }
 return 0;
}
InitializeClientOnDB(Client)
{
 if (!isDonator(Client))
 {
  return 0;
 }
 decl String:ConUsrSteamID[60];
 decl String:buffer[96];
 GetClientAuthString(Client, ConUsrSteamID, 60);
 Format(buffer, 96, "SELECT STEAMID FROM `Glow` WHERE STEAMID = '%s'", ConUsrSteamID);
 SQL_TQuery(db, T_CheckConnectingUsr, buffer, Client, DBPriority:1);
 return 0;
}
public T_CheckConnectingUsr(Handle:owner, Handle:hndl, String:error[], Client)
{
 if (!IsClientInGame(Client))
 {
  return 0;
 }
 if (hndl)
 {
  decl String:ClientSteamID[60];
  GetClientAuthString(Client, ClientSteamID, 60);
  decl String:buffer[128];
  if (!SQL_GetRowCount(hndl))
  {
   Format(buffer, 128, "INSERT INTO Glow (`STEAMID`) VALUES ('%s')", ClientSteamID);
   SQL_TQuery(db, SQLErrorCheckCallback, buffer, any:0, DBPriority:1);
  }
  decl String:name[60];
  GetClientName(Client, name, 60);
  ReplaceString(name, 60, "'", "", true);
  ReplaceString(name, 60, "<?", "", true);
  ReplaceString(name, 60, "?>", "", true);
  ReplaceString(name, 60, "\"", "", true);
  Format(buffer, 128, "UPDATE Glow SET NAME = '%s' WHERE STEAMID = '%s'", name, ClientSteamID);
  SQL_TQuery(db, SQLErrorCheckCallback, buffer, any:0, DBPriority:1);
  GetSavedSetting(Client);
 }
 else
 {
  LogError("Query failed [#009]! %s", error);
 }
 return 0;
}
public SQLErrorCheckCallback(Handle:owner, Handle:hndl, String:error[], data)
{
 if (!StrEqual("", error, true))
 {
  ResetPack(data, false);
  decl String:query[256];
  ReadPackString(data, query, 255);
  LogError("SQL Error: %s", error);
  LogError("Query: %s", query);
 }
 return 0;
}
CreateDBGlow()
{
 new len = 0;
 decl String:query[1000];
 len = Format(query[len], 1000 - len, "CREATE TABLE IF NOT EXISTS `Glow` (") + len;
 len = Format(query[len], 1000 - len, "`STEAMID` varchar(25) NOT NULL,") + len;
 len = Format(query[len], 1000 - len, "`NAME` varchar(64) NOT NULL ,") + len;
 len = Format(query[len], 1000 - len, "`ONOFF` int(1) NOT NULL default '0',") + len;
 len = Format(query[len], 1000 - len, "PRIMARY KEY  (`STEAMID`)") + len;
 len = Format(query[len], 1000 - len, ") ENGINE=MyISAM DEFAULT CHARSET=utf8;") + len;
 SQL_FastQuery(db, query, -1);
 return 0;
}
public OnPluginStart()
{
 DB_OnPluginStart();
 RegAdminCmd("sm_glow", donatorGlow, 32768, "Sets a glow on self", "", 0);
 HookEvent("player_changeclass", Event_changeClass, EventHookMode:1);
 HookEvent("player_death", Event_playerDeath, EventHookMode:1);
 HookEvent("player_spawn", Event_playerSpawn, EventHookMode:1);
 HookEvent("teamplay_round_win", Event_winRound, EventHookMode:2);
 return 0;
}
public OnClientPostAdminCheck(Client)
{
 InitializeClientOnDB(Client);
 return 0;
}
public OnClientDisconnect(Client)
{
 if (isDonator(Client))
 {
  SaveSetting(Client);
 }
 clientList[Client] = 0;
 clientEnt[Client] = 0;
 return 0;
}
public Action:donatorGlow(client, args)
{
 if (!IsClientInGame(client))
 {
  return Action:3;
 }
 if (!clientList[client][0][0])
 {
  new TFClassType:class = TF2_GetPlayerClass(client);
  if (class == TFClassType:8)
  {
   PrintToChat(client, "\x04[Donator]:");
   return Action:3;
  }
  new team = GetClientTeam(client);
  if (team == 3)
  {
   AttachParticle(client, "teleporter_blue_entrance_level1");
   SetEntityRenderMode(client, RenderMode:1);
   SetEntityRenderColor(client, 0, 0, 255, 255);
  }
  if (team == 2)
  {
   AttachParticle(client, "teleporter_red_entrance_level1");
   SetEntityRenderMode(client, RenderMode:1);
   SetEntityRenderColor(client, 255, 0, 0, 255);
  }
  PrintToChat(client, "\x04[Donator]:");
 }
 else
 {
  DeleteParticle(clientEnt[client][0][0]);
  clientList[client] = 0;
  clientEnt[client] = 0;
  SetEntityRenderMode(client, RenderMode:1);
  SetEntityRenderColor(client, 255, 255, 255, 255);
  PrintToChat(client, "\x04[Donator]:");
 }
 return Action:3;
}
AttachParticle(client, String:particleType[])
{
 DeleteParticle(clientEnt[client][0][0]);
 new particle = CreateEntityByName("info_particle_system", -1);
 decl String:tName[128];
 if (IsValidEdict(particle))
 {
  decl Float:pos[3];
  GetEntPropVector(client, PropType:0, "m_vecOrigin", pos);
  pos[2] += 10;
  TeleportEntity(particle, pos, NULL_VECTOR, NULL_VECTOR);
  Format(tName, 128, "target%i", client);
  DispatchKeyValue(client, "targetname", tName);
  DispatchKeyValue(particle, "targetname", "tf2particle");
  DispatchKeyValue(particle, "parentname", tName);
  DispatchKeyValue(particle, "effect_name", particleType);
  DispatchSpawn(particle);
  SetVariantString(tName);
  AcceptEntityInput(particle, "SetParent", particle, particle, 0);
  SetVariantString("head");
  AcceptEntityInput(particle, "SetParentAttachment", particle, particle, 0);
  ActivateEntity(particle);
  AcceptEntityInput(particle, "start", -1, -1, 0);
  clientEnt[client] = particle;
  clientList[client] = 1;
 }
 return 0;
}
DeleteParticle(particle)
{
 if (IsValidEntity(particle))
 {
  decl String:classname[256];
  GetEdictClassname(particle, classname, 256);
  if (StrEqual(classname, "info_particle_system", false))
  {
   RemoveEdict(particle);
  }
 }
 return 0;
}
public Action:Event_changeClass(Handle:event, String:name[], bool:dontBroadcast)
{
 new client = GetClientOfUserId(GetEventInt(event, "userid"));
 new class = GetEventInt(event, "class");
 if (class == 8)
 {
  DeleteParticle(clientEnt[client][0][0]);
  clientEnt[client] = 0;
  SetEntityRenderMode(client, RenderMode:1);
  SetEntityRenderColor(client, 255, 255, 255, 255);
  PrintToChat(client, "\x04[Donator]:");
 }
 return Action:0;
}
public Action:Event_playerDeath(Handle:event, String:name[], bool:dontBroadcast)
{
 new client = GetClientOfUserId(GetEventInt(event, "userid"));
 if (clientList[client][0][0] == 1)
 {
  DeleteParticle(clientEnt[client][0][0]);
  clientEnt[client] = 0;
 }
 return Action:0;
}
public Action:Event_playerSpawn(Handle:event, String:name[], bool:dontBroadcast)
{
 new client = GetClientOfUserId(GetEventInt(event, "userid"));
 new team = GetClientTeam(client);
 if (clientList[client][0][0] == 1)
 {
  if (team == 3)
  {
   AttachParticle(client, "teleporter_blue_entrance_level1");
   SetEntityRenderMode(client, RenderMode:1);
   SetEntityRenderColor(client, 0, 0, 255, 255);
  }
  if (team == 2)
  {
   AttachParticle(client, "teleporter_red_entrance_level1");
   SetEntityRenderMode(client, RenderMode:1);
   SetEntityRenderColor(client, 255, 0, 0, 255);
  }
 }
 return Action:0;
}
public Action:Event_winRound(Handle:event, String:name[], bool:dontBroadcast)
{
 new client = 1;
 while (client <= MaxClients)
 {
  if (clientList[client][0][0] == 1)
  {
   DeleteParticle(clientEnt[client][0][0]);
   clientEnt[client] = 0;
   SetEntityRenderMode(client, RenderMode:1);
   SetEntityRenderColor(client, 255, 255, 255, 255);
   client++;
  }
  client++;
 }
 return Action:0;
}
So basically: Currently the plugin requires the existence of a donatormenu.smx, which I want to see if the dependency can be removed. I'm trying to get this to be a standalone plugin with no actual interface....just need the command itself to function properly as I have my own menu to add it into. Would like the admin flag checked to be Custom1 or "o" to be exact.

For anyone who is curious what it does or interested in results: This plugin does grant users a glow effect as well as a teleporter type ring particle effect. The effects will stay through death, class change, team change, etc. I forgot if it stays on through map change or not.

Last edited by KiRRA; 12-30-2012 at 13:31.
KiRRA is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 12-30-2012 , 14:36   Re: [TF2] Glow Plugin Rebuild Help
Reply With Quote #2

Uhm, is this what your talking about?

http://forums.alliedmods.net/showthread.php?t=79562
__________________
Chaosxk is offline
KiRRA
Senior Member
Join Date: Nov 2012
Old 12-30-2012 , 19:10   Re: [TF2] Glow Plugin Rebuild Help
Reply With Quote #3

Unfortunately not.

The plugin linked does not allow players to remove glow from themselves as it is a punishment plugin more than anything. It also does not last through player death, which is an issue as nobody wants to have to activate a perk every single time they respawn.

The plugin I have provided (source code atleast) lasts through player death, and players can toggle on or off at will. The only issue with it was that it is hard-coded to require the menu plugin which technically isn't required for the plugin to function but was only added as a gui for users and the author made it so the plugin could not be distributed without the menu as well.
KiRRA is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 12-31-2012 , 09:33   Re: [TF2] Glow Plugin Rebuild Help
Reply With Quote #4

You should have gotten the source with the smx file, you could try demanding it now but it's likely long lost.
__________________
asherkin is offline
KiRRA
Senior Member
Join Date: Nov 2012
Old 12-31-2012 , 11:08   Re: [TF2] Glow Plugin Rebuild Help
Reply With Quote #5

Quote:
Originally Posted by asherkin View Post
You should have gotten the source with the smx file, you could try demanding it now but it's likely long lost.
I understand and agree with you 100%. The plugin was obtained by our server admins over a year or two ago (I think) and at the time I wasn't an admin, nor part of the community for that matter actually. I have indeed tried contacting the author but with no luck, no response. I am sure the original source is definitely long gone.

I'm just trying to go through and clean up all the mess that was caused by some of the plugin choices from back in the day. I knew it was a longshot trying to get the code cleaned up. I also knew the functionality of this plugin and figured IF this plugin was cleaned up that would be definitely help alot of users as I see alot of people asking for a glow plugin with the functionality this one has.

Thanks so far for the help guys, it was worth a try atleast.
KiRRA is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 01-01-2013 , 21:54   Re: [TF2] Glow Plugin Rebuild Help
Reply With Quote #6

Without the actual .smx this might be what the plugin looked like. The donator stuff at the top would fit in some donator include file.

The chat output is trimmed btw.

PHP Code:
#include <sourcemod>
#include <tf2>
#include <tf2_stocks>
#include <sdktools>
#include <topmenus>

#define DATABASE_VERSION 10

public Plugin:myinfo =
{
    name = "Donator Plugin: Glow",
    description = "Grants donators glow effect",
    author = "Wazz",
    version = "1.0.0.0",
    url = ""
};

new clientList[MAXPLAYERS+1];
new clientEnt[MAXPLAYERS+1];
new Handle:db;


bool:isDonator(Client)
{
    new AdminId:adminId = GetUserAdmin(Client);
    if (GetAdminFlag(adminId, Admin_Custom1))
    {
        return true;
    }
    return false;
}
public DB_OnPluginStart()
{
    CreateDBConnection();
    CreateDBTables();
}
SaveSetting(Client)
{
    decl String:query[128];
    decl String:ConUsrSteamID[60];
    GetClientAuthString(Client, ConUsrSteamID, sizeof(ConUsrSteamID));
    Format(query, sizeof(query), "UPDATE Glow SET ONOFF = %i WHERE STEAMID = '%s'", (clientList[Client]?1:0), ConUsrSteamID);
    SQL_TQuery(db, SQLErrorCheckCallback, query);
}
GetSavedSetting(Client)
{
    decl String:ConUsrSteamID[60];
    decl String:query[128];
    GetClientAuthString(Client, ConUsrSteamID, sizeof(ConUsrSteamID));
    Format(query, sizeof(query), "SELECT ONOFF FROM `Glow` WHERE STEAMID = '%s'", ConUsrSteamID);
    SQL_TQuery(db, T_GetSavedColor, query, Client);
}
public T_GetSavedColor(Handle:owner, Handle:hndl, const String:error[], any:Client)
{
    if (!IsClientInGame(Client))
        return;
    
    if (!hndl)
    {
        LogError("Query failed [#002]! %s", error);
        return;
    }
    
    while (SQL_FetchRow(hndl))
    {
        clientList[Client] = SQL_FetchInt(hndl, 0);
    }
}
CreateDBConnection()
{
    if (SQL_CheckConfig("donator"))
    {
        decl String:error[256];
        db = SQL_Connect("donator", true, error, sizeof(error));
        if (db)
        {
            LogMessage("DatabaseInit (CONNECTED) with donator config");
            decl String:query[256];
            Format(query, sizeof(query), "SET NAMES 'utf8'");
            if (!SQL_FastQuery(db, query))
            {
                LogError("Can't select character set (%s)", query);
            }
        }
        else
        {
            SetFailState("Failed to connect: %s", error);
        }
    }
    else
    {
        if (SQL_CheckConfig("default"))
        {
            decl String:error[256];
            db = SQL_Connect("default", true, error, sizeof(error));
            if (db)
            {
                LogMessage("DatabaseInit (CONNECTED) with default config");
                decl String:query[256];
                Format(query, sizeof(query), "SET NAMES 'utf8'");
                if (!SQL_FastQuery(db, query))
                {
                    LogError("Can't select character set (%s)", query);
                }
            }
            else
            {
                SetFailState("Failed to connect: %s", error);
            }
        }
        SetFailState("Failed to connect: Cannot find any configuration in databases.cfg");
    }
}
CreateDBTables()
{
    new len;
    decl String:query[192];
    len += Format(query[len], sizeof(query) - len, "CREATE TABLE IF NOT EXISTS `Data`");
    len += Format(query[len], sizeof(query) - len, "(`name` TEXT, `datatxt` TEXT, `dataint` INTEGER);");
    SQL_TQuery(db, T_CheckDBUptodate1, query);
}
public T_CheckDBUptodate1(Handle:owner, Handle:hndl, const String:error[], any:data)
{
    if (!hndl)
    {
        LogError("Query failed [#007]! %s", error);
        return;
    }
    
    decl String:buffer[64];
    Format(buffer, sizeof(buffer), "SELECT dataint FROM `Data` where `name` = 'dbversion'");
    SQL_TQuery(db, T_CheckDBUptodate2, buffer);
}
public T_CheckDBUptodate2(Handle:owner, Handle:hndl, const String:error[], any:data)
{
    if (!hndl)
    {
        LogError("Query failed [#008]! %s", error);
        return;
    }
    
    CreateDBGlow();
    if (!SQL_GetRowCount(hndl))
    {
        decl String:buffer[96];
        Format(buffer, sizeof(buffer), "INSERT INTO Data (`name`,`dataint`) VALUES ('dbversion', %i)", DATABASE_VERSION);
        SQL_TQuery(db, SQLErrorCheckCallback, buffer);
    }
    
    for(new Client = 1;Client <= MaxClients;Client++)
    {
        if (IsClientInGame(Client))
        {
            InitializeClientOnDB(Client);
        }
    }
}
InitializeClientOnDB(Client)
{
    if (!isDonator(Client))
        return;

    decl String:ConUsrSteamID[60];
    decl String:buffer[96];
    GetClientAuthString(Client, ConUsrSteamID, sizeof(ConUsrSteamID));
    Format(buffer, sizeof(buffer), "SELECT STEAMID FROM `Glow` WHERE STEAMID = '%s'", ConUsrSteamID);
    SQL_TQuery(db, T_CheckConnectingUsr, buffer, Client);
}
public T_CheckConnectingUsr(Handle:owner, Handle:hndl, const String:error[], any:Client)
{
    if (!IsClientInGame(Client))
        return;

    if (!hndl)
    {
        LogError("Query failed [#009]! %s", error);
        return;
    }
    
    decl String:ClientSteamID[60];
    GetClientAuthString(Client, ClientSteamID, sizeof(ClientSteamID));
    
    decl String:buffer[128];
    if (!SQL_GetRowCount(hndl))
    {
        Format(buffer, sizeof(buffer), "INSERT INTO Glow (`STEAMID`) VALUES ('%s')", ClientSteamID);
        SQL_TQuery(db, SQLErrorCheckCallback, buffer);
    }
    
    decl String:name[60];
    GetClientName(Client, name, sizeof(name));
    ReplaceString(name, sizeof(name), "'", "");
    ReplaceString(name, sizeof(name), "<?", "");
    ReplaceString(name, sizeof(name), "
?>", "");
    ReplaceString(name, sizeof(name), "\"", "");
    Format(buffer, sizeof(buffer), "UPDATE Glow SET NAME = '%s' WHERE STEAMID = '%s'", name, ClientSteamID);
    SQL_TQuery(db, SQLErrorCheckCallback, buffer);
    GetSavedSetting(Client);
}

public SQLErrorCheckCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
{
    if (!StrEqual("", error, true))
    {
        ResetPack(data);
        decl String:query[256];
        ReadPackString(data, query, sizeof(query));
        LogError("SQL Error: %s", error);
        LogError("Query: %s", query);
        CloseHandle(data);
    }
}

CreateDBGlow()
{
    new len;
    decl String:query[1000];
    len += Format(query[len], sizeof(query) - len, "CREATE TABLE IF NOT EXISTS `Glow` (");
    len += Format(query[len], sizeof(query) - len, "`STEAMID` varchar(25) NOT NULL,");
    len += Format(query[len], sizeof(query) - len, "`NAME` varchar(64) NOT NULL ,");
    len += Format(query[len], sizeof(query) - len, "`ONOFF` int(1) NOT NULL default '0',");
    len += Format(query[len], sizeof(query) - len, "PRIMARY KEY  (`STEAMID`)");
    len += Format(query[len], sizeof(query) - len, ") ENGINE=MyISAM DEFAULT CHARSET=utf8;");
    SQL_FastQuery(db, query);
}

public OnPluginStart()
{
    DB_OnPluginStart();
    RegAdminCmd("sm_glow", donatorGlow, ADMFLAG_CUSTOM1, "Sets a glow on self");
    HookEvent("player_changeclass", Event_changeClass);
    HookEvent("player_death", Event_playerDeath);
    HookEvent("player_spawn", Event_playerSpawn);
    HookEvent("teamplay_round_win", Event_winRound, EventHookMode_PostNoCopy);
}

public OnClientPostAdminCheck(Client)
{
    InitializeClientOnDB(Client);
}

public OnClientDisconnect(Client)
{
    if (isDonator(Client))
    {
        SaveSetting(Client);
    }
    
    clientList[Client] = 0;
    clientEnt[Client] = 0;
}

public Action:donatorGlow(client, args)
{
    if (!IsClientInGame(client))
        return Plugin_Handled;

    if (!clientList[client])
    {
        new TFClassType:class = TF2_GetPlayerClass(client);
        if (class == TFClass_Spy)
        {
            PrintToChat(client, "\x04[Donator]:");
            return Plugin_Handled;
        }
        
        new team = GetClientTeam(client);
        if (team == 3)
        {
            AttachParticle(client, "teleporter_blue_entrance_level1");
            SetEntityRenderMode(client, RENDER_TRANSCOLOR);
            SetEntityRenderColor(client, 0, 0, 255, 255);
        }
        if (team == 2)
        {
            AttachParticle(client, "teleporter_red_entrance_level1");
            SetEntityRenderMode(client, RENDER_TRANSCOLOR);
            SetEntityRenderColor(client, 255, 0, 0, 255);
        }
        PrintToChat(client, "\x04[Donator]:");
    }
    else
    {
        DeleteParticle(clientEnt[client]);
        clientList[client] = 0;
        clientEnt[client] = 0;
        SetEntityRenderMode(client, RENDER_TRANSCOLOR);
        SetEntityRenderColor(client, 255, 255, 255, 255);
        PrintToChat(client, "\x04[Donator]:");
    }
    return Plugin_Handled;
}

AttachParticle(client, String:particleType[])
{
    DeleteParticle(clientEnt[client]);
    
    new particle = CreateEntityByName("info_particle_system");
    
    decl String:tName[128];
    if (IsValidEdict(particle))
    {
        decl Float:pos[3];
        GetEntPropVector(client, Prop_Send, "m_vecOrigin", pos);
        pos[2] += 10;
        TeleportEntity(particle, pos, NULL_VECTOR, NULL_VECTOR);
        
        Format(tName, sizeof(tName), "target%i", client);
        DispatchKeyValue(client, "targetname", tName);
        
        DispatchKeyValue(particle, "targetname", "tf2particle");
        DispatchKeyValue(particle, "parentname", tName);
        DispatchKeyValue(particle, "effect_name", particleType);
        DispatchSpawn(particle);
        
        SetVariantString(tName);
        AcceptEntityInput(particle, "SetParent", particle, particle);
        
        SetVariantString("head");
        AcceptEntityInput(particle, "SetParentAttachment", particle, particle);
        
        ActivateEntity(particle);
        AcceptEntityInput(particle, "start");
        
        clientEnt[client] = particle;
        clientList[client] = 1;
    }
}

DeleteParticle(particle)
{
    if (IsValidEntity(particle))
    {
        decl String:classname[256];
        GetEdictClassname(particle, classname, sizeof(classname));
        if (StrEqual(classname, "info_particle_system", false))
        {
            RemoveEdict(particle);
        }
    }
}

public Action:Event_changeClass(Handle:event, String:name[], bool:dontBroadcast)
{
    new client = GetClientOfUserId(GetEventInt(event, "userid"));
    new class = GetEventInt(event, "class");
    if (class == _:TFClass_Spy)
    {
        DeleteParticle(clientEnt[client]);
        clientEnt[client] = 0;
        SetEntityRenderMode(client, RENDER_TRANSCOLOR);
        SetEntityRenderColor(client, 255, 255, 255, 255);
        PrintToChat(client, "\x04[Donator]:");
    }
    return Plugin_Continue;
}

public Action:Event_playerDeath(Handle:event, String:name[], bool:dontBroadcast)
{
    new client = GetClientOfUserId(GetEventInt(event, "userid"));
    if (clientList[client] == 1)
    {
        DeleteParticle(clientEnt[client]);
        clientEnt[client] = 0;
    }
    return Plugin_Continue;
}

public Action:Event_playerSpawn(Handle:event, String:name[], bool:dontBroadcast)
{
    new client = GetClientOfUserId(GetEventInt(event, "userid"));
    new team = GetClientTeam(client);
    if (clientList[client] == 1)
    {
        if (team == 3)
        {
            AttachParticle(client, "teleporter_blue_entrance_level1");
            SetEntityRenderMode(client, RENDER_TRANSCOLOR);
            SetEntityRenderColor(client, 0, 0, 255, 255);
        }
        if (team == 2)
        {
            AttachParticle(client, "teleporter_red_entrance_level1");
            SetEntityRenderMode(client, RENDER_TRANSCOLOR);
            SetEntityRenderColor(client, 255, 0, 0, 255);
        }
    }
    return Plugin_Continue;
}

public Action:Event_winRound(Handle:event, String:name[], bool:dontBroadcast)
{
    for (new client = 1;client <= MaxClients; client++)
    {
        if (clientList[client] == 1)
        {
            DeleteParticle(clientEnt[client]);
            clientEnt[client] = 0;
            
            SetEntityRenderMode(client, RENDER_TRANSCOLOR);
            SetEntityRenderColor(client, 255, 255, 255, 255);
        }
    }
    return Plugin_Continue;
}
__________________
Peace-Maker is offline
KiRRA
Senior Member
Join Date: Nov 2012
Old 01-02-2013 , 11:13   Re: [TF2] Glow Plugin Rebuild Help
Reply With Quote #7

Dear lord....you went through and cleaned up all that coding!?

If you seriously went through and cleaned up all that code, I owe you soooo much. I will definitely give that bit of coding a try when I get home. Now I'm excited to give it a try.

Oh, I could provide the .smx files if needed, just can't provide the .sp files since they don't exist.

ANYWAYS! Will try when I get home....I owe you big regardless if it works actually. Just for the time spent staring at all that coding.

Thank you!
KiRRA is offline
KiRRA
Senior Member
Join Date: Nov 2012
Old 01-03-2013 , 13:46   Re: [TF2] Glow Plugin Rebuild Help
Reply With Quote #8

You sir, are a true godsend....good man, oh boy....my good man, THANK YOU!

I have yet to be able to test the database effectiveness for player death, map change, respawns, etc. BUT I did load it up in game and without a single glitch, it worked instantly. On and off, easily without any menus and just by the command. Exactly what I needed it to do, no muss no fuss, simple and easy for menu integration.

Thank you soooo much for this help! Should be testing the database portion of plugin tonight to make sure the effect holds through those specified events but I'm sure it will. Thanks again!
KiRRA is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:06.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode