搜索
查看: 8346|回复: 16

(问题没解决)为什么会出来这么多的重复提示信息

[复制链接]
发表于 2011-8-17 12:46:50 | 显示全部楼层 |阅读模式 来自 中国–甘肃–天水
本帖最后由 我是新手 于 2011-8-24 18:05 编辑

给急救包插件加上权限,用client_print(id, print_chat, "Sorry,只有成为UIP才能使用急救包" );
输出提示语句,结果出来一堆重复的提示语句。
只想要一行就够了,该如何做? 请达人指教!不胜感激!
见图:
代码重新贴了
  1. /*        Copyright ?2009, tuty
  2. Healthkit On Dead Body is free software;
  3. you can redistribute it and/or modify it under the terms of the
  4. GNU General Public License as published by the Free Software Foundation.

  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  8. GNU General Public License for more details.

  9. You should have received a copy of the GNU General Public License
  10. along with Teleport Destination Angles Editor; if not, write to the
  11. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  12. Boston, MA 02111-1307, USA.
  13. */

  14. #include <amxmodx>
  15. #include <engine>
  16. #include <fakemeta>
  17. #include <fakemeta_util>


  18. /* --| Plugin information */
  19. #define PLUGIN                 "Healthkit on dead body"
  20. #define AUTHOR                 "tuty"
  21. #define VERSION         "3.2b"

  22. /* --| Some plugin defines */
  23. #define MEDKIT_MINSZ         Float:{ -23.160000, -13.660000, -0.050000 }
  24. #define MEDKIT_MAXSZ         Float:{ 11.470000, 12.780000, 6.720000 }
  25. #define MODEL_KIT         "models/w_medkit.mdl"
  26. #define MODEL_KITT         "models/w_medkitt.mdl"
  27. #define SOUND_KIT         "items/smallmedkit1.wav"
  28. #define FFADE_IN         0x0000

  29. /* --| Some globals... */
  30. new gToggleKitEnable;
  31. new gToggleGlowShow;
  32. new gGMsgFade;
  33. new gToggleFadeEnable;
  34. new gToggleRemoveAtRstart;
  35. new gKitHealthCvar;
  36. new gLimitHealthCvar;
  37. new gGMsgItemPickup;

  38. /* --| Medkit classname */
  39. new const gMedKitClassname[] = "medkit_entity";

  40. /* --| Let's start the plugin */
  41. public plugin_init()
  42. {
  43.         /* --| Registering the plugin to show it on plugins list */
  44.         register_plugin( PLUGIN, VERSION, AUTHOR );
  45.        
  46.         /* --| Some usefull events */
  47.         register_event( "DeathMsg","drop_kit","a" );
  48.         register_logevent( "logevent_round_start", 2, "1=Round_Start" );
  49.        
  50.         /* --| Register the touch forward */
  51.         register_touch("medkit_entity","player","touched");
  52.        
  53.         /* --| Cvar list */
  54.         gToggleKitEnable = register_cvar( "kit_enable", "1" );
  55.         gToggleGlowShow = register_cvar( "kit_glow", "1" );
  56.         gToggleFadeEnable = register_cvar( "kit_fade", "1" );
  57.         gToggleRemoveAtRstart = register_cvar( "kit_remove", "1" );
  58.         gKitHealthCvar = register_cvar( "kit_health", "20" );
  59.         gLimitHealthCvar = register_cvar( "kit_limit_health", "100" );
  60.        
  61.         /* --| Let's catch the user message id's */
  62.         gGMsgFade = get_user_msgid( "ScreenFade" );
  63.         gGMsgItemPickup = get_user_msgid( "ItemPickup" );
  64. }

  65. /* --| Precaching stuff */  
  66. public plugin_precache()
  67. {
  68.         precache_model( MODEL_KIT );
  69.         precache_model( MODEL_KITT );
  70.         precache_sound( SOUND_KIT );
  71. }

  72. /* --| When player dies, let's drop the kit if plugin is elabled */
  73. public drop_kit()
  74. {
  75.         /* --| Check if plugin is enabled/disabled */
  76.         if( get_pcvar_num( gToggleKitEnable ) == 0 )
  77.         {
  78.                 return PLUGIN_HANDLED;
  79.         }       
  80.        
  81.         /* --| Get the victim id */
  82.         new victim = read_data( 2 );
  83.        
  84.         /* --| Get the victim origin */
  85.         static Float:origin[ 3 ];
  86.         pev( victim, pev_origin, origin );
  87.        
  88.         /* --| Creating healthkit entity */
  89.         new ent = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "info_target" ) );
  90.        
  91.         /* --| Modify the origin a little bit. This is calculated to be set on floor */
  92.         origin[ 2 ] -= 36;
  93.        
  94.         /* --| Setting the ent origin */
  95.         engfunc( EngFunc_SetOrigin, ent, origin );
  96.        
  97.         /* --| Check if isn't a valid ent */
  98.         if( !pev_valid( ent ) )
  99.         {
  100.                 return PLUGIN_HANDLED;
  101.         }
  102.        
  103.         /* --| Now let's set the entity model and some stuff */
  104.         set_pev( ent, pev_classname, gMedKitClassname );
  105.         engfunc( EngFunc_SetModel, ent, MODEL_KIT );
  106.         dllfunc( DLLFunc_Spawn, ent );
  107.         set_pev( ent, pev_solid, SOLID_BBOX );
  108.         set_pev( ent, pev_movetype, MOVETYPE_NONE );
  109.         engfunc( EngFunc_SetSize, ent, MEDKIT_MINSZ, MEDKIT_MAXSZ );
  110.         engfunc( EngFunc_DropToFloor, ent );
  111.        
  112.         /* --| If cvar is set to 1, let's glow the entity */
  113.         if( get_pcvar_num( gToggleGlowShow ) == 1 )
  114.         {
  115.                 if (get_user_team(victim)==1)
  116.                 {
  117.                         fm_set_rendering( ent, kRenderFxGlowShell, 255, 0, 0, kRenderFxNone, 27 );
  118.                         entity_set_int(ent,EV_INT_team,1);
  119.                 }
  120.                 else if (get_user_team(victim)==2)
  121.                 {
  122.                         fm_set_rendering( ent, kRenderFxGlowShell, 0, 0, 255, kRenderFxNone, 27 );
  123.                         entity_set_int(ent,EV_INT_team,2);
  124.                 }
  125.         }
  126.        
  127.         return PLUGIN_HANDLED;
  128. }

  129. /* --| Calling the touch forward from fakemeta to see if player touched the entity */  
  130. public touched( ent, id )
  131. {
  132.         /* --| Check if is a valid entity and is plugin enabled */
  133.         if( !pev_valid( ent ) || get_pcvar_num( gToggleKitEnable ) == 0 )
  134.         {
  135.                 return FMRES_IGNORED;
  136.         }
  137.        
  138.         new ownerTeam = get_user_team(id);
  139.         new whitchTeam = entity_get_int(ent, EV_INT_team);
  140.         if (whitchTeam==ownerTeam)
  141.         {
  142.                 return FMRES_IGNORED;
  143.         }
  144.        
  145.         /* --| Find the ent classname */
  146.         new classname[ 32 ];
  147.         pev( ent, pev_classname, classname, charsmax( classname ) );
  148.        
  149.         /* --| Check if isn't our classname */
  150.         if( !equal( classname, gMedKitClassname ) )
  151.         {
  152.                 return FMRES_IGNORED;
  153.         }
  154.        
  155.         /* --| Get the user health, and check some cvars */
  156.         new health = get_user_health( id );
  157.         new cvarhealth = get_pcvar_num( gKitHealthCvar );
  158.         new maxhealth = get_pcvar_num( gLimitHealthCvar );
  159.        
  160.         /* --| Check player health */

  161.         if( health >= maxhealth )
  162.         {
  163.                 //client_print( id, print_center, "Sorry, your health is %d. You can't take the kit! You must have less then %d to take it.", health, maxhealth );
  164.                 return FMRES_IGNORED;
  165.         }

  166.         /* --| Show a red hud message to client */
  167.         //set_hudmessage( 255, 0, 0, -1.0, 0.83, 2, 6.0, 3.0 );
  168.         //show_hudmessage( id, "You received %d HP", cvarhealth );
  169.        
  170.         /* Set the health and show some minor things, for fun */
  171.         if(get_user_flags(id) & read_flags("m") == 0)
  172.         {
  173.         client_print( id, print_center, "Sorry,只有成为UIP才能使用急救包" );
  174.         client_print(id, print_chat, "Sorry,只有成为UIP才能使用急救包" );
  175.         return PLUGIN_HANDLED;
  176.         }
  177.         else
  178.         fm_set_user_health( id, health + cvarhealth );
  179.         emit_sound( id, CHAN_ITEM, SOUND_KIT, VOL_NORM, ATTN_NORM ,0 , PITCH_NORM );
  180.        
  181.         /* --| Show the healthkit item on hud */
  182.         message_begin( MSG_ONE_UNRELIABLE, gGMsgItemPickup, _, id );
  183.         write_string( "item_healthkit" );
  184.         message_end();
  185.        
  186.         /* --| If cvar for fade is enabled, let's create the fade */
  187.         if( get_pcvar_num( gToggleFadeEnable ) == 1 )
  188.         {
  189.                 message_begin( MSG_ONE_UNRELIABLE, gGMsgFade , _, id );
  190.                 write_short( 1<<10 );
  191.                 write_short( 1<<10 );
  192.                 write_short( FFADE_IN );
  193.                 write_byte( 255 );
  194.                 write_byte( 0 );
  195.                 write_byte( 0 );
  196.                 write_byte( 75 );
  197.                 message_end();
  198.         }
  199.        
  200.         /* --| Now we need to remove the entity from floor */
  201.         engfunc( EngFunc_RemoveEntity, ent );

  202.         return FMRES_IGNORED;
  203. }

  204. /* --| Round start, we need to check entity and remove it */
  205. public logevent_round_start()
  206. {
  207.         /* --| If cvar to remove ent on round start is enabled, let's remove the ent */
  208.         if( get_pcvar_num( gToggleRemoveAtRstart ) == 1 )
  209.         {
  210.                 new hkit = FM_NULLENT;
  211.                 while( ( hkit = fm_find_ent_by_class( hkit, gMedKitClassname ) ) )
  212.                 {
  213.                         engfunc( EngFunc_RemoveEntity, hkit );
  214.                 }
  215.         }       
  216. }

  217. /* --| End of plugin */
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注个册吧

