Raised This Month: $51 Target: $400
 12% 

[Help] Change Team score values


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jppmarujo
Junior Member
Join Date: Nov 2011
Location: Portugal
Old 11-30-2011 , 14:57   [Help] Change Team score values
Reply With Quote #1

Hey there guys.

So, i pick this structure up, and i am trying to edit it, but keep it simple, because i'm learning how to script in Pawn and C, and i want to be able to fully understand the source code and what's the function of every piece.

So, this piece of code is supposed to make teams play 15 rounds (in total : for example CT: 8 and T: 7) and then swap them.

But, what's happening is that the values don't change. So, if i play for the Counter-Terrorist team in the first half, and i win 14 rounds and the Terrorists team only 1, what happens is that when teams swap i am in disavantadge, because the score don't swap to. So, i'm looking in the cstrike func wiki, and can't find a way to swap the scores when teams swap places.

PHP Code:
#include <amxmodx>
#include <cstrike>

new enablehalf_roundsrounds_count

public plugin_init() 
{
    
register_plugin("Auto Swap Teams""0.1""#Kz.Tw | nobody")
    
half_rounds register_cvar("amx_half_rounds","15")
    
enable register_cvar("swap_teams""1")
    
register_event("HLTV""event_round_start""a""1=0""2=0")
    
register_event("TextMsg""Event_TextMsg""a""2&#Game_C")
}

public 
event_round_start()
{
    if(
get_pcvar_num(enable))
    {
        
rounds_count++
        if(
rounds_count == get_pcvar_num(half_rounds))
            
swap_teams()
    }
}

public 
Event_TextMsg()
    
rounds_count 0

public swap_teams()
{
    new 
CT[32],T[32]
    new 
chCTchT
    
new tround
    
    client_print
(0,print_chat,"* [AST] Switching Teams ")
    
get_players(CT,chCT,"e","CT")
    
get_players(T,chT,"e","TERRORIST")

    for(new 
0chCTi++)
    {
        
cs_set_user_team(CT[i], CS_TEAM_T)

        
client_print(CT[i],print_chat,"* [AST] You're Team is CT now")
    }

    for(new 
0chTi++)
    {
        
cs_set_user_team(T[i], CS_TEAM_CT)
        
        
client_print(T[i], print_chat"* [AST] You're Team is T now")
    }

What i did was to put in my server.cfg win_limit 16 . So, if i reset rounds when teams swap instead of swaping the scores too, the scores stay stored? Meaning:

I am terrorist and i win the first half: 14 - 1;

When teams are swaped, scores are resetted to : 0 - 0;

When i am in CT (the second half), would it take only two rounds to win?

Sorry if this is confusing, and thanks for your help in advance.
</span></span>

Last edited by jppmarujo; 11-30-2011 at 14:58.
jppmarujo is offline
kotinha
Senior Member
Join Date: Jun 2009
Location: Alentejo, Portugal :)
Old 11-30-2011 , 19:20   Re: [Help] Change Team score values
Reply With Quote #2

Don't use get_players() with "e" flag, it is has a bug (I believe it's explained in amxmodx.org), use instead only with flag h (skip HLTV) and in the loop check what's the players team.

To save the scores, I think that there is no function to retrieve team scores. So, you'll have to register TeamScore event and save the score to a global variable. Then you can check each round if a team has reached max wins.
__________________
"If God exists, I hope he has a good excuse." - Woody Allen
kotinha is offline
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 12-01-2011 , 16:23   Re: [Help] Change Team score values
Reply With Quote #3

Quote:
Originally Posted by kotinha View Post
Don't use get_players() with "e" flag, it is has a bug (I believe it's explained in amxmodx.org), use instead only with flag h (skip HLTV) and in the loop check what's the players team.
Note: "e" flag can return incorrect results (for cstrike/czero at least) when not used with the "a" flag. This is because when players change team, get_players() and get_user_team() will return their old team until they spawn again.

get_players with the "e" flag is perfectly fine to use if used with another flag that verifies their status (such as "a" - alive).

An update (of the last code I showed you - in this thread) to suite your current problem:

