Stats: Replace len hardcoded contents by charsmax and sizeof

This commit is contained in:
Freeman-AM 2014-10-11 21:29:10 +02:00
parent 2a5fae43b8
commit 15b160e51a

View File

@ -222,19 +222,19 @@ public cmdStatsMe(id){
displayStats(id,dest) {
new name[32], stats[8], body[8]
get_user_wstats(id,0,stats,body)
new pos = format(g_Buffer,2047,"Kills: %d^nDeaths: %d^nTKs: %d^nDamage: %d^nHits: %d^nShots: %d^n^n",
new pos = format(g_Buffer,charsmax(g_Buffer),"Kills: %d^nDeaths: %d^nTKs: %d^nDamage: %d^nHits: %d^nShots: %d^n^n",
stats[0],stats[1],stats[3],stats[6],stats[5],stats[4])
new a
for( a = 1; a < TFCMAX_WEAPONS; a++) {
if (get_user_wstats(id,a,stats,body)){
if ( xmod_is_melee_wpn(a) )
stats[4] = -1;
xmod_get_wpnname(a,name,31)
pos += format(g_Buffer[pos],2047-pos,"%s shots: %d hits: %d damage: %d kills: %d deaths: %d^n",
xmod_get_wpnname(a,name,charsmax(name))
pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"%s shots: %d hits: %d damage: %d kills: %d deaths: %d^n",
name,stats[4],stats[5],stats[6],stats[0],stats[1])
}
}
get_user_name(id,name,31)
get_user_name(id,name,charsmax(name))
show_motd(dest,g_Buffer,name)
}
@ -250,13 +250,13 @@ public cmdRank(id){
displayRank(id,dest) {
new name[MAX_NAME_LENGTH], stats[8], body[8]
new rank_pos = get_user_stats(id,stats,body)
new pos = format(g_Buffer,2047,"Kills: %d^nDeaths: %d^nTKs: %d^nDamage: %d^nHits: %d^nShots: %d^n^n",
new pos = format(g_Buffer,charsmax(g_Buffer),"Kills: %d^nDeaths: %d^nTKs: %d^nDamage: %d^nHits: %d^nShots: %d^n^n",
stats[0],stats[1],stats[3],stats[6],stats[5],stats[4])
pos += format(g_Buffer[pos],2047-pos,"Hits:^n%s: %d^n%s: %d^n%s: %d^n%s: %d^n%s: %d^n%s: %d^n%s: %d^n^n",
pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"Hits:^n%s: %d^n%s: %d^n%s: %d^n%s: %d^n%s: %d^n%s: %d^n%s: %d^n^n",
g_bodyParts[1],body[1],g_bodyParts[2],body[2],g_bodyParts[3],body[3], g_bodyParts[4],body[4],
g_bodyParts[5],body[5],g_bodyParts[6],body[6],g_bodyParts[7],body[7])
format(g_Buffer[pos],2047-pos,"%s rank is %d of %d",(id==dest)?"Your":"His", rank_pos,get_statsnum())
get_user_name(id,name,31)
format(g_Buffer[pos],charsmax(g_Buffer)-pos,"%s rank is %d of %d",(id==dest)?"Your":"His", rank_pos,get_statsnum())
get_user_name(id,name,charsmax(name))
show_motd(dest,g_Buffer,name)
}
@ -273,14 +273,14 @@ public cmdTop15(id) {
/* get top 15 */
getTop15(){
new stats[8], body[8], name[MAX_NAME_LENGTH]
new pos = copy(g_Buffer,2047,"# nick kills/deaths TKs hits/shots/headshots^n")
new pos = copy(g_Buffer,charsmax(g_Buffer),"# nick kills/deaths TKs hits/shots/headshots^n")
new imax = get_statsnum()
if (imax > 15) imax = 15
for(new a = 0; a < imax; ++a){
get_stats(a,stats,body,name,31)
replace_all(name, 31, "<", "[")
replace_all(name, 31, ">", "]")
pos += format(g_Buffer[pos],2047-pos,"%2d. %-28.27s %d/%d %d %d/%d/%d^n",a+1,name,stats[0],stats[1],stats[3],stats[5],stats[4],stats[2])
get_stats(a,stats,body,name,charsmax(name))
replace_all(name, charsmax(name), "<", "[")
replace_all(name, charsmax(name), ">", "]")
pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"%2d. %-28.27s %d/%d %d %d/%d/%d^n",a+1,name,stats[0],stats[1],stats[3],stats[5],stats[4],stats[2])
}
}
@ -319,17 +319,17 @@ public cmdStats(id){
/* build list of attackers */
getAttackers(id) {
new name[MAX_NAME_LENGTH],wpn[32], stats[8],body[8],found=0
new pos = copy(g_Buffer,2047,"Attackers:^n")
new pos = copy(g_Buffer,charsmax(g_Buffer),"Attackers:^n")
for(new a = 1; a <= MaxClients; ++a){
if(get_user_astats(id,a,stats,body,wpn,31)){
if(get_user_astats(id,a,stats,body,wpn,charsmax(wpn))){
found = 1
if (stats[0])
format(wpn,31," -- %s",wpn)
format(wpn,charsmax(wpn)," -- %s",wpn)
else
wpn[0] = 0
get_user_name(a,name,31)
pos += format(g_Buffer[pos],2047-pos,"%s -- %d dmg / %d hit(s)%s^n",name,stats[6],stats[5],wpn)
get_user_name(a,name,charsmax(name))
pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"%s -- %d dmg / %d hit(s)%s^n",name,stats[6],stats[5],wpn)
}
}
return found
@ -339,16 +339,16 @@ getAttackers(id) {
/* build list of victims */
getVictims(id) {
new name[MAX_NAME_LENGTH],wpn[32], stats[8],body[8],found=0
new pos = copy(g_Buffer,2047,"Victims:^n")
new pos = copy(g_Buffer,charsmax(g_Buffer),"Victims:^n")
for(new a = 1; a <= MaxClients; ++a){
if(get_user_vstats(id,a,stats,body,wpn,31)){
if(get_user_vstats(id,a,stats,body,wpn,charsmax(wpn))){
found = 1
if (stats[1])
format(wpn,31," -- %s",wpn)
format(wpn,charsmax(wpn)," -- %s",wpn)
else
wpn[0] = 0
get_user_name(a,name,31)
pos += format(g_Buffer[pos],2047-pos,"%s -- %d dmg / %d hit(s)%s^n",name,stats[6],stats[5],wpn)
get_user_name(a,name,charsmax(name))
pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"%s -- %d dmg / %d hit(s)%s^n",name,stats[6],stats[5],wpn)
}
}
return found
@ -359,22 +359,22 @@ getHits(id,killer) {
new stats[8], body[8], pos = 0
g_Buffer[0] = 0
get_user_astats(id,killer,stats,body)
for(new a = 1; a < 8; ++a)
for(new a = 1; a < sizeof(body); ++a)
if(body[a])
pos += format(g_Buffer[pos],2047-pos,"%s: %d^n",g_bodyParts[a],body[a])
pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"%s: %d^n",g_bodyParts[a],body[a])
}
/* build list of hits for say hp */
getMyHits(id,killed) {
new name[MAX_NAME_LENGTH], stats[8], body[8], found = 0
get_user_name(killed,name,31)
new pos = format(g_Buffer,2047,"You hit %s in:",name)
get_user_name(killed,name,charsmax(name))
new pos = format(g_Buffer,charsmax(g_Buffer),"You hit %s in:",name)
get_user_vstats(id,killed,stats,body)
for(new a = 1; a < 8; ++a){
for(new a = 1; a < sizeof(body); ++a){
if(body[a]){
found = 1
pos += format(g_Buffer[pos],2047-pos," %s: %d ",g_bodyParts[a],body[a])
pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos," %s: %d ",g_bodyParts[a],body[a])
}
}
return found
@ -390,9 +390,9 @@ public cmdKiller(id) {
return PLUGIN_HANDLED
}
if (g_Killers[id][0]) {
new name[MAX_NAME_LENGTH], stats[8], body[8], wpn[33], mstats[8], mbody[8]
get_user_name(g_Killers[id][0],name,31)
get_user_astats(id,g_Killers[id][0],stats,body,wpn,31)
new name[MAX_NAME_LENGTH], stats[8], body[8], wpn[32], mstats[8], mbody[8]
get_user_name(g_Killers[id][0],name,charsmax(name))
get_user_astats(id,g_Killers[id][0],stats,body,wpn,charsmax(wpn))
client_print(id,print_chat,"%s killed you with %s from distance of %.2f meters", name,wpn,float(g_Killers[id][3]) * 0.0254 )
client_print(id,print_chat,"He did %d damage to you with %d hit%s and still had %dhp and %dap",
stats[6],stats[5],(stats[5]==1)?"":"s" , g_Killers[id][1],g_Killers[id][2] )
@ -441,22 +441,22 @@ showStatsMenu(id,pos){
get_players(g_userPlayers[id],inum)
if (start >= inum) start = pos = g_userPosition[id] = 0
new len = format(menu_body,511,"Server Stats %d/%d^n^n",pos + 1,((inum/max_menupos)+((inum%max_menupos)?1:0)))
new len = format(menu_body,charsmax(menu_body),"Server Stats %d/%d^n^n",pos + 1,((inum/max_menupos)+((inum%max_menupos)?1:0)))
new name[MAX_NAME_LENGTH], end = start + max_menupos, keys = (1<<9)|(1<<7)
if (end > inum) end = inum
for(new a = start; a < end; ++a){
get_user_name(g_userPlayers[id][a],name,31)
get_user_name(g_userPlayers[id][a],name,charsmax(name))
keys |= (1<<k)
len += format(menu_body[len],511-len,"%d. %s^n",++k,name)
len += format(menu_body[len],charsmax(menu_body)-len,"%d. %s^n",++k,name)
}
len += format(menu_body[len],511-len,"^n8. %s^n",g_userState[id] ? "Show rank" : "Show stats" )
len += format(menu_body[len],charsmax(menu_body)-len,"^n8. %s^n",g_userState[id] ? "Show rank" : "Show stats" )
if (end != inum){
len += format(menu_body[len],511-len,"^n9. More...^n0. %s" , pos ? "Back" : "Exit" )
len += format(menu_body[len],charsmax(menu_body)-len,"^n9. More...^n0. %s" , pos ? "Back" : "Exit" )
keys |= (1<<8)
}
else len += format(menu_body[len],511-len,"^n0. %s" , pos ? "Back" : "Exit" )
else len += format(menu_body[len],charsmax(menu_body)-len,"^n0. %s" , pos ? "Back" : "Exit" )
show_menu(id,keys,menu_body)
return PLUGIN_HANDLED
}
@ -481,7 +481,7 @@ public client_damage(attacker,victim,damage,wpnindex,hitplace,TA){
/* save state at death */
public client_death(killer,victim,wpnindex,hitplace,TK){
new killer_name[MAX_NAME_LENGTH]
get_user_name(killer,killer_name,31)
get_user_name(killer,killer_name,charsmax(killer_name))
if ( KillingStreak || KillingStreakSound ){
g_streakKills[ victim ][ 1 ]++
@ -493,7 +493,7 @@ public client_death(killer,victim,wpnindex,hitplace,TK){
new selfKill = ( killer == victim ) ? 1:0
new victim_name[MAX_NAME_LENGTH]
get_user_name(victim,victim_name,31)
get_user_name(victim,victim_name,charsmax(victim_name))
new Float:statstime = get_cvar_float("tfcstats_statstime")
@ -527,9 +527,9 @@ public client_death(killer,victim,wpnindex,hitplace,TK){
if ( ShowKiller && !(!get_cvar_num("tfcstats_rankbots") && (is_user_bot(killer) || is_user_bot(killer))) ){
new stats[8], body[8], wpn[33], mstats[8], mbody[8]
new stats[8], body[8], wpn[32], mstats[8], mbody[8]
get_user_astats(victim,killer,stats,body,wpn,31)
get_user_astats(victim,killer,stats,body,wpn,charsmax(wpn))
get_user_vstats(victim,killer,mstats,mbody)
set_hudmessage(220,80,0,0.05,0.15,0, statstime, 12.0, 1.0, 2.0, -1)
getHits(victim,killer)
@ -540,7 +540,7 @@ public client_death(killer,victim,wpnindex,hitplace,TK){
if ( KillerHp ){
new kmsg[128]
format(kmsg,127,"%s still has %dhp and %d ap",killer_name,g_Killers[victim][1],g_Killers[victim][1])
format(kmsg,charsmax(kmsg),"%s still has %dhp and %d ap",killer_name,g_Killers[victim][1],g_Killers[victim][1])
client_print(victim,print_console, "%s", kmsg)
set_hudmessage(255,255,255,0.02,0.9,2, 1.5, 3.0, 0.02, 5.0, -1)
show_hudmessage(victim, "%s", kmsg)
@ -572,7 +572,7 @@ public client_death(killer,victim,wpnindex,hitplace,TK){
new param[2]
param[0] = killer
param[1] = g_multiKills[killer][0]
set_task( 4.0 + float( param[1] ) ,"checkKills",0,param,2)
set_task( 4.0 + float( param[1] ) ,"checkKills",0,param,sizeof(param))
}
if ( xmod_is_melee_wpn(wpnindex) && ( KnifeKill || KnifeKillSound ) ){
@ -601,11 +601,11 @@ public client_death(killer,victim,wpnindex,hitplace,TK){
if ( headshot && (HeadShotKill || HeadShotKillSound) && !xmod_is_melee_wpn(wpnindex) ){
if ( HeadShotKill ){
new weapon[32], message[256]
xmod_get_wpnname(wpnindex,weapon,31)
copy( message, sizeof(message)-1, g_HeadShots[ random_num(0,6) ] )
replace( message, sizeof(message)-1, "$vn", victim_name )
replace( message, sizeof(message)-1, "$wn", weapon )
replace( message, sizeof(message)-1, "$kn", killer_name )
xmod_get_wpnname(wpnindex,weapon,charsmax(weapon))
copy( message, charsmax(message), g_HeadShots[ random_num(0,6) ] )
replace( message, charsmax(message), "$vn", victim_name )
replace( message, charsmax(message), "$wn", weapon )
replace( message, charsmax(message), "$kn", killer_name )
set_hudmessage(100, 100, 255, -1.0, 0.19, 0, 6.0, 6.0, 0.5, 0.15, -1)
for (new i=1;i<=MaxClients;i++){
if ( g_Killers[i][0] && g_DeathStats[i] > get_gametime() )
@ -642,13 +642,13 @@ public showDoubleKill(){
if ( DoubleKill ) {
new name[MAX_NAME_LENGTH],message[128]
get_user_name(g_prevKillerId,name,31)
copy( message, 127, g_DoubleKillMsg[pos] )
replace( message, 127 , "$kn", name )
get_user_name(g_prevKillerId,name,charsmax(name))
copy( message, charsmax(message), g_DoubleKillMsg[pos] )
replace( message, charsmax(message) , "$kn", name )
if ( pos == 2 ){
new kills[3]
num_to_str(g_KillCount,kills,2)
replace( message, 127 , "$kk", kills )
num_to_str(g_KillCount,kills,charsmax(kills))
replace( message, charsmax(message) , "$kk", kills )
}
set_hudmessage(65, 102, 158, -1.0, 0.25, 0, 6.0, 6.0, 0.5, 0.15, -1)
for (new i=1;i<=MaxClients;i++){
@ -671,7 +671,7 @@ public checkKills(param[]){
if ( a > -1 ){
if ( MultiKill ) {
new name[MAX_NAME_LENGTH]
get_user_name(id,name,31)
get_user_name(id,name,charsmax(name))
set_hudmessage(255, 0, 100, 0.05, 0.65, 2, 0.02, 6.0, 0.01, 0.1, -1)
if ( a > 6 ) a = 6
for (new i=1;i<=MaxClients;i++){