×
发表于 2011-8-17 14:38:19 | 显示全部楼层 来自 中国–广东–清远
register_touch("medkit_entity","player","touched");

应该是接触后的提示,当然会多次触发,我的想法是if( health >= maxhealth )中加个判定变量,然后在里面将这个开关打开,再用set_task过几十秒后关闭,这样就可以避免重复
回复

使用道具 举报

 楼主| 发表于 2011-8-17 14:54:10 | 显示全部楼层 来自 中国–甘肃–天水
多谢版主提示!
可弄了半天还是弄不来,要么没作用,要么就还是老样子、
恳请版主帮忙给修正!
回复

使用道具 举报

发表于 2011-8-17 20:28:46 | 显示全部楼层 来自 中国–广东–清远
添加一个新变量
new playershowvip[33]
修改
if( health >= maxhealth && !playershowvip[id])
在这里增加
playershowvip[id]=1
set_task(30.0, resetshowvip,id)

增加函数
public resetshovip(id)
{
playershowvip[id]=0
}
回复

使用道具 举报

 楼主| 发表于 2011-8-17 21:06:39 | 显示全部楼层 来自 中国–甘肃–天水
大体上看明白了。
谢谢版主的指点!
我去试试先!
回复

使用道具 举报

 楼主| 发表于 2011-8-18 21:22:58 | 显示全部楼层 来自 中国–甘肃–天水
