AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Solved]Force spectator's m_hObserverTarget (https://forums.alliedmods.net/showthread.php?t=242177)

SpeeDeeR 06-15-2014 09:39

[Solved]Force spectator's m_hObserverTarget
 
I want to force m_hObserverTarget to be CT team only.

Quote:

Originally Posted by Arkshine (Post 2122885)
... you just need to call CBasePlayer::Observer_FindNextPlayer. You can pass name as param.

Using the code below throws that error and the server shutdowns.
Code:

[AMXX] Forwards with more than 32 parameters are not supported (tried to prepare array # 33).
Code:
#include <amxmodx> #include <orpheu> #include <fakemeta> #include <engine> #define get_team(%0) ( get_pdata_int( %0, m_iTeam ) ) const m_iTeam = 114; const TEAM_CT = 2; new OrpheuFunction:Observer_FindNextPlayer; public plugin_init() {     Observer_FindNextPlayer = OrpheuGetFunction( "Observer_FindNextPlayer", "CBasePlayer" );         OrpheuRegisterHook( Observer_FindNextPlayer, "OnObserver_FindNextPlayer_Post" , OrpheuHookPost); } public  OnObserver_FindNextPlayer_Post( const player, const bool:searchDown, const playerNameToSearch[] ) {     static m_hObserverTarget; m_hObserverTarget = pev( player, pev_iuser2 );         if( get_team( m_hObserverTarget ) != TEAM_CT )     {         static id; id = m_hObserverTarget;         while ( (id = find_ent_by_class( id, "player" )) != m_hObserverTarget )         {             if(get_team( id ) != TEAM_CT )                 continue;                             static szName[32]; get_user_name(id, szName, charsmax(szName));                         OrpheuCallSuper( Observer_FindNextPlayer, player, searchDown, szName );                         break;         }     } }

claudiuhks 06-15-2014 14:04

Re: [Orpheu] Force spectator's m_hObserverTarget
 
Well something is wrong. Make sure your code is alright so Orpheu won't get problems. If your code is alright and you are still getting this error, either Orpheu or your currently version of AMX Mod X have problems.

Furthermore, try that with the latest AMX Mod X build on AMX Mod X Snapshots.

PHP Code:

#include <amxmodx>
#include <orpheu>
#include <fakemeta>

#define Invalid -1
#define Offset 114
#define Ct 2
#define Team(%0) pev_valid(%0) && is_user_connected(%0) ? get_pdata_int(%0, Offset) : Invalid;

new OrpheuFunction:g_pFindNextPlayer OrpheuFunction:Invalid;

public 
plugin_init()
{
 
g_pFindNextPlayer OrpheuGetFunction("FindNextPlayer""CBasePlayer");
 
 if (
g_pFindNextPlayer == OrpheuFunction:Invalid)
  
set_fail_state("g_pFindNextPlayer is Invalid!");
  
 
OrpheuRegisterHook(g_pFindNextPlayer"FindNextPlayer_Post"OrpheuHookPost);
}

public 
FindNextPlayer_Post(Playerbool:DownName[])
{
 static 
pObserver InvalidId InvalidTeamId InvalidPlayerName[32], Loops 0;
 
 if (!
is_user_connected(Player))
  return;

 
pObserver pev(Playerpev_iuser2);
 
TeamId Team(pObserver);
 
 if (
TeamId == Invalid)
  
set_fail_state("Invalid Team for pObserver?");

 else if (
TeamId != Ct)
 {
  
Loops 0;
  
Id pObserver

  while ((
Id engfunc(EngFunc_FindEntityByStringId"classname""player")) != pObserver
  {
   
TeamId Team(Id);

   if (
TeamId == Invalid)
     
set_fail_state("Invalid Team for Id?");

   else if (
TeamId != Ct
     continue;

   else if (++
Loops >= 32
     
log_to_file("Debug.LOG""Reached Loop #32");
    
   
get_user_name(IdPlayerNamecharsmax(PlayerName));

   
OrpheuCallSuper(g_pFindNextPlayerPlayerDownPlayerName);

   break;
  }  
 }



SpeeDeeR 06-15-2014 19:46

Re: [Orpheu] Force spectator's m_hObserverTarget
 
With your code, server shutdowns and throws the same error.
I'm refering to this thread and I wish not to upgrade to 1.8.3.
Using Orpheu 2.5.1 and amxx 1.8.2. I'm testing this plugin on PodBots

hornet 06-15-2014 21:57

Re: [Orpheu] Force spectator's m_hObserverTarget
 
Your executing OrpheuCallSuper() from inside the hook your calling = infinite loop :nono:

NiHiLaNTh 06-16-2014 04:01

Re: [Orpheu] Force spectator's m_hObserverTarget
 
Hook it as pre, and supercede the original function call.

SpeeDeeR 06-16-2014 07:30

Re: [Orpheu] Force spectator's m_hObserverTarget
 
Quote:

Originally Posted by NiHiLaNTh (Post 2152463)
Hook it as pre, and supercede the original function call.

The reason I'm not hooking it pre is that iuser2 is not set to the current m_hObserverTarget but the last. That way I can't check if the spectated player is a certain team. If you know a different method let me know.

hornet 06-16-2014 09:26

Re: [Orpheu] Force spectator's m_hObserverTarget
 
Another method is with CBasePlayer::Observer_CheckTarget(). You can use the checkteam param.

SpeeDeeR 06-16-2014 11:10

Re: [Orpheu] Force spectator's m_hObserverTarget
 
Quote:

Originally Posted by hornet (Post 2152574)
Another method is with CBasePlayer::Observer_CheckTarget(). You can use the checkteam param.

What are you talking about?
PHP Code:

void CBasePlayer::Observer_CheckTarget()
{
    if( 
pev->iuser1 == OBS_ROAMING )
        return;

    
// try to find a traget if we have no current one
    
if ( m_hObserverTarget == NULL)
    {
        
Observer_FindNextPlayerfalseNULL );

        if (
m_hObserverTarget == NULL)
        {
            
// no target found at all 

            
int lastMode pev->iuser1;

            
Observer_SetModeOBS_ROAMING );

            
m_iObserverLastMode lastMode;    // don't overwrite users lastmode

            
return;    // we still have np target return
        
}
    }

    
CBasePlayertarget = (CBasePlayer*)(UTIL_PlayerByIndexENTINDEX(m_hObserverTarget->edict())));

    if ( !
target )
    {
        
Observer_FindNextPlayerfalseNULL );
        return;
    }

    
// check taget
    
if (target->pev->deadflag == DEAD_DEAD)
    {
        if ( (
target->m_fDeadTime 2.0f ) < gpGlobals->time )
        {
            
// 3 secs after death change target
            
Observer_FindNextPlayerfalseNULL );
            return;
        }
    }



hornet 06-16-2014 18:37

Re: [Orpheu] Force spectator's m_hObserverTarget
 
Quote:

Originally Posted by SpeeDeeR (Post 2152627)
What are you talking about?

Sorry, half asleep, I meant CBasePlayer::Observer_IsValidTarget().

SpeeDeeR 06-16-2014 20:26

Re: [Orpheu] Force spectator's m_hObserverTarget
 
Quote:

Originally Posted by hornet (Post 2152844)
CBasePlayer::Observer_IsValidTarget().

Quote:

Originally Posted by hornet (Post 2152574)
You can use the checkteam param.

Actually it was the iTarget param that did the job. bOnlyTeam is boolean. It's for spectating team only I guess.
Thank you!


All times are GMT -4. The time now is 21:15.

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