нужно сделать чтобы плагином могли пользваться только админы
спойлер не работает
Код
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#pragma semicolon 1
#define PLUGIN "Team Changer"
#define VERSION "1.0"
#define AUTHOR "SchlumPF"
#define EXTRAOFFSET 5
#define OFFSET_TEAM 114
#define OFFSET_INTERNALMODEL 126
enum CsTeams
{
CS_TEAM_UNASSIGNED = 0,
CS_TEAM_T = 1,
CS_TEAM_CT = 2,
CS_TEAM_SPECTATOR = 3
};
enum CsInternalModels
{
CS_DONTCHANGE = 0,
CS_CT_URBAN = 1,
CS_T_TERROR = 2,
CS_T_LEET = 3,
CS_T_ARCTIC = 4,
CS_CT_GSG9 = 5,
CS_CT_GIGN = 6,
CS_CT_SAS = 7,
CS_T_GUERILLA = 8,
CS_CT_VIP = 9,
CZ_T_MILITIA = 10,
CZ_CT_SPETSNAZ = 11
};
new g_iMessageSayText;
new g_iMessageTeamInfo;
new g_iMaxPlayers;
new g_iCvar[2];
public plugin_init( )
{
register_plugin( PLUGIN, VERSION, AUTHOR );
g_iCvar[0] = register_cvar( "teamchange_terrorists", "1" );
g_iCvar[1] = register_cvar( "teamchange_scout", "0" );
register_clcmd( "say /spec", "cmdSpectator" );
register_clcmd( "say /ct", "cmdCounterTerrorist" );
register_clcmd( "say /t", "cmdTerrorist" );
g_iMessageSayText = get_user_msgid( "SayText" );
g_iMessageTeamInfo = get_user_msgid( "TeamInfo" );
g_iMaxPlayers = get_maxplayers( );
set_msg_block( get_user_msgid( "ClCorpse" ), BLOCK_SET );
}
public cmdSpectator( plr )
{
if( fm_cs_get_user_team( plr ) == CS_TEAM_SPECTATOR )
{
fnGreenChat( plr, "[GG] You are already a spectator, say '/ct' %sto change your team.", get_pcvar_num( g_iCvar[0] ) ? "or '/t'" : "" );
return PLUGIN_HANDLED;
}
set_pev( plr, pev_deadflag, DEAD_DISCARDBODY );
fm_cs_set_user_team( plr, CS_TEAM_SPECTATOR );
fnGreenChat( plr, "[GG] You became a spectator." );
return PLUGIN_HANDLED;
}
public cmdCounterTerrorist( plr )
{
if( fm_cs_get_user_team( plr ) == CS_TEAM_CT )
{
fnGreenChat( plr, "[GG] You are already a counter-terrorist, say '/spec' %sto change your team.", get_pcvar_num( g_iCvar[0] ) ? "or '/t'" : "" );
return PLUGIN_HANDLED;
}
fm_cs_set_user_team( plr, CS_TEAM_CT );
ExecuteHamB( Ham_CS_RoundRespawn, plr );
if( !user_has_weapon( plr, CSW_KNIFE ) )
{
fm_give_item( plr, "weapon_knife" );
}
if( !user_has_weapon( plr, CSW_USP ) )
{
fm_give_item( plr, "weapon_usp" );
}
if( get_pcvar_num( g_iCvar[1] ) && !user_has_weapon( plr, CSW_SCOUT ) )
{
fm_give_item( plr, "weapon_scout" );
}
fnGreenChat( plr, "[GG] You became a counter-terrorist." );
return PLUGIN_HANDLED;
}
public cmdTerrorist( plr )
{
if( !get_pcvar_num( g_iCvar[0] ) )
{
return PLUGIN_CONTINUE;
}
if( fm_cs_get_user_team( plr ) == CS_TEAM_T )
{
fnGreenChat( plr, "[GG] You are already a terrorist, say '/spec' or '/ct' to change your team." );
return PLUGIN_HANDLED;
}
fm_cs_set_user_team( plr, CS_TEAM_T, CS_T_LEET );
ExecuteHamB( Ham_CS_RoundRespawn, plr );
fm_give_item( plr, "weapon_knife" );
fm_give_item( plr, "weapon_usp" );
if( get_pcvar_num( g_iCvar[1] ) )
{
fm_give_item( plr, "weapon_scout" );
}
fnGreenChat( plr, "[GG] You became a terrorist." );
return PLUGIN_HANDLED;
}
fm_give_item( plr, const item[] )
{
new ent = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, item ) );
if(! pev_valid( ent ) )
{
return 0;
}
new Float:origin[3];
pev( plr, pev_origin, origin );
set_pev( ent, pev_origin, origin );
set_pev( ent, pev_spawnflags, pev( ent, pev_spawnflags ) | SF_NORESPAWN );
dllfunc( DLLFunc_Spawn, ent );
new save = pev( ent, pev_solid );
dllfunc( DLLFunc_Touch, ent, plr );
if( pev( ent, pev_solid ) != save )
{
return ent;
}
engfunc( EngFunc_RemoveEntity, ent );
return -1;
}
fm_cs_set_user_team( plr, {CsTeams,_}:team, {CsInternalModels,_}:model = CS_DONTCHANGE )
{
switch( team )
{
case CS_TEAM_T: set_pdata_int( plr, OFFSET_TEAM, 1, EXTRAOFFSET );
case CS_TEAM_CT: set_pdata_int( plr, OFFSET_TEAM, 2, EXTRAOFFSET );
case CS_TEAM_SPECTATOR: set_pdata_int( plr, OFFSET_TEAM, 3, EXTRAOFFSET );
}
if( model )
{
switch( model )
{
case CS_CT_URBAN: set_pdata_int( plr, OFFSET_INTERNALMODEL, 1, EXTRAOFFSET );
case CS_T_TERROR: set_pdata_int( plr, OFFSET_INTERNALMODEL, 2, EXTRAOFFSET );
case CS_T_LEET: set_pdata_int( plr, OFFSET_INTERNALMODEL, 3, EXTRAOFFSET );
case CS_T_ARCTIC: set_pdata_int( plr, OFFSET_INTERNALMODEL, 4, EXTRAOFFSET );
case CS_CT_GSG9: set_pdata_int( plr, OFFSET_INTERNALMODEL, 5, EXTRAOFFSET );
case CS_CT_GIGN: set_pdata_int( plr, OFFSET_INTERNALMODEL, 6, EXTRAOFFSET );
case CS_CT_SAS: set_pdata_int( plr, OFFSET_INTERNALMODEL, 7, EXTRAOFFSET );
case CS_T_GUERILLA: set_pdata_int( plr, OFFSET_INTERNALMODEL, 8, EXTRAOFFSET );
case CS_CT_VIP: set_pdata_int( plr, OFFSET_INTERNALMODEL, 9, EXTRAOFFSET );
case CZ_T_MILITIA: set_pdata_int( plr, OFFSET_INTERNALMODEL, 10, EXTRAOFFSET );
case CZ_CT_SPETSNAZ: set_pdata_int( plr, OFFSET_INTERNALMODEL, 11, EXTRAOFFSET );
}
}
dllfunc( DLLFunc_ClientUserInfoChanged, plr );
new teaminfo[32];
switch( team )
{
case CS_TEAM_UNASSIGNED: copy( teaminfo, 31, "UNASSIGNED" );
case CS_TEAM_T: copy( teaminfo, 31, "TERRORIST" );
case CS_TEAM_CT: copy( teaminfo, 31, "CT" );
case CS_TEAM_SPECTATOR: copy( teaminfo, 31, "SPECTATOR" );
}
message_begin( MSG_ALL, g_iMessageTeamInfo );
write_byte( plr );
write_string( teaminfo );
message_end( );
}
CsTeams:fm_cs_get_user_team( plr )
{
switch( get_pdata_int( plr, OFFSET_TEAM ) )
{
case 1: return CS_TEAM_T;
case 2: return CS_TEAM_CT;
case 3: return CS_TEAM_SPECTATOR;
}
return CS_TEAM_UNASSIGNED;
}
// by fatalis
fnGreenChat( plr, const message[], {Float,Sql,Result,_}:... )
{
static msg[192];
msg[0] = 0x04;
vformat( msg[1], sizeof msg - 2, message, 3 );
if( plr > 0 && plr <= g_iMaxPlayers )
{
message_begin( MSG_ONE, g_iMessageSayText, { 0, 0, 0 }, plr );
write_byte( plr );
write_string( msg );
message_end( );
}
else if( plr == 0 )
{
for( new i = 1; i <= g_iMaxPlayers; i++ )
{
if( !is_user_connected( i ) )
continue;
message_begin( MSG_ONE, g_iMessageSayText, { 0, 0, 0 }, i );
write_byte( i );
write_string( msg );
message_end( );
}
}
return 1;
}