Code:
#include < amxmodx > #include < cstrike > // team names // CS_TEAM_UNASSIGNED // CS_TEAM_T // CS_TEAM_CT // CS_TEAM_SPECTATOR new const TeamNames[ CsTeams ][ ] = {     "",     "Terrorist",     "Counter-Terrorist",     "" }; // variable holding the current round new CurrentRound; // bool whether it's the 15th round or not new bool:LastRound; // current team round count new RoundsWon[ CsTeams ]; // holding get_maxplayers( ) value new MaxPlayers; public plugin_init( ) {     // hook round start     register_logevent( "LogEvent_RoundStart", 2, "1=Round_Start" );         // hook round win     register_event( "SendAudio", "Event_SendAudio_TWin", "a", "2&%!MRAD_terwin" );     register_event( "SendAudio", "Event_SendAudio_CTWin", "a", "2&%!MRAD_ctwin" );         // assign MaxPlayers the value of get_maxplayers( )     MaxPlayers = get_maxplayers( ); } public LogEvent_RoundStart( ) {     // increment round counter     CurrentRound++;         // check if rounds == 15, if so, set last true (will be handled when round is won by a team)     if( CurrentRound == 15 )     {         LastRound = true;     } } public Event_SendAudio_TWin( ) {     // increment the team round counter for T team     RoundsWon[ CS_TEAM_T ]++;         // check if they have 16 rounds in the bag     CheckWinner( CS_TEAM_T );         // if it's the 15th round, reset the round counter, and swap team scores     if( LastRound )     {         Reset( );                 Swap( );     } } public Event_SendAudio_CTWin() {     // increment the team round counter for CT team     RoundsWon[ CS_TEAM_CT ]++;         // check if they have 16 rounds in the bag     CheckWinner( CS_TEAM_CT );         // if it's the 15th round, reset the round counter, and swap team scores     if( LastRound )     {         Reset( );                 Swap( );     } } CheckWinner( CsTeams:Team ) {     // check if team has won 16 rounds     if( RoundsWon[ Team ] == 16 )     {         client_print( 0, print_chat, "%s team has won 16 rounds now, resetting!", TeamNames[ Team ] );                 // reset         Reset( true );     } } Reset( bool:TeamWon = false ) {     // check if a teamwon is true (false by default), if so (see comment below)     if( TeamWon )     {         // reset rounds for terrorists and cts         for( new CsTeams:Team = CS_TEAM_T; Team <= CS_TEAM_CT; Team++ )         {             RoundsWon[ Team ] = 0;         }     }         // set round counter to 0     CurrentRound = 0;         // restart round     server_cmd( "sv_restartround 1" );         // set last round false     LastRound = false; } Swap( ) {     // iterate through all players     for( new PlayerIndex = 1; PlayerIndex <= MaxPlayers; PlayerIndex++ )     {         // check if connected         if( is_user_connected( PlayerIndex ) )         {             // swap team             switch( cs_get_user_team( PlayerIndex ) )             {                 case CS_TEAM_T: cs_set_user_team( PlayerIndex, CS_TEAM_CT );                 case CS_TEAM_CT: cs_set_user_team( PlayerIndex, CS_TEAM_T );             }         }     }         // swap scores     new TempScore = RoundsWon[ CS_TEAM_T ];     RoundsWon[ CS_TEAM_T ] = RoundsWon[ CS_TEAM_CT ];     RoundsWon[ CS_TEAM_CT ] = TempScore; }
__________________
Achievements API - a simple way for you to create your OWN custom achievements!

Last edited by Xellath; 12-03-2011 at 14:38. Reason: Minor typo
Xellath is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 12-01-2011 , 17:53   Re: [Help] Change Team score values
Reply With Quote #4

Cool how you did that with your comments Xellath!
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
joshknifer
Veteran Member
Join Date: Jun 2011
Location: Denver, CO
Old 12-01-2011 , 18:08   Re: [Help] Change Team score values
Reply With Quote #5

I agree. That was super helpful!
__________________
joshknifer is offline
Send a message via Skype™ to joshknifer
jppmarujo
Junior Member
Join Date: Nov 2011
Location: Portugal
Old 12-03-2011 , 14:32   Re: [Help] Change Team score values
Reply With Quote #6

