- 听众
- 收听
- 积分
- 3894
- 主题
- 回帖
- 0
- 精华
注册时间2008-4-22
最后登录1970-1-1
该用户从未签到
|
发表于 2009-8-13 21:29:42
|
显示全部楼层
本帖最后由 Pledges 于 2009-8-13 21:35 编辑
/*=====================================
KZ Stats by Chris
To be used with Kz Jump Plugin v0.08 by teame06
Functions offered:
- Top15
More to come...
这个可以吗?
我没测试过哈!
=====================================
Credits / Thanks / Notes:
=====================================
teame06 for the Kz Jump Plugin and help
AssKicR for KZ Multiplugin
I took the top15 from Multiplugin
=====================================*/
#include <amxmodx>
#include <amxmisc>
#include <nvault>
#include <kz>
#define VERSION "0.3"
#define MP_COMPATIBLE 1 //Enable/Disable reading&converting Top15 from KZ Multiplugin
//TaskIds
//UpdateScoreboard TaskId = 0
//Pointers
new kz_enabled;
new kz_top15;
//Vault File
new Vault;
new const TOP15_FILE[] = "kz_Top15";
new const EMPTY[] = "X"; //Assigned to SteamId to know if a top15 slot is empty or not
#if MP_COMPATIBLE
new const TOP15_FOLDER[] = "kz_top15";//Folder name where old Top15 from KZ Multiplugin will be read
#endif
//Top15 Vars
new Top15_SteamId[15][33];
new Top15_Name[15][33];
new Top15_Time[15];
new Top15_CP[15]; //Checkpoints
new Top15_GC[15]; //GoChecks
new deleteNum = -1;
//Other vars
new CurrentMap[32]; //Current map name
/*================
plugin_init
Called on plugin load
================*/
public plugin_init()
{
register_plugin("KZ Stats", VERSION, "Chris");
//Setting Cvars
kz_top15 = register_cvar("kz_top15", "1");
//Getting Other Cvar Pointers
kz_enabled = get_cvar_pointer("kz_enabled");
//Setting mapname
get_mapname(CurrentMap, 31);
}
/*================
kz_Init
Called by main plugin when it loads
================*/
public kz_Init(_state)
{
if(!_state)
{
pause("a");
return PLUGIN_HANDLED;
}
if(!get_pcvar_num(kz_enabled))
return PLUGIN_HANDLED;
//Register say command
register_saycmd("top15", "Top15_Show", -1, "");
register_concmd("amx_removetop15","Top15_Remove",ADMIN_RCON,"Shows the edit menu");
register_concmd("amx_cleartop15", "Top15_Clear",ADMIN_RCON,"Deletes the Top15 of the current map");
register_concmd("amx_printtop15","Top15_Print",ADMIN_RCON,"Shows the top15 in console");
//Top15_Read(); //commentend because using below block
//*********************************************************
#if MP_COMPATIBLE
new Top15_TxtFilePath[128];
new BaseDir[32];
get_basedir(BaseDir,31);
format(Top15_TxtFilePath,sizeof(Top15_TxtFilePath),"%s/%s/%s.txt", BaseDir, TOP15_FOLDER, CurrentMap);
if(file_exists(Top15_TxtFilePath))
{
//Reads the Top15
Top15_MP_Read(Top15_TxtFilePath);
//Deletes the file since it's not needed anymore (Top 15 is saved with nvault)
delete_file(Top15_TxtFilePath);
return PLUGIN_HANDLED;
}
else
{
Top15_Read();
}
#else
Top15_Read();
#endif
//*********************************************************
return PLUGIN_HANDLED;
}
/*================
kz_FinishClimb
Called by main plugin when the player pushes the end button
================*/
public kz_FinishClimb(player, time, cp_count, gc_count)
{
if(!get_pcvar_num(kz_top15))
return PLUGIN_HANDLED;
new Name[33];
get_user_name(player,Name,32);
// will be eventualy a variable with the minimum time per map
// preventing to fast times with exploits or boosting
if(time > 20)
{
Top15_Check(player,time,cp_count,gc_count);
}
else
{
if(time > 1)
{
kz_ColorChat(player,green,"[KZ Top15] Your time is too fast...cheater !!");
log_to_file("KZ_Cheats.txt","[KZ Top15] %s was beaten in %s by %s", CurrentMap, GetStrTime(time), Name);
}
else
{
kz_ColorChat(player,green,"[KZ Top15] To bad you didn't have a timer...");
}
}
return PLUGIN_HANDLED;
}
public Top15_Clear(id,level,cid)
{
if ( !cmd_access(id,level,cid,1) )
return PLUGIN_HANDLED ;
new VerificationNumber[5];
read_argv(1,VerificationNumber,4);
if(str_to_num(VerificationNumber) != deleteNum)
{
deleteNum = random_num(1,999);
client_print(id, print_console, "Type amx_top15clear %i to delete the top 15", deleteNum);
return PLUGIN_HANDLED;
}
else
{
deleteNum = -1;
}
Vault = nvault_open(TOP15_FILE);
if(Vault == INVALID_HANDLE)
{
log_amx("Error opening nVault file: %s", TOP15_FILE);
return PLUGIN_HANDLED;
}
new Key[40];
for( new i = 0; i < 15; i++ )
{
GetKey(i+1,Key);
Top15_SteamId = EMPTY;
Top15_Time = 99999;
Top15_CP = 99999;
nvault_remove(Vault, Key);
}
nvault_close(Vault);
client_print(id, print_console, "Top15 of %s has been deleted", CurrentMap);
return PLUGIN_HANDLED;
}
public Top15_Remove(id,level,cid)
{
if ( !cmd_access(id,level,cid,1) )
return PLUGIN_HANDLED ;
return PLUGIN_HANDLED;
}
public Top15_Print(id,level,cid)
{
if ( !cmd_access(id,level,cid,1) )
return PLUGIN_HANDLED ;
Vault = nvault_open(TOP15_FILE);
if(Vault == INVALID_HANDLE)
{
log_amx("Error opening nVault file: %s", TOP15_FILE);
return PLUGIN_HANDLED;
}
client_print(id, print_console, "-------------------------------------------------------------------");
for( new i = 0; i < 15; i++ )
{
client_print(id, print_console, " %d. %s %s %s %i %i",(i+1),Top15_SteamId, Top15_Name,GetStrTime(Top15_Time),Top15_CP,Top15_GC);
}
client_print(id, print_console, "-------------------------------------------------------------------");
new Key[40], Data[100];
new TimeStamp;
new tSteamId[32],tName[32],tTime[5],tCP[5],tGC[5];
for( new i = 0; i < 15; i++ )
{
GetKey(i+1,Key);
if(nvault_lookup(Vault, Key, Data, 99, TimeStamp))
{
parse(Data,tSteamId,31,tName,31,tTime,4,tCP,4,tGC,4);
client_print(id, print_console, " %d.%s %s %s %i %i",(i+1),tSteamId,tName,GetStrTime(str_to_num(tTime)),str_to_num(tCP),str_to_num(tGC));
}
}
return PLUGIN_HANDLED;
}
/*================
Top15_Read
Reads the Top15 file if there is already one
================*/
public Top15_Read()
{
Vault = nvault_open(TOP15_FILE);
if(Vault == INVALID_HANDLE)
{
log_amx("Error opening nVault file: %s", TOP15_FILE);
return PLUGIN_HANDLED;
}
new Key[40], Data[100];
new TimeStamp;
new tSteamId[32],tName[32],tTime[5],tCP[5],tGC[5];
for( new i = 0; i < 15; i++ )
{
GetKey(i+1,Key);
if(nvault_lookup(Vault, Key, Data, 99, TimeStamp))
{
parse(Data,tSteamId,31,tName,31,tTime,4,tCP,4,tGC,4);
Top15_SteamId = tSteamId;
Top15_Name = tName;
Top15_Time = str_to_num(tTime);
Top15_CP = str_to_num(tCP);
Top15_GC = str_to_num(tGC);
}
else
{
Top15_SteamId = EMPTY;
Top15_Time = 99999;
Top15_CP = 99999;
}
}
nvault_close(Vault);
return PLUGIN_HANDLED;
}
/*================
Top15_MP_Read
Reads the Top15 from a KZ Multiplugin File
================*/
public Top15_MP_Read(Top15_File[])
{
if(file_exists(Top15_File))
{
new line, stxtsize ;
new data[192] ;
new tAuth[32],tName[32],tMins[10],tSecs[10],tHuns[10],tChecks[10];
new Mins,Secs,Huns;
for(line = 0; line < 15; ++line)
{
read_file(Top15_File,line,data,191,stxtsize);
parse(data,tAuth,31,tName,31,tMins,9,tSecs,9,tHuns,9,tChecks,9);
Top15_SteamId[line] = tAuth;
Top15_Name[line] = tName;
Mins = str_to_num(tMins);
Secs = str_to_num(tSecs);
Huns = str_to_num(tHuns);
Top15_Time[line] = MinSecHunToSecs(Mins,Secs,Huns);
Top15_CP[line] = str_to_num(tChecks);
Top15_GC[line] = -1;
}
//Save to nVault file;
Top15_Save();
}
return PLUGIN_HANDLED;
}
MinSecHunToSecs(&Mins,&Secs,&Huns)
{
new Result = (Mins * 60) + Secs;
if(Huns >= 5)
++Result;
return Result;
}
/*================
Top15_Save
Saves the Top15 to file
================*/
Top15_Save()
{
Vault = nvault_open(TOP15_FILE);
if(Vault == INVALID_HANDLE)
{
log_amx("Error opening nVault file: %s", TOP15_FILE);
return PLUGIN_HANDLED;
}
static Key[40], Data[100];
for( new i = 0; i < 15; i++ )
{
if(equali(Top15_SteamId,EMPTY))
return PLUGIN_HANDLED;
format(Data, 99, "^"%s^" ^"%s^" %i %i %i", Top15_SteamId,Top15_Name,Top15_Time,Top15_CP,Top15_GC);
GetKey(i+1,Key);
nvault_set(Vault, Key, Data);
}
nvault_close(Vault);
return PLUGIN_HANDLED;
}
/*================
Top15_Check
Checks if the player's time is good enough to go in the top15
================*/
Top15_Check(id, PlayerTime, cp_count, gc_count)
{
if(PlayerTime <= Top15_Time[14]) //if the player has a better or the same time than the last person in the Top 15
{
if(PlayerTime == Top15_Time[14] && cp_count > Top15_CP[14]) //if they have the same time and the player has more checkpoints
{
kz_ColorChat(id, green, "[KZ Top15] Too bad, you have the same time as the 15th but you used to much checkpoints");
return PLUGIN_HANDLED; //too bad he didn't make it in the top15
}
//Get the SteamId and player name
static Name[33],SteamId[33];
get_user_name(id, Name, 32 );
get_user_authid(id, SteamId ,32 );
for( new i = 0; i < 15; i++ )
{
if( PlayerTime < Top15_Time) //if the player's time is less
{
new pos = i;
while( !equal( Top15_SteamId[pos], SteamId ) && pos < 14 )
{
pos++;
}
for( new j = pos; j > i; j-- )
{
format( Top15_SteamId[j], 32, Top15_SteamId[j-1] );
format( Top15_Name[j], 32, Top15_Name[j-1] );
Top15_Time[j] = Top15_Time[j-1];
Top15_CP[j] = Top15_CP[j-1];
Top15_GC[j] = Top15_GC[j-1];
}
format( Top15_SteamId, 32, SteamId );
format( Top15_Name, 32, Name );
Top15_Time = PlayerTime;
Top15_CP = cp_count;
Top15_GC = gc_count;
kz_ColorChat(id,green,"[KZ Top15] Congratulations you made it in the Top15");
Top15_Save();
return PLUGIN_HANDLED;
}
if( equal( Top15_SteamId, SteamId ) ) //if the player already has a better time
{
kz_ColorChat(id,green,"[KZ Top15] Too bad, you didn't beat your time in the Top15");
return PLUGIN_HANDLED;
}
}
}
else
{
kz_ColorChat(id,green,"[KZ Top15] Too bad, you didn't make it in the Top15");
}
return PLUGIN_HANDLED;
}
/*================
Top15_Show
Shows the Top15 on /top15 command
================*/
public Top15_Show(id)
{
if(!get_pcvar_num(kz_enabled))
{
return PLUGIN_HANDLED;
}
else if(!get_pcvar_num(kz_top15))
{
kz_ColorChat(id, green, "[KZ Top15] Server has disabled that option");
return PLUGIN_HANDLED;
}
new buffer[2100];
new line[250];
new strGC[5];
new len = format( buffer, sizeof(buffer), "<table cellspacing=0 rules=all border=2>" );
len += format( buffer[len], sizeof(buffer)-len, "<tr><th> # <th> Nick <th> Climb time <th> Checkpoints <th> Go Checks" );
for(new i = 0; i < 15; ++i)
{
if(equali(Top15_SteamId,EMPTY)) //if the slot is free
{
format(line, sizeof(line), "<tr><td> %d. <td> %s <td> %s <td> %s <td> %s", (i+1), "<--------------------------->", "---- min. -- sec.", "---", "---");
}
else
{
num_to_str(Top15_GC,strGC,4);
format(line, sizeof(line), "<tr><td> %d. <td> %s <td> %s <td> %i <td> %s", (i+1),Top15_Name,GetStrTime(Top15_Time),Top15_CP,Top15_GC==-1?"---":strGC);
}
len += format( buffer[len], sizeof(buffer)-len, line );
}
format(line, sizeof(line), "</table>" );
len += format( buffer[len], sizeof(buffer)-len, line );
show_motd(id, buffer, "Top 15 Climbers" );
return PLUGIN_HANDLED;
}
/*================
Sets the correct Key for top15
================*/
GetKey(Rank, Key[])
{
format(Key, 39,"%s %i",CurrentMap, Rank);
}
/*================
GetStrTime
Recives time in secs and returns a string: X min. X sec.
================*/
GetStrTime(Seconds)
{
new sTime[18];
new Minutes;
Minutes=Seconds/60;
Seconds=Seconds%60;
format(sTime,17, "%i min. %i sec.", Minutes,Seconds);
return sTime;
} |
|