|
发表于 2011-8-22 11:22:40
|
显示全部楼层
来自 中国–广东–深圳
- #include <amxmodx>
- #include <engine>
- #include <fakemeta>
- #include <fakemeta_util>
- #define PLUGIN "Healthkit on dead body"
- #define AUTHOR "Jakyo"
- #define VERSION "1.0"
- #define MEDKIT_MINSZ Float:{ -23.160000, -13.660000, -0.050000 }
- #define MEDKIT_MAXSZ Float:{ 11.470000, 12.780000, 6.720000 }
- #define MODEL_KIT "models/w_medkit.mdl" // 急救包模型
- #define MODEL_KITT "models/w_medkitt.mdl" // 急救包加密模型
- #define SOUND_KIT "items/smallmedkit1.wav" // 捡取急救包时播放的声效
- #define FFADE_IN 0x0000 // 播放客户端ICO使用的对应内存值
- new gToggleKitEnable;
- new gToggleGlowShow;
- new gGMsgFade;
- new gToggleFadeEnable;
- new gToggleRemoveAtRstart;
- new gKitHealthCvar;
- new gLimitHealthCvar;
- new gGMsgItemPickup;
- new gLimitTouchDelayCvar
- new g_medkittouchtime[33]
- new const gMedKitClassname[] = "medkit_entity"; // 急救包实体名称
- public plugin_init()
- {
- register_plugin( PLUGIN, VERSION, AUTHOR ); // 插件注册
- register_event( "DeathMsg","drop_kit","a" ); // 玩家死亡事件,处理急救包掉落
- register_logevent( "logevent_round_start", 2, "1=Round_Start" ); // 新一局开始时间
- register_touch(gMedKitClassname, "player", "touched"); // 急救包碰触时间
- gToggleKitEnable = register_cvar( "kit_enable", "1" ); // 是否打开急救包掉落功能
- gToggleGlowShow = register_cvar( "kit_glow", "1" ); // 地上的急救包是否发光
- gToggleFadeEnable = register_cvar( "kit_fade", "1" ); // 捡取急救包时是否播放ICO提示
- gToggleRemoveAtRstart = register_cvar( "kit_remove", "1" ); // 局开始时是否清除上局产生的急救包
- gKitHealthCvar = register_cvar( "kit_health", "20" ); // 急救包恢复的血量
- gLimitHealthCvar = register_cvar( "kit_limit_health", "100" ); // 最大血量
- gLimitTouchDelayCvar = register_cvar( "kit_limit_touchdelay", "100" ); // 最大血量
- gGMsgFade = get_user_msgid( "ScreenFade" );
- gGMsgItemPickup = get_user_msgid( "ItemPickup" );
- }
- public plugin_precache()
- {
- precache_model( MODEL_KIT ); // 急救包模型加载
- precache_model( MODEL_KITT ); // 急救包加密模型加载
- precache_sound( SOUND_KIT ); // 急救包捡取声音加载
- }
- // 玩家死亡急救包掉落事件
- public drop_kit()
- {
- if( get_pcvar_num( gToggleKitEnable ) == 0 ) // 判断是否打开急救包掉落功能
- return PLUGIN_HANDLED;
- new victim = read_data( 2 ); // 获取死亡者ID
- static Float:origin[ 3 ];
- pev( victim, pev_origin, origin ); // 获取死亡者死亡时的地图坐标
- new ent = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "info_target" ) ); // 生成一个实体
- origin[ 2 ] -= 36; // 玩家死亡坐标的Z坐标(高度)降低36
- engfunc( EngFunc_SetOrigin, ent, origin ); // 设置新生成的实体到计算好的坐标上
- if( !pev_valid( ent ) )
- return PLUGIN_HANDLED;
- set_pev( ent, pev_classname, gMedKitClassname ); // 设置实体的模型名
- engfunc( EngFunc_SetModel, ent, MODEL_KIT ); // 设置实体的模型
- dllfunc( DLLFunc_Spawn, ent ); // 重生实体
- set_pev( ent, pev_solid, SOLID_BBOX ); // 设置实体的碰触类型
- set_pev( ent, pev_movetype, MOVETYPE_NONE ); // 设置实体的移动类型
- engfunc( EngFunc_SetSize, ent, MEDKIT_MINSZ, MEDKIT_MAXSZ ); // 设置实体的大小
- engfunc( EngFunc_DropToFloor, ent ); // 把实体掉到地面上
- if( get_pcvar_num( gToggleGlowShow ) == 1 ) // 判断急救包是否需要发光
- {
- if (get_user_team(victim)==1) // 获取死亡者的队伍,是匪徒急救包即发红光,警察即发烂光
- {
- fm_set_rendering( ent, kRenderFxGlowShell, 255, 0, 0, kRenderFxNone, 27 );
- entity_set_int(ent,EV_INT_team,1);
- }
- else if (get_user_team(victim)==2)
- {
- fm_set_rendering( ent, kRenderFxGlowShell, 0, 0, 255, kRenderFxNone, 27 );
- entity_set_int(ent,EV_INT_team,2);
- }
- }
- return PLUGIN_HANDLED;
- }
- // 急救包碰触事件
- public touched( ent, id )
- {
- // 判断实体是否有效,捡取者是否存活,急救包掉落功能是否打开
- if( !pev_valid( ent ) || !is_user_alive(id) || get_pcvar_num( gToggleKitEnable ) == 0 )
- return PLUGIN_HANDLED;
- // 碰触间隔
- if (g_medkittouchtime[id]>=floatround(get_gametime()))
- return PLUGIN_HANDLED;
- new ownerTeam = get_user_team(id); // 获取捡取者的队伍
- new whitchTeam = entity_get_int(ent, EV_INT_team); // 获取掉落急救包的死亡者的队伍
- new health = get_user_health( id ); // 捡取者当前血量
- new cvarhealth = get_pcvar_num( gKitHealthCvar ); // 急救包增加的血量
- new maxhealth = get_pcvar_num( gLimitHealthCvar ); // 玩家最大血量
- // 设置捡取延迟X秒
- g_medkittouchtime[id] = floatround(get_gametime()) + get_pcvar_num( gLimitTouchDelayCvar )
- // 急救包掉落者队伍与捡取者队伍一致,禁止捡取
- if (whitchTeam==ownerTeam)
- {
- client_print( id, print_center, "Sorry,您不能捡取对方阵型的急救包" );
- client_print(id, print_chat, "Sorry,您不能捡取对方阵型的急救包" );
- return PLUGIN_HANDLED;
- }
- // 判断玩家权限
- if(get_user_flags(id) && read_flags("m") == 0)
- {
- client_print( id, print_center, "Sorry,只有成为VIP才能使用急救包" );
- client_print(id, print_chat, "Sorry,只有成为VIP才能使用急救包" );
- return PLUGIN_HANDLED;
- }
- else
- {
- // 如果玩家当前血量大于最大血量,禁止捡取
- if( health >= maxhealth )
- {
- client_print( id, print_center, "Sorry,您还没有收到任何损伤,无法捡取急救包" );
- client_print(id, print_chat, "Sorry,您还没有收到任何损伤,无法捡取急救包" );
- return PLUGIN_HANDLED;
- }
- else
- {
- new addhealth = health + cvarhealth
- fm_set_user_health( id, addhealth>=maxhealth ? maxhealth:addhealth); // 设置玩家血量
- emit_sound( id, CHAN_ITEM, SOUND_KIT, VOL_NORM, ATTN_NORM ,0 , PITCH_NORM ); // 播放捡取声音
- message_begin( MSG_ONE_UNRELIABLE, gGMsgItemPickup, _, id );
- write_string( "item_healthkit" );
- message_end();
- // 播放玩家客户端ICO
- if( get_pcvar_num( gToggleFadeEnable ) == 1 )
- {
- message_begin( MSG_ONE_UNRELIABLE, gGMsgFade , _, id );
- write_short( 1<<10 );
- write_short( 1<<10 );
- write_short( FFADE_IN );
- write_byte( 255 );
- write_byte( 0 );
- write_byte( 0 );
- write_byte( 75 );
- message_end();
- }
- }
- }
- // 移除急救包实体
- engfunc( EngFunc_RemoveEntity, ent );
- return PLUGIN_CONTINUE;
- }
- // 新局开始时间
- public logevent_round_start()
- {
- if( get_pcvar_num( gToggleRemoveAtRstart ) == 1 )
- {
- new hkit = FM_NULLENT;
- while( ( hkit = fm_find_ent_by_class( hkit, gMedKitClassname ) ) )
- {
- engfunc( EngFunc_RemoveEntity, hkit );
- }
- }
- }
复制代码 |
|