AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   [Any] Allow Admins to spectate the other team (https://forums.alliedmods.net/showthread.php?t=179757)

FudgePoly 03-05-2012 07:02

[Any] Allow Admins to spectate the other team
 
I've been looking for a way to do this and I haven't found one yet...

I'm using Simple Spectate to give my Admins moderating options when they're dead or if they want to spectate and punish players who break the rules.

My problem is that I have mp_forcecam 1 selected in my server.cfg, I don't want players to be able to spectate the other team for obvious gameplay reasons. However, I DO want my Admins to spectate the other team for obvious moderating reasons.

I've found this plugin for AMX Mod but haven't found anything similar for Sourcemod... Can anyone please offer some assistance?

FudgePoly 03-12-2012 19:24

Re: [Any] Allow Admins to spectate the other team
 
Anyone? It doesn't seem to be extremely difficult...

Doodil 03-13-2012 14:15

Re: [Any] Allow Admins to spectate the other team
 
Have you tried that other plugin?
I kinda think he switches every dead admin to spectator until the round begins again or am I wrong there?

Dreamy 03-13-2012 17:14

Re: [Any] Allow Admins to spectate the other team
 
edit: sry, fail post.

FudgePoly 03-13-2012 17:25

Re: [Any] Allow Admins to spectate the other team
 
Quote:

Originally Posted by Doodil (Post 1668164)
Have you tried that other plugin?
I kinda think he switches every dead admin to spectator until the round begins again or am I wrong there?

The "other plugin" is an AMX Mod plugin, I use Sourcemod naturally.

Quote:

Originally Posted by Dreamy (Post 1668315)
edit: sry, fail post.

Why is that a fail post? I just tried it (I saw it before the edit) and my Admin said he could spectate the other team! Tell me your secrets, oh Dreamy one!

EDIT: Yeah I just figured by reading it, normal players will fade to black when they die right? Damn. If you could offer something else I'll be really grateful, you seem awfully helpful around here.

Dreamy 03-13-2012 17:36

Re: [Any] Allow Admins to spectate the other team
 
ye no fail post afterall xD thought u can still see the radar after the fade, which apparently is NOT the case ;)

here it is:
PHP Code:

#include <sourcemod>

#define FFADE_OUT           0x0002  
#define FFADE_STAYOUT       0x0008
#define FFADE_PURGE         0x0010

public Plugin:myinfo 
{
    
name "FadeForce",
    
author "Dreamy",
    
description "mp_forcecam done via screen fade",
    
version "1.0",
    
url "SourceMod.net"
}

public 
OnPluginStart()
{
    
ServerCommand("mp_forcecamera 0");
    
ServerCommand("mp_fadetoblack 0");
    
HookEvent("player_spawn"Event_Spawn);
    
HookEvent("player_death"Event_Death);
}

public 
Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
{    
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if (
GetClientTeam(client) < 2)
        
FadeToBlack(client);
}

public 
Event_Death(Handle:event, const String:name[], bool:dontBroadcast)
    
FadeToBlack(GetClientOfUserId(GetEventInt(event"userid")));

