Raised This Month: $ Target: $400
 0% 

Function done twice


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-07-2007 , 21:19   Re: Function done twice
Reply With Quote #1

Because you restart so TeamInfo is called again. swapMess become true again and then swap() function is called too.

You have just to intercept restart event.


Code:
#include <amxmodx> #include <cstrike> new team_wins[2] new bool:swapMess; public plugin_init() {     register_plugin("ready", "1.00", "hehu")         register_event( "TeamScore", "team_score", "a" );     register_event( "TextMsg" , "event_restart_attempt", "a", "2=#Game_will_restart_in" );         register_logevent( "round_start", 2, "1=Round_Start" );     } public team_score() {     static team[2];     read_data( 1, team, sizeof team - 1 );         switch( team[0]  )     {         case 'T' : team_wins[0] = read_data( 2 ) ;         case 'C' : team_wins[1] = read_data( 2 ) ;     }         if( team_wins[0] + team_wins[1] == 2 )         swapMess = true;     } public round_start() {     if( !swapMess )         return;             swapMess = false;       swap(); } public event_restart_attempt() {     if( swapMess )         swapMess = false; } swap() {     new  iPlayers[32], iNum, pid, CsTeams:team;     get_players( iPlayers, iNum, "a" );         for( new i = 0; i < iNum;i++ )     {           pid = iPlayers[i];                 team = cs_get_user_team( pid )                 user_kill( pid );         cs_set_user_team( pid, team == CS_TEAM_CT  ?  CS_TEAM_T : CS_TEAM_CT );     }         server_cmd( "sv_restartround 10" ); }
__________________
Arkshine is offline
lagbeast
Junior Member
Join Date: Jul 2007
Old 07-08-2007 , 18:25   Re: Function done twice
Reply With Quote #2

Quote:
Originally Posted by arkshine View Post
Because you restart so TeamInfo is called again. swapMess become true again and then swap() function is called too.

You have just to intercept restart event.


<span style="color: rgb(51, 153, 0);">
PHP Code:
#include <amxmodx>
#include <cstrike>

new team_wins[2]
new 
bool:swapMess;

public 
plugin_init() 
{
    
register_plugin("ready""1.00""hehu")
    
    
register_event"TeamScore""team_score""a" );
    
register_event"TextMsg" "event_restart_attempt""a""2=#Game_will_restart_in" );
    
    
register_logevent"round_start"2"1=Round_Start" );
    
}

public 
team_score()
{
    static 
team[2];
    
read_data1teamsizeof team );
    
    switch( 
team[0]  )
    {
        case 
'T' team_wins[0] = read_data) ;
        case 
'C' team_wins[1] = read_data) ;
    }
    
    if( 
team_wins[0] + team_wins[1] == )
        
swapMess true;
    
}

public 
round_start()
{
    if( !
swapMess )
        return;
        
    
swapMess false;   
    
swap();
}

public 
event_restart_attempt()
{
    if( 
swapMess )
        
swapMess false;
}

swap()
{
    new  
iPlayers[32], iNumpidCsTeams:team;
    
get_playersiPlayersiNum"a" );
    
    for( new 
0iNum;i++ )
    {   
        
pid iPlayers[i];
        
        
team cs_get_user_teampid )
        
        
user_killpid );
        
cs_set_user_teampidteam == CS_TEAM_CT  ?  CS_TEAM_T CS_TEAM_CT );
    } 
server_cmd( "sv_restartround 10" );
}


it worked pretty good, but sometimes it still swaps teams 2 times....
lagbeast is offline
- Billy The Kid -
Member
Join Date: Oct 2006
Old 07-08-2007 , 18:45   Re: Function done twice
Reply With Quote #3

I can't recollect but I think round start and round end logevents are sometimes called two times in a row, sending two groups of infos... I'm not sure, but I think it depends on team score changes...

Anyway I didn't want to get so much into that problem so I added some code like this

Code:
register_logevent("roundEnd", 2, "1=Round_End")
in plugin_init

Code:
public roundEnd()
{
 if (g_Repeat == 1)
  return PLUGIN_CONTINUE

//blablah what you wanna do in function
 
 g_Repeat = 1
 set_task(4.0, "delRepeatFlag")
 
 return PLUGIN_CONTINUE
}
 
public delRepeatFlag()
 g_Repeat = 0
I know... Crude, yet effective!
__________________
- Billy The Kid - 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:34.


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