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

Solved Force observing a team as spectator


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pokezao
Member
Join Date: Oct 2014
Old 07-01-2023 , 07:10   Force observing a team as spectator
Reply With Quote #1

Hi, I want to force non-admin Spectators to only spectate CT players in a Hide'n'Seek day (Jailbreak mod).

What I'm doing right now is hooking CBasePlayer_Observer_IsValidTarget and doing this:
PHP Code:
public CBasePlayer_Observer_IsValidTarget(const thisiPlayerIndexbool:bSameTeam
{
    if( 
is_user_alive(iPlayerIndex) && day == HIDENSEEK )
    {
        if( !(
get_user_flags(this) & ADMIN_FLAG) )
        {
            if( 
cs_get_user_team(iPlayerIndex) != CS_TEAM_CT )
            {
                static 
idid iPlayerIndex;
                while( (
id find_ent_by_class(id"player")) != iPlayerIndex 
                {
                    if( !
is_user_alive(id) ) continue;
                    if( 
cs_get_user_team(id) != CS_TEAM_CT 
                        continue;
                    
                    
SetHookChainReturn(ATYPE_INTEGERid);
                    break;
                }
            }
        }
    }

This is working for observing players that are in a team (T or CT) but not for SPECTATOR players.

PS: Another thing to note is that I'm changing "mp_forcechasecam" to 2 only in HNS day, normally it is set to 0.

Last edited by pokezao; 07-03-2023 at 17:41. Reason: Marked as solved
pokezao is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-01-2023 , 09:57   Re: Force observing a team as spectator
Reply With Quote #2

learn to use get_players instead looping the player entity
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
pokezao
Member
Join Date: Oct 2014
Old 07-01-2023 , 11:28   Re: Force observing a team as spectator
Reply With Quote #3

Does that solve my problem?
I'm only doing as suggested here: https://forums.alliedmods.net/showpo...50&postcount=2
pokezao is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 07-01-2023 , 13:55   Re: Force observing a team as spectator
Reply With Quote #4

use this as an example: https://amxx-bg.info/forum/viewtopic.php?f=18&t=1009


use flags parameters from get_players to get only ct team players, it's a better practice than loop every entity from the map
lexzor is offline
pokezao
Member
Join Date: Oct 2014
Old 07-01-2023 , 17:07   Re: Force observing a team as spectator
Reply With Quote #5

I appreciate your help, but that's not the problem here.
This code is working if the observing player is in a team (T or CT) but, for some reason, doesn't work for Spectators.
I'm only interested in knowing why and what I can do to force ALL players, including spectators, to spectate only the CT team.
pokezao is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-01-2023 , 18:12   Re: Force observing a team as spectator
Reply With Quote #6

there.....

PHP Code:
public CBasePlayer_Observer_IsValidTarget(const this, const iTarget, const bool:bSameTeam)
{
    static 
players[32], pnum;
    
get_players(playerspnum"ahe""CT");

    const 
PDATA_SAFE 2;

    if( !
iTarget || ( pev_valid(iTarget) == PDATA_SAFE && cs_get_user_team(iPlayerIndex) != CS_TEAM_CT ) )
    {
        if(
pnum 0)
        {
            
SetHookChainArg(2ATYPE_INTEGERplayers[randompnum )]);
            
SetHookChainArg(3ATYPE_BOOLfalse);
        }
    }

__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 07-01-2023 at 18:15.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 07-01-2023 , 20:20   Re: Force observing a team as spectator
Reply With Quote #7

where is used "bSameTeam"? xd

cs_get_user_team(iPlayerIndex) = cs_get_user_team(iTarget) ?

Last edited by MrPickles; 07-01-2023 at 20:21.
MrPickles is offline
WaLkMaN
Senior Member
Join Date: Oct 2010
Location: Varna, Bulgaria
Old 07-02-2023 , 10:05   Re: Force observing a team as spectator
Reply With Quote #8

Quote:
Originally Posted by Natsheh View Post
there.....
A small edit:

Code:
#include <amxmodx> #include <reapi> public plugin_init() {     register_plugin("Force Spectate", "1.0", "Alliedmods");         RegisterHookChain(RG_CBasePlayer_Observer_IsValidTarget, "Observer_IsValidTarget_Pre", .post = false); } public Observer_IsValidTarget_Pre(const this, const iTarget, const bool:bOnlyTeam) {     static players[32], pnum;     get_players(players, pnum, "ahe", "CT");         static currentPlayerId = 0;     if ( !iTarget || ( is_user_alive(iTarget) && get_member(iTarget, m_iTeam) != TEAM_CT ) )     {         if (pnum > 0)         {             if (currentPlayerId >= pnum)             {                 currentPlayerId = 0             }             SetHookChainArg(2, ATYPE_INTEGER, players[currentPlayerId]);             SetHookChainArg(3, ATYPE_BOOL, false);                         currentPlayerId++;         }     } }
__________________

Last edited by WaLkMaN; 07-04-2023 at 08:19. Reason: Removed fakemeta and cstrike natives
WaLkMaN is offline
pokezao
Member
Join Date: Oct 2014
Old 07-02-2023 , 10:49   Re: Force observing a team as spectator
Reply With Quote #9

I have yet to test it but I trust it's working perfectly!

Just to understand: the problem was that I was not returning "false" on bSameTeam? Or it has something to do with the PDATA_SAFE thingy?
I deduce that this PDATA_SAFE condition is just a way to check if iTarget is a player, right?

Thank you very much Natsheh for the correct solution, and WaLkMaN for the small edit!

Last edited by pokezao; 07-02-2023 at 10:50.
pokezao is offline
pokezao
Member
Join Date: Oct 2014
Old 07-02-2023 , 12:28   Re: Force observing a team as spectator
Reply With Quote #10

Guys, for some reason it is working but exactly the opposite of what it should: we can only spectate Terrorists and not CTs
pokezao 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 15:54.


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