【建议】使用TimeProjector插件的朋友进来看看
昨天没事,想修改一个插件代码,无意中发现TimeProjector代码有个问题,代码需要优化。原码:
#include <amxmodx>
new bool:g_PlayerStatus
public dis_delay(id){
g_PlayerStatus = true
}
public show_timer(){
new MONTHS[] = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"}
new WEEK[] = {"一","二","三","四","五","六","日"}
new DAY[] = {"一","二","三","四","五","六","七","八","九","十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十","廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十","三十一"}
new nextmap
new cumap
new timel = get_timeleft()
new ns_Hour, ns_Minutes,ns_Month,ns_Day,ns_Year,ns_second,ns_week
get_cvar_string("amx_nextmap",nextmap,31)
get_mapname(cumap,31)
get_time("%H", ns_Hour, 2)
get_time("%M", ns_Minutes, 2)
get_time("%m", ns_Month, 2)
get_time("%d", ns_Day, 2)
get_time("%Y", ns_Year, 4)
get_time("%S", ns_second, 2)
get_time("%w", ns_week, 4)
set_hudmessage(0,255,0,0.75,0.18,0, 1.0, 1.0, 0.1, 0.2, 12)
for (new id=1; id<33; id++){
if (g_PlayerStatus){
if((str_to_num(ns_week)) ==0){
show_hudmessage(id,"%s年%s%s日星期%s^n北京时间: %s:%s:%s^n当前地图: %s^n下个地图: %s^n剩余时间: %d:%02d",ns_Year,MONTHS,DAY,WEEK,ns_Hour,ns_Minutes,ns_second,cumap,nextmap,timel / 60, timel % 60)
}else{
show_hudmessage(id,"%s年%s%s日星期%s^n北京时间: %s:%s:%s^n当前地图: %s^n下个地图: %s^n剩余时间: %d:%02d",ns_Year,MONTHS,DAY,WEEK,ns_Hour,ns_Minutes,ns_second,cumap,nextmap,timel / 60, timel % 60)
}
}
}
return PLUGIN_CONTINUE
}
public client_death(killer,victim,wpnindex,hitplace,TK)
set_task(5.0, "dis_delay",victim)
public statusReset(){
for (new i=0; i<33; i++)
g_PlayerStatus = false
}
public plugin_init(){
register_plugin("TimeProjector","0.11","olol & nwb13")
register_event( "ResetHUD", "statusReset", "be" )
//register_clcmd("say nowtime","show_timer")
set_task(1.0, "show_timer",0,"",0,"b")
return PLUGIN_CONTINUE
}
如果把“ new WEEK[] = {"一","二","三","四","五","六","日"}”改为
“ new WEEK[] = {"日","一","二","三","四","五","六"} ”
那就根本不用“if((str_to_num(ns_week)) ==0){......else.....}”这段IF代码了。只需以下代码即可:
show_hudmessage(id,"%s年%s%s日星期%s^n北京时间: %s:%s:%s^n当前地图: %s^n下个地图: %s^n剩余时间: %d:%02d",ns_Year,MONTHS,DAY,WEEK,ns_Hour,ns_Minutes,ns_second,cumap,nextmap,timel / 60, timel % 60)
经过以上修正也可以达到同样效果。并且可以简化代码,增强代码的执行效率。
我说的是否正确?请指正! 我有用这个插件,但是里面的内容我不太会~ :burn:
页:
[1]