AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   Module: CS Team Changer Ultimate [avoids crashes in aggressive changes] (https://forums.alliedmods.net/showthread.php?t=163555)

claudiuhks 07-31-2011 15:15

Module: CS Team Changer Ultimate [avoids crashes in aggressive changes]
 
1 Attachment(s)

- Counter-Strike Team Changer -


Download
View CPP file

I see that all plugins that change the teams excessively contain delay to avoid crashes. Native get_user_team is not used because of receiving wrong values and there are tasks with TeamInfo message.

Using this extension you may change the teams without any crash, indifferently you are using an aggressive changing type or not!

Also, this extension updates the AMX Mod X team indexes at clients then you will be able to use get_user_team native without problems, it will return fair values.

The difference between this and CStrike module is here (42).

An example is listed below.

PHP Code:

static iPlayers32 ], iNumiiPlayer;
get_playersiPlayersiNum );

for( 
0iNumi++ )
{
     
iPlayer iPlayers];

     switch( 
get_user_teamiPlayer ) )
     {
           case 
_:CSTEAM_TERRORISTcs_set_teamiPlayerCSTEAM_CT );
           case 
_:CSTEAM_CTcs_set_teamiPlayerCSTEAM_TERRORIST );
     }

     
// If you will use again this function, get_user_team native will give you a fair result!
     // The players will be transfering from a team to other without problems.




It is tested, it works perfectly with thirty two players. It changes sixteen players from Terrorists to Counter-terrorists and sixteen players from Counter-terrorists to Terrorists in the same time without any headaches instead of CStrike extension that crashes the server.

The header file is the one listed below.

PHP Code:

/**
 * Counter-Strike Team Changer
 * by Hattrick (Claudiu HKS)
 */

#if defined _cs_team_changer_included
  #endinput
#endif

#define _cs_team_changer_included

#if AMXX_VERSION_NUM >= 175
  #pragma reqlib cs_team_changer

  #if !defined AMXMODX_NOAUTOLOAD
    #pragma loadlib cs_team_changer
  #endif
#else
  #pragma library cs_team_changer
#endif

/** There are the teams you may use.
 */
enum CSTeam
{
  
CSTEAM_UNASSIGNED 0,
  
CSTEAM_TERRORIST 1,
  
CSTEAM_CT 2,
  
CSTEAM_SPECTATOR 3
};

/** You may do 64 transfers once a second using this extension! Server will not crash!
 * CStrike extension using cs_set_user_team native will crash server when approximately 24 transfers are reached!
 */

/** Transfers a player from a team to other one. The player's model will not be touched. The server will not be forged.
 * This native will automatically send a TeamInfo message. Will also change the team offset and the team index declared by AMX Mod X extension.
 */
native cs_set_team(ClientCSTeam:Team);

/** Changes the player's team index declared by AMX Mod X extension. The team offset and the scores' table will not be touched.
 * There will not be a TeamInfo message.
 */
native cs_set_team_id(ClientCSTeam:Team);

/** Changes the player's team offset. Scores' table will not be touched.
 */
native cs_set_team_offset(ClientCSTeam:Team);

/** Sends a fast TeamInfo message. The player will be transfered at the team you want but only in the scores' table.
*/
native cs_set_team_tablescore(ClientCSTeam:Team); 


Pastout 07-31-2011 16:10

Re: Module: CS Team Changer [avoid crashes in aggressive changes]
 
Wow dude keep up the good work man.

abdul-rehman 08-01-2011 15:46

Re: Module: CS Team Changer [avoid crashes in aggressive changes]
 
Plz also point out the differences between this native and cs_set_user_team.

Arkshine 08-01-2011 16:31

Re: Module: CS Team Changer [avoid crashes in aggressive changes]
 
It's written in the first post.

hleV 08-02-2011 08:55

Re: Module: CS Team Changer [avoid crashes in aggressive changes]
 
I remember the normal cs_set_user_team() way working on normal server, but crashing on Zombie Plague with a lot of players. Have you tried this on ZP?