Xellath,

Working flawlessly this time. Thank you very much, once again!

Sorry to insist in this topic, but i think that you guys understand the difficulties of finding some workarounds when we are new to scripting.

Thanks again, and yes, the job with the comments it's perfect, because it helps me to understand what's the function of everything.

Cheers mate.


P.S. - By the way, is it possible to, just by executing a server command, change the map to the next one registered in the mapcycle? It was suppose to work that way with the mp_winlimit "16", but i don't know why, it's not.

Last edited by jppmarujo; 12-03-2011 at 14:39.
jppmarujo is offline
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 12-03-2011 , 14:41   Re: [Help] Change Team score values
Reply With Quote #7

Saw a minor typo in the Swap() function. Forgot to increment the player index. Fixed.

Glad my comments are helping you guys!
__________________
Achievements API - a simple way for you to create your OWN custom achievements!
Xellath is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 12-03-2011 , 16:54   Re: [Help] Change Team score values
Reply With Quote #8

@Xellath: That code would work well if there aren't too many people on the server. I'd have some problems with switching everybody's teams when there are 32 people on the server (the server crashes). The only ways I know to fix them are to either delay the team switches (1-8 go 0.1 seconds after change, 9-17 go 0.2 seconds after, 18-24 go 0.3 seconds after, and 24-32 go 0.4 seconds after) OR you can use this module: http://forums.alliedmods.net/showthread.php?t=163555
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 12-03-2011 , 17:20   Re: [Help] Change Team score values
Reply With Quote #9

Quote:
Originally Posted by nikhilgupta345 View Post
@Xellath: That code would work well if there aren't too many people on the server. I'd have some problems with switching everybody's teams when there are 32 people on the server (the server crashes). The only ways I know to fix them are to either delay the team switches (1-8 go 0.1 seconds after change, 9-17 go 0.2 seconds after, 18-24 go 0.3 seconds after, and 24-32 go 0.4 seconds after) OR you can use this module: http://forums.alliedmods.net/showthread.php?t=163555
Yes of course. Swapping the team of 32 players instantly is problematic. I think I stated that this was just the basic thought behind this concept in the other thread:

Quote:
Originally Posted by Xellath View Post
From your post, I assume that you want it to restart after 15 rounds, but not reset the team score. However, if a team reaches 16 rounds - the team wins - and everything is reset.

Below code is just the basic thought behind this to show you how;

...code....
__________________
Achievements API - a simple way for you to create your OWN custom achievements!
Xellath is offline
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 12-17-2011 , 09:29   Re: [Help] Change Team score values
Reply With Quote #10

Nbanow requested a "live" - "warmup" version of the code I posted above - so here it is.