版主,还是麻烦你把这个插件完整的给改下吧....让我也能学习学习....

我....确实能力不咋地,改出来的东西实在没法用...

麻烦版主了!
回复

使用道具 举报

发表于 2011-8-19 00:02:41 | 显示全部楼层 来自 中国–广东–清远
  1. /*        Copyright ?2009, tuty
  2. Healthkit On Dead Body is free software;
  3. you can redistribute it and/or modify it under the terms of the
  4. GNU General Public License as published by the Free Software Foundation.

  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  8. GNU General Public License for more details.

  9. You should have received a copy of the GNU General Public License
  10. along with Teleport Destination Angles Editor; if not, write to the
  11. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  12. Boston, MA 02111-1307, USA.
  13. */

  14. #include <amxmodx>
  15. #include <engine>
  16. #include <fakemeta>
  17. #include <fakemeta_util>


  18. /* --| Plugin information */
  19. #define PLUGIN                 "Healthkit on dead body"
  20. #define AUTHOR                 "tuty"
  21. #define VERSION         "3.2b"

  22. /* --| Some plugin defines */
  23. #define MEDKIT_MINSZ         Float:{ -23.160000, -13.660000, -0.050000 }
  24. #define MEDKIT_MAXSZ         Float:{ 11.470000, 12.780000, 6.720000 }
  25. #define MODEL_KIT         "models/w_medkit.mdl"
  26. #define MODEL_KITT         "models/w_medkitt.mdl"
  27. #define SOUND_KIT         "items/smallmedkit1.wav"
  28. #define FFADE_IN         0x0000

  29. /* --| Some globals... */
  30. new gToggleKitEnable;
  31. new gToggleGlowShow;
  32. new gGMsgFade;
  33. new gToggleFadeEnable;
  34. new gToggleRemoveAtRstart;
  35. new gKitHealthCvar;
  36. new gLimitHealthCvar;
  37. new gGMsgItemPickup;
  38. new playershowvip[33]
  39. /* --| Medkit classname */
  40. new const gMedKitClassname[] = "medkit_entity";

  41. /* --| Let's start the plugin */
  42. public plugin_init()
  43. {
  44.         /* --| Registering the plugin to show it on plugins list */
  45.         register_plugin( PLUGIN, VERSION, AUTHOR );
  46.         
  47.         /* --| Some usefull events */
  48.         register_event( "DeathMsg","drop_kit","a" );
  49.         register_logevent( "logevent_round_start", 2, "1=Round_Start" );
  50.         
  51.         /* --| Register the touch forward */
  52.         register_touch("medkit_entity","player","touched");
  53.         
  54.         /* --| Cvar list */
  55.         gToggleKitEnable = register_cvar( "kit_enable", "1" );
  56.         gToggleGlowShow = register_cvar( "kit_glow", "1" );
  57.         gToggleFadeEnable = register_cvar( "kit_fade", "1" );
  58.         gToggleRemoveAtRstart = register_cvar( "kit_remove", "1" );
  59.         gKitHealthCvar = register_cvar( "kit_health", "20" );
  60.         gLimitHealthCvar = register_cvar( "kit_limit_health", "100" );
  61.         
  62.         /* --| Let's catch the user message id's */
  63.         gGMsgFade = get_user_msgid( "ScreenFade" );
  64.         gGMsgItemPickup = get_user_msgid( "ItemPickup" );
  65. }

  66. /* --| Precaching stuff */  
  67. public plugin_precache()
  68. {
  69.         precache_model( MODEL_KIT );
  70.         precache_model( MODEL_KITT );
  71.         precache_sound( SOUND_KIT );
  72. }

  73. /* --| When player dies, let's drop the kit if plugin is elabled */
  74. public drop_kit()
  75. {
  76.         /* --| Check if plugin is enabled/disabled */
  77.         if( get_pcvar_num( gToggleKitEnable ) == 0 )
  78.         {
  79.                 return PLUGIN_HANDLED;
  80.         }        
  81.         
  82.         /* --| Get the victim id */
  83.         new victim = read_data( 2 );
  84.         
  85.         /* --| Get the victim origin */
  86.         static Float:origin[ 3 ];
  87.         pev( victim, pev_origin, origin );
  88.         
  89.         /* --| Creating healthkit entity */
  90.         new ent = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "info_target" ) );
  91.         
  92.         /* --| Modify the origin a little bit. This is calculated to be set on floor */
  93.         origin[ 2 ] -= 36;
  94.         
  95.         /* --| Setting the ent origin */
  96.         engfunc( EngFunc_SetOrigin, ent, origin );
  97.         
  98.         /* --| Check if isn't a valid ent */
  99.         if( !pev_valid( ent ) )
  100.         {
  101.                 return PLUGIN_HANDLED;
  102.         }
  103.         
  104.         /* --| Now let's set the entity model and some stuff */
  105.         set_pev( ent, pev_classname, gMedKitClassname );
  106.         engfunc( EngFunc_SetModel, ent, MODEL_KIT );
  107.         dllfunc( DLLFunc_Spawn, ent );
  108.         set_pev( ent, pev_solid, SOLID_BBOX );
  109.         set_pev( ent, pev_movetype, MOVETYPE_NONE );
  110.         engfunc( EngFunc_SetSize, ent, MEDKIT_MINSZ, MEDKIT_MAXSZ );
  111.         engfunc( EngFunc_DropToFloor, ent );
  112.         
  113.         /* --| If cvar is set to 1, let's glow the entity */
  114.         if( get_pcvar_num( gToggleGlowShow ) == 1 )
  115.         {
  116.                 if (get_user_team(victim)==1)
  117.                 {
  118.                         fm_set_rendering( ent, kRenderFxGlowShell, 255, 0, 0, kRenderFxNone, 27 );
  119.                         entity_set_int(ent,EV_INT_team,1);
  120.                 }
  121.                 else if (get_user_team(victim)==2)
  122.                 {
  123.                         fm_set_rendering( ent, kRenderFxGlowShell, 0, 0, 255, kRenderFxNone, 27 );
  124.                         entity_set_int(ent,EV_INT_team,2);
  125.                 }
  126.         }
  127.         
  128.         return PLUGIN_HANDLED;
  129. }

  130. /* --| Calling the touch forward from fakemeta to see if player touched the entity */  
  131. public touched( ent, id )
  132. {
  133.         /* --| Check if is a valid entity and is plugin enabled */
  134.         if( !pev_valid( ent ) || get_pcvar_num( gToggleKitEnable ) == 0 )
  135.         {
  136.                 return FMRES_IGNORED;
  137.         }
  138.         
  139.         new ownerTeam = get_user_team(id);
  140.         new whitchTeam = entity_get_int(ent, EV_INT_team);
  141.         if (whitchTeam==ownerTeam)
  142.         {
  143.                 return FMRES_IGNORED;
  144.         }
  145.         
  146.         /* --| Find the ent classname */
  147.         new classname[ 32 ];
  148.         pev( ent, pev_classname, classname, charsmax( classname ) );
  149.         
  150.         /* --| Check if isn't our classname */
  151.         if( !equal( classname, gMedKitClassname ) )
  152.         {
  153.                 return FMRES_IGNORED;
  154.         }
  155.         
  156.         /* --| Get the user health, and check some cvars */
  157.         new health = get_user_health( id );
  158.         new cvarhealth = get_pcvar_num( gKitHealthCvar );
  159.         new maxhealth = get_pcvar_num( gLimitHealthCvar );
  160.         
  161.         /* --| Check player health */

  162.         if( health >= maxhealth )
  163.         {
  164.                 //client_print( id, print_center, "Sorry, your health is %d. You can't take the kit! You must have less then %d to take it.", health, maxhealth );
  165.                 return FMRES_IGNORED;
  166.         }

  167.         /* --| Show a red hud message to client */
  168.         //set_hudmessage( 255, 0, 0, -1.0, 0.83, 2, 6.0, 3.0 );
  169.         //show_hudmessage( id, "You received %d HP", cvarhealth );
  170.         
  171.         /* Set the health and show some minor things, for fun */
  172.         if(get_user_flags(id) read_flags("m") == 0 && !playershowvip[id])
  173.         {
  174.         client_print( id, print_center, "Sorry,只有成为UIP才能使用急救包" );
  175.         client_print(id, print_chat, "Sorry,只有成为UIP才能使用急救包" );
  176.         playershowvip[id]=1
  177.         set_task(30.0, resetshowvip,id)

  178.         return PLUGIN_HANDLED;
  179.         }
  180.         else
  181.         fm_set_user_health( id, health + cvarhealth );
  182.         emit_sound( id, CHAN_ITEM, SOUND_KIT, VOL_NORM, ATTN_NORM ,0 , PITCH_NORM );
  183.         
  184.         /* --| Show the healthkit item on hud */
  185.         message_begin( MSG_ONE_UNRELIABLE, gGMsgItemPickup, _, id );
  186.         write_string( "item_healthkit" );
  187.         message_end();
  188.         
  189.         /* --| If cvar for fade is enabled, let's create the fade */
  190.         if( get_pcvar_num( gToggleFadeEnable ) == 1 )
  191.         {
  192.                 message_begin( MSG_ONE_UNRELIABLE, gGMsgFade , _, id );
  193.                 write_short( 1<<10 );
  194.                 write_short( 1<<10 );
  195.                 write_short( FFADE_IN );
  196.                 write_byte( 255 );
  197.                 write_byte( 0 );
  198.                 write_byte( 0 );
  199.                 write_byte( 75 );
  200.                 message_end();
  201.         }
  202.         
  203.         /* --| Now we need to remove the entity from floor */
  204.         engfunc( EngFunc_RemoveEntity, ent );

  205.         return FMRES_IGNORED;
  206. }

  207. /* --| Round start, we need to check entity and remove it */
  208. public logevent_round_start()
  209. {
  210.         /* --| If cvar to remove ent on round start is enabled, let's remove the ent */
  211.         if( get_pcvar_num( gToggleRemoveAtRstart ) == 1 )
  212.         {
  213.                 new hkit = FM_NULLENT;
  214.                 while( ( hkit = fm_find_ent_by_class( hkit, gMedKitClassname ) ) )
  215.                 {
  216.                         engfunc( EngFunc_RemoveEntity, hkit );
  217.                 }
  218.         }        
  219. }

  220. public resetshovip(id)
  221. {
  222. playershowvip[id]=0
  223. }

  224. /* --| End of plugin */
