Raised This Month: $32 Target: $400
 8% 

Player Transfer


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

Hello, I have a certain problem. When round ends, the best player should be transferred with the random player with the opposite team, but sometimes it transfers only one player and sometimes both of them. Why? If you find an error, please correct it and tell me why it was necessary, thanks!

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cromchat>
#include <cstrike>
#include <fun>

#define PLUGIN "Transfer Plugin"
#define VERSION "1.0"
#define AUTHOR "Reddington"

new g_iEnemiesKilled[33];
new 
cvar_transferafter;

new 
rounds;

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_logevent("logevent_round_end"2"1=Round_End");
    
cvar_transferafter register_cvar("r_transferafter""5.0");
    
}

public 
logevent_round_end() {
    
    
rounds++;
    
    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);
            
            
formatex(msgsizeof(msg), "&x07[&x04LamdaProCS&x07] &x03Player &x04%s &x03has been replaced by player &x04%s"namename2); 
            
            for(new 
133x++) {
                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);
            
            
formatex(msgsizeof(msg), "&x07[&x04LamdaProCS&x07] &x03Player &x04%s &x03has been replaced by player &x04%s"namename2); 
            
            for(new 
133x++) {
                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"ceh"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;

LemoNSK is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 08-16-2018 , 05:30   Re: Player Transfer
Reply With Quote #2

Why
__________________

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


Probably Left AM
Ghosted is offline
LemoNSK
Member
Join Date: Jul 2018
Location: Criminal Underworld
Old 08-16-2018 , 06:20   Re: Player Transfer
Reply With Quote #3

Quote:
Originally Posted by Ghosted View Post
Maybe because nothing what you said helped me out with my problem. And no one has posted anything there since your last post. It seems they give a shit about it. That's why. I have also tried posting it on other certain forums and nothing. That's why....
LemoNSK is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 08-16-2018 , 06:33   Re: Player Transfer
Reply With Quote #4

Plugin even throws error in console. You just posted here code without checking console? error is that the (ctKills / ctDeaths) you dividing by zero.
__________________

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


Probably Left AM
Ghosted is offline
LemoNSK
Member
Join Date: Jul 2018
Location: Criminal Underworld
Old 08-16-2018 , 08:20   Re: Player Transfer
Reply With Quote #5

Quote:
Originally Posted by Ghosted View Post
Plugin even throws error in console. You just posted here code without checking console? error is that the (ctKills / ctDeaths) you dividing by zero.
Yea, it is divided by zero when you or enemy has zero deaths or kills. I understand this. But if they have both above zero, it does the error I provided you with at the top of this page.
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 23:47.


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