AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   FM_Think (https://forums.alliedmods.net/showthread.php?t=224228)

@.SizNeR 08-21-2013 14:40

FM_Think
 
PHP Code:

#include < amxmodx >
#include < fakemeta >

new const g_szEntityClass[] = "MyEntity";

new 
g_iEntity;


public 
plugin_init()
{
    
register_plugin"Using FM_Think""v1.0""@.SizNeR" );
    
    
register_forwardFM_Think"FwThink" );
    
    
    
CmdCreateEntity();
}

public 
FwThinkiEntity )
{
    if ( !
pev_validiEntity ) )
        return 
1;
        
    static 
szEntityClass32 ];
    
    
peviEntitypev_classnameszEntityClasscharsmaxszEntityClass ) );
    
    if ( !
equaliszEntityClassg_szEntityClass ) )
    {
        
CmdSetThinkg_iEntity1.0 );
        
        return 
1;
    }
    
    new 
iPlayers32 ], iCtCountiTerrorCount;
    
    
get_playersiPlayersiCtCount"ceh""CT" );
    
    
get_playersiPlayersiTerrorCount"ceh""TERRORIST" );
    
    if ( ( 
iCtCount <= && iTerrorCount >= ) || ( iCtCount <= && iTerrorCount >= 10 ) || ( iCtCount <= && iTerrorCount >= 15 ) || ( iCtCount <= && iTerrorCount >= 20 ) )
    {
        
MyPublic();
        
        return 
1;
    }
    
    
CmdSetThinkg_iEntity1.0 );
    
    return 
1;
}

public 
MyPublic()
{
    
log_amx"On My Public." );
}

stock CmdCreateEntity()
{
    
g_iEntity engfuncEngFunc_CreateNamedEntityengfuncEngFunc_AllocString"info_target" ) );
    
    
set_pevg_iEntitypev_classnameg_szEntityClass );
    
    
CmdSetThinkg_iEntity1.0 );
}

stock CmdSetThinkiEntityFloat:flTime )
{
    
set_peviEntitypev_nextthinkget_gametime() + flTime );


Help please?

Arkshine 08-21-2013 14:55

Re: FM_Think
 
This is not going to help if you don't explain what is your problem.

@.SizNeR 08-21-2013 14:56

Re: FM_Think
 
Quote:

Originally Posted by Arkshine (Post 2018859)
This is not going to help if you don't explain what is your problem.

The server is not printing the message in MyPublic().

Black Rose 08-21-2013 18:33

Re: FM_Think
 
Every time think is called for any other entity it will update the think time of your entity. This is obviously why it's never called. The next think is always getting pushed forward by other entitys.

Also since you only have one entity just do
Code:
if ( iEntity != g_iEntity )     return;

And here's what you should've done.
Code:
public FwThink( iEntity ) {     server_print("FwThink was called.");     if ( !pev_valid( iEntity ) )     return 1;     server_print("Entity is valid.");     static szEntityClass[ 32 ];         pev( iEntity, pev_classname, szEntityClass, charsmax( szEntityClass ) );         if ( !equali( szEntityClass, g_szEntityClass ) )     {         server_print("Wrong entity, updating nextthink.");         CmdSetThink( g_iEntity, 1.0 );                 return 1;     }         new iPlayers[ 32 ], iCtCount, iTerrorCount;         get_players( iPlayers, iCtCount, "ceh", "CT" );         get_players( iPlayers, iTerrorCount, "ceh", "TERRORIST" );         server_print("iCtCount: %d, iTerrorCount: %d", iCtCount, iTerrorCount);             if ( ( iCtCount <= 0 && iTerrorCount >= 1 ) || ( iCtCount <= 1 && iTerrorCount >= 10 ) || ( iCtCount <= 2 && iTerrorCount >= 15 ) || ( iCtCount <= 3 && iTerrorCount >= 20 ) )     {         MyPublic();                 return 1;     }         CmdSetThink( g_iEntity, 1.0 );         return 1; }

@.SizNeR 08-21-2013 18:48

Re: FM_Think
 
Quote:

Originally Posted by Black Rose (Post 2019003)
Every time think is called for any other entity it will update the think time of your entity. This is obviously why it's never called. The next think is always getting pushed forward by other entitys.

Also since you only have one entity just do
Code:
if ( iEntity != g_iEntity )     return;

And here's what you should've done.
Code:
public FwThink( iEntity ) {     server_print("FwThink was called.");     if ( !pev_valid( iEntity ) )     return 1;     server_print("Entity is valid.");     static szEntityClass[ 32 ];         pev( iEntity, pev_classname, szEntityClass, charsmax( szEntityClass ) );         if ( !equali( szEntityClass, g_szEntityClass ) )     {         server_print("Wrong entity, updating nextthink.");         CmdSetThink( g_iEntity, 1.0 );                 return 1;     }         new iPlayers[ 32 ], iCtCount, iTerrorCount;         get_players( iPlayers, iCtCount, "ceh", "CT" );         get_players( iPlayers, iTerrorCount, "ceh", "TERRORIST" );         server_print("iCtCount: %d, iTerrorCount: %d", iCtCount, iTerrorCount);             if ( ( iCtCount <= 0 && iTerrorCount >= 1 ) || ( iCtCount <= 1 && iTerrorCount >= 10 ) || ( iCtCount <= 2 && iTerrorCount >= 15 ) || ( iCtCount <= 3 && iTerrorCount >= 20 ) )     {         MyPublic();                 return 1;     }         CmdSetThink( g_iEntity, 1.0 );         return 1; }