复制代码
之前的回复看错了一个地方
回复

使用道具 举报

 楼主| 发表于 2011-8-19 10:14:45 | 显示全部楼层 来自 中国–甘肃–天水
本帖最后由 我是新手 于 2011-8-19 10:34 编辑

版主很不好意思。您改的这个还是编译报错。能再给看下吗?
另:热心的版主能留下你的Q吗或者加我Q:286136660 很希望能请教您!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注个册吧

×
回复

使用道具 举报

发表于 2011-8-20 16:07:40 | 显示全部楼层 来自 中国–广东–清远
那是你原来给我的源码就有错误。。。
回复

使用道具 举报

发表于 2011-8-20 16:11:47 | 显示全部楼层 来自 中国–广东–清远
  1. /*        Copyright ?2009, tuty
  2. Healthkit On Dead Body is free software;
  3. you can redistribute it and/or modify it under the terms of the
  4. GNU General Public License as published by the Free Software Foundation.

  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  8. GNU General Public License for more details.

  9. You should have received a copy of the GNU General Public License
  10. along with Teleport Destination Angles Editor; if not, write to the
  11. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  12. Boston, MA 02111-1307, USA.
  13. */

  14. #include <amxmodx>
  15. #include <engine>
  16. #include <fakemeta>
  17. #include <fakemeta_util>


  18. /* --| Plugin information */
  19. #define PLUGIN                 "Healthkit on dead body"
  20. #define AUTHOR                 "tuty"
  21. #define VERSION         "3.2b"

  22. /* --| Some plugin defines */
  23. #define MEDKIT_MINSZ         Float:{ -23.160000, -13.660000, -0.050000 }
  24. #define MEDKIT_MAXSZ         Float:{ 11.470000, 12.780000, 6.720000 }
  25. #define MODEL_KIT         "models/w_medkit.mdl"
  26. #define MODEL_KITT         "models/w_medkitt.mdl"
  27. #define SOUND_KIT         "items/smallmedkit1.wav"
  28. #define FFADE_IN         0x0000

  29. /* --| Some globals... */
  30. new gToggleKitEnable;
  31. new gToggleGlowShow;
  32. new gGMsgFade;
  33. new gToggleFadeEnable;
  34. new gToggleRemoveAtRstart;
  35. new gKitHealthCvar;
  36. new gLimitHealthCvar;
  37. new gGMsgItemPickup;
  38. new playershowvip[33]
  39. /* --| Medkit classname */
  40. new const gMedKitClassname[] = "medkit_entity";

  41. /* --| Let's start the plugin */
  42. public plugin_init()
  43. {
  44.         /* --| Registering the plugin to show it on plugins list */
  45.         register_plugin( PLUGIN, VERSION, AUTHOR );
  46.         
  47.         /* --| Some usefull events */
  48.         register_event( "DeathMsg","drop_kit","a" );
  49.         register_logevent( "logevent_round_start", 2, "1=Round_Start" );
  50.         
  51.         /* --| Register the touch forward */
  52.         register_touch("medkit_entity","player","touched");
  53.         
  54.         /* --| Cvar list */
  55.         gToggleKitEnable = register_cvar( "kit_enable", "1" );
  56.         gToggleGlowShow = register_cvar( "kit_glow", "1" );
  57.         gToggleFadeEnable = register_cvar( "kit_fade", "1" );
  58.         gToggleRemoveAtRstart = register_cvar( "kit_remove", "1" );
  59.         gKitHealthCvar = register_cvar( "kit_health", "20" );
  60.         gLimitHealthCvar = register_cvar( "kit_limit_health", "100" );
  61.         
  62.         /* --| Let's catch the user message id's */
  63.         gGMsgFade = get_user_msgid( "ScreenFade" );
  64.         gGMsgItemPickup = get_user_msgid( "ItemPickup" );
  65. }

  66. /* --| Precaching stuff */  
  67. public plugin_precache()
  68. {
  69.         precache_model( MODEL_KIT );
  70.         precache_model( MODEL_KITT );
  71.         precache_sound( SOUND_KIT );
  72. }

  73. /* --| When player dies, let's drop the kit if plugin is elabled */
  74. public drop_kit()
  75. {
  76.         /* --| Check if plugin is enabled/disabled */
  77.         if( get_pcvar_num( gToggleKitEnable ) == 0 )
  78.         {
  79.                 return PLUGIN_HANDLED;
  80.         }        
  81.         
  82.         /* --| Get the victim id */
  83.         new victim = read_data( 2 );
  84.         
  85.         /* --| Get the victim origin */
  86.         static Float:origin[ 3 ];
  87.         pev( victim, pev_origin, origin );
  88.         
  89.         /* --| Creating healthkit entity */
  90.         new ent = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "info_target" ) );
  91.         
  92.         /* --| Modify the origin a little bit. This is calculated to be set on floor */
  93.         origin[ 2 ] -= 36;
  94.         
  95.         /* --| Setting the ent origin */
  96.         engfunc( EngFunc_SetOrigin, ent, origin );
  97.         
  98.         /* --| Check if isn't a valid ent */
  99.         if( !pev_valid( ent ) )
  100.         {
  101.                 return PLUGIN_HANDLED;
  102.         }
  103.         
  104.         /* --| Now let's set the entity model and some stuff */
  105.         set_pev( ent, pev_classname, gMedKitClassname );
  106.         engfunc( EngFunc_SetModel, ent, MODEL_KIT );
  107.         dllfunc( DLLFunc_Spawn, ent );
  108.         set_pev( ent, pev_solid, SOLID_BBOX );
  109.         set_pev( ent, pev_movetype, MOVETYPE_NONE );
  110.         engfunc( EngFunc_SetSize, ent, MEDKIT_MINSZ, MEDKIT_MAXSZ );
  111.         engfunc( EngFunc_DropToFloor, ent );
  112.         
  113.         /* --| If cvar is set to 1, let's glow the entity */
  114.         if( get_pcvar_num( gToggleGlowShow ) == 1 )
  115.         {
  116.                 if (get_user_team(victim)==1)
  117.                 {
  118.                         fm_set_rendering( ent, kRenderFxGlowShell, 255, 0, 0, kRenderFxNone, 27 );
  119.                         entity_set_int(ent,EV_INT_team,1);
  120.                 }
  121.                 else if (get_user_team(victim)==2)
  122.                 {
  123.                         fm_set_rendering( ent, kRenderFxGlowShell, 0, 0, 255, kRenderFxNone, 27 );
  124.                         entity_set_int(ent,EV_INT_team,2);
  125.                 }
  126.         }
  127.         
  128.         return PLUGIN_HANDLED;
  129. }

  130. /* --| Calling the touch forward from fakemeta to see if player touched the entity */  
  131. public touched( ent, id )
  132. {
  133.         /* --| Check if is a valid entity and is plugin enabled */
  134.         if( !pev_valid( ent ) || get_pcvar_num( gToggleKitEnable ) == 0 )
  135.         {
  136.                 return FMRES_IGNORED;
  137.         }
  138.         
  139.         new ownerTeam = get_user_team(id);
  140.         new whitchTeam = entity_get_int(ent, EV_INT_team);
  141.         if (whitchTeam==ownerTeam)
  142.         {
  143.                 return FMRES_IGNORED;
  144.         }
  145.         
  146.         /* --| Find the ent classname */
  147.         new classname[ 32 ];
  148.         pev( ent, pev_classname, classname, charsmax( classname ) );
  149.         
  150.         /* --| Check if isn't our classname */
  151.         if( !equal( classname, gMedKitClassname ) )
  152.         {
  153.                 return FMRES_IGNORED;
  154.         }
  155.         
  156.         /* --| Get the user health, and check some cvars */
  157.         new health = get_user_health( id );
  158.         new cvarhealth = get_pcvar_num( gKitHealthCvar );
  159.         new maxhealth = get_pcvar_num( gLimitHealthCvar );
  160.         
  161.         /* --| Check player health */

  162.         if( health >= maxhealth )
  163.         {
  164.                 //client_print( id, print_center, "Sorry, your health is %d. You can't take the kit! You must have less then %d to take it.", health, maxhealth );
  165.                 return FMRES_IGNORED;
  166.         }

  167.         /* --| Show a red hud message to client */
  168.         //set_hudmessage( 255, 0, 0, -1.0, 0.83, 2, 6.0, 3.0 );
  169.         //show_hudmessage( id, "You received %d HP", cvarhealth );
  170.         
  171.         /* Set the health and show some minor things, for fun */
  172.         if((get_user_flags(id) & read_flags("m") == 0 )&& !playershowvip[id])
  173.         {
  174.         client_print( id, print_center, "Sorry,只有成为UIP才能使用急救包" );
  175.         client_print(id, print_chat, "Sorry,只有成为UIP才能使用急救包" );
  176.         playershowvip[id]=1
  177.         set_task(30.0, "resetshowvip",id)

  178.         return PLUGIN_HANDLED;
  179.         }
  180.         else
  181.         fm_set_user_health( id, health + cvarhealth );
  182.         emit_sound( id, CHAN_ITEM, SOUND_KIT, VOL_NORM, ATTN_NORM ,0 , PITCH_NORM );
  183.         
  184.         /* --| Show the healthkit item on hud */
  185.         message_begin( MSG_ONE_UNRELIABLE, gGMsgItemPickup, _, id );
  186.         write_string( "item_healthkit" );
  187.         message_end();
  188.         
  189.         /* --| If cvar for fade is enabled, let's create the fade */
  190.         if( get_pcvar_num( gToggleFadeEnable ) == 1 )
  191.         {
  192.                 message_begin( MSG_ONE_UNRELIABLE, gGMsgFade , _, id );
  193.                 write_short( 1<<10 );
  194.                 write_short( 1<<10 );
  195.                 write_short( FFADE_IN );
  196.                 write_byte( 255 );
  197.                 write_byte( 0 );
  198.                 write_byte( 0 );
  199.                 write_byte( 75 );
  200.                 message_end();
  201.         }
  202.         
  203.         /* --| Now we need to remove the entity from floor */
  204.         engfunc( EngFunc_RemoveEntity, ent );

  205.         return FMRES_IGNORED;
  206. }

  207. /* --| Round start, we need to check entity and remove it */
  208. public logevent_round_start()
  209. {
  210.         /* --| If cvar to remove ent on round start is enabled, let's remove the ent */
  211.         if( get_pcvar_num( gToggleRemoveAtRstart ) == 1 )
  212.         {
  213.                 new hkit = FM_NULLENT;
  214.                 while( ( hkit = fm_find_ent_by_class( hkit, gMedKitClassname ) ) )
  215.                 {
  216.                         engfunc( EngFunc_RemoveEntity, hkit );
  217.                 }
  218.         }        
  219. }

  220. public resetshovip(id)
  221. {
  222. playershowvip[id]=0
  223. }

  224. /* --| End of plugin */
复制代码
回复

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

快速回复 返回顶部 返回列表