Code:
#include < amxmodx > #include < cstrike > // team names // CS_TEAM_UNASSIGNED // CS_TEAM_T // CS_TEAM_CT // CS_TEAM_SPECTATOR new const TeamNames[ CsTeams ][ ] = {     "",     "Terrorist",     "Counter-Terrorist",     "" }; // variable holding the current round new CurrentRound; // bool whether it's the 15th round or not new bool:LastRound; // current team round count new RoundsWon[ CsTeams ]; // holding get_maxplayers( ) value new MaxPlayers; public plugin_init( ) {     register_clcmd( "say /score", "ClientCommand_Score" );         register_clcmd( "live", "ClientCommand_Live" );     register_clcmd( "warmup", "ClientCommand_Warmup" );         // hook round start     register_logevent( "LogEvent_RoundStart", 2, "1=Round_Start" );         // hook round win     register_event( "SendAudio", "Event_SendAudio_TWin", "a", "2&%!MRAD_terwin" );     register_event( "SendAudio", "Event_SendAudio_CTWin", "a", "2&%!MRAD_ctwin" );     // assign MaxPlayers the value of get_maxplayers( )     MaxPlayers = get_maxplayers( );     state warmup; } public ClientCommand_Score( Client ) <warmup> {     // print score (in this case warmup doesn't have any scores.. so print a message)     client_print( Client, print_chat, "Game mode is currently in Warmup mode - no scores available!" ); } public ClientCommand_Score( Client ) <live> {     // print score     client_print( Client, print_chat, "CT Score: %i T Score: %i", RoundsWon[ CS_TEAM_CT ], RoundsWon[ CS_TEAM_T ] ); } public ClientCommand_Live( Client ) {     // switch state to live     state live;         RoundsWon[ CS_TEAM_CT ] = 0;     RoundsWon[ CS_TEAM_T ] = 0;         Reset( ); } public ClientCommand_Warmup( Client ) {     // switch state to warmup     state warmup;         Reset( ); } public LogEvent_RoundStart( ) <warmup> {     // print every warmup round     client_print( 0, print_chat, "Warmup Round", RoundsWon[ CS_TEAM_CT ], RoundsWon[ CS_TEAM_T ] ); } public LogEvent_RoundStart( ) <live> {     // increment round counter     CurrentRound++;     client_print( 0, print_chat, "CT Score: %i T Score: %i", RoundsWon[ CS_TEAM_CT ], RoundsWon[ CS_TEAM_T ] );     // check if rounds == 15, if so, set last true (will be handled when round is won by a team)     if( CurrentRound == 15 )     {         client_print( 0, print_chat, "This is the last round before switching teams!" );                 LastRound = true;     } } public Event_SendAudio_TWin( ) <warmup> { } public Event_SendAudio_TWin( ) <live> {     // increment the team round counter for T team     RoundsWon[ CS_TEAM_T ]++;         // check if they have 16 rounds in the bag     CheckWinner( CS_TEAM_T );         // if it's the 15th round, reset the round counter, and swap team scores     if( LastRound )     {         Reset( );                 Swap( );     } } public Event_SendAudio_CTWin( ) <warmup> { } public Event_SendAudio_CTWin( ) <live> {     // increment the team round counter for CT team     RoundsWon[ CS_TEAM_CT ]++;         // check if they have 16 rounds in the bag     CheckWinner( CS_TEAM_CT );         // if it's the 15th round, reset the round counter, and swap team scores     if( LastRound )     {         Reset( );                 Swap( );     } } CheckWinner( CsTeams:Team ) {     // check if team has won 15 rounds     if( RoundsWon[ Team ] == 15 )     {         client_print( 0, print_chat, "%s team has won 15 rounds now - they're only one away from winning!", TeamNames[ Team ] );     }     // check if team has won 16 rounds     else if( RoundsWon[ Team ] == 16 )     {         client_print( 0, print_chat, "%s team has won 16 rounds now, resetting!", TeamNames[ Team ] );                 // reset         Reset( true );     } } Reset( bool:TeamWon = false ) {     // check if a teamwon is true (false by default), if so (see comment below)     if( TeamWon )     {         // reset rounds for terrorists and cts         for( new CsTeams:Team = CS_TEAM_T; Team <= CS_TEAM_CT; Team++ )         {             RoundsWon[ Team ] = 0;         }     }         // set round counter to 0     CurrentRound = 0;         // restart round     server_cmd( "sv_restartround 1" );         // set last round false     LastRound = false; } Swap( ) {     // iterate through all players     for( new PlayerIndex = 1; PlayerIndex <= MaxPlayers; PlayerIndex++ )     {         // check if connected         if( is_user_connected( PlayerIndex ) )         {             // swap team             switch( cs_get_user_team( PlayerIndex ) )             {                 case CS_TEAM_T: cs_set_user_team( PlayerIndex, CS_TEAM_CT );                 case CS_TEAM_CT: cs_set_user_team( PlayerIndex, CS_TEAM_T );             }         }     }         // swap scores     new TempScore = RoundsWon[ CS_TEAM_T ];     RoundsWon[ CS_TEAM_T ] = RoundsWon[ CS_TEAM_CT ];     RoundsWon[ CS_TEAM_CT ] = TempScore; }
__________________
Achievements API - a simple way for you to create your OWN custom achievements!

Last edited by Xellath; 12-22-2011 at 05:07.
Xellath 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 23:13.


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