I did it, its don't print any thing.

Black Rose 08-21-2013 18:58

Re: FM_Think
 
Wrong answer.
Code:

FwThink was called.
Entity is valid.
Wrong entity, updating nextthink.
FwThink was called.
Entity is valid.
Wrong entity, updating nextthink.
FwThink was called.
Entity is valid.
Wrong entity, updating nextthink.
FwThink was called.
Entity is valid.
Wrong entity, updating nextthink.
FwThink was called.
Entity is valid.
Wrong entity, updating nextthink.
FwThink was called.
Entity is valid.
Wrong entity, updating nextthink.
FwThink was called.
Entity is valid.
Wrong entity, updating nextthink.
FwThink was called.
Entity is valid.
Wrong entity, updating nextthink.

Here's what it should look like.
Code:
public FwThink( iEntity ) {     if ( iEntity != g_iEntity || ! pev_valid(iEntity) )         return;         new iPlayers[ 32 ], iCtCount, iTerrorCount;         get_players( iPlayers, iCtCount, "ceh", "CT" );     get_players( iPlayers, iTerrorCount, "ceh", "TERRORIST" );         if ( ( ! iCtCount && iTerrorCount 1 ) || ( iCtCount <= 1 && iTerrorCount >= 10 ) || ( iCtCount <= 2 && iTerrorCount >= 15 ) || ( iCtCount <= 3 && iTerrorCount >= 20 ) )     {         MyPublic();                 return;     }         CmdSetThink( g_iEntity, 1.0 ); }

@.SizNeR 08-21-2013 19:02

Re: FM_Think
 
Quote:

Originally Posted by Black Rose (Post 2019017)
Wrong answer.
Code:

FwThink was called.
Entity is valid.
Wrong entity, updating nextthink.
FwThink was called.
Entity is valid.
Wrong entity, updating nextthink.
FwThink was called.
Entity is valid.
Wrong entity, updating nextthink.
FwThink was called.
Entity is valid.
Wrong entity, updating nextthink.
FwThink was called.
Entity is valid.
Wrong entity, updating nextthink.
FwThink was called.
Entity is valid.
Wrong entity, updating nextthink.
FwThink was called.
Entity is valid.
Wrong entity, updating nextthink.
FwThink was called.
Entity is valid.
Wrong entity, updating nextthink.


Its not printing on my server. :(

Edit:
Its work, but MyPublic() is not called.

Black Rose 08-21-2013 19:14

Re: FM_Think
 
... what are you doing? It's working fine.
Code:

L 08/22/2013 - 01:12:11: "Black Rose<53><STEAM_0:1:-snip-><>" joined team "TERRORIST"
L 08/22/2013 - 01:12:12: [test7.amxx] On My Public.


@.SizNeR 08-21-2013 19:32

Re: FM_Think
 
Quote:

Originally Posted by Black Rose (Post 2019022)
... what are you doing? It's working fine.
Code:

L 08/22/2013 - 01:12:11: "Black Rose<53><STEAM_0:1:-snip-><>" joined team "TERRORIST"
L 08/22/2013 - 01:12:12: [test7.amxx] On My Public.


I change a little the code and its always printing me the same message.

Code:
Code:
public FwFirstThink( iEntity ) {       static szClassname[ 32 ];         pev( iEntity, pev_classname, szClassname, charsmax( szClassname ) );         server_print( "On think." );         if( !equali( szClassname, g_szFirstClass ) )     {         set_think( g_iFirstEnt, 1.0 );                 server_print( "Updating next time. [1]" );                 return 1;     }         if( g_bActive )     {         set_think( iEntity, 1.0 );                 server_print( "Updating next time. [2]" );                 return 1;     }         new players[ 32 ], pnum;         new tCount, ctCount;         get_players( players, pnum, "c" );         for( new i = 0; i < pnum; i++ )     {         if( !is_user_connected( players[ i ] ) )             continue;                 switch( cs_get_user_team( players[ i ] ) )         {             case CS_TEAM_T:                 tCount++;                         case CS_TEAM_CT:                 ctCount++;         }     }         if ( ( tCount <= 1 && ctCount >= 0 ) || ( tCount / ctCount > 5 ) && !g_bActive )     {         server_print( "Starting First" );                 g_bActive = true;             g_iCountdown = 5;             set_task( 1.0, "CmdFirstCountdown", g_iCountdownTask, _, _, "b" );     }     set_think( iEntity, 1.0 );         server_print( "Updating next time. [3]" );         return 1; }

Message:
PHP Code:

On think.
Updating next time. [1

Thanks for help.

Black Rose 08-21-2013 19:37

Re: FM_Think
 
So you broke it exactly the same way again? I already told you in #4 this is wrong. Don't update think time if you get the wrong entity. Just exit the function.

On top of that, after it finishes one run it will return on "if( g_bActive )" and break again.


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

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