checkster
Thread owner
2014-Nov-11 19:21
```
#include
#include
#pragma semicolon 1
#define VERSION "1.2.4"
#define NAME "Observe Client"
public Plugin:myinfo =
{
name = NAME,
author = "WhiteWolf, puopjik, psychonic, RedSword",
description = "Observe client when dead",
version = VERSION,
url = "http://www.whitewolf.us"
};
/* Credits:
Mani - Showed me his observer code from MAP
*/
/* Globals */
new g_offObserverTarget;
new g_clientObserveTarget[MAXPLAYERS+1];
new bool:g_useSteamBans = false;
//CSGO-related
new bool:g_isCSGO;
new Handle:g_hSpec_freeze_time;
new Handle:g_hSpec_freeze_traveltime;
new Handle:g_hSpec_freeze_deathanim_time;
public OnPluginStart() {
new Handle:conVar;
CreateConVar("observe_version", VERSION, NAME, FCVAR_SPONLY|FCVAR_NOTIFY);
HookEvent("player_spawn", EventPlayerSpawn);
HookEvent("player_death", EventPlayerDeath);
RegConsoleCmd("sm_observe", CommandObserve, "Spectate a player when dead.");
RegConsoleCmd("sm_endobserve", CommandEndObserve, "End spectating a player.");
LoadTranslations("common.phrases");
LoadTranslations("observe.phrases");
g_offObserverTarget = FindSendPropOffs("CBasePlayer", "m_hObserverTarget");
if(g_offObserverTarget == -1) {
SetFailState("Expected to find the offset to m_hObserverTarget, couldn't.");
}
conVar = FindConVar("sbsrc_version");
if(conVar != INVALID_HANDLE) {
g_useSteamBans = true;
}
decl String:szBuffer[ 8 ];
GetGameFolderName(szBuffer, sizeof(szBuffer));
g_isCSGO = StrEqual(szBuffer, "csgo", false);
if (g_isCSGO)
{
g_hSpec_freeze_time = FindConVar("spec_freeze_time");
g_hSpec_freeze_traveltime = FindConVar("spec_freeze_traveltime");
g_hSpec_freeze_deathanim_time = FindConVar("spec_freeze_deathanim_time");
}
}
/********************************************************************************
Events
*********************************************************************************/
public Action:EventPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) {
/* Suggestions for improvement, or single-shot method? */
new target = GetClientOfUserId(GetEventInt(event, "userid"));
for(new client = 1; client 0 && IsClientInGame(client) && IsPlayerAlive(client))
{
return Plugin_Handled;//prevent late kill messages
}
//Won't be a real Timer
if(g_clientObserveTarget[client] > 0) {
new target = g_clientObserveTarget[client];
if(!isValidHumanClient(target)) {
g_clientObserveTarget[client] = 0;
return Plugin_Handled;
}
if(IsPlayerAlive(target)) {
SetClientObserver(client, target, true);
}
}
return Plugin_Handled;
}
public OnClientDisconnect(client) {
new String:clientName[MAX_NAME_LENGTH];
GetClientName(client, clientName, MAX_NAME_LENGTH);
g_clientObserveTarget[client] = 0;
for(new i = 1; i 0 && IsClientInGame(client) && IsClientConnected(client)) {
return true;
}
return false;
}
public bool:SetClientObserver(client, target, bool:sendMessage) {
if(!isValidHumanClient(client) || !isValidHumanClient(target)) {
return false;
}
SetEntDataEnt2(client, g_offObserverTarget, target, true);
if(sendMessage) {
SendClientObserveMessage(client, target);
}
if(g_useSteamBans) {
ClientCommand(client, "sb_status");
}
return true; //we assume it went through, else SM would throw a native error and we wouldn't get here anyway
}
public SendClientObserveMessage(client, target) {
decl String:targetName[MAX_NAME_LENGTH], String:targetSteamID[65];
GetClientName(target, targetName, MAX_NAME_LENGTH);
GetClientAuthString(target, targetSteamID, 65);
PrintToChat(client, "%t", "Observing", targetName, targetSteamID);
}
```
I redid it to make it a public command.
I find this useful on surf servers, since one can just type Observe name, naturally the command can be changed to what ever, but it saves time having to find the player.
<https://forums.alliedmods.net/showthread.php?t=62324?t=62324>
There is the original and the phrases you need.And if you add it to admin menu, that be nice to, just exclude the "admin" "sm_kick" part, so if anyone types !observe it triggers a menu.
#include
#include
#pragma semicolon 1
#define VERSION "1.2.4"
#define NAME "Observe Client"
public Plugin:myinfo =
{
name = NAME,
author = "WhiteWolf, puopjik, psychonic, RedSword",
description = "Observe client when dead",
version = VERSION,
url = "http://www.whitewolf.us"
};
/* Credits:
Mani - Showed me his observer code from MAP
*/
/* Globals */
new g_offObserverTarget;
new g_clientObserveTarget[MAXPLAYERS+1];
new bool:g_useSteamBans = false;
//CSGO-related
new bool:g_isCSGO;
new Handle:g_hSpec_freeze_time;
new Handle:g_hSpec_freeze_traveltime;
new Handle:g_hSpec_freeze_deathanim_time;
public OnPluginStart() {
new Handle:conVar;
CreateConVar("observe_version", VERSION, NAME, FCVAR_SPONLY|FCVAR_NOTIFY);
HookEvent("player_spawn", EventPlayerSpawn);
HookEvent("player_death", EventPlayerDeath);
RegConsoleCmd("sm_observe", CommandObserve, "Spectate a player when dead.");
RegConsoleCmd("sm_endobserve", CommandEndObserve, "End spectating a player.");
LoadTranslations("common.phrases");
LoadTranslations("observe.phrases");
g_offObserverTarget = FindSendPropOffs("CBasePlayer", "m_hObserverTarget");
if(g_offObserverTarget == -1) {
SetFailState("Expected to find the offset to m_hObserverTarget, couldn't.");
}
conVar = FindConVar("sbsrc_version");
if(conVar != INVALID_HANDLE) {
g_useSteamBans = true;
}
decl String:szBuffer[ 8 ];
GetGameFolderName(szBuffer, sizeof(szBuffer));
g_isCSGO = StrEqual(szBuffer, "csgo", false);
if (g_isCSGO)
{
g_hSpec_freeze_time = FindConVar("spec_freeze_time");
g_hSpec_freeze_traveltime = FindConVar("spec_freeze_traveltime");
g_hSpec_freeze_deathanim_time = FindConVar("spec_freeze_deathanim_time");
}
}
/********************************************************************************
Events
*********************************************************************************/
public Action:EventPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) {
/* Suggestions for improvement, or single-shot method? */
new target = GetClientOfUserId(GetEventInt(event, "userid"));
for(new client = 1; client 0 && IsClientInGame(client) && IsPlayerAlive(client))
{
return Plugin_Handled;//prevent late kill messages
}
//Won't be a real Timer
if(g_clientObserveTarget[client] > 0) {
new target = g_clientObserveTarget[client];
if(!isValidHumanClient(target)) {
g_clientObserveTarget[client] = 0;
return Plugin_Handled;
}
if(IsPlayerAlive(target)) {
SetClientObserver(client, target, true);
}
}
return Plugin_Handled;
}
public OnClientDisconnect(client) {
new String:clientName[MAX_NAME_LENGTH];
GetClientName(client, clientName, MAX_NAME_LENGTH);
g_clientObserveTarget[client] = 0;
for(new i = 1; i 0 && IsClientInGame(client) && IsClientConnected(client)) {
return true;
}
return false;
}
public bool:SetClientObserver(client, target, bool:sendMessage) {
if(!isValidHumanClient(client) || !isValidHumanClient(target)) {
return false;
}
SetEntDataEnt2(client, g_offObserverTarget, target, true);
if(sendMessage) {
SendClientObserveMessage(client, target);
}
if(g_useSteamBans) {
ClientCommand(client, "sb_status");
}
return true; //we assume it went through, else SM would throw a native error and we wouldn't get here anyway
}
public SendClientObserveMessage(client, target) {
decl String:targetName[MAX_NAME_LENGTH], String:targetSteamID[65];
GetClientName(target, targetName, MAX_NAME_LENGTH);
GetClientAuthString(target, targetSteamID, 65);
PrintToChat(client, "%t", "Observing", targetName, targetSteamID);
}
```
I redid it to make it a public command.
I find this useful on surf servers, since one can just type Observe name, naturally the command can be changed to what ever, but it saves time having to find the player.
<https://forums.alliedmods.net/showthread.php?t=62324?t=62324>
There is the original and the phrases you need.And if you add it to admin menu, that be nice to, just exclude the "admin" "sm_kick" part, so if anyone types !observe it triggers a menu.
checkster
Thread owner
2014-Nov-11 19:43
Fui adminmenu_custom is all you need to add menu.