Raised This Month: $ Target: $400
 0% 

Help with T to CT ratio


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
zssz
Member
Join Date: Aug 2008
Old 10-14-2008 , 02:22   Help with T to CT ratio
Reply With Quote #1

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

#define PLUGIN "Deathrun Handler"
#define VERSION "0.1"
#define AUTHOR "ZssZ"

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_cvar("dr_enabled""1")
    
register_cvar("dr_tnum""10")
    
server_cmd("amx_lock T")
    
set_cvar_num("mp_limitteams"get_cvar_num("dr_tnum"))
    
register_event("HLTV""new_round""a""1=0""2=0")
}

// On new round
public new_round() {
    new 
tdiff get_cvar_num("dr_tnum")
    new 
players[32]
    new 
num
    get_players
(playersnum)

    new 
pid

    
new team_ct 0

    client_print
(0,print_chat,"[Deathrun] New Round - Getting new T")
    
// Put everyone onto CT and get team count
    
for(new 0numi++) {
        
pid players[i]

        
// Check if user is connect and if user has selected a team already and put them on CT
        
if (is_user_connected(pid) && (get_user_team(pid) == || get_user_team(pid) == 2)) {
            
cs_set_user_team(pidCS_TEAM_CTget_model(random_num(4,7)))
        }

        
// Get ct count
        
if (get_user_team(pid) == 2) {
            
team_ct++
        }
    }

    
// Get amount of CT's
    
if (team_ct%tdiff == || team_ct tdiff) {
        new 
num_ts

        
// If more than tdiff CT's
        
if (team_ct%tdiff == && team_ct tdiffnum_ts team_ct/tdiff
        
// If less than tdiff CT's
        
if (team_ct tdiffnum_ts 1

        
// Pick random T(s)
        
new picked
        
new randnum        
        
for (new 0num_tsi++) {
            
randnum random_num(1,team_ct)
            if (
picked != randnum) { // If not picked already
                
cs_set_user_team(random_num(1,team_ct), CS_TEAM_Tget_model(random_num(0,3)))
                
picked randnum
            
} else { // If picked, decrease i and start again
                
i--
            }
        }
    }
}

public 
get_model(a) {
    new 
modeltype
    
switch (a) {

        case 
0: {
            
modeltype CS_T_TERROR
        
}
        case 
1: {
            
modeltype CS_T_LEET
        
}
        case 
2: {
            
modeltype CS_T_ARCTIC
        
}
        case 
3: {
            
modeltype CS_T_GUERILLA
        
}
        case 
4: {
            
modeltype CS_CT_URBAN
        
}
        case 
5: {
            
modeltype CS_CT_GSG9
        
}
        case 
6: {
            
modeltype CS_CT_GIGN
        
}
        case 
7: {
            
modeltype CS_CT_SAS
        
}
        default: {
            
modeltype CS_DONTCHANGE
        
}
    }
    return 
modeltype

This is the first plugin I have ever made, so sorry if it seems crappy or some of the natives aren't used right. Please let me know on anything I can correct in this plugin to make it better. I looked at other peoples code and VEN's New Round / Player Spawn / Round Start / Round Endtutorial for the new round function.

Alright, so some information on this plugin -- This plugin is my attempt at making a deathrun map handler. This is only the first stage of it. Right now, all it is supposed to do is make sure the T to CT ratio is dr_tnum. So, by default dr_tnum is set to 10, meaning for every 10 CT, there is 1 T. I have tested this plugin for a few maps and sometimes it puts 2 T, or sometimes it puts everyone on the same team. I am unsure of why it is doing this. I commented the code with what should be happening at that point, if that is NOT what is happening then, please let me know.

Also, what does this mean?
Code:
/home/groups/amxmodx/tmp3/phpbqmsMt.sma(79 -- 80) : warning 213: tag mismatch
/home/groups/amxmodx/tmp3/phpbqmsMt.sma(82 -- 83) : warning 213: tag mismatch
/home/groups/amxmodx/tmp3/phpbqmsMt.sma(85 -- 86) : warning 213: tag mismatch
/home/groups/amxmodx/tmp3/phpbqmsMt.sma(88 -- 89) : warning 213: tag mismatch
/home/groups/amxmodx/tmp3/phpbqmsMt.sma(91 -- 92) : warning 213: tag mismatch
/home/groups/amxmodx/tmp3/phpbqmsMt.sma(94 -- 95) : warning 213: tag mismatch
/home/groups/amxmodx/tmp3/phpbqmsMt.sma(97 -- 98) : warning 213: tag mismatch
/home/groups/amxmodx/tmp3/phpbqmsMt.sma(100 -- 101) : warning 213: tag mismatch
/home/groups/amxmodx/tmp3/phpbqmsMt.sma(103 -- 104) : warning 213: tag mismatch
I get that we I use the webcompiler. The line numbers correspond to the switch statement.

Thanks for any help!

Last edited by zssz; 10-14-2008 at 02:26.
zssz is offline
zwfgdlc
Senior Member
Join Date: May 2006
Old 10-14-2008 , 02:56   Re: Help with T to CT ratio
Reply With Quote #2

--->
Code:
public CsInternalModel:get_model(a) {     new CsInternalModel:modeltype;     switch (a) {                 case 0: {             modeltype = CS_T_TERROR         }         case 1: {             modeltype = CS_T_LEET         }         case 2: {             modeltype = CS_T_ARCTIC         }         case 3: {             modeltype = CS_T_GUERILLA         }         case 4: {             modeltype = CS_CT_URBAN         }         case 5: {             modeltype = CS_CT_GSG9         }         case 6: {             modeltype = CS_CT_GIGN         }         case 7: {             modeltype = CS_CT_SAS         }         default: {             modeltype = CS_DONTCHANGE         }     }     return modeltype }
zwfgdlc is offline
zssz
Member
Join Date: Aug 2008
Old 10-14-2008 , 18:41   Re: Help with T to CT ratio
Reply With Quote #3

I didn't know you needed to use the tag with it (I couldn't think of what the word 'tag' meant last night, but now I remember what they are). Thanks a lot!
zssz is offline
MeRcyLeZZ
Veteran Member
Join Date: Dec 2007
Old 10-14-2008 , 23:43   Re: Help with T to CT ratio
Reply With Quote #4

Pretty good for a first plugin. Though it looked a bit hacky to me, but that's ok.

How to make it better? well...
  • Replace get_user_team() with cs_get_user_team() since it's more accurate
  • Use CVAR pointers (pcvars)
  • Make an array with the modeltypes since they're constants
  • Maybe replace get_players() with a "for (id = 1; id <= g_MaxClients; id++)..."
Oh, and if you're still getting weird results maybe add some server_print()'s for debugging so you can see what your code is actually doing at runtime.
__________________
MeRcyLeZZ is offline
zssz
Member
Join Date: Aug 2008
Old 10-15-2008 , 00:16   Re: Help with T to CT ratio
Reply With Quote #5

Thanks for the input!
A few questions about it though:
Does get_pcvar do the same thing as get_cvar? If not, what is the difference?
I see these g_* variables used in plugins, but cannot find anything about them, is there a place that has a list of them or what they do? I've tried to google and search the documentation


I have 2 problems that I cannot find the solution to:

1st:
Setting players teams (puts them on ct first, then selects random T) sometimes makes it where if 1 certain player dies (usually the CT), it says something like "Counter-Terrorist Win!" (Correct me if I am wrong on this, but if you switch a players team when they're alive, they keep some property of their previous team (assumption I am making, based on no known facts)). So if that is true, I think they were spawned as a T before the plugin set them onto CT (and since mp_limitteams is set to whatever dr_tnum is, they could have been the only T spawned). How could I prevent this from happening? Is there a function that will set users teams before they a spawned for the coming round?

2nd: I haven't been able to test this with more than a few people, but whenever theres a low number of people (4-5), sometimes no player gets selected as T and everyone stays on CT (until the new round comes). Is there an error in the logic in my script somewhere? I don't see anything wrong from my noob-ish view.


My hopeful solution to problem number 2:
PHP Code:
        for (new = -1num_ts; ++i) {
            
randnum random_num(1,team_ct)
            if (
picked != randnum) { // If not picked already
                
cs_set_user_team(random_num(1,team_ct), CS_TEAM_Tget_model(random_num(0,3)))
                
picked randnum
            
} else { // If picked, decrease i and start again
                
i--
            }
        } 
I made i start at -1 and increase before the for statement. I think that when the plugin would find a new player for T, it would select one twice, and i-- would decrease it too low before i++ increased the first time.


Hope I don't annoy you with all of these questions, I really appreciate your help!

Last edited by zssz; 10-15-2008 at 00:51.
zssz is offline
MeRcyLeZZ
Veteran Member
Join Date: Dec 2007
Old 10-16-2008 , 22:35   Re: Help with T to CT ratio
Reply With Quote #6

Quote:
Originally Posted by zssz
Does get_pcvar do the same thing as get_cvar? If not, what is the difference?
It's the same thing, only faster. Especially if you check cvars frequently, which is what many big plugins do.

Quote:
Originally Posted by zssz
I see these g_* variables used in plugins, but cannot find anything about them, is there a place that has a list of them or what they do?
You can name variables any way you like. Some people prepend "g_" for global vars, "f" for floats, etc. but it only effects readability.

Quote:
Originally Posted by zssz
Setting players teams (puts them on ct first, then selects random T) sometimes makes it where if 1 certain player dies (usually the CT), it says something like "Counter-Terrorist Win!"
If you switch every player to the same team (e.g. CT), CS says "Scoring will not start until both teams have players". When they do, the game restarts (and you see a "Game Commencing" message). You can only prevent this by leaving at least one player on the opposite team.

Quote:
Originally Posted by zssz
2nd: I haven't been able to test this with more than a few people, but whenever theres a low number of people (4-5), sometimes no player gets selected as T and everyone stays on CT (until the new round comes). Is there an error in the logic in my script somewhere? I don't see anything wrong from my noob-ish view.
Well I didn't check the rest of the code, but your randnum = random_num(1,team_ct) is located within the loop, which means it will choose a different player on every iteration.

But if you just need to randomly switch a specific amount of players to Terrorists I'd use a while instead:
Code:
new player new t_num new t_max = 5 // this is how many Ts you want to be randomly picked while (t_num < t_max) // keep looping as long as we haven't reached the max amount {     // this makes it so we go through all players (1 to 32)     if (player++ > 32) player = 1         // skip disconnected or non-CT players         if (!is_user_connected(player) || cs_get_user_team(player) != CS_TEAM_CT)         continue;         // randomly turn this player to T with a chance of 1 out of 10     if (random_num(1, 10) == 1)     {         cs_set_user_team(player, CS_TEAM_T, get_model(random_num(0,3))         t_num++     } }
Just make sure you don't set t_max higher than the amount of CTs or you will end up with an infinite loop.
__________________
MeRcyLeZZ is offline
zssz
Member
Join Date: Aug 2008
Old 10-18-2008 , 15:49   Re: Help with T to CT ratio
Reply With Quote #7

Alright, this is getting annoying now haha.

This is what I have... (Started to use AMXX Studio too)

PHP Code:
/* Plugin generated by AMXX-Studio */


#include <amxmodx>
#include <amxmisc>
#include <cstrike>

#define PLUGIN "Deathrun"
#define VERSION "0.1"
#define AUTHOR "ZssZ"


new g_MaxClients
new dr_enableddr_tnum

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_cvar("dr_version"VERSIONFCVAR_SERVER)
    
set_cvar_string("dr_version"VERSION)
    
    
dr_enabled register_cvar("dr_enabled""1")
    
dr_tnum register_cvar("dr_tnum""8")
    
    
server_cmd("amx_lock T")
    
server_exec()
    
    
set_cvar_num("mp_limitteams"get_pcvar_num(dr_tnum))

    
g_MaxClients get_maxplayers()
    
    
register_event("HLTV""new_round""a""1=0""2=0")
}

// On new round
public new_round() {
    
    if (
get_pcvar_num(dr_enabled) == 1) { 
        new 
tdiff get_pcvar_num(dr_tnum)
        
    
        new 
players[32], num[32], num_tspid
        
new team_ct 0    
        
new teamt
        
        
        
for (new id 1id <= g_MaxClientsid++) {
            
num[id-1] = id
        
}
        

        
client_print(0,print_chat,"[Deathrun] New Round - Getting T")
        
        for (new 
0g_MaxClientsi++) {
            
pid players[i]
            
            
// Check if user connected & if user is on T or CT. Then place them onto CT.
            
if (is_user_connected(pid) && (cs_get_user_team(pid) == CS_TEAM_T || cs_get_user_team(pid) == CS_TEAM_CT)) {
                
cs_set_user_team(pidCS_TEAM_CT)
            }
            
            
// Get CT Count
            
if (cs_get_user_team(pid) == CS_TEAM_CTteam_ct++
        }
        
client_print(0,print_console,"%s CTs"team_ct)
        
        if (
team_ct%tdiff == || team_ct tdiff || team_ct tdiff) {
            
// If less than tdiff CTs
            
if (team_ct tdiffnum_ts 1
            
            
// If more than tdiff CTs
            
else if (team_ct%tdiff == && team_ct tdiffnum_ts team_ct/tdiff
            
            
// Pick random Ts
            
new player
            
            
// Keep going through loop while we haven't gotten teamt Ts
            
while (teamt num_ts) {
                
                
// Makes loop be able to work properly if player >= g_MaxClients
                
if (player++ > g_MaxClientsplayer 1
                
                
// Skip disconnected or non-CTs
                
if (!is_user_connected(player) || cs_get_user_team(player) != CS_TEAM_CT) continue;
                
                
// Player has 1 in 10 chance of being selected as the T
                
if (random_num(1,10) == 1) {
                    
cs_set_user_team(playerCS_TEAM_Tget_model(random_num(0,3)))
                    
teamt++
                }
            }
        }
        
client_print(0,print_console,"%s %s %s %s"team_cttdiffnum_tsteamt)
    }

        
}


public 
CsInternalModel:get_model(a) {
    new 
CsInternalModel:modeltype[9] = { CS_T_TERRORCS_T_LEETCS_T_ARCTICCS_T_GUERILLACS_CT_URBANCS_CT_GSG9CS_CT_GIGNCS_CT_SASCS_DONTCHANGE }
    new 
CsInternalModel:retmodel
    
switch (a) {
        
        case 
0: {
            
retmodel modeltype[0]
        }
        case 
1: {
            
retmodel modeltype[1]
        }
        case 
2: {
            
retmodel modeltype[2]
        }
        case 
3: {
            
retmodel modeltype[3]
        }
        case 
4: {
            
retmodel modeltype[4]
        }
        case 
5: {
            
retmodel modeltype[5]
        }
        case 
6: {
            
retmodel modeltype[6]
        }
        case 
7: {
            
retmodel modeltype[7]
        }
        default: {
            
retmodel modeltype[8]
        }
    }
    return 
retmodel

Its like, the plugin only gets to the point
PHP Code:
client_print(0,print_chat,"[Deathrun] New Round - Getting T"
Thats all that I can get to work. The client_print's with the print_console don't work. The new T is not selected, nothing is done except for the [Deathrun] New Round - Getting T part. I've been messing with it all last night when no one was on. Couldn't get any closer to it working. Any ideas?
zssz is offline
MeRcyLeZZ
Veteran Member
Join Date: Dec 2007
Old 10-19-2008 , 21:19   Re: Help with T to CT ratio
Reply With Quote #8

Ok I kinda fixed the code, it looks clearer and seems to be working now. If you have doubts about anything just ask.
Code:
#include <amxmodx> #include <cstrike> #define PLUGIN "Deathrun" #define VERSION "0.1" #define AUTHOR "ZssZ" new const CsInternalModel:g_TModels[] = { CS_T_TERROR, CS_T_LEET, CS_T_ARCTIC, CS_T_GUERILLA } new g_MaxClients new dr_enabled, dr_tnum public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         register_cvar("dr_version", VERSION, FCVAR_SERVER)     set_cvar_string("dr_version", VERSION)         dr_enabled = register_cvar("dr_enabled", "1")     dr_tnum = register_cvar("dr_tnum", "8")         server_cmd("amx_lock T")     server_exec()         set_cvar_num("mp_limitteams", get_pcvar_num(dr_tnum))     set_cvar_num("mp_autoteambalance", 0)         g_MaxClients = get_maxplayers()         register_event("HLTV", "new_round", "a", "1=0", "2=0") } // On new round public new_round() {     // Plugin disabled?     if (get_pcvar_num(dr_enabled) == 0)         return;         // Get players count     new player_count, player, CsTeams:team         for (player = 1; player <= g_MaxClients; player++)     {         // Check if user connected         if (!is_user_connected(player))             continue;                 // Get player team         team = cs_get_user_team(player)                 // Check if user not on a team yet         if (team == CS_TEAM_UNASSIGNED || team == CS_TEAM_SPECTATOR)             continue;                 // Switch to CT         cs_set_user_team(player, CS_TEAM_CT)                 // Increase player count         player_count++     }         // Do we have enough players?     if (player_count < 1)         return;         // Calculate how many Ts should we have     new num_ts = player_count / get_pcvar_num(dr_tnum)         // Make sure we have at least one     if (num_ts < 1) num_ts = 1         // DEBUG     client_print(0, print_chat, "[Deathrun] %d Players Total - Randomly choosing %d Ts", player_count, num_ts)         // Now pick random Ts     new teamt         // Keep going through loop while we haven't gotten num_ts Ts     while (teamt < num_ts)     {         // Makes loop be able to work properly if player > g_MaxClients         if (player++ > g_MaxClients) player = 1                 // Check if user connected         if (!is_user_connected(player))             continue;                 // Only switch players from the CT team         if (cs_get_user_team(player) != CS_TEAM_CT)             continue;                 // Player has 1 in 10 chance of being selected as the T         if (random_num(1,10) == 1)         {             cs_set_user_team(player, CS_TEAM_T, g_TModels[random_num(0, 3)])             teamt++         }     } }
__________________
MeRcyLeZZ is offline
zssz
Member
Join Date: Aug 2008
Old 10-20-2008 , 04:09   Re: Help with T to CT ratio
Reply With Quote #9

Ohhh. I see what you meant about the array now. Stupid me, didn't think about getting a random array element value...

I will try this out tomorrow when more people are on.

Really appreciate your help!

Edit: Works great. Now I'm just adding in other features to make it better and more unique.
__________________

Last edited by zssz; 10-23-2008 at 01:56.
zssz 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 11:21.


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