fysiks 08-02-2011 09:00

Re: Module: CS Team Changer [avoid crashes in aggressive changes]
 
Quote:

Originally Posted by claudiuhks (Post 1522786)
Also, this module updates the AMXX API team's ID at clients and you will can use the get_user_team native without problems, it will be giving you a fair result (not wrong)

This will be fixed in version 1.8.2dev as soon as Bail pushes the fix.

Quote:

Originally Posted by claudiuhks (Post 1522786)
Lot of thanks to Arkshine for rewriting and compiling the module in windows and linux!

This makes it sound like Arkshine did everything except post it on the forums.

Arkshine 08-02-2011 09:13

Re: Module: CS Team Changer [avoid crashes in aggressive changes]
 
I've not rewritten it, even if the code is quite small, I've just cleaned up a bit the code, changing some things (like changing 80% of code taken by few "if..else if..else" replacing by a "switch") and compiling. Don't know why he says "rewritten", it was not the purpose and with such small code, not really possible. So, claudiuhks, you should fix to avoid fysiks be traumatized more ;).

claudiuhks 08-02-2011 12:35

Re: Module: CS Team Changer [avoid crashes in aggressive changes]
 
Mister fysiks, I just said that Arkshine opened the source, wrote something in it and closed. Why did you think he made all the code? Am I supposed to say what exactly he wrote in the source? And am I supposed to hide that he helped me with some code?

How to fix the problem with 'get_user_team' while the big plugins are using set_pdata_int? Do you think the offset changing with the fakemeta module will update the AMXX API team's ID?

The people are supposed to do thousands of things for make you happy mister fysiks... :)

@Arkshine at

Code:

you should fix to avoid fysiks be traumatized more ;).
Sorry but I don't think I have mind/power enough for do this...

@hleV at

Code:

I remember the normal cs_set_user_team() way working on normal server, but crashing on Zombie Plague with a lot of players. Have you tried this on ZP?
Tested at 32 players with like 120 team changes in one second
Also this cs_team_changer module is running on my zombie plague server, it is still alive since two or three days ago...

[IMG]http://img607.**************/img607/1240/unledhly.th.png[/IMG]

Without proofs we don't speak :D

fysiks 08-02-2011 12:45

Re: Module: CS Team Changer [avoid crashes in aggressive changes]
 
Quote:

Originally Posted by claudiuhks (Post 1524236)
Mister fysiks, I just said that Arkshine opened the source, wrote something in it and closed. Why did you think he made all the code?

In English, you said that he wrote the whole thing again. In reality, he "added/remove/optimized" a few things. No need to get all defensive.

Arkshine's comment about me being "traumatized" was a joke. FYI

K.K.Lv 08-02-2011 12:53

Re: Module: CS Team Changer [avoid crashes in aggressive changes]
 
can you explain what does "FYI" mean:mrgreen:
I'm poor in english!:oops:

Arkshine 08-02-2011 12:58

Re: Module: CS Team Changer [avoid crashes in aggressive changes]
 
Quote:

Mister fysiks, I just said that Arkshine opened the source, wrote something in it and closed. Why did you think he made all the code? Am I supposed to say what exactly he wrote in the source? And am I supposed to hide that he helped me with some code?
It's true the word may not the best, because rewritten would mean here I have redone the whole module myself, and that's not the case. Just fast optimization, cleaning up. :P

Quote:

How to fix the problem with 'get_user_team' while the big plugins are using set_pdata_int?
See the issue about get_players on the bug tracker. I've attached a patch which updates the AMXX team's id in TeamInfo message.

Quote:

can you explain what does "FYI" mean
For Your Information, it means. :)
FYI, the answer can be found fastly on google. :mrgreen:

Destro- 08-12-2011 21:06

Re: Module: CS Team Changer [avoid crashes in aggressive changes]
 
Hello.

I do not know a lot of modules, you should not check if the player is valid?.

