| 
注册时间2008-4-22
最后登录1970-1-1
 听众收听积分3894主题回帖0精华 
 该用户从未签到 | 
 
 发表于 2010-10-19 09:45:05
|
显示全部楼层 
| 回复 8# lovehuai 
 
 
 复制代码#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <cstrike>
new const ZOMBIE_MODEL[] = "zombie" // 模型的名称
#define MODELSET_TASK 100 // an offset for our models task设置模型的任务ID = id + MODELSET_TASK
#define MODELCHANGE_DELAY 0.5 // 更换模型延迟的时间
new Float:g_models_targettime // target time for the last model change(最后一人模型更换的时间点)
new Float:g_roundstarttime // last round start time(获取每一局开局的时间点)
new g_has_custom_model[33] // whether the player is using a custom model(玩家是否采用自定义模型)
new g_player_model[33][32] // player's model name (string)(玩家模型的名字)
new g_zombie[33] // whether the player is a zombie(玩家是否为僵尸)
/*================================================================================
[Plugin Start](插件开始)
=================================================================================*/
public plugin_precache()//必要的模型,当月客户端没有时强制下载
{
new modelpath[100]
formatex( modelpath, charsmax( modelpath ), "models/player/%s/%s.mdl", ZOMBIE_MODEL, ZOMBIE_MODEL )
engfunc( EngFunc_PrecacheModel, modelpath )
}
public plugin_init()
{
register_plugin( "Player Model Changer Example", "0.3", "MeRcyLeZZ" )
register_event( "HLTV", "event_round_start", "a", "1=0", "2=0" )//注入开局的函数
RegisterHam( Ham_Spawn, "player", "fw_PlayerSpawn", 1 )//注入玩家出生的函数
register_forward( FM_SetClientKeyValue, "fw_SetClientKeyValue" )//设置客户端的键值
register_forward( FM_ClientUserInfoChanged, "fw_ClientUserInfoChanged" )//当客户端的信息修改时,自动勾起这个函数
}
/*================================================================================
[Round Start Event](开始事件)
=================================================================================*/
public event_round_start()
{
g_roundstarttime = get_gametime()
}
/*================================================================================
[Player Spawn Event](玩家出生事件)
=================================================================================*/
public fw_PlayerSpawn( id )
{
// Not alive or didn't join a team yet(如果是死亡或都观察者,自动返回)
if ( !is_user_alive( id ) || !cs_get_user_team( id ) )
return;
// Set to zombie if on Terrorist team(如果玩家队伍为TE,设置玩家为僵尸)
g_zombie[id] = cs_get_user_team( id ) == CS_TEAM_T ? true : false;
// Remove previous tasks (if any)(删除ID为id + MODELSET_TASK的一个任务,补充:尽管没有,不过为了保险起见,有备无患嘛)
remove_task( id + MODELSET_TASK )
// Check whether the player is a zombie(检测玩家是否为僵尸)
if ( g_zombie[id] )
{
// Store our custom model in g_player_model[id](把模型的名称存进g_player_model[id]这个变量里)
copy( g_player_model[id], charsmax( g_player_model[] ), ZOMBIE_MODEL )
// Get current model(获取当前玩家的模型)
new currentmodel[32]
fm_get_user_model( id, currentmodel, charsmax( currentmodel ) )
// Check whether it matches the custom model(检测当前模型是否与g_player_model[id]这个模型相符,不相符则执行以下程序)
if ( !equal( currentmodel, g_player_model[id] ) )
{
// An additional delay is offset at round start
// since SVC_BAD is more likely to be triggered there
if ( get_gametime() - g_roundstarttime < 5.0 )//检测当前更换模型的时间点与开局时间点之前的时间间隔,如果不于5秒,就延迟5秒再进行模型更新
set_task( 5.0 * MODELCHANGE_DELAY, "fm_user_model_update", id + MODELSET_TASK )
else//否则立刻更新模型
fm_user_model_update( id + MODELSET_TASK )
}
}
// Not a zombie, but still has a custom model(如果不是僵尸,则不更新玩家模型)
else if ( g_has_custom_model[id] )
{
// Reset it back to the default one
fm_reset_user_model( id )
}
}
/*================================================================================
[Forwards]
=================================================================================*/
public fw_SetClientKeyValue( id, const infobuffer[], const key[] )
{ 
// Block CS model changes(破坏CS更换模型的键值,以在接下的代码中重新建立一下更换模型的函数)
if ( g_has_custom_model[id] && equal( key, "model" ) )
return FMRES_SUPERCEDE;//这个返回值的意思是返回你想设置的东西
return FMRES_IGNORED;
}
public fw_ClientUserInfoChanged( id )
{
// Player doesn't have a custom model(玩家没有自定义模型)
if ( !g_has_custom_model[id] )
return FMRES_IGNORED;
// Get current model(获取当前玩家模型)
static currentmodel[32]
fm_get_user_model( id, currentmodel, charsmax( currentmodel ) )
// Check whether it matches the custom model - if not, set it again(检测当前模型是否与更换后的模型相符,如果不是,再更换一次)
if ( !equal( currentmodel, g_player_model[id] ) && !task_exists( id + MODELSET_TASK ) )
fm_set_user_model( id + MODELSET_TASK )
return FMRES_IGNORED;
}
/*================================================================================
[Tasks](执行任务)
=================================================================================*/
public fm_user_model_update( taskid )
{
static Float:current_time
current_time = get_gametime()
// Do we need a delay?是否需要延迟
if ( current_time - g_models_targettime >= MODELCHANGE_DELAY )//如果当前时间与最后一个更换模型的时间相隔大于这个延迟时间,则不延迟
{
fm_set_user_model( taskid )
g_models_targettime = current_time
}
else//否则延迟更换模型的时间
{
set_task( (g_models_targettime + MODELCHANGE_DELAY) - current_time, "fm_set_user_model", taskid )
g_models_targettime = g_models_targettime + MODELCHANGE_DELAY
}
}
public fm_set_user_model( player )//设置玩家模型
{
// Get actual player id获取玩家ID
player -= MODELSET_TASK
// Set new model更换玩家模型
engfunc( EngFunc_SetClientKeyValue, player, engfunc( EngFunc_GetInfoKeyBuffer, player ), "model", g_player_model[player] )
// Remember this player has a custom model玩家更换模型成功后,自定义模型为真
g_has_custom_model[player] = true
}
/*================================================================================
[Stocks]
=================================================================================*/
stock fm_get_user_model( player, model[], len )
{
// Retrieve current model检测当前模型
engfunc( EngFunc_InfoKeyValue, engfunc( EngFunc_GetInfoKeyBuffer, player ), "model", model, len )
}
stock fm_reset_user_model( player )
{
// Player doesn't have a custom model any longer玩家不再有自定义模型
g_has_custom_model[player] = false
dllfunc( DLLFunc_ClientUserInfoChanged, player, engfunc( EngFunc_GetInfoKeyBuffer, player ) )
}
 | 
 |