Raised This Month: $ Target: $400
 0% 

[Solved]Force spectator's m_hObserverTarget


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 06-15-2014 , 09:39   [Solved]Force spectator's m_hObserverTarget
Reply With Quote #1

I want to force m_hObserverTarget to be CT team only.

Quote:
Originally Posted by Arkshine View Post
... 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;         }     } }

Last edited by SpeeDeeR; 06-16-2014 at 20:27.
SpeeDeeR is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 06-15-2014 , 14:04   Re: [Orpheu] Force spectator's m_hObserverTarget
Reply With Quote #2

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;
  }  
 }

__________________

Last edited by claudiuhks; 06-15-2014 at 14:25.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 06-15-2014 , 19:46   Re: [Orpheu] Force spectator's m_hObserverTarget
Reply With Quote #3

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

Last edited by SpeeDeeR; 06-15-2014 at 19:50.
SpeeDeeR is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 06-15-2014 , 21:57   Re: [Orpheu] Force spectator's m_hObserverTarget
Reply With Quote #4

Your executing OrpheuCallSuper() from inside the hook your calling = infinite loop
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 06-16-2014 , 04:01   Re: [Orpheu] Force spectator's m_hObserverTarget
Reply With Quote #5

Hook it as pre, and supercede the original function call.
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 06-16-2014 , 07:30   Re: [Orpheu] Force spectator's m_hObserverTarget
Reply With Quote #6

Quote:
Originally Posted by NiHiLaNTh View Post
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.
SpeeDeeR is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 06-16-2014 , 09:26   Re: [Orpheu] Force spectator's m_hObserverTarget
Reply With Quote #7

Another method is with CBasePlayer::Observer_CheckTarget(). You can use the checkteam param.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 06-16-2014 , 11:10   Re: [Orpheu] Force spectator's m_hObserverTarget
Reply With Quote #8

Quote:
Originally Posted by hornet View Post
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;
        }
    }

SpeeDeeR is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 06-16-2014 , 18:37   Re: [Orpheu] Force spectator's m_hObserverTarget
Reply With Quote #9

Quote:
Originally Posted by SpeeDeeR View Post
What are you talking about?
Sorry, half asleep, I meant CBasePlayer::Observer_IsValidTarget().
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 06-16-2014 , 20:26   Re: [Orpheu] Force spectator's m_hObserverTarget
Reply With Quote #10

Quote:
Originally Posted by hornet View Post
CBasePlayer::Observer_IsValidTarget().
Quote:
Originally Posted by hornet View Post
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!
SpeeDeeR 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 21:15.


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