AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Unapproved/Old Plugins (https://forums.alliedmods.net/forumdisplay.php?f=27)
-   -   CS Team Win (https://forums.alliedmods.net/showthread.php?t=60609)

hebusletroll 09-08-2007 08:43

CS Team Win
 
2 Attachment(s)
This plugin allow administrators to give victory to a CounterStrike team.

Original concept from VEN's plugin : http://forums.alliedmods.net/showthr...light=team+win

I've search another way to set victory, and after some days of working i found the solution : using a planted C4 bomb (don't miss me in credits if you use it in your plugin.!)

Enjoy !

Code:

/**************************************************************************************************/
/*                                  CsTeamWin by Hebusletroll - 08 September 2007                          */
/*                                        [email protected]                                  */
/*                                                                                                  */
/* This plugin allow to give win for specified team. There is an already existing plugin made by  */
/* VEN : http://forums.alliedmods.net/showthread.php?t=40287&highlight=team+win.                  */ 
/*                                                                                                  */
/* Why this plugin ? Just for an ehanced management for giving victory.                                  */
/*          - The plugin doesn't create any Fake client                                              */
/*            - There is not player team switching and silent kill                                  */
/*            - Work when your'e playing in 1vs1                                                          */
/*                                                                                                  */
/* This plugin use an alernate mode : it create a C4 planted bomb and defuse it immedialty !          */
/* It trig all necessaries event to give the victory to the selected team.                          */
/*                                                                                                  */
/*      CREDITS :                                                                                  */
/*                VEN's for the original team win concept                                          */
/*                ARKSHINE for his help for sound blocking                                          */
/*                                                                                                  */
/*        COMMAND :                                                                                  */
/*                amx_csteamwin <1|2> : give victory for the team                        .                  */
/*                1 = Terrorist                                                                          */
/*                2 = Counter-Terrorist                                                                  */
/*                                                                                                  */
/*        Changes : 0.1 (08 September 2007) => First release.                                          */
/*                                                                                                  */
/**************************************************************************************************/
/*                                                                                                  */
/* THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN  */
/* OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM    */
/* "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED  */
/* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE */
/* RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE    */
/* DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.                  */
/*                                                                                                  */
/**************************************************************************************************/

#define AMXX_VERSION_NUM        176

#include <fakemeta>
#include <amxmodx>
#include <engine>
#include <cstrike>
#include <amxmisc>
#include <fun>

#define AMXX_PLUGIN_NAME        "CsTeamWin"
#define AMXX_PLUGIN_AUTHOR        "Hebusletroll"
#define AMXX_PLUGIN_VERSION        "0.1"

#define WIN32_C4_CTWINOFFSTER        99
#define WIN32_C4_PARAM                0.0

#define MODEL_C4                "models/w_c4.mdl"

#define CMD_TEAM_PARAM                1
#define CMD_TEAM_T                1
#define CMD_TEAM_CT                2       

#define ID_WINSOUND                0
#define ID_WINTEXT                1

#define MODE_TEAMWIN_AVAILABLE                0
#define MODE_TEAMWIN_TTEAMSELECTED        1
#define MODE_TEAMWIN_CTTEAMSELECTED        2

new        game_progressbar, game_text, game_sendaudio, game_player,
        game_roundstarted, game_teamscoremanagement[2],game_teamscore, game_processed
       
new        givevictory=MODE_TEAMWIN_AVAILABLE


new teamsoundvictory[2][2][]=
{
        {"radio/terwin.wav",        "terwin"},
        {"radio/ctwin.wav",        "ctwin"}
}

// Here the first called function, registering needed event for the plugin.
public plugin_init()
{
        register_plugin(AMXX_PLUGIN_NAME,
                        AMXX_PLUGIN_AUTHOR,
                        AMXX_PLUGIN_VERSION)
       
        //Multilanguage support.
        register_dictionary("locale/csteamwin/locale.ctg")
       
        //Getting required user_msgid.
        game_progressbar = get_user_msgid("BarTime")
        game_text        = get_user_msgid("TextMsg")
        game_sendaudio  = get_user_msgid("SendAudio")
        game_teamscore        = get_user_msgid("TeamScore")
               
        register_concmd("amx_csteamwin","on_teamwin",ADMIN_KICK)
        register_logevent("on_draw", 2, "1=Round_End")
        register_logevent("on_roundstart", 2, "1=Round_Start")
        register_event("SendAudio", "on_terwin", "a", "2&%!MRAD_terwin")
        register_event("SendAudio", "on_ctwin", "a","2&%!MRAD_ctwin")
        register_event("SendAudio", "on_draw", "a","2&%!MRAD_draw")
        register_event("ResetHUD","on_teamscore","b","1=1") 
        register_event("TeamScore","on_teamscore","a")
        register_message(game_text, "on_newmessage")
        register_message(game_sendaudio,"on_soundmessage")
        register_forward(FM_EmitSound,"on_soundemitted")
}


// Blocking bomb plant and defusing. This is an entity sound, not trigger by
// message game_sendaudio.
public on_soundemitted(entity, channel, const sample[])
{
        //Only trap of givevictory is set.
        if(givevictory)
        {
                if(equali(sample,"weapons/c4_plant.wav")||
                  equali(sample,"weapons/c4_disarm.wav")||
                  equali(sample,"weapons/cs_disarmed.wav"))
                {
                        return FMRES_SUPERCEDE
                }
        }
        return FMRES_IGNORED
}

//Trig sound message to manage new player score.
public on_soundmessage(msg_id,msg_dest, msg_entity)
{
        if(givevictory)
        {
                new msgid[64]
                get_msg_arg_string(2,msgid,64)
               
                //Check the message if match the good condition to change default round result.
                if(equali(msgid,"%!MRAD_terwin")||equali(msgid,"%!MRAD_ctwin")||equali(msgid,"%!MRAD_BOMBDEF"))
                {
                        //Sending new round sound to all players.
                        client_cmd(0,"spk %s",teamsoundvictory[givevictory==MODE_TEAMWIN_TTEAMSELECTED?MODE_TEAMWIN_TTEAMSELECTED-1:MODE_TEAMWIN_CTTEAMSELECTED-1][ID_WINSOUND])
                       
                        //Sending text.
                        client_print(0,print_center,"%L",LANG_PLAYER,teamsoundvictory[givevictory==MODE_TEAMWIN_TTEAMSELECTED?MODE_TEAMWIN_TTEAMSELECTED-1:MODE_TEAMWIN_CTTEAMSELECTED-1][ID_WINTEXT])
       
                        //If victory score is not processed then enter.
                        if(!game_processed)
                        {
                                //Removing all others c4 entity to prevent others end rounds.
                                new c4_entity = get_c4entity()
                                while(c4_entity)
                                {
                                        remove_entity(c4_entity)
                                        c4_entity = get_c4entity()
                                }
                               
                                //Setting score.
                                if(givevictory==CMD_TEAM_T)
                                {
                                        game_teamscoremanagement[CMD_TEAM_CT-1]-=1
                                        game_teamscoremanagement[CMD_TEAM_T-1]+=1
                                }
                                //Raising game processed.
                                game_processed=true
                        }
                        return PLUGIN_HANDLED
                }
        }
        return PLUGIN_CONTINUE
}

//Catching game message.
public on_newmessage(msg_id, msg_dest, msg_entity)
{
        new msgid[64]
        get_msg_arg_string(2, msgid, 64)
       
        //Resetting plugin victory state and score.
        if(equali(msgid, "#Game_Commencing") || equali(msgid, "#Game_will_restart_in"))
        {
                game_teamscoremanagement[0]=0
                game_teamscoremanagement[1]=0
                on_draw()
        }
               
        //Block "Defused bomb".
        if(givevictory!=MODE_TEAMWIN_AVAILABLE)
                if(equali(msgid,"#Bomb_Defused"))
                        return PLUGIN_HANDLED

        return PLUGIN_CONTINUE
}

//Updating teamscore.
public on_teamscore()
{
        message_begin(MSG_ALL,game_teamscore,{0,0,0},0)
        write_string ("TERRORIST") 
        write_short(game_teamscoremanagement[CMD_TEAM_T-1])
        message_end()
        message_begin(MSG_ALL,game_teamscore,{0,0,0},0)
        write_string ("CT") 
        write_short(game_teamscoremanagement[CMD_TEAM_CT-1])
        message_end()
        return PLUGIN_HANDLED
}

//Victory for terrorists team.
public on_terwin()
{
        game_roundstarted=false
        game_teamscoremanagement[CMD_TEAM_T-1]+=1
}

//Victory for Counter-terrorists team.
public on_ctwin()
{
        game_roundstarted=false
        game_teamscoremanagement[CMD_TEAM_CT-1]+=1
}

//Game draw
public on_draw()
        game_roundstarted=false

//New round, that allow administrator to give victory.
public on_roundstart()
{
        givevictory=MODE_TEAMWIN_AVAILABLE
        game_roundstarted=true
        game_processed = false
}

//Main function to give victory.
public on_teamwin(id,level,cid)
{
        //Checking requested user rights.
        if (!cmd_access(id, level, cid, 1))
                return PLUGIN_HANDLED

        //Check if the round is started, if not send a message and exit function.
        if(!game_roundstarted)
        {
                client_print(id,print_chat,"%L",LANG_PLAYER,"roundnotstarted")
                return PLUGIN_HANDLED
        }
               
        //Reading teamindex to give victory.
        new teamindex[1]
        read_argv(CMD_TEAM_PARAM,teamindex,1)
       
        //Searching valid player : a valid player must be a Counter-terrorists, but an alive
        //terrorists is required to  finish round.
        //If there is not Counter-terrorists, terrorists are natively win the round.
        //If there is not Terrorirts, Counter-terrorists are natively win the round.
       
        game_player = get_validplayer()
       
        givevictory=str_to_num(teamindex[0])
       
        //Checking the team index : 1=Terrorists, 2=Counter-terrorists.
        if(givevictory<1||givevictory>2)
        {
                givevictory = MODE_TEAMWIN_AVAILABLE
                client_print(id,print_chat,"%L",LANG_PLAYER,"badteamindex")
                return PLUGIN_HANDLED
        }
       
        //If there is not a valid player, there is not an eligible team.
        if(!game_player)
        {
                givevictory = MODE_TEAMWIN_AVAILABLE
                client_print(id,print_chat,"%L",LANG_PLAYER,"noteligibleteam")
                return PLUGIN_HANDLED
        }

        //Checking if there is an already C4 planted bomb.
        new entity = get_c4entity()
       
        //If not ? Creating it now ! This code will create an armed bomb YEAH ! It's possible !
        if(!entity)
        {
                entity = create_entity("weapon_c4")
                new Float:origin[3]
                entity_set_string(entity,EV_SZ_classname,"weapon_c4")
                entity_get_vector(game_player,EV_VEC_origin,origin)
                entity_set_model(entity,MODEL_C4)
                DispatchKeyValue(entity,"detonatedelay",get_cvar_num("mp_c4timer"))
                entity_set_origin(entity,origin)
                force_use(game_player,entity)
        }
       
        //If the entity is done, defusing the bomb immediatly (i've created the Time To Defuse
        //plugin before to create this plugin).
        if(entity)
        {
                //Block progressbar.
                set_msg_block(game_progressbar,BLOCK_ONCE)
               
                //Block game text for "Defusing text"
                set_msg_block(game_text,BLOCK_ONCE)
               
                //Force eligible player to start defusing bomb.
                force_use(game_player,get_c4entity())
               
                //Set instant defusing.
                set_pdata_float(get_c4entity(),WIN32_C4_CTWINOFFSTER,WIN32_C4_PARAM)
               
                //Removing game scoring for player that defuse the bomb.
                set_user_frags(game_player,get_user_frags(game_player)-3)
               
        }
        return PLUGIN_HANDLED
}

//Searching the bomb entity.
stock get_c4entity()
        return engfunc(EngFunc_FindEntityByString, -1, "model", MODEL_C4)
       
//Searching an alive player. Must be a Counter-Terrorists.
//If there is not available CT, the round is over because there is only one team.
stock get_validplayer()
{
        new ctplayerindex,tplayerindex
        for(new player=1;player<get_maxplayers()+1;player++)
                if(is_user_alive(player))
                        if(cs_get_user_team(player)==CS_TEAM_CT)
                        {
                                ctplayerindex = player
                                break
                        }
        if(ctplayerindex)
        {
                for(new player=1;player<get_maxplayers()+1;player++)
                        if(is_user_alive(player))
                                if(cs_get_user_team(player)==CS_TEAM_T)
                                {
                                        tplayerindex = player
                                        break
                                }
        }
        return (ctplayerindex?(tplayerindex?ctplayerindex:0):0)
}


nr1lolz 09-08-2007 09:46

Re: CS Team Win
 
Nice work :P

so does this plugin creates a C4 outside the map? and then blows up when the timer gets to 0 for T to win, and gets defused for CT to win??

Alka 09-08-2007 10:01

Re: CS Team Win
 
Actually this is very nice...Gj! :up:

hebusletroll 09-08-2007 17:44

Re: CS Team Win
 
Quote:

Originally Posted by nr1lolz (Post 528836)
Nice work :P

so does this plugin creates a C4 outside the map? and then blows up when the timer gets to 0 for T to win, and gets defused for CT to win??

The plugin create a planted C4 at the first alive player available position in Counter-Terrorist team, and defuse it, not blow it.
It's not possible to blow the bomb to give victory @t terrorist team without placing the planted bomb in valid world area (inside map). And the problem that if you blow the bomb, the explosion may be viewed by players (and you can die).

I wil update all code to fake meta and add draw team victory with optimization.

Mr.Bot 09-08-2007 19:00

Re: CS Team Win
 
Sorry but this plugin crash my server

FATAL ERROR (shutting down): Bad entity in IndexOfEdict()
Add "-debug" to the ./hlds_run command line to generate a debug.log to help with solving this problem

hebusletroll 09-09-2007 16:13

Re: CS Team Win
 
Quote:

Originally Posted by Mr.Bot (Post 529091)
Sorry but this plugin crash my server

FATAL ERROR (shutting down): Bad entity in IndexOfEdict()
Add "-debug" to the ./hlds_run command line to generate a debug.log to help with solving this problem

Hello Mr.Bot

Can you tell me theses informations :

- The plugin crash each time you call the function.
- On which server type (Win/Linux) ?

Thank you for your feedback.

Mr.Bot 09-09-2007 17:52

Re: CS Team Win
 
Thank you for your attention my server user linux and your plugin work in my windows server ( dedicate server ) thx you if you can resolve this problem

bye

Hawk552 09-09-2007 21:26

Re: CS Team Win
 
Broken (although you have more time to fix it). Bad method. Probably bad coding (didn't look).

Unapproved.

hebusletroll 09-13-2007 15:25

Re: CS Team Win
 
Okee dokee Hawk.

I'll post an update this weekend.

Mr.Bot 09-16-2007 14:35

Re: CS Team Win
 
thx you

hugz` 01-04-2008 19:29

Re: CS Team Win
 
Doesn't work with the no objective plugin..

M249-M4A1 01-05-2008 19:36

Re: CS Team Win
 
Necropost much? It's unapproved for a reason.


All times are GMT -4. The time now is 20:34.

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