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

[TF2] Switch % of RED to BLU


Post New Thread Reply   
 
Thread Tools Display Modes
Phil25
AlliedModders Donor
Join Date: Feb 2015
Old 05-03-2016 , 23:11   Re: [TF2] Switch % of RED to BLU
Reply With Quote #11

This works for me:
PHP Code:
stock void ScramblePercent(TFTeam tfTeamint iPerc){

    
int iNum RoundToNearest(float(GetTeamClientCount(view_as<int>(tfTeam))) *(float(iPerc)/100));
    if(
iNum 1)
        return;
    
    
int iCount 0;

    for(
int i 1<= MaxClientsi++){

        if(!
IsClientInGame(i))
            continue;

        if(
GetClientTeam(i) == view_as<int>(tfTeam)){

            
iCount++;
            
TF2_ChangeClientTeam(itfTeam == TFTeam_Blue TFTeam_Red TFTeam_Blue);

            if(
iCount == iNum)
            break;

        }

    }


It appears that view_as<float>() can't be used while converting an integer to float, use float() instead.

The only thing is that it won't be random, and will work properly only when there are about 5 players on the team or above. If there is one player and the iPerc is 50 or above it is guaranteed for that player to be switched.
Phil25 is offline
SomePanns
Senior Member
Join Date: Dec 2013
Old 05-04-2016 , 07:59   Re: [TF2] Switch % of RED to BLU
Reply With Quote #12

Quote:
Originally Posted by Phil25 View Post
This works for me:
PHP Code:
stock void ScramblePercent(TFTeam tfTeamint iPerc){

    
int iNum RoundToNearest(float(GetTeamClientCount(view_as<int>(tfTeam))) *(float(iPerc)/100));
    if(
iNum 1)
        return;
    
    
int iCount 0;

    for(
int i 1<= MaxClientsi++){

        if(!
IsClientInGame(i))
            continue;

        if(
GetClientTeam(i) == view_as<int>(tfTeam)){

            
iCount++;
            
TF2_ChangeClientTeam(itfTeam == TFTeam_Blue TFTeam_Red TFTeam_Blue);

            if(
iCount == iNum)
            break;

        }

    }


It appears that view_as<float>() can't be used while converting an integer to float, use float() instead.

The only thing is that it won't be random, and will work properly only when there are about 5 players on the team or above. If there is one player and the iPerc is 50 or above it is guaranteed for that player to be switched.
Kind of works, not entirely. If I set iPerc at 20, then out of 6 people in red, 4 will become blue. I don't see how that is 20% exactly. If I set it to 80, everyone becomes blue (as suspected). So when I'm using iPerc = 20, it will always transfer almost everyone to blue, leaving the amount of players in red less than in blue and it should not be like that.
SomePanns is offline
Farbror Godis
AlliedModders Donor
Join Date: Feb 2016
Old 05-04-2016 , 08:25   Re: [TF2] Switch % of RED to BLU
Reply With Quote #13

I don't know about Phil's code, but if you decide to try mine out, this is the results i've gotten when set to 20%:

2 out of 8 (8 / 5 == 1.6)
1 out of 6 (6 / 5 == 1.2)
2 out of 10 (10 / 5 == 2)

I also tweaked it a little bit, because Phil found out viewing an integer as a float messed things up.

PHP Code:
ArrayList client_list = new ArrayList(1MaxClients);
int count;
int num_clients RoundToNearest(float(GetTeamClientCount(2)) / 5.0);
                                                            
for(
int i 1<= MaxClientsi++) {
    if(
IsClientInGame(i) && (GetClientTeam(i) == 2)) {
        
client_list.Set(count++, i);
    }
}

int index;
for(
int i 0num_clientsi++) {
    
index GetRandomInt(0count--);
        
    
TF2_ChangeClientTeam(client_list.Get(index), TFTeam_Blue);
    
client_list.Erase(index);
}

delete client_list
__________________

Last edited by Farbror Godis; 05-04-2016 at 08:42. Reason: nvm
Farbror Godis is offline
Phil25
AlliedModders Donor
Join Date: Feb 2015
Old 05-04-2016 , 10:14   Re: [TF2] Switch % of RED to BLU
Reply With Quote #14

I honestly don't know what's going on. I tested it out and it all seemed okay. Stick with Farbror's code, I guess
Phil25 is offline
SomePanns
Senior Member
Join Date: Dec 2013
Old 05-04-2016 , 16:02   Re: [TF2] Switch % of RED to BLU
Reply With Quote #15

Quote:
Originally Posted by Farbror Godis View Post
I don't know about Phil's code, but if you decide to try mine out, this is the results i've gotten when set to 20%:

2 out of 8 (8 / 5 == 1.6)
1 out of 6 (6 / 5 == 1.2)
2 out of 10 (10 / 5 == 2)

I also tweaked it a little bit, because Phil found out viewing an integer as a float messed things up.

PHP Code:
ArrayList client_list = new ArrayList(1MaxClients);
int count;
int num_clients RoundToNearest(float(GetTeamClientCount(2)) / 5.0);
                                                            
for(
int i 1<= MaxClientsi++) {
    if(
IsClientInGame(i) && (GetClientTeam(i) == 2)) {
        
client_list.Set(count++, i);
    }
}

int index;
for(
int i 0num_clientsi++) {
    
index GetRandomInt(0count--);
        
    
TF2_ChangeClientTeam(client_list.Get(index), TFTeam_Blue);
    
client_list.Erase(index);
}

delete client_list
This works fine, the only problem is that if player amount is below 5 in red, it does absolutely nothing. Any way to force it to put 1 from red to blue if that's the case? I've tried it myself but doesn't work.

Thank you both for helping, btw.

Last edited by SomePanns; 05-04-2016 at 16:06.
SomePanns 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 22:36.


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