FadeToBlack(client
{
    if (
GetUserAdmin(client) != INVALID_ADMIN_ID)
        return;
    
    new 
Handle:hFadeClient StartMessageOne("Fade",client);
    
BfWriteShort(hFadeClient0);
    
BfWriteShort(hFadeClient0);
    
BfWriteShort(hFadeClient, (FFADE_OUT|FFADE_PURGE|FFADE_STAYOUT));
    
BfWriteByte(hFadeClient0);
    
BfWriteByte(hFadeClient0);
    
BfWriteByte(hFadeClient0);    
    
BfWriteByte(hFadeClient255);
    
EndMessage();


what else do u want?

FudgePoly 03-14-2012 10:23

Re: [Any] Allow Admins to spectate the other team
 
Quote:

Originally Posted by Dreamy (Post 1668333)
ye no fail post afterall xD thought u can still see the radar after the fade, which apparently is NOT the case ;)

here it is:
what else do u want?

I appreciate the coding effort but your system isn't working well. From what I can tell it does allow my admin to spectate the other team but normal players have a black screen every time they die...

I just want my admins to be able to spectate everyone with nothing else changing.

EDIT: upon further inspection all your plugin does is change mp_forcecamera to 0 (which I can do in my server.cfg but of course players will be able to spectate the other team) and then cause non-admins to get a black screen. Any other ideas?

TnTSCS 03-14-2012 10:42

Re: [Any] Allow Admins to spectate the other team
 
*post removed.

Ask me if you want to see the code I had - don't want people thinking I'm jumping their work!!

Dreamy 03-14-2012 11:55

Re: [Any] Allow Admins to spectate the other team
 
*post removed.
coz im maaaaad!

FudgePoly 03-14-2012 12:05

Re: [Any] Allow Admins to spectate the other team
 
If it works it's some workaround I guess, but maybe we can work from there? Instead of creating a timer, would it be possible to deny the command entirely (but silently) and instead supply the user with his next target manually?

Dreamy 03-14-2012 12:19

Re: [Any] Allow Admins to spectate the other team
 
nah there was a reason why I created a timer.. :P

but its actually quite simple with sdkhooks:
PHP Code:

#include <sourcemod>
#include <sdkhooks>

public OnPluginStart()
    
HookEvent("player_death"Event_Death);

public 
Event_Death(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if (
GetUserAdmin(client) == INVALID_ADMIN_ID)
        
SDKHook(clientSDKHook_PostThinkCheckObserver);
}

public 
Action:CheckObserver(client)
{
    new 
team GetClientTeam(client);
    new 
ent GetEntPropEnt(clientProp_Send"m_hObserverTarget");
    if (
team != GetClientTeam(ent))
    {
        for (new 
1MaxClients+1i++)
        {
            if (
IsClientInGame(i))
            {
                if (
IsPlayerAlive(i) && (team == GetClientTeam(i)))
                {
                    
SetEntPropEnt(clientProp_Send"m_hObserverTarget"i);
                    return 
Plugin_Handled;
                }
            }
        }
    }
    return 
Plugin_Handled;



TnTSCS 03-14-2012 12:46

Re: [Any] Allow Admins to spectate the other team
 
sorry, you're right - doesn't really matter I guess

FudgePoly 03-14-2012 12:47

Re: [Any] Allow Admins to spectate the other team
 
Quote:

Originally Posted by Dreamy (Post 1668796)
nah there was a reason why I created a timer.. :P

but its actually quite simple with sdkhooks:
PHP Code:

#include <sourcemod>
#include <sdkhooks>

public OnPluginStart()
    
HookEvent("player_death"Event_Death);

public 
Event_Death(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if (
GetUserAdmin(client) == INVALID_ADMIN_ID)
        
SDKHook(clientSDKHook_PostThinkCheckObserver);
}

public 
Action:CheckObserver(client)
{
    new 
team GetClientTeam(client);
    new 
ent GetEntPropEnt(clientProp_Send"m_hObserverTarget");
    if (
team != GetClientTeam(ent))
    {
        for (new 
1MaxClients+1i++)
        {
            if (
IsClientInGame(i))
            {
                if (
IsPlayerAlive(i) && (team == GetClientTeam(i)))
                {
                    
SetEntPropEnt(clientProp_Send"m_hObserverTarget"i);
                    return 
Plugin_Handled;
                }
            }
        }
    }
    return 
Plugin_Handled;



Code:

L 03/14/2012 - 18:42:43: [SM]  [0]  Line 18, admincam.sp::CheckObserver()
L 03/14/2012 - 18:42:43: [SM] Native "GetClientTeam" reported: Client index 151 is invalid
L 03/14/2012 - 18:42:43: [SM] Displaying call stack trace for plugin "admincam.smx":
L 03/14/2012 - 18:42:43: [SM]  [0]  Line 18, admincam.sp::CheckObserver()
L 03/14/2012 - 18:42:43: [SM] Native "GetClientTeam" reported: Client index 151 is invalid
L 03/14/2012 - 18:42:43: [SM] Displaying call stack trace for plugin "admincam.smx":
L 03/14/2012 - 18:42:43: [SM]  [0]  Line 18, admincam.sp::CheckObserver()
L 03/14/2012 - 18:42:43: [SM] Native "GetClientTeam" reported: Client index 151 is invalid
L 03/14/2012 - 18:42:43: [SM] Displaying call stack trace for plugin "admincam.smx":
L 03/14/2012 - 18:42:43: [SM]  [0]  Line 18, admincam.sp::CheckObserver()
L 03/14/2012 - 18:42:43: [SM] Native "GetClientTeam" reported: Client index 151 is invalid
L 03/14/2012 - 18:42:43: [SM] Displaying call stack trace for plugin "admincam.smx":
L 03/14/2012 - 18:42:43: [SM]  [0]  Line 18, admincam.sp::CheckObserver()
L 03/14/2012 - 18:42:43: [SM] Native "GetClientTeam" reported: Client index 151 is invalid
L 03/14/2012 - 18:42:43: [SM] Displaying call stack trace for plugin "admincam.smx":
L 03/14/2012 - 18:42:43: [SM]  [0]  Line 18, admincam.sp::CheckObserver()
L 03/14/2012 - 18:42:43: [SM] Native "GetClientTeam" reported: Client index 151 is invalid
L 03/14/2012 - 18:42:43: [SM] Displaying call stack trace for plugin "admincam.smx":
L 03/14/2012 - 18:42:43: [SM]  [0]  Line 18, admincam.sp::CheckObserver()
L 03/14/2012 - 18:42:43: [SM] Native "GetClientTeam" reported: Client index 151 is invalid
L 03/14/2012 - 18:42:43: [SM] Displaying call stack trace for plugin "admincam.smx":
L 03/14/2012 - 18:42:43: [SM]  [0]  Line 18, admincam.sp::CheckObserver()
L 03/14/2012 - 18:42:43: [SM] Native "GetClientTeam" reported: Client index 151 is invalid
L 03/14/2012 - 18:42:43: [SM] Displaying call stack trace for plugin "admincam.smx":
L 03/14/2012 - 18:42:43: [SM]  [0]  Line 18, admincam.sp::CheckObserver()

Oh boy...

TnTSCS 03-14-2012 12:49

Re: [Any] Allow Admins to spectate the other team
 
again, sorry about pointing stuff out

Dreamy 03-14-2012 13:05

Re: [Any] Allow Admins to spectate the other team
 
**lets remove our posts so others dont see our buggy code anymore
and while we are at it, lets make it appear like somebody explicitly told us to remove them**

FudgePoly 03-14-2012 13:26

Re: [Any] Allow Admins to spectate the other team
 
I have root access and I still can't spectate the other team 100% of the time, it's almost random... (using the fixed version). Does this work in TF2 arena or is that the issue?

Dreamy 03-14-2012 13:42

Re: [Any] Allow Admins to spectate the other team
 
**removing posts is so fun**

TnTSCS 03-14-2012 14:41

Re: [Any] Allow Admins to spectate the other team
 
*post removed.

Ask me if you want to see the code I had - don't want people thinking I'm jumping their work!!

TnTSCS 03-14-2012 19:29

Re: [Any] Allow Admins to spectate the other team
 
*post removed.

Ask me if you want to see the code I had - don't want people thinking I'm jumping their work!!

Dreamy 03-14-2012 19:54

Re: [Any] Allow Admins to spectate the other team
 
set mp_forcecamera 0 and try this:
PHP Code:

#pragma semicolon 1
#include <sourcemod>

#define FFADE_IN               0x0001
#define FFADE_OUT           0x0002  
#define FFADE_STAYOUT       0x0008
#define FFADE_PURGE         0x0010

public OnPluginStart()
{
    
HookEvent("player_death"Event_Death); 
}

public 
Action:Event_Death(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if (
GetUserAdmin(client) != INVALID_ADMIN_ID)
        return 
Plugin_Continue;
    
    
PerformFade(client);
    
CreateTimer(7.0SpecTeamclient);
    return 
Plugin_Continue;
}

public 
Action:OnClientCommand(clientargs)
{
    if (
GetUserAdmin(client) != INVALID_ADMIN_ID)
        return 
Plugin_Continue;
    
    
decl String:arg[128];
    
GetCmdArg(0argsizeof(arg));

    if (
StrEqual(arg"spec_mode"))
        return 
Plugin_Handled;
    
    if (
StrEqual(arg"spec_next"))
    {
        
SpecNext(clientGetEntPropEnt(clientProp_Send"m_hObserverTarget"));
        return 
Plugin_Handled;
    }
    else if(
StrEqual(arg"spec_prev"))
    {
        
SpecPrev(clientGetEntPropEnt(clientProp_Send"m_hObserverTarget"));
        return 
Plugin_Handled;
    }
    
    return 
Plugin_Continue;
}

stock SpecNext(clientcurrent)
{
    new 
team GetClientTeam(client);
    for (new 
current+1!= currenti++)
    {    
        if (
team == GetClientTeamEx(i))
        {
            
SetEntPropEnt(clientProp_Send"m_hObserverTarget"i);
            return;
        }
        if (
== MaxClients)
            
1;
    }
}

stock SpecPrev(clientcurrent)
{
    new 
team GetClientTeam(client);
    for (new 
current-1!= currenti--)
    {
        if (
team == GetClientTeamEx(i))
        {
            
SetEntPropEnt(clientProp_Send"m_hObserverTarget"i);
            return;
        }
        if (
== 1)
            
MaxClients;
    }
}

GetClientTeamEx(client)
{
    return (!
client || !IsClientInGame(client) || !IsPlayerAlive(client)) ? -1:GetClientTeam(client);
}

public 
Action:SpecTeam(Handle:timerany:client)
{
    
SetEntProp(clientProp_Send"m_iObserverMode"4);
    
SpecNext(clientGetEntPropEnt(clientProp_Send"m_hObserverTarget"));
    return 
Plugin_Handled;
}

public 
PerformFade(client)
{
    new 
Handle:hFadeClient StartMessageOne("Fade"client);
    
BfWriteShort(hFadeClient3250);
    
BfWriteShort(hFadeClient350);
    
BfWriteShort(hFadeClient, (FFADE_OUT|FFADE_PURGE));
    
BfWriteByte(hFadeClient0);
    
BfWriteByte(hFadeClient0);
    
BfWriteByte(hFadeClient0);
    
BfWriteByte(hFadeClient255);
    
EndMessage();


this is just to see if its working or not (so dont complain about OnClientCommand), I can make a plugin out of it if everything is alright.

TnTSCS 03-14-2012 21:33

Re: [Any] Allow Admins to spectate the other team
 
*post removed.

Ask me if you want to see the code I had - don't want people thinking I'm jumping their work!!

Despirator 03-15-2012 03:45

Re: [Any] Allow Admins to spectate the other team
 
1 Attachment(s)
try this one

Corneus 03-15-2012 09:03

Re: [Any] Allow Admins to spectate the other team
 
Doesn't work, because admin can spec only 1 random player without possibility to change him.

Dreamy 03-15-2012 13:13

Re: [Any] Allow Admins to spectate the other team
 
1 Attachment(s)
final code, just ~120 lines and working smoothly on css (for me).. can sb test it on other games as well pls? =)

Powerlord 03-15-2012 15:25

Re: [Any] Allow Admins to spectate the other team
 
Is there any reason we're removing all our old code posts? I was under the impression that the forum mods frowned on that sort of thing.

TnTSCS 03-15-2012 18:31

Re: [Any] Allow Admins to spectate the other team
 
Powerlord, you're right. Here's a more complete code of the version I removed:

Still working on code for forcing specmode_firstperson though
code

Dr!fter 03-16-2012 12:37

Re: [Any] Allow Admins to spectate the other team
 
You can do this easily with a hook :P here is a quick example

Example

Gamedata


The example requires DHooks

All the example does is even with mp_forcecamera 1 it still allows everybody to spec anybody (I was too lazy to add anything else to it). But if someone wants to use it they are free to use this method if they want. Note that I only provided the gamedata for cstrike. But if someone wants the offset for another game feel free to ask and ill try to get them.

Dreamy 03-16-2012 13:18

Re: [Any] Allow Admins to spectate the other team
 
haha really thought about taking your awesome extension (did it with sdkhooks b4 but hooking playerthink kinda felt wrong)..
+i didnt know how to get those offsets..

dammit its only in alpha, but I already love it :D

Dr!fter 03-16-2012 13:43

Re: [Any] Allow Admins to spectate the other team
 
Quote:

Originally Posted by Dreamy (Post 1670024)
haha really thought about taking your awesome extension (did it with sdkhooks b4 but hooking playerthink kinda felt wrong)..
+i didnt know how to get those offsets..

dammit its only in alpha, but I already love it :D

http://wiki.alliedmods.net/Finding_Virtual_Offsets Thats a tutorial on how to get them.

Also, its only in pre alpha since I didnt test it fully (I didnt test all the possible combinations of params/returns which if something is wrong can cause a crash) and Im still adding param types/other things. But its safe to use (as long as you test the hook) and wont change much in terms of what is there already.

As for your pm for the offsets for TF2
Gamedata


If it dosnt work let me know. Linux should be right, but windows might not.

Edit:
Also just realized you can get them from here http://www.sourcemodplugins.org/inde...=vtableoffsets Select the game and search for "IsValidObserverTarget"

FudgePoly 03-16-2012 18:11

Re: [Any] Allow Admins to spectate the other team
 
So should I wait for a DHooks-based plugin or does one of the above succeed? I already crashed my Arena server several times (my fault, obviously) by doing this so I'd rather have something at least semi-stable to test.

Dr!fter 03-16-2012 18:21

Re: [Any] Allow Admins to spectate the other team
 
Quote:

Originally Posted by FudgePoly (Post 1670194)
So should I wait for a DHooks-based plugin or does one of the above succeed? I already crashed my Arena server several times (my fault, obviously) by doing this so I'd rather have something at least semi-stable to test.

Which one is crashing? The DHooks one? If so it'd need to be looked into. I know in CS:S it works.

FudgePoly 03-16-2012 20:04

Re: [Any] Allow Admins to spectate the other team
 
Nah, Dreamy and some of the earlier ones crashed it because something was incomplete (he said it worked in CS:S but TF2 was having troubles). I haven't checked out your example since I don't have DHooks installed, I want to know if we have a working WIP to test so that installing it won't go to waste.

TnTSCS 03-16-2012 20:18

Re: [Any] Allow Admins to spectate the other team
 
using the code Dr!fter posted and putting in a check for admin works, however, if you have mp_forcecamera 1, then even if you're allowed to spec as an admin, the radar doesn't work, but it definitely is a WIP project for me. :)

Dr!fter 03-16-2012 21:21

Re: [Any] Allow Admins to spectate the other team
 
Quote:

Originally Posted by TnTSCS (Post 1670250)
using the code Dr!fter posted and putting in a check for admin works, however, if you have mp_forcecamera 1, then even if you're allowed to spec as an admin, the radar doesn't work, but it definitely is a WIP project for me. :)

You could simple switch the logic and have mp_forcecamera 0. Then just check if they arent admin and that the target isnt on their team. If they arent change the return to false and done. Or if you want a challenge find what gets called to update the radar or not hook that and return true :P although it might not exist.

Edit:

After some thinking the above idea might not work. Since you might not want them to show up on radar, plus you have to check Observer Mode (you could hook the observer mode and block them changing it). As for the radar im pretty sure there is a snippet on how to remove them somewhere iirc (or how to add them). In tf2 however you dont have to worry about the radar :P

FudgePoly 03-17-2012 04:44

Re: [Any] Allow Admins to spectate the other team
 
I'm only using TF2 so I really do not care for CS:S elements... but if we're gonna help the community I guess we should have it fully working right?

Dr!fter 03-21-2012 15:17

Re: [Any] Allow Admins to spectate the other team
 
So for cs:s i had a look if i could fake the radar (I couldn't fake the spectator one). I also had a look if there was something that changed how data was passed to the client (couldn't see anything specific). So i came up with the idea of hiding the radar from non admins, leaving mp_forcecamera to 0, and blocking non admins from spec other team. So you could give that a try :P I will look into it further though see if i can find anything for the radar.

Dreamy 03-21-2012 15:51

Re: [Any] Allow Admins to spectate the other team
 
first of all fudgepoly should investigate the problem of his server crashing when using dhooks...
wrote him this a couple of days ago:

PHP Code:

#include <sourcemod>
#include <dhooks>

new Handle:hIsValidTarget;

public 
OnPluginStart()
{
    new 
Handle:temp LoadGameConfigFile("allow-spec.games");
    if(!
temp)
        
SetFailState("Y U NO has gamedata? (3o_O)3");
    
    new 
offset GameConfGetOffset(temp"IsValidObserverTarget");
    
hIsValidTarget DHookCreate(offsetHookType_EntityReturnType_BoolThisPointer_CBaseEntityIsValidTarget);
    
DHookAddParam(hIsValidTargetHookParamType_CBaseEntity);
    
CloseHandle(temp);

    
AddCommandListener(cmd_mode"spec_mode");
}

public 
OnClientPostAdminCheck(client)
{
    if ((
GetUserAdmin(client) == INVALID_ADMIN_ID) && !IsFakeClient(client))
        
DHookEntity(hIsValidTargettrueclientRemoveCB);
}

public 
Action:cmd_mode(client, const String:command[], args)
{
    return (
GetUserAdmin(client) == INVALID_ADMIN_ID)?Plugin_Handled:Plugin_Continue;
}

public 
MRESReturn:IsValidTarget(thisHandle:hReturnHandle:hParams)
{
    new 
team GetClientTeam(this);
    new 
target DHookGetParam(hParams1);
    if (
team && target && target <= MaxClients)
    {    
        if(
team != GetClientTeam(target))
        {
            
DHookSetReturn(hReturnfalse);
            return 
MRES_Override;
        }
    }
    return 
MRES_Ignored;
}
public 
RemoveCB(hookid){} 

dont get why this is crashing, coz its working perfectly in css.. ;P

FudgePoly 03-23-2012 12:16

Re: [Any] Allow Admins to spectate the other team
 
Like I said Dreamy it only crashed once and for some reason it didn't after the auto-restart... but spectating treated me (admin with every single flag) as a normal player as far as spectation goes (could only spectate my own team).

*I tested with bots so maybe it does work with normal players? I dunno. Not like it's much different for TF2...

Dr!fter 03-24-2012 03:00

Re: [Any] Allow Admins to spectate the other team
 
Quote:

Originally Posted by FudgePoly (Post 1674188)
Like I said Dreamy it only crashed once and for some reason it didn't after the auto-restart... but spectating treated me (admin with every single flag) as a normal player as far as spectation goes (could only spectate my own team).

*I tested with bots so maybe it does work with normal players? I dunno. Not like it's much different for TF2...

I tested with bots on tf2 and got it to work fine. Ill have a look tomorrow at the actual plugin.

FudgePoly 03-24-2012 06:03

Re: [Any] Allow Admins to spectate the other team
 
Got what to work fine? DHooks was operational after the crash, the problem was with the plugin that Dreamy made (but that could be related to CVARs etc. so I'd appreciate someone else having a look).


All times are GMT -4. The time now is 23:03.

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