Advertisement
Guest User

11

a guest
Apr 8th, 2020
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.07 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <fakemeta>
  3. #include <fun>
  4. #include <engine>
  5.  
  6. #define GIVE_HEALTH 50 //Сколько ХП восстанавливать
  7. #define EXPLODE_TIME 5 //Через сколько секунд взорвется граната
  8. #define HEAL_RADIUS 300.0 //Радиус
  9. #define GENERAL_EXPLODE //Включить основной спрайт взрыва
  10. #define TWO_EXPLODE //включить дополнительные осколки от взрыва
  11. #define SHOKWAVE //Включить Shokwave вокруг гранаты при взрыве
  12. //#define SCREENFADE //Включить скринфейд
  13. #define STATUSICON //показывать иконку
  14. #define TOUCH_EXPLODE //Взрываться ли сразу при соприкосновении с обьектами
  15.  
  16. #define FLAG_ADM        ADMIN_LEVEL_H
  17. #define AMOUNT_GRENADE      2
  18.  
  19. //-------------------------------------
  20. #define V_MODEL "models/v_he_mk_nade_sib.mdl"
  21. #define P_MODEL "models/p_he_mk_nade_sib.mdl"
  22. #define W_MODEL "models/w_he_mk_nade_sib.mdl"
  23.  
  24. #if defined GENERAL_EXPLODE
  25. #define EXPLODE_SPRITE  "sprites/heal_explode_sib.spr"
  26. #endif
  27.  
  28. #if defined TWO_EXPLODE
  29. #define EXPLODE_SPRITE2 "sprites/heal_shape_sib.spr"
  30. #endif
  31.  
  32. #define HEAL_SOUND  "woomen_expr_sib.wav"
  33. //--------------------------------------
  34.  
  35. #if defined GENERAL_EXPLODE
  36. new ExplSpr;
  37. #endif
  38.  
  39. #if defined TWO_EXPLODE
  40. new ExplSpr2;
  41. #endif
  42.  
  43. #if defined SHOKWAVE
  44. new g_iSpriteCircle;
  45. #endif
  46.  
  47. #if defined STATUSICON
  48. new g_IconStatus;
  49. #endif
  50.  
  51. new const g_sound_explosion[] = "weapons/sg_explode.wav";
  52. new const g_classname_grenade[] = "grenade";
  53. new g_eventid_createsmoke;
  54.  
  55. new g_Mode[33]
  56. new g_HowMuch[33]
  57.  
  58. public plugin_init()
  59. {
  60.     register_plugin("Nade Health", "1.2", "medusa");
  61.  
  62.     #if defined STATUSICON
  63.     g_IconStatus = get_user_msgid("StatusIcon");
  64.     #endif
  65.  
  66.     register_forward(FM_EmitSound, "FMForward_EmitSound");
  67.     register_forward(FM_PlaybackEvent, "FMForward_PlaybackEvent");
  68.     register_event("CurWeapon", "EVCurWeapon", "be", "1=1");
  69.     register_forward(FM_SetModel, "FMForward_SetModel", 1);
  70.     //register_forward(FM_PlayerPreThink, "FW_PlayerPreThink");
  71.     register_forward(FM_CmdStart,   "fw_cmdstart")
  72.  
  73.     register_logevent("round_start", 2, "0=World triggered", "1=Round_Start")
  74.     register_logevent("round_start", 2, "1=Round_End")
  75.  
  76.     register_think("grenade", "FMForward_Think" )
  77.  
  78.     register_clcmd("say /grena", "TakeGrenade")
  79.  
  80.     #if defined TOUCH_EXPLODE
  81.     register_touch("grenade", "*", "FMForward_Touch")
  82.     #endif
  83.     g_eventid_createsmoke = engfunc(EngFunc_PrecacheEvent, 1, "events/createsmoke.sc");
  84. }
  85. public client_conntct(id)
  86. {
  87.     g_HowMuch[id] = 0
  88. }
  89. public round_start()
  90. {
  91.     for(new id = 1; id <= get_maxplayers(); id++)
  92.     {
  93.         if(is_user_connected(id) && get_user_flags(id) & FLAG_ADM)
  94.             g_HowMuch[id] = 0
  95.     }
  96. }
  97.  
  98. public TakeGrenade(id)
  99. {
  100.     if(!is_user_connected(id) || !is_user_alive(id))
  101.         return
  102.     if(get_user_flags(id) & FLAG_ADM)
  103.     {
  104.         if(g_HowMuch[id] >= AMOUNT_GRENADE)
  105.         {
  106.             color_chat(id, "!g[Режим гранат] !tБесплатно можно брать только %d гранат!", AMOUNT_GRENADE)
  107.             return
  108.         }
  109.    
  110.         give_item(id, "weapon_smokegrenade")
  111.         g_Mode[id] = 0
  112.    
  113.         g_HowMuch[id]++
  114.    
  115.         color_chat(id, "!g[Режим гранат] !tЧто бы изменить режим, нажми правую кнопку мыши!")
  116.     }
  117. }
  118. public fw_cmdstart(id, uc_handle, seed)
  119. {
  120.     if (!is_user_alive(id))
  121.         return FMRES_IGNORED
  122.    
  123.     static bool:key[32 + 1] = {false, ...}
  124.    
  125.     static buttons
  126.     buttons = get_uc(uc_handle, UC_Buttons)
  127.  
  128.     if(get_user_flags(id) & FLAG_ADM)
  129.     {
  130.         if(get_user_weapon(id) != CSW_SMOKEGRENADE)
  131.             return FMRES_IGNORED
  132.         if (buttons & IN_ATTACK2)
  133.         {
  134.             if (!key[id])
  135.             {
  136.                 if(!g_Mode[id])
  137.                 {
  138.                     g_Mode[id] = 1
  139.                     client_print(id, print_center, "Режим гранаты: Дым")
  140.                     set_pev(id, pev_viewmodel2, "models/v_smokegrenade.mdl");
  141.                     set_pev(id, pev_weaponmodel2, "models/p_smokegrenade.mdl");
  142.                 }
  143.                 else
  144.                 {
  145.                     g_Mode[id] = 0
  146.                     client_print(id, print_center, "Режим гранаты: Хилл")
  147.                     set_pev(id, pev_viewmodel2, V_MODEL);
  148.                     set_pev(id, pev_weaponmodel2, P_MODEL);
  149.  
  150.                 }
  151.             }
  152.             key[id] = true
  153.         }
  154.         else
  155.         {
  156.             key[id] = false
  157.         }
  158.     }
  159.     return FMRES_IGNORED;
  160. }
  161.  
  162. public plugin_precache()
  163. {
  164.     #if defined GENERAL_EXPLODE
  165.     ExplSpr = precache_model(EXPLODE_SPRITE);
  166.     #endif
  167.  
  168.     #if defined TWO_EXPLODE
  169.     ExplSpr2 = precache_model(EXPLODE_SPRITE2);
  170.     #endif
  171.  
  172.     precache_model(V_MODEL);
  173.     precache_model(W_MODEL);
  174.     precache_model(P_MODEL);
  175.  
  176.     precache_sound(HEAL_SOUND);
  177.  
  178.     #if defined SHOKWAVE
  179.     g_iSpriteCircle = precache_model("sprites/shockwave.spr");
  180.     #endif
  181. }
  182.  
  183. public EVCurWeapon(id)
  184. {
  185.     if(is_user_connected(id) && is_user_alive(id) && !g_Mode[id] && get_user_flags(id) & FLAG_ADM)
  186.     {
  187.         if(get_user_weapon(id) == CSW_SMOKEGRENADE)
  188.         {
  189.             set_pev(id, pev_viewmodel2, V_MODEL);
  190.             set_pev(id, pev_weaponmodel2, P_MODEL);
  191.  
  192.             #if defined STATUSICON
  193.             message_begin(MSG_ONE_UNRELIABLE, g_IconStatus, {0,0,0}, id);
  194.             write_byte(2)
  195.             write_string("cross");
  196.             write_byte(0);
  197.             write_byte(255);
  198.             write_byte(0);
  199.             message_end();
  200.             #endif
  201.         }
  202.         #if defined STATUSICON
  203.         else
  204.         {
  205.             message_begin(MSG_ONE_UNRELIABLE, g_IconStatus, {0,0,0}, id);
  206.             write_byte(0)
  207.             write_string("cross");
  208.             message_end();
  209.         }
  210.         #endif
  211.     }
  212. }
  213.  
  214. public FMForward_SetModel(entity, const model[])
  215. {
  216.     if(!pev_valid(entity)) return FMRES_IGNORED;
  217.  
  218.     static id
  219.    
  220.     id = entity_get_edict(entity, EV_ENT_owner)
  221.    
  222.     if(get_user_flags(id) & FLAG_ADM)
  223.     {
  224.         if(g_Mode[id]) return FMRES_IGNORED;
  225.        
  226.         if(equal(model, "models/w_smokegrenade.mdl"))
  227.         {
  228.             engfunc(EngFunc_SetModel, entity, W_MODEL);
  229.             set_pev(entity, pev_dmgtime, get_gametime() + EXPLODE_TIME);
  230.             set_pev(entity, pev_flTimeStepSound, 555)
  231.         }
  232.     }
  233.     return FMRES_IGNORED;
  234. }
  235.  
  236. #if defined TOUCH_EXPLODE
  237. public FMForward_Touch(entity)
  238. {
  239.     if(~get_pdata_int(entity, 114) & (1<<1))
  240.         return;
  241.  
  242.     new iPlayer = entity_get_edict(entity, EV_ENT_owner)
  243.  
  244.     if(g_Mode[iPlayer])
  245.         return;
  246.  
  247.     set_pev(entity, pev_dmgtime, get_gametime());
  248. }
  249. #endif
  250.  
  251.  
  252. public FMForward_EmitSound(entity, channel, const sound[])
  253. {
  254.     if (!equal(sound, g_sound_explosion) || !is_grenade(entity))
  255.         return FMRES_IGNORED;
  256.  
  257.     static Float:origin[3];
  258.     static id; id = pev(entity, pev_owner);
  259.     pev(entity, pev_origin, origin);
  260.  
  261.     if(!(get_user_flags(id) & FLAG_ADM)) return FMRES_IGNORED;
  262.  
  263.     if(g_Mode[id] == 0)
  264.     {
  265.         engfunc(EngFunc_EmitSound, entity, CHAN_WEAPON, HEAL_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
  266.    
  267.         #if defined GENERAL_EXPLODE
  268.         message_begin(MSG_PVS,SVC_TEMPENTITY,{0,0,0});
  269.         write_byte(TE_EXPLOSION);
  270.         write_coord(floatround(origin[0]));
  271.         write_coord(floatround(origin[1]));
  272.         write_coord(floatround(origin[2])+65);
  273.         write_short(ExplSpr);
  274.         write_byte(30);
  275.         write_byte(20);
  276.         write_byte(TE_EXPLFLAG_NOSOUND|TE_EXPLFLAG_NOPARTICLES);
  277.         message_end();
  278.         #endif
  279.        
  280.         #if defined TWO_EXPLODE
  281.         message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0});
  282.         write_byte(TE_SPRITETRAIL);
  283.         write_coord(floatround(origin[0]));
  284.         write_coord(floatround(origin[1]));
  285.         write_coord(floatround(origin[2])+20);
  286.         write_coord(floatround(origin[0]));
  287.         write_coord(floatround(origin[1]));
  288.         write_coord(floatround(origin[2])+80);
  289.         write_short(ExplSpr2);
  290.         write_byte(20);
  291.         write_byte(20);
  292.         write_byte(4);
  293.         write_byte(20);
  294.         write_byte(10);
  295.         message_end();
  296.         #endif
  297.    
  298.         #if defined SHOKWAVE
  299.         message_begin(MSG_ALL, SVC_TEMPENTITY, {0,0,0});
  300.         write_byte(TE_BEAMCYLINDER);
  301.         write_coord(floatround(origin[0]));
  302.         write_coord(floatround(origin[1]));
  303.         write_coord(floatround(origin[2]));
  304.         write_coord(floatround(origin[0]));
  305.         write_coord(floatround(origin[1]));
  306.         write_coord(floatround(origin[2] + HEAL_RADIUS));
  307.         write_short(g_iSpriteCircle);
  308.         write_byte(0);
  309.         write_byte(1);
  310.         write_byte(5);
  311.         write_byte(30);
  312.         write_byte(1);
  313.         write_byte(10);
  314.         write_byte(255);
  315.         write_byte(40);
  316.         write_byte(255);   
  317.         write_byte(5);
  318.         message_end();
  319.         #endif
  320.        
  321.         new user
  322.         while((user = find_ent_in_sphere(user,origin,HEAL_RADIUS)) != 0)
  323.         {
  324.             if(is_user_alive(user) && g_Mode[id] == 0)
  325.             {
  326.                 #if defined SCREENFADE
  327.                 message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, user);
  328.                 write_short(1<<10);
  329.                 write_short(1<<10);
  330.                 write_short(0x0000);
  331.                 write_byte(170);
  332.                 write_byte(255);
  333.                 write_byte(0);
  334.                 write_byte(75);
  335.                 message_end();
  336.                 #endif
  337.            
  338.                 new health[33];
  339.                 health[user] = get_user_health(user);
  340.    
  341.                 if (health[user] <= 100 - GIVE_HEALTH)
  342.                     set_user_health(user,health[user] + GIVE_HEALTH);
  343.                 else if(health[user] > 100 - GIVE_HEALTH)
  344.                     set_user_health(user,100);
  345.             }
  346.         }
  347.     }
  348.  
  349.     return FMRES_SUPERCEDE;
  350. }
  351.  
  352. public FMForward_PlaybackEvent(flags, invoker, eventindex)
  353. {
  354.     if (eventindex == g_eventid_createsmoke)
  355.         return FMRES_IGNORED
  356.  
  357.     if(!g_Mode[invoker])
  358.         return FMRES_SUPERCEDE
  359.  
  360.     return FMRES_IGNORED
  361. }
  362.  
  363. public FMForward_Think(entity)
  364. {
  365.     static id; id = pev(entity, pev_owner);
  366.  
  367.     if(!g_Mode[id])
  368.     {
  369.         if(get_pdata_int(entity, 114) & (1<<1))
  370.             set_pev( entity, pev_flags, FL_ONGROUND )
  371.     }
  372. }
  373.  
  374. bool:is_grenade(entity)
  375. {
  376.     if (!pev_valid(entity))
  377.         return false;
  378.  
  379.     static classname[sizeof g_classname_grenade + 1]
  380.     pev(entity, pev_classname, classname, sizeof g_classname_grenade);
  381.  
  382.     if (equal(classname, g_classname_grenade))
  383.         return true;
  384.  
  385.     return false;
  386. }
  387.  
  388. public CHECK_ValidPlayer(id){
  389.    
  390.     if (1<=id<=get_maxplayers() && is_user_alive(id))
  391.         return 1;
  392.    
  393.     return 0;
  394. }
  395. stock color_chat(const id, const input[], any:...)
  396. {
  397.     new count = 1, players[32];
  398.     static msg[191];
  399.     vformat(msg, 190, input, 3);
  400.    
  401.     replace_all(msg, 190, "!g", "^4");
  402.     replace_all(msg, 190, "!y", "^1");
  403.     replace_all(msg, 190, "!t", "^3");
  404.    
  405.     if (id) players[0] = id; else get_players(players, count, "ch");
  406.     {
  407.         for (new i = 0; i < count; i++)
  408.         {
  409.             if (is_user_connected(players[i]))
  410.             {
  411.                 message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i]);
  412.                 write_byte(players[i]);
  413.                 write_string(msg);
  414.                 message_end();
  415.             }
  416.         }
  417.     }
  418. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement