This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Function done twice


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lagbeast
Junior Member
Join Date: Jul 2007
Old 07-07-2007 , 20:07   Function done twice
Reply With Quote #1

im not sure why this is happening. i have a function that once you get to two rounds, the script will transfer the players to the other team and the restart the round. now the script does that, but it does it two times and i have been sitting here for two hours and trying to figure out why and now i have given up and ask for ur pro-assistance!

also, how do you print out the value of a boolean? with string u use %s and int %i but how do u do with bool?

anyways, here is the relevant code

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fakemeta>
#include <fun>
#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_logevent("round_start"2"1=Round_Start")
    
//register_logevent("round_end",2,"1=Round_End")
}

public 
team_score()
{
     new 
team[2]
     
read_data(1team1)
     
    if(
team[0] == 'C') {
        
team_wins[0] = read_data(2
     } else if(
team[0] == 'T') {
        
team_wins[1] = read_data(2
    }
     
     if(
team_wins[0]+team_wins[1]==2)
     {
         
swapMess=true
        
     
}
     return 
PLUGIN_CONTINUE
}

public 
round_start()
{
    if(
swapMess==true)
    {    
        
swapMess=false
        swap
()
        
//server_cmd("sv_restartround 10")
        
        
    
}
    return 
swapMess
}
public 
swap() {
    new 
maxplayers=get_maxplayers()
    new 
team[16]
    for(new 
i=0;i<=maxplayers;i++)
        if(
is_user_connected(i)) {
            
get_user_team(i,team,15)
            if(
equal(team,"CT")) {
                if(
is_user_alive(i)) 
                {
                    
user_kill(i)
                    
cs_set_user_team(iCS_TEAM_T)
                }
            } 
            else 
            {
                if(
equal(team,"TERRORIST")) {
                    if(
is_user_alive(i)) 
                    {
                        
user_kill(i)
                        
cs_set_user_team(iCS_TEAM_CT)
                    }
                }
            }

        }
    return 
PLUGIN_CONTINUE
    
}
    

some of the code i have found in the forums, like the one for swapping teams
lagbeast is offline
lagbeast
Junior Member
Join Date: Jul 2007
Old 07-07-2007 , 21:00   Re: Function done twice
Reply With Quote #2

I think i solved it. I just put the swap on round end, instead of round start.
lagbeast is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-07-2007 , 21:19   Re: Function done twice
Reply With Quote #3

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 #4

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 #5

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
Rolnaaba
Veteran Member
Join Date: May 2006
Old 07-09-2007 , 22:19   Re: Function done twice
Reply With Quote #6

to print out a boolean just use %i, because dep down inside the heart of the computer, a boolean is just a int except it is made to hold only two values. 1 or 0. 1=true, 0=false. The boolean varriable it 1bit. just enough to make the binary god happy.
__________________
DO NOT PM me about avp mod.
Rolnaaba 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 16:03.


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