So I started working on something I was calling Admin Anno-tags (combination of Annotation and Tags). Then I ran into an issue where the annotations were visible through walls, and at any distance, so I gave up on it.
I also originally had some code in there to hide the annotations when a player died, but I didn't do it properly, so if a player died, all annotations would disappear for them. Once an admin respawned, the annotations would re-appear to that player. It was incredibly glitchy. So I commented it out.
Luckily, I was smart enough to keep the code, so I've decided to post it here. I know that Geit's Annotations plugin was unapproved, and people are wanting that to be fixed, so hopefully my code can be of some use.
NOTE 1: Some code was taken from that excellent Gravestone Markers plugin made by Friagram, in regards to the Bitstring stuff, that I was having trouble with.
NOTE 2: If you do make a plugin using any of this code, you do NOT have to give me credit. You can if you want to, but I don't find it necessary. Do give credit to Friagram though, he deserves it!
PHP Code:
// Massive credit to Friagram for his Gravestone Markers plugin. Without that, I wouldn't have gotten this far!
#include <sourcemod>
#include <sdktools>
#include <tf2_stocks>
#pragma semicolon 1
#define PLUGIN_VERSION "1.0"
#define SOUND_NULL "vo/null.wav"
public Plugin:myinfo =
{
name = "[WIP] Annotation Admin Tags",
author = "abrandnewday",
description = "Adds neat little annotation tags for admins",
version = PLUGIN_VERSION,
}
public OnPluginStart()
{
HookEvent("player_spawn", Event_PlayerSpawn);
// HookEvent("player_death", Event_PlayerDeath);
}
/*
// Event: Plugin has been unloaded, hide annotations.
public OnPluginEnd()
{
for (new i=1; i <= MaxClients; i++)
{
HideAnnotation(i);
}
}
*/
// Event: Player has spawned, check if they're an admin, and if so, assign the annotation.
public Action:Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
new user = GetEventInt(event, "userid");
new client = GetClientOfUserId(user);
if(GetUserFlagBits(client) && ADMFLAG_GENERIC)
{
ShowAnnotation(client);
}
return Plugin_Continue;
}
/*
// Event: Player has died, hide the annotation.
public Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
new user = GetEventInt(event, "userid");
new client = GetClientOfUserId(user);
if(GetUserFlagBits(client) && ADMFLAG_GENERIC)
{
HideAnnotation(client);
}
return Plugin_Continue;
}
*/
// Function: Show the annotation!
ShowAnnotation(client)
{
for (new i=1; i <= MaxClients; i++)
{
new bitstring = 1 | RoundFloat(Pow(2.0, float(i)));
if (bitstring > 1)
{
new Handle:event = CreateEvent("show_annotation");
if (event != INVALID_HANDLE)
{
SetEventFloat(event, "lifetime", 999999.0); // Long-ass lifetime.
SetEventInt(event, "id", i);
SetEventString(event, "text", "Admin"); // Displays "Admin" in the annotation
SetEventInt(event, "visibilityBitfield", bitstring);
SetEventInt(event, "follow_entindex", client); // Follow the player
SetEventString(event, "play_sound", SOUND_NULL);
SetEventBool(event, "show_distance", 100); // Not sure what the distance is measured in
FireEvent(event);
}
}
}
}
/*
// Function: Hide Annotation
HideAnnotation(client)
{
new Handle:event = CreateEvent("hide_annotation");
if(event == INVALID_HANDLE) return;
SetEventInt(event, "id", client);
FireEvent(event);
}
*/
// Function: Build Bitstring for visibility
public BuildBitString(Float:position[3])
{
new bitstring = 1;
for (new client=1; client <= MaxClients; client++)
{
if (IsClientInGame(client))
{
decl Float:EyePos[3];
GetClientEyePosition(client, EyePos);
if (GetVectorDistance(position, EyePos) < 400)
{
bitstring |= RoundFloat(Pow(2.0, float(client)));
}
}
}
return bitstring;
}
/*
// Old bitstring code I used to use.
DoFilter(client)
{
new bitstring;
for(new viewer = 1; viewer <= MaxClients; viewer++)
{
if(client == viewer) continue;
if(IsClientInGame(viewer) && IsPlayerAlive(viewer) && IsWithinRange(client, viewer))
{
bitstring |= (1 << viewer);
}
}
return bitstring;
}
bool:IsWithinRange(client, viewer)
{
new Float:clientpos[3], Float:viewerpos[3];
GetClientAbsOrigin(client, clientpos);
GetClientAbsOrigin(viewer, viewerpos);
if(GetVectorDistance(clientpos, viewerpos) <= 500.0) return true;
else return false;
}
*/