Raised This Month: $ Target: $400
 0% 

Player Transfer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LemoNSK
Member
Join Date: Jul 2018
Location: Criminal Underworld
Old 08-13-2018 , 13:01   Player Transfer
Reply With Quote #1

Hello, I need a help with my script.

Problem:

1) it writes chat message twice to every player.
2) Sometimes it transfer one player instead of two players and sometimes both (both is what I need)
(I want them to swap each other, but you will see that in code)

Code:

PHP Code:
    if(rounds get_pcvar_num(cvar_transferafter)) 
    {
    
        
//Retrieve the IDs of best killers in the server.
        
new ctID GetTopKiller(2);
        new 
tID GetTopKiller(1);
        
        
//Retriev user frags
        
new ctKills get_user_frags(ctID);
        new 
tKills get_user_frags(tID);
        
        
//Retrieve user deaths.
        
new ctDeaths get_user_deaths(ctID);
        new 
tDeaths get_user_deaths(tID);
            
        
//Compare kill to deaths ratio.
        
if((ctKills ctDeaths) > (tKills tDeaths)) 
        {    
//CT is better 
            
            //Get user's name.
            
new name[255], name2[255] ,msg[255], iPnumplayers[32], player1;
            
get_user_name(ctIDnamesizeof(name));
        
            if(
is_user_alive(ctID)) { set_user_health(ctID0); }
        
            
//Transfer the best player to opponent team.
            
cs_set_user_team(ctIDCS_TEAM_T);
            
            
            
get_players(playersiPnum"ceh""TERRORIST");
            
player1 players[random(iPnum)];
            
            
//Get the name of the opposite random enemy.
            
get_user_name(player1name2sizeof(name2));
            
            if(
is_user_alive(player1)) { set_user_health(player10); }
            
            
//Swap the random player from T to CT.
            
cs_set_user_team(player1CS_TEAM_CT);
            
            
format(msgsizeof(msg), "&x07[&x04LamdaProCS&x07] &x03Player &x04%s &x03has been replaced by player &x04%s"namename2); 
            
            for(new 
033x++) {
                if(
is_user_connected(x)) {
                    
CC_SendMessage(xmsg);
                }
            }
            
            
ctKills 0;
            
ctDeaths 0;
            
tKills 0;
            
tDeaths 0;
            
rounds 0;
            
player1 0;
        }
        
        if((
ctKills ctDeaths) < (tKills tDeaths)) //T is better
        
{
            
//Get user's name.
            
new name[255], name2[255] ,msg[255], iPnumplayers[32], player1;
            
get_user_name(tIDnamesizeof(name));
        
            if(
is_user_alive(tID)) { set_user_health(tID0); }
        
            
//Transfer the best player to opponent team.
            
cs_set_user_team(tIDCS_TEAM_CT);
            
            
get_players(playersiPnum"ceh""CT");
            
player1 players[random(iPnum)];
            
            
//Get the name of the opposite random enemy.
            
get_user_name(player1name2sizeof(name2));
            
            if(
is_user_alive(player1)) { set_user_health(player10); }
            
            
//Swap the random player from CT to T.
            
cs_set_user_team(player1CS_TEAM_T);
            
            
format(msgsizeof(msg), "&x07[&x04LamdaProCS&x07] &x03Player &x04%s &x03has been replaced by player &x04%s"namename2); 
            
            for(new 
033x++) {
                if(
is_user_connected(x)) {
                    
CC_SendMessage(xmsg);
                }
            }
            
            
ctKills 0;
            
ctDeaths 0;
            
tKills 0;
            
tDeaths 0;
            
rounds 0;
            
player1 0;
        } 
        
        if((
ctKills ctDeaths) == (tKills tDeaths)) {
            
        }
    }
    
    
}

GetTopKiller(iTeam

    new 
iPlayers[32], iPlayersnum
    
    
get_players(iPlayersiPlayersnum"e"iTeam == "TERRORIST" "CT"
    
SortCustom1D(iPlayersiPlayersnum"SortByKills"
    
    return 
iPlayers[0


public 
SortByKills(elem1elem2)  

    if ( 
g_iEnemiesKilled[elem1] > g_iEnemiesKilled[elem2] ) { 
        return -
1
    } 
    else 
    { 
        return 
1
    } 
    return 
0;

Thank you for help.

Last edited by LemoNSK; 08-13-2018 at 13:04.
LemoNSK is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 08-13-2018 , 13:20   Re: Player Transfer
Reply With Quote #2

* name/name2 variable size should be MAX_NAME_LENGTH (=32)
* You getting message two times cause your x variable loop starts with 0, and CromChat has support to display message to everyone when player index is zero. Start looping from 1
* set_user_health to zero means player's health will change to zero and hud will be updated, player will move incorrectly but player will be alive, if you want to kill him use dllfunc & DLLFunc_ClientKill
*
Code:
2) Sometimes it transfer one player instead of two players and sometimes both (both is what I need)
(I want them to swap each other, but you will see that in code)
Try debugging use server_print if you haven't hosted server. Print player indexes their teams if you want better understanding write also player names. Check if GetTopKiller is working well.
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM

Last edited by Ghosted; 08-13-2018 at 13:21.
Ghosted is offline
LemoNSK
Member
Join Date: Jul 2018
Location: Criminal Underworld
Old 08-13-2018 , 15:41   Re: Player Transfer
Reply With Quote #3

Nothing worked, still writes twice and transfers only one player.. any other solution?
LemoNSK is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 08-13-2018 , 15:44   Re: Player Transfer
Reply With Quote #4

Quote:
Originally Posted by LemoNSK View Post
Nothing worked, still writes twice and transfers only one player.. any other solution?
About x and loop was wrong cause you are checking if user is connected but still playerIndex starts from 1.
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM

Last edited by Ghosted; 08-13-2018 at 15:45.
Ghosted is offline
LemoNSK
Member
Join Date: Jul 2018
Location: Criminal Underworld
Old 08-13-2018 , 15:48   Re: Player Transfer
Reply With Quote #5

Quote:
Originally Posted by Ghosted View Post
About x and loop was wrong cause you are checking if user is connected but still playerIndex starts from 1.
Even though I set it to 1, still writes two messages.
LemoNSK is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 08-13-2018 , 16:05   Re: Player Transfer
Reply With Quote #6

Quote:
Originally Posted by LemoNSK View Post
Even though I set it to 1, still writes two messages.
Ofcouse, but it must start from 1
* You should use formatex instead of format if you not use same thing you are formatting.
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM

Last edited by Ghosted; 08-13-2018 at 16:06.
Ghosted is offline
LemoNSK
Member
Join Date: Jul 2018
Location: Criminal Underworld
Old 08-13-2018 , 16:10   Re: Player Transfer
Reply With Quote #7

Quote:
Originally Posted by Ghosted View Post
Ofcouse, but it must start from 1
* You should use formatex instead of format if you not use same thing you are formatting.
Okay, and do you have any idea how to actually get those teams working? Can you check on it, please?
LemoNSK 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 20:44.


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