pd:the delay is to use emessage.

pd2:Sorry for my English.

claudiuhks 08-13-2011 08:20

Re: Module: CS Team Changer [avoid crashes in aggressive changes]
 
PHP Code:

/* These are the same as above, except that the messages sent
 *  are also sent to all other plugins and Metamod plugins.
 * This means that if you send one of these messages, other plugins will
 *  be notified, which was previously impossible.  
 * BE CAREFUL! Using these incorrectly, or not for their intended purpose,
 *  could cause infinite recursion or something just as bad. 
 * NOTE! These natives are experimental.
 */
native emessage_begin(destmsg_type, const origin[3] = {0,0,0}, player 0);
native emessage_end();
native ewrite_byte(x);
native ewrite_char(x);
native ewrite_short(x);
native ewrite_long(x);
native ewrite_entity(x);
native ewrite_angle(x);
native ewrite_coord(x);
native ewrite_string(const x[]); 

The player validity check is optional. The AmxModX scripters would like to check the validity in their AmxModX plugins!

The emessage_begin and message_begin are doing approximately the same thing...

Destro- 08-13-2011 11:33

Re: Module: CS Team Changer [avoid crashes in aggressive changes]
 
I know.
The zp use emessage + delay for to work register_message,but not necessary.

Sorry for my English use a translator.

Owyn 08-17-2011 07:48

Re: Module: CS Team Changer [avoid crashes in aggressive changes]
 
Quote:

This works perfectly with 32 players (tested)
could you do the same but on the ES_ map? :)

i mean would this fix fix agressive team changing crash on counter-strike es_* maps?

claudiuhks 11-27-2011 12:41

Re: Module: CS Team Changer [avoid crashes in aggressive changes]
 
I can't say that it fix something for avoid the crashing, but, if you are thinking to change the player's team by using the CStrike extension, it will be trying to change the player's model, that is the reason why the server get crashed.

This extension, CS Team Changer, won't change any player physical information or any value, it will just update the tablescore, the API's team index and the team offset.

I make sure it won't crash the server by changing the team at 32 players in same time.

yokomo 02-06-2012 07:33

Re: Module: CS Team Changer [avoids crashes in aggressive changes]
 
Tested with 31 players (30bots 1human) in Zombie Plague Mod server, it give wrong team set in scoreboard when i set into Survivor round (change 31 player's team in a second).

To solve this we must add delay in team update (just like Mercylezz do in his ZP).

claudiuhks 02-08-2012 14:58

Re: Module: CS Team Changer [avoids crashes in aggressive changes]
 
PHP Code:

static iSurvivoriPlayers32 ], iNumi;
iSurvivor GetRandomAlive( );
get_playersiPlayersiNum"a" );

for( 
0iNumi++ )
  if( 
iPlayers] != iSurvivor MakeZombieiPlayers] );

MakeSurvivoriSurvivor );



GetRandomAlive( )
{
  static 
iPlayers32 ], iNum;
  
get_playersiPlayersiNum"a" );

  return 
iPlayersrandom_num0iNum ) ];


It's impossible to give a bad result...

yokomo 02-09-2012 00:28

Re: Module: CS Team Changer [avoids crashes in aggressive changes]
 
That was your own code, not from ZP4.3. Please take a look at this.
On function humanme:
PHP Code:

