2014-08-04 10:55:54 +00:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
// Copyright (C) 2004 Lukasz Wlasinski.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
|
|
|
|
|
|
|
//
|
|
|
|
// TSX Module
|
|
|
|
//
|
2005-12-11 18:42:19 +00:00
|
|
|
|
|
|
|
#include "tsx.h"
|
|
|
|
|
|
|
|
funEventCall modMsgsEnd[MAX_REG_MSGS];
|
|
|
|
funEventCall modMsgs[MAX_REG_MSGS];
|
|
|
|
void (*function)(void*);
|
|
|
|
void (*endfunction)(void*);
|
|
|
|
CPlayer* mPlayer;
|
|
|
|
int mPlayerIndex;
|
|
|
|
int mState;
|
|
|
|
CPlayer players[33];
|
|
|
|
|
|
|
|
bool is_theonemode;
|
|
|
|
bool rankBots;
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
int g_death_info = -1;
|
|
|
|
int g_damage_info = -1;
|
2005-12-11 18:42:19 +00:00
|
|
|
|
|
|
|
int gKnifeOffset;
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
int gmsgResetHUD;
|
|
|
|
int gmsgWeaponInfo;
|
|
|
|
int gmsgClipInfo;
|
|
|
|
int gmsgScoreInfo;
|
|
|
|
int gmsgTSHealth;
|
2006-02-26 08:11:25 +00:00
|
|
|
int gmsgTSState;
|
2006-02-26 06:42:48 +00:00
|
|
|
|
|
|
|
int gmsgWStatus;
|
|
|
|
int gmsgTSCash;
|
|
|
|
int gmsgTSSpace;
|
|
|
|
int gmsgPwUp;
|
|
|
|
|
2005-12-11 18:42:19 +00:00
|
|
|
RankSystem g_rank;
|
|
|
|
|
|
|
|
cvar_t init_tsstats_maxsize ={"tsstats_maxsize","3500", 0 , 3500.0 };
|
|
|
|
cvar_t init_tsstats_reset ={"tsstats_reset","0"};
|
|
|
|
cvar_t init_tsstats_rank ={"tsstats_rank","0"};
|
|
|
|
cvar_t *tsstats_rankbots;
|
|
|
|
cvar_t *tsstats_pause;
|
|
|
|
|
|
|
|
cvar_t init_tsstats_rankbots ={"tsstats_rankbots","1"};
|
|
|
|
cvar_t init_tsstats_pause = {"tsstats_pause","0"};
|
|
|
|
cvar_t *tsstats_maxsize;
|
|
|
|
cvar_t *tsstats_reset;
|
|
|
|
cvar_t *tsstats_rank;
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
struct sUserMsg
|
|
|
|
{
|
|
|
|
const char* name;
|
|
|
|
int* id;
|
|
|
|
funEventCall func;
|
|
|
|
bool endmsg;
|
|
|
|
} g_user_msg[] = {
|
|
|
|
{ "ResetHUD",&gmsgResetHUD,Client_ResetHUD_End,true },
|
|
|
|
{ "WeaponInfo",&gmsgWeaponInfo,Client_WeaponInfo,false },
|
|
|
|
{ "ClipInfo",&gmsgClipInfo,Client_ClipInfo,false },
|
|
|
|
{ "ScoreInfo",&gmsgScoreInfo,Client_ScoreInfo,false },
|
|
|
|
{ "TSHealth",&gmsgTSHealth,Client_TSHealth_End,true },
|
2006-02-26 08:11:25 +00:00
|
|
|
{ "TSState",&gmsgTSState,Client_TSState,false },
|
2006-02-26 06:42:48 +00:00
|
|
|
{ "WStatus",&gmsgWStatus,Client_WStatus,false },
|
|
|
|
{ "TSCash",&gmsgTSCash,Client_TSCash,false },
|
|
|
|
{ "TSSpace",&gmsgTSSpace,Client_TSSpace,false },
|
|
|
|
{ "PwUp",&gmsgPwUp,Client_PwUp,false},
|
|
|
|
|
|
|
|
{ 0,0,0,false }
|
|
|
|
};
|
|
|
|
|
2005-12-11 18:42:19 +00:00
|
|
|
const char* get_localinfo( const char* name , const char* def = 0 )
|
|
|
|
{
|
|
|
|
const char* b = LOCALINFO( (char*)name );
|
|
|
|
if (((b==0)||(*b==0)) && def )
|
|
|
|
SET_LOCALINFO((char*)name,(char*)(b = def) );
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
int RegUserMsg_Post(const char *pszName, int iSize)
|
|
|
|
{
|
2006-02-26 06:42:48 +00:00
|
|
|
for (int i = 0; g_user_msg[ i ].name; ++i ){
|
|
|
|
if ( !*g_user_msg[i].id && strcmp( g_user_msg[ i ].name , pszName ) == 0 ){
|
2005-12-11 18:42:19 +00:00
|
|
|
int id = META_RESULT_ORIG_RET( int );
|
|
|
|
|
|
|
|
*g_user_msg[ i ].id = id;
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
if ( g_user_msg[ i ].endmsg )
|
|
|
|
modMsgsEnd[ id ] = g_user_msg[ i ].func;
|
|
|
|
else
|
|
|
|
modMsgs[ id ] = g_user_msg[ i ].func;
|
2005-12-11 18:42:19 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_META_VALUE(MRES_IGNORED, 0);
|
|
|
|
}
|
|
|
|
|
2006-02-26 08:11:25 +00:00
|
|
|
void check_stunts(edict_s *player)
|
|
|
|
{
|
|
|
|
CPlayer *pPlayer = GET_PLAYER_POINTER(player);
|
|
|
|
|
|
|
|
if(pPlayer->checkstate == 0) return;
|
|
|
|
|
2013-08-10 11:01:23 +00:00
|
|
|
/*int stunttype;
|
2006-02-26 08:11:25 +00:00
|
|
|
int newstate = pPlayer->state;
|
|
|
|
int oldstate = pPlayer->oldstate;
|
|
|
|
|
|
|
|
if(newstate == 0) stunttype = STUNT_NONE;
|
|
|
|
else if(newstate == 2) stunttype = STUNT_DIVE;
|
|
|
|
else if(oldstate == 2) stunttype = STUNT_GETUP;
|
|
|
|
else if( pPlayer->GetOffset(TSX_SROLL_OFFSET) == 1) stunttype = STUNT_ROLL;
|
|
|
|
else if( pPlayer->GetOffset(TSX_SDUCK_OFFSET) == 1 ) stunttype = STUNT_DUCK;
|
2013-08-10 11:01:23 +00:00
|
|
|
else stunttype = STUNT_FLIP;*/
|
2006-02-26 08:11:25 +00:00
|
|
|
|
|
|
|
pPlayer->checkstate = 0;
|
|
|
|
|
|
|
|
//MF_ExecuteForward(Stunt,pPlayer->index,stunttype);
|
|
|
|
}
|
|
|
|
|
2005-12-11 18:42:19 +00:00
|
|
|
void ServerActivate_Post( edict_t *pEdictList, int edictCount, int clientMax )
|
|
|
|
{
|
|
|
|
|
|
|
|
is_theonemode = (int)CVAR_GET_FLOAT("mp_theonemode") ? true:false;
|
|
|
|
|
|
|
|
rankBots = (int)tsstats_rankbots->value ? true:false;
|
|
|
|
|
|
|
|
for( int i = 1; i <= gpGlobals->maxClients; ++i )
|
|
|
|
GET_PLAYER_POINTER_I(i)->Init( i , pEdictList + i );
|
|
|
|
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerPreThink_Post( edict_t *pEntity )
|
|
|
|
{
|
2006-02-26 06:42:48 +00:00
|
|
|
CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity);
|
2005-12-11 18:42:19 +00:00
|
|
|
|
2006-02-26 08:11:25 +00:00
|
|
|
check_stunts(pEntity);
|
|
|
|
|
2005-12-11 18:42:19 +00:00
|
|
|
if ( !isModuleActive() ) // stats only
|
|
|
|
return;
|
|
|
|
|
2006-02-26 08:11:25 +00:00
|
|
|
if (pPlayer->clearStats && pPlayer->clearStats < gpGlobals->time && pPlayer->ingame)
|
|
|
|
{
|
2005-12-11 18:42:19 +00:00
|
|
|
pPlayer->clearStats = 0.0f;
|
|
|
|
pPlayer->rank->updatePosition( &pPlayer->life );
|
|
|
|
pPlayer->restartStats(false);
|
|
|
|
}
|
2006-02-26 08:11:25 +00:00
|
|
|
|
2005-12-11 18:42:19 +00:00
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
void ServerDeactivate()
|
2005-12-11 18:42:19 +00:00
|
|
|
{
|
|
|
|
int i;
|
2006-02-26 06:42:48 +00:00
|
|
|
for(i = 1;i<=gpGlobals->maxClients; ++i){
|
2005-12-11 18:42:19 +00:00
|
|
|
CPlayer *pPlayer = GET_PLAYER_POINTER_I(i);
|
|
|
|
if (pPlayer->rank) pPlayer->Disconnect();
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
if ( (g_rank.getRankNum() >= (int)tsstats_maxsize->value) || ((int)tsstats_reset->value == 1) ) {
|
2005-12-11 18:42:19 +00:00
|
|
|
CVAR_SET_FLOAT("tsstats_reset",0.0);
|
|
|
|
g_rank.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
g_rank.saveRank( MF_BuildPathname("%s",get_localinfo("tsstats") ) );
|
|
|
|
|
|
|
|
// clear custom weapons info
|
|
|
|
for ( i=TSMAX_WEAPONS-TSMAX_CUSTOMWPNS;i<TSMAX_WEAPONS;i++)
|
|
|
|
weaponData[i].custom = false;
|
|
|
|
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
BOOL ClientConnect_Post( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ])
|
2005-12-11 18:42:19 +00:00
|
|
|
{
|
|
|
|
GET_PLAYER_POINTER(pEntity)->Connect(pszAddress);
|
|
|
|
RETURN_META_VALUE(MRES_IGNORED, TRUE);
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
void ClientDisconnect( edict_t *pEntity )
|
2005-12-11 18:42:19 +00:00
|
|
|
{
|
|
|
|
CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity);
|
|
|
|
if (pPlayer->ingame) pPlayer->Disconnect();
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientPutInServer_Post( edict_t *pEntity )
|
|
|
|
{
|
|
|
|
GET_PLAYER_POINTER(pEntity)->PutInServer();
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientUserInfoChanged_Post( edict_t *pEntity, char *infobuffer )
|
|
|
|
{
|
|
|
|
CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity);
|
|
|
|
const char* name = INFOKEY_VALUE(infobuffer,"name");
|
|
|
|
const char* oldname = STRING(pEntity->v.netname);
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
if ( pPlayer->ingame ){
|
|
|
|
if ( strcmp(oldname,name) ) {
|
2005-12-11 18:42:19 +00:00
|
|
|
if (!tsstats_rank->value)
|
|
|
|
pPlayer->rank = g_rank.findEntryInRank( name, name );
|
|
|
|
else
|
|
|
|
pPlayer->rank->setName( name );
|
|
|
|
}
|
|
|
|
}
|
2006-02-26 06:42:48 +00:00
|
|
|
else if ( pPlayer->IsBot() ) {
|
2005-12-11 18:42:19 +00:00
|
|
|
pPlayer->PutInServer();
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
void MessageBegin_Post(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed)
|
2005-12-11 18:42:19 +00:00
|
|
|
{
|
2006-02-26 06:42:48 +00:00
|
|
|
if (ed){
|
2005-12-11 18:42:19 +00:00
|
|
|
mPlayerIndex = ENTINDEX(ed);
|
|
|
|
mPlayer = GET_PLAYER_POINTER_I(mPlayerIndex);
|
2006-02-26 06:42:48 +00:00
|
|
|
} else {
|
2005-12-11 18:42:19 +00:00
|
|
|
mPlayerIndex = 0;
|
|
|
|
mPlayer = NULL;
|
|
|
|
}
|
|
|
|
mState = 0;
|
2006-02-26 06:42:48 +00:00
|
|
|
if ( msg_type < 0 || msg_type >= MAX_REG_MSGS )
|
|
|
|
msg_type = 0;
|
2005-12-11 18:42:19 +00:00
|
|
|
function=modMsgs[msg_type];
|
|
|
|
endfunction=modMsgsEnd[msg_type];
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
void MessageEnd_Post(void)
|
2005-12-11 18:42:19 +00:00
|
|
|
{
|
|
|
|
if (endfunction) (*endfunction)(NULL);
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
void WriteByte_Post(int iValue)
|
2005-12-11 18:42:19 +00:00
|
|
|
{
|
|
|
|
if (function) (*function)((void *)&iValue);
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
void WriteChar_Post(int iValue)
|
2005-12-11 18:42:19 +00:00
|
|
|
{
|
|
|
|
if (function) (*function)((void *)&iValue);
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
void WriteShort_Post(int iValue)
|
2005-12-11 18:42:19 +00:00
|
|
|
{
|
|
|
|
if (function) (*function)((void *)&iValue);
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
void WriteLong_Post(int iValue)
|
2005-12-11 18:42:19 +00:00
|
|
|
{
|
|
|
|
if (function) (*function)((void *)&iValue);
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
void WriteAngle_Post(float flValue)
|
2005-12-11 18:42:19 +00:00
|
|
|
{
|
|
|
|
if (function) (*function)((void *)&flValue);
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WriteCoord_Post(float flValue)
|
|
|
|
{
|
|
|
|
if (function) (*function)((void *)&flValue);
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
void WriteString_Post(const char *sz)
|
2005-12-11 18:42:19 +00:00
|
|
|
{
|
|
|
|
if (function) (*function)((void *)sz);
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
void WriteEntity_Post(int iValue)
|
2005-12-11 18:42:19 +00:00
|
|
|
{
|
|
|
|
if (function) (*function)((void *)&iValue);
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
void TraceLine_Post(const float *v1, const float *v2, int fNoMonsters, edict_t *e, TraceResult *ptr)
|
2005-12-11 18:42:19 +00:00
|
|
|
{
|
|
|
|
if (ptr->pHit&&(ptr->pHit->v.flags& (FL_CLIENT | FL_FAKECLIENT) )&&
|
2006-02-26 06:42:48 +00:00
|
|
|
e&&(e->v.flags& (FL_CLIENT | FL_FAKECLIENT) )){
|
2005-12-11 18:42:19 +00:00
|
|
|
GET_PLAYER_POINTER(e)->aiming = ptr->iHitgroup;
|
|
|
|
}
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
void OnMetaAttach()
|
|
|
|
{
|
2005-12-11 18:42:19 +00:00
|
|
|
|
|
|
|
CVAR_REGISTER (&init_tsstats_maxsize);
|
|
|
|
CVAR_REGISTER (&init_tsstats_reset);
|
|
|
|
CVAR_REGISTER (&init_tsstats_rank);
|
|
|
|
tsstats_maxsize=CVAR_GET_POINTER(init_tsstats_maxsize.name);
|
|
|
|
tsstats_reset=CVAR_GET_POINTER(init_tsstats_reset.name);
|
|
|
|
tsstats_rank=CVAR_GET_POINTER(init_tsstats_rank.name);
|
|
|
|
|
|
|
|
CVAR_REGISTER (&init_tsstats_rankbots);
|
|
|
|
CVAR_REGISTER (&init_tsstats_pause);
|
|
|
|
tsstats_rankbots = CVAR_GET_POINTER(init_tsstats_rankbots.name);
|
|
|
|
tsstats_pause = CVAR_GET_POINTER(init_tsstats_pause.name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
void OnPluginsLoaded()
|
|
|
|
{
|
|
|
|
g_damage_info = MF_RegisterForward("client_damage", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
|
|
|
|
g_death_info = MF_RegisterForward("client_death", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
|
|
|
|
}
|
2006-02-04 23:21:03 +00:00
|
|
|
|
2008-04-29 06:53:55 +00:00
|
|
|
int AmxxCheckGame(const char *game)
|
|
|
|
{
|
|
|
|
if (strcasecmp(game, "ts") == 0)
|
|
|
|
return AMXX_GAME_OK;
|
|
|
|
|
|
|
|
return AMXX_GAME_BAD;
|
|
|
|
}
|
2006-02-26 06:42:48 +00:00
|
|
|
void OnAmxxAttach()
|
|
|
|
{
|
2005-12-11 18:42:19 +00:00
|
|
|
|
|
|
|
gKnifeOffset = TSKNIFE_OFFSET;
|
|
|
|
|
|
|
|
MF_AddNatives( stats_Natives );
|
2006-02-26 06:42:48 +00:00
|
|
|
MF_AddNatives( base_Natives );
|
2005-12-11 18:42:19 +00:00
|
|
|
|
|
|
|
const char* path = get_localinfo("tsstats_score","addons/amxmodx/data/tsstats.amxx");
|
|
|
|
if ( path && *path )
|
|
|
|
{
|
|
|
|
char error[128];
|
|
|
|
g_rank.loadCalc( MF_BuildPathname("%s",path) , error );
|
|
|
|
}
|
|
|
|
if ( !g_rank.begin() )
|
|
|
|
{
|
|
|
|
g_rank.loadRank( MF_BuildPathname("%s",get_localinfo("tsstats","addons/amxmodx/data/tsstats.dat") ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:42:48 +00:00
|
|
|
void OnAmxxDetach()
|
2005-12-11 18:42:19 +00:00
|
|
|
{
|
2006-02-26 06:42:48 +00:00
|
|
|
g_rank.clear();
|
|
|
|
g_rank.unloadCalc();
|
2005-12-11 18:42:19 +00:00
|
|
|
}
|