From 2cc771371a94a5e5e70a34230b6f0b3c19a13fad Mon Sep 17 00:00:00 2001 From: Freeman-AM Date: Wed, 8 Oct 2014 22:52:57 +0200 Subject: [PATCH] Stats: Replace len hardcoded contents by charsmax Note: TOPX is over 8 char len in some languages. --- plugins/dod/stats.sma | 138 +++++++++++++++++++++--------------------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/plugins/dod/stats.sma b/plugins/dod/stats.sma index 59421fd6..3400f2a5 100755 --- a/plugins/dod/stats.sma +++ b/plugins/dod/stats.sma @@ -269,9 +269,9 @@ public endGameStats(){ new players[32], inum get_players(players,inum) - new g_Top[8], top = get_cvar_num("dodstats_topvalue") + new g_Top[16], top = get_cvar_num("dodstats_topvalue") for(i = 0; i < inum; ++i){ - format(g_Top,15,"%L",i,"TOPX",top) + format(g_Top,charsmax(g_Top),"%L",i,"TOPX",top) getTop15_steam(i) show_motd(players[i],g_Buffer,g_Top) } @@ -295,18 +295,18 @@ public cmdStats(id){ /* build list of attackers */ getAttackers(id) { new name[MAX_NAME_LENGTH],wpn[32], stats[9],body[8],found=0 - new pos = format(g_Buffer,2047,"%L^n",id,"ATTACKERS") + new pos = format(g_Buffer,charsmax(g_Buffer),"%L^n",id,"ATTACKERS") 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 %L / %d %L%s^n",name,stats[6],id,"DMG",stats[5],id,"HIT_S",wpn) + get_user_name(a,name,charsmax(name)) + pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"%s -- %d %L / %d %L%s^n",name,stats[6],id,"DMG",stats[5],id,"HIT_S",wpn) } } return found @@ -316,17 +316,17 @@ getAttackers(id) { /* build list of victims */ getVictims(id) { new name[MAX_NAME_LENGTH],wpn[32], stats[9],body[8],found=0 - new pos = format(g_Buffer,2047,"%L^n",id,"VICTIMS") + new pos = format(g_Buffer,charsmax(g_Buffer),"%L^n",id,"VICTIMS") 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 %L / %d %L%s^n",name,stats[6],id,"DMG",stats[5],id,"HITS",wpn) + get_user_name(a,name,charsmax(name)) + pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"%s -- %d %L / %d %L%s^n",name,stats[6],id,"DMG",stats[5],id,"HITS",wpn) } } return found @@ -339,19 +339,19 @@ getHits(id,killer) { get_user_astats(id,killer,stats,body) for(new a = 1; a < 8; ++a) if(body[a]) - pos += format(g_Buffer[pos],2047-pos,"%L: %d^n",id,g_bodyParts[a],body[a]) + pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"%L: %d^n",id,g_bodyParts[a],body[a]) } /* build list of hits for say hp */ getMyHits(id,killed) { new name[MAX_NAME_LENGTH], stats[9], body[8], found = 0 - get_user_name(killed,name,31) - new pos = format(g_Buffer,2047,"%L",id,"YOU_HIT",name) + get_user_name(killed,name,charsmax(name)) + new pos = format(g_Buffer,charsmax(g_Buffer),"%L",id,"YOU_HIT",name) get_user_vstats(id,killed,stats,body) for(new a = 1; a < 8; ++a){ if(body[a]){ found = 1 - pos += format(g_Buffer[pos],2047-pos," %L: %d ",id,g_bodyParts[a],body[a]) + pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos," %L: %d ",id,g_bodyParts[a],body[a]) } } return found @@ -367,9 +367,9 @@ public cmdKiller(id) { return PLUGIN_HANDLED } if (g_Killers[id][0]) { - new name[MAX_NAME_LENGTH], stats[9], body[8], wpn[33], mstats[9], 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[9], body[8], wpn[32], mstats[9], 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)) get_user_vstats(id,g_Killers[id][0],mstats,mbody) client_print(id,print_chat,"%L",id,"KILL_INFO1", name,wpn,float(g_Killers[id][2]) * 0.0254 ) client_print(id,print_chat,"%L",id,"KILL_INFO2", stats[6],stats[5], g_Killers[id][1] ) @@ -415,22 +415,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,"\y%L\R%d/%d^n\w^n",id,"SERVER_STATS",pos + 1,((inum/max_menupos)+((inum%max_menupos)?1:0))) + new len = format(menu_body,charsmax(menu_body),"\y%L\R%d/%d^n\w^n",id,"SERVER_STATS",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< get_gametime() ) continue - format( message, sizeof(message)-1, "%L",players[i],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 ) + format( message, charsmax(message), "%L",players[i],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) ShowSyncHudMsg(players[i], g_center2_sync, "%s", message) } @@ -770,10 +770,10 @@ public showDoubleKill(){ if ( pos > 2 ) pos = 2 if ( DoubleKill ) { new name[MAX_NAME_LENGTH] - get_user_name(g_prevKillerId,name,31) + get_user_name(g_prevKillerId,name,charsmax(name)) if ( pos == 2 ){ new kills[3] - num_to_str(g_KillCount,kills,2) + num_to_str(g_KillCount,kills,charsmax(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++){ @@ -795,7 +795,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++){ @@ -922,28 +922,28 @@ displayStats_steam(id,dest) { new name[MAX_NAME_LENGTH], stats[9], body[8] get_user_wstats(id,0,stats,body) - new pos = copy(g_Buffer,2047,"
")
- pos += format(g_Buffer[pos],2047-pos,"",
+ new pos = copy(g_Buffer,charsmax(g_Buffer),"
")
+ pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"
%L%L%L%L%L%L%L
", dest,"M_KILLS",dest,"M_DEATHS",dest,"M_SCORE",dest,"M_TKS",dest,"M_HITS",dest,"M_SHOTS",dest,"M_HS") - pos += format(g_Buffer[pos],2047-pos,"
%L%L%L%L%L%L%L
%d%d%d%d%d%d%d



", + pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"%d%d%d%d%d%d%d


", stats[0],stats[1],stats[7],stats[3],stats[5],stats[4],stats[2]) - pos += format(g_Buffer[pos],2047-pos,"", + pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"
%L%L%L%L%L%L
", dest,"M_WEAPON",dest,"M_SHOTS",dest,"M_HITS",dest,"M_DAMAGE",dest,"M_KILLS",dest,"M_DEATHS") for(new a = 1; a < DODMAX_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,"^n", + xmod_get_wpnname(a,name,charsmax(name)) + pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"^n", name,stats[4],stats[5],stats[6],stats[0],stats[1]) } } - copy(g_Buffer[pos],2047-pos,"
%L%L%L%L%L%L
%s%d%d%d%d%d
%s%d%d%d%d%d
") + copy(g_Buffer[pos],charsmax(g_Buffer)-pos,"") - get_user_name(id,name,31) + get_user_name(id,name,charsmax(name)) show_motd(dest,g_Buffer,name) } @@ -961,23 +961,23 @@ displayRank_steam(id,dest) { new name[MAX_NAME_LENGTH], stats[9], body[8] new rank_pos = get_user_stats(id,stats,body) - new pos = copy(g_Buffer,2047,"
")
+ new pos = copy(g_Buffer,charsmax(g_Buffer),"
")
 
- pos += format(g_Buffer[pos],2047-pos,
+ pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,
                "",dest,"M_KILLS",dest,"M_DEATHS",dest,"M_SCORE",dest,"M_TKS",dest,"M_HITS",dest,"M_SHOTS",dest,"M_HS")
 
- pos += format(g_Buffer[pos],2047-pos,
+ pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,
                "
%L%L%L%L%L%L%L
%d%d%d%d%d%d%d


", stats[0],stats[1],stats[7],stats[3],stats[5],stats[4],stats[2]) - pos += format(g_Buffer[pos],2047-pos,"%L^n%L: %d^n%L: %d^n%L: %d^n%L: %d^n%L: %d^n%L: %d^n%L: %d^n",dest,"M_HITS",dest,g_bodyParts[1],body[1],dest,g_bodyParts[2],body[2],dest,g_bodyParts[3],body[3],dest,g_bodyParts[4],body[4],dest,g_bodyParts[5],body[5],dest,g_bodyParts[6],body[6],dest,g_bodyParts[7],body[7]) + pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"%L^n%L: %d^n%L: %d^n%L: %d^n%L: %d^n%L: %d^n%L: %d^n%L: %d^n",dest,"M_HITS",dest,g_bodyParts[1],body[1],dest,g_bodyParts[2],body[2],dest,g_bodyParts[3],body[3],dest,g_bodyParts[4],body[4],dest,g_bodyParts[5],body[5],dest,g_bodyParts[6],body[6],dest,g_bodyParts[7],body[7]) - pos += format(g_Buffer[pos],2047-pos,"%L %d %L %d",dest,(id==dest)?"M_YOUR_RANK_IS":"M_THEIR_RANK_IS", + pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"%L %d %L %d",dest,(id==dest)?"M_YOUR_RANK_IS":"M_THEIR_RANK_IS", rank_pos,dest,"M_OF",get_statsnum()) - pos += format(g_Buffer[pos],2047-pos,"
") + pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"
") - get_user_name(id,name,31) + get_user_name(id,name,charsmax(name)) show_motd(dest,g_Buffer,name) } @@ -988,8 +988,8 @@ public cmdTop15(id) { return PLUGIN_HANDLED } getTop15_steam(id) - new g_Top[8] - format(g_Top,7,"%L",id,"TOPX",get_cvar_num("dodstats_topvalue")) + new g_Top[16] + format(g_Top,charmax(g_Top),"%L",id,"TOPX",get_cvar_num("dodstats_topvalue")) show_motd(id,g_Buffer,g_Top) return PLUGIN_CONTINUE @@ -999,21 +999,21 @@ public cmdTop15(id) { getTop15_steam(id){ new stats[9], body[8], name[MAX_NAME_LENGTH] - new pos = copy(g_Buffer,2047,"
")
+  new pos = copy(g_Buffer,charsmax(g_Buffer),"
")
 
-  pos += format(g_Buffer[pos],2047-pos,"",
+  pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"
#%L%L%L%L%L%L%L%L
", id,"M_NICK",id,"M_KILLS",id,"M_DEATHS",id,"M_SCORE",id,"M_TKS",id,"M_HITS",id,"M_SHOTS",id,"M_HS") new imax = get_statsnum() new itmax = get_cvar_num("dodstats_topvalue") if (imax > itmax ) imax = itmax 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,"^n", + 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,"^n", a+1,name,stats[0],stats[1],stats[7],stats[3],stats[5],stats[4],stats[2]) } - pos += format(g_Buffer[pos],2047-pos,"
#%L%L%L%L%L%L%L%L
%d.%s%d%d%d%d%d%d%d
%d.%s%d%d%d%d%d%d%d
") + pos += format(g_Buffer[pos],charsmax(g_Buffer)-pos,"
") }