// Function Human Me (player id, turn into a survivor, silent mode)
humanme(idsurvivorsilentmode

Look at:
PHP Code:

    // Switch to CT
    
if (fm_cs_get_user_team(id) != FM_CS_TEAM_CT// need to change team?
    
{
        
remove_task(id+TASK_TEAM)
        
fm_cs_set_user_team(idFM_CS_TEAM_CT)
        
//fm_user_team_update(id)
    


It only give wrong result when i comment on "fm_user_team_update(id)"

My fm_cs_set_user_team stock:
PHP Code:

// Set a Player's Team
fm_cs_set_user_team(idteam)
{    
    
//set_pdata_int(id, OFFSET_CSTEAMS, team, OFFSET_LINUX)
    
cs_set_team(idteam)


My fm_user_team_update stock:
PHP Code:

// Update Player's Team on all clients (adding needed delays)
fm_user_team_update(id)
{
    static 
Float:current_time
    current_time 
get_gametime()
    
    if (
current_time g_teams_targettime >= 0.1)
    {
        
set_task(0.1"fm_cs_set_user_team_msg"id+TASK_TEAM)
        
g_teams_targettime current_time 0.1
    
}
    else
    {
        
set_task((g_teams_targettime 0.1) - current_time"fm_cs_set_user_team_msg"id+TASK_TEAM)
        
g_teams_targettime g_teams_targettime 0.1
    
}
}

// Send User Team Message
public fm_cs_set_user_team_msg(taskid)
{
    
// Note to self: this next message can now be received by other plugins
    
    // Set the switching team flag
    
g_switchingteam true
    
    
// Tell everyone my new team
    
cs_set_team_tablescore(ID_TEAMfm_cs_get_user_team(ID_TEAM))
    
    
// Done switching team
    
g_switchingteam false


Thats mean we still need to add delay at least 0.1 for team update on scoreboard.

claudiuhks 02-09-2012 12:08

Re: Module: CS Team Changer [avoids crashes in aggressive changes]
 
The Zombie Plague modification by me was wrong, so, it not needs any delay for this extension.

To edit Zombie Plague without delay takes so long.

Sorry for inconvenience :cry:.

bibu 09-30-2012 12:39

Re: Module: CS Team Changer [avoids crashes in aggressive changes]
 
I tried cs_set_user_team and cs_set_team native from here. But both don't call TeamInfo:

Try to hook it with that:

PHP Code:

register_event("TeamInfo""EventTeamInfo""a"


Arkshine 09-30-2012 14:15

Re: Module: CS Team Changer [avoids crashes in aggressive changes]
 
You can't hook message which have not been sent from the game ( and through metamod ).

bibu 09-30-2012 14:19

Re: Module: CS Team Changer [avoids crashes in aggressive changes]
 
Quote:

Originally Posted by Arkshine (Post 1809857)
You can't hook message which have not been sent from the game.

Quote from the include file:

PHP Code:

This native will automaticaly send a TeamInfo message

And else, how can I still hook it, is there another way?

Arkshine 09-30-2012 14:53

Re: Module: CS Team Changer [avoids crashes in aggressive changes]
 
To hook such message, you will have to update the source, to do like does "emessage" using the hook table pointer from metamod. This way amxx should be able to hook it. For more informations, check AMXX source code.

claudiuhks 09-30-2012 15:05

Re: Module: CS Team Changer [avoids crashes in aggressive changes]
 
Quote:

Originally Posted by bibu (Post 1809861)
Quote from the include file:

PHP Code:

This native will automaticaly send a TeamInfo message

And else, how can I still hook it, is there another way?

It means that you don't have to send a TeamInfo message from your AMX Mod X plugin. It will be sent from the module by default.

I suggest using this:

PHP Code:

cs_set_teamiClient);
EventTeamInfo( -1MSG_BROADCAST);

public 
EventTeamInfoiMsgiDestiEnt ) {




claudiuhks 10-16-2012 18:04

Re: Module: CS Team Changer v2.0 [avoids crashes in aggressive changes]
 
CS Team Changer has been updated at second version!
Check the changes in foreword.

yokomo 10-17-2012 01:18

Re: Module: CS Team Changer v2.0 [avoids crashes in aggressive changes]
 
Thanks for update, but strange why no people update the amxmodx into stable version. Also update the team change method in cstrike module. This is 2012 btw.

AllMassive 10-25-2012 18:49

Re: Module: CS Team Changer v2.0 [avoids crashes in aggressive changes]
 
Do i get it right:
Using this Module will 'fix' those broken Teamchange-Plugins ?

S0m3Th1nG_AwFul 10-26-2012 04:55

Re: Module: CS Team Changer v2.0 [avoids crashes in aggressive changes]
 
Quote:

Originally Posted by AllMassive (Post 1825760)
Do i get it right:
Using this Module will 'fix' those broken Teamchange-Plugins ?

It won't fix them 'automatically' - you should rewrite them firstly.

AllMassive 10-26-2012 12:46

Re: Module: CS Team Changer v2.0 [avoids crashes in aggressive changes]
 
oh - ok.

is there a plugin available which uses this module ?

btw:
it would be nice if a forumuser is able to search plugins by modules :wink:

yokomo 11-02-2012 00:47

Re: Module: CS Team Changer v2.0 [avoids crashes in aggressive changes]
 
Can someone confirm me is this plugin works perfect? i've tested it on my hlds with 9 bots and 3 humans. When someone connecting to server the "Overflow message" appear. Sorry forgot to take screenshot.

AllMassive 11-02-2012 13:53

Re: Module: CS Team Changer v2.0 [avoids crashes in aggressive changes]
 
Quote:

Originally Posted by yokomo (Post 1830861)
Can someone confirm me is this plugin works perfect? i've tested it on my hlds with 9 bots and 3 humans. When someone connecting to server the "Overflow message" appear. Sorry forgot to take screenshot.

This is not a Plugin - its a Module.
Someone needs to write a Plugin which uses this Module.

claudiuhks 11-03-2012 03:22

Re: Module: CS Team Changer v2.0 [avoids crashes in aggressive changes]
 
Quote:

Originally Posted by yokomo (Post 1830861)
Can someone confirm me is this plugin works perfect? i've tested it on my hlds with 9 bots and 3 humans. When someone connecting to server the "Overflow message" appear. Sorry forgot to take screenshot.

No, this extension has nothing to do with clients while connecting.

Killer zm 11-20-2012 08:35

Re: Module: CS Team Changer v2.0 [avoids crashes in aggressive changes]
 
a question : with this i can solve the server crash at the begining of the map in zombie plague mode ? I use zp 4.3 fix 5a

Bos93 11-21-2012 17:22

Re: Module: CS Team Changer v2.0 [avoids crashes in aggressive changes]
 
Quote:

Originally Posted by Killer zm (Post 1840802)
a question : with this i can solve the server crash at the begining of the map in zombie plague mode ? I use zp 4.3 fix 5a


Quote:

- Version: 4.3 Fix 1 (Jun 12, 2011)
* Fixed server crashes during mapchange and some potential crashes due to accessing uninitialized entity's private data
Check your API plugins

FromTheFuture 04-22-2013 15:52

Re: Module: CS Team Changer v2.0 [avoids crashes in aggressive changes]
 
I get this error:
FATA ERROR (shutting down): Tried to create a message with a bogus message type ( 0 )

claudiuhks 04-27-2013 10:29

Re: Module: CS Team Changer v2.0 [avoids crashes in aggressive changes]
 
Quote:

Originally Posted by FromTheFuture (Post 1937858)
I get this error:
FATA ERROR (shutting down): Tried to create a message with a bogus message type ( 0 )

Yeah, the fast conversion using math between edict_t * and int and between int and edict_t * does not work anymore. Will recompile it soon.

edeloa 05-30-2013 22:45

Re: Module: CS Team Changer v2.0 [avoids crashes in aggressive changes]
 
Any info on when then module will be recompiled?

mottzi 08-01-2013 11:25

Re: Module: CS Team Changer v2.0 [avoids crashes in aggressive changes]
 
Quote:

Originally Posted by edeloa (Post 1961528)
Any info on when then module will be recompiled?


yokomo 08-02-2013 03:08

Re: Module: CS Team Changer v2.0 [avoids crashes in aggressive changes]
 
Sorry, what is the point to use this module? since it still make server crash/kick client with overflow message. It need delay.


All times are GMT -4. The time now is 19:04.

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