AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Force observing a team as spectator (https://forums.alliedmods.net/showthread.php?t=343237)

pokezao 07-01-2023 07:10

Force observing a team as spectator
 
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.

Natsheh 07-01-2023 09:57

Re: Force observing a team as spectator
 
learn to use get_players instead looping the player entity

pokezao 07-01-2023 11:28

Re: Force observing a team as spectator
 
Does that solve my problem?
I'm only doing as suggested here: https://forums.alliedmods.net/showpo...50&postcount=2

lexzor 07-01-2023 13:55

Re: Force observing a team as spectator
 
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

pokezao 07-01-2023 17:07

Re: Force observing a team as spectator
 
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.

Natsheh 07-01-2023 18:12

Re: Force observing a team as spectator
 
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);
        }
    }



MrPickles 07-01-2023 20:20

Re: Force observing a team as spectator
 
where is used "bSameTeam"? xd

cs_get_user_team(iPlayerIndex) = cs_get_user_team(iTarget) ?

WaLkMaN 07-02-2023 10:05

Re: Force observing a team as spectator
 
Quote:

Originally Posted by Natsheh (Post 2806678)
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++;         }     } }

pokezao 07-02-2023 10:49

Re: Force observing a team as spectator
 
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! :fox:

pokezao 07-02-2023 12:28

Re: Force observing a team as spectator
 
Guys, for some reason it is working but exactly the opposite of what it should: we can only spectate Terrorists and not CTs


All times are GMT -4. The time now is 16:52.

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