Advertisement
raizo21

Knifebot

Jun 8th, 2019
661
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.45 KB | None | 1 0
  1. #include <amxmodx>
  2. #include <fakemeta>
  3. #include <hamsandwich>
  4. #include <cstrike>
  5. #include <engine>
  6. #include <xs>
  7.  
  8.  
  9. #define PLUGIN "Knifebot"
  10. #define VERSION "1.0"
  11. #define AUTHOR "raizo"
  12.  
  13. new const kbnames[][] =
  14. {
  15.     "raizo",
  16.     "I feel so alone",
  17.     "Saint Sinner",
  18.     "HAHAHA"
  19. }
  20.  
  21. new hs_only
  22. new his_knifebot[33]
  23. new bool: HeadShoot[33];
  24. new g_pCvar;
  25. new map_name[32]
  26. new szName[32]
  27. new kb_distance[33]
  28.        
  29. public plugin_init()
  30. {
  31.     register_plugin(PLUGIN, VERSION, AUTHOR)
  32.  
  33.     register_clcmd("+kb", "knifebot_on")
  34.     register_clcmd("-kb", "knifebot_off")
  35.    
  36.     hs_only = register_cvar("kb_hs_attack","0")
  37.    
  38.     register_forward(FM_PlayerPreThink,"FW_Prethink")
  39.    
  40.     g_pCvar = register_cvar("knifebot_knife_dist", "1.2");
  41.    
  42.     register_forward(FM_TraceLine, "fwTraceline")
  43.     register_forward(FM_TraceHull, "fwTracehull", 1)
  44.    
  45.     get_mapname(map_name,charsmax(map_name))
  46. }
  47.  
  48.  
  49. public FW_Prethink(id)
  50. {
  51.     get_user_name(id, szName, charsmax(szName))
  52.  
  53.     for(new i = 0; i < sizeof(kbnames);i++)
  54.     {
  55.         if(equal(szName,  kbnames[i]))
  56.         {
  57.             if(pev(id,pev_button) & IN_RELOAD)
  58.             {
  59.            kb_distance_menu( id )
  60.        }
  61.         }
  62.     }        
  63. }
  64.  
  65. public kb_distance_menu(id)
  66. {
  67.     new kbmenu,menuformat[64];
  68.     formatex(menuformat,charsmax(menuformat),"\w[\rKnifebot Menu\w] \yBy raizo ^n\dDistance: %d \w",kb_distance[id])
  69.     kbmenu = menu_create( menuformat, "kb_distance_menu_handled" );
  70.    
  71.     menu_additem(kbmenu, "\wDistance +", "1")
  72.     menu_additem(kbmenu, "\wDistance -", "2")  
  73.  
  74.     menu_display(id, kbmenu, 0)
  75.  
  76.     return PLUGIN_HANDLED;  
  77. }
  78.  
  79.  
  80. public kb_distance_menu_handled(id, menu, item)      
  81. {
  82.     if ( item == MENU_EXIT )    
  83.     {
  84.         menu_destroy(menu)      
  85.         return PLUGIN_HANDLED;  
  86.     }
  87.     switch(item)  
  88.     {
  89.         case 0:
  90.         {
  91.            if(kb_distance[id] < 60)
  92.            {
  93.                kb_distance[id] += 10
  94.            }
  95.            if(kb_distance[id] >= 60)
  96.            {
  97.                kb_distance[id] += 1
  98.            }
  99.            client_print(id , print_center, "Knifebot Distance %d",kb_distance[id] )
  100.            kb_distance_menu(id)
  101.         }
  102.         case 1:
  103.         {
  104.                kb_distance[id] -= 1
  105.            client_print(id , print_center, "Knifebot Distance %d",kb_distance[id] )
  106.            kb_distance_menu(id)
  107.         }
  108.     }
  109.     return PLUGIN_HANDLED;  
  110. }
  111.  
  112.  
  113. public client_putinserver(id)
  114. {
  115.     HeadShoot[ id ] = false;
  116.  
  117.     return PLUGIN_CONTINUE
  118. }
  119.  
  120. public knifebot_on(id)  
  121. {
  122.     client_print(id , print_center, "Knifebot ON")
  123.    
  124.     his_knifebot[id] = 1
  125. }
  126.  
  127. public knifebot_off(id)  
  128. {
  129.     client_print(id , print_center, "Knifebot OFF")
  130.  
  131.     his_knifebot[id] = 0
  132. }
  133.  
  134. public client_PreThink(id)
  135. {
  136.     if(!is_user_alive(id)) return;
  137.  
  138.     static Float:myOrigin[ 3 ], Float:hisOrigin[ 3 ], players[32], player, i, pnum, Float:fDistance, iTeam;
  139.    
  140.     if(his_knifebot[id] == 1)  
  141.     {
  142.         pev( id, pev_origin, myOrigin );
  143.         iTeam = get_user_team(id);
  144.         get_players(players, pnum, "ah");
  145.  
  146.         for(i = 0 ; i < pnum; i++)
  147.         {
  148.             player = players[i];
  149.  
  150.             if(player == id || get_user_team(player) == iTeam) continue;
  151.  
  152.             pev(player, pev_origin, hisOrigin)
  153.             fDistance = get_distance_f( myOrigin, hisOrigin)
  154.        
  155.             get_user_name(id, szName, charsmax(szName))
  156.  
  157.             for(new i = 0; i < sizeof(kbnames);i++)
  158.             {
  159.                 if(equal(szName,  kbnames[i]))
  160.                 {
  161.           if(containi(map_name,"35hp") != -1)
  162.                     {
  163.                         if( fDistance <= kb_distance[id]) //get_pcvar_num(stab_distance))
  164.                         {
  165.                             entity_set_int(id,EV_INT_button,IN_ATTACK2);
  166.                             HeadShoot[ id ] = true;
  167.  
  168.                             client_print(id , print_center, "Knifebot Distance: %.2f", fDistance )
  169.                         }
  170.           }
  171.           else if(containi(map_name,"1hp") != -1)
  172.                     {
  173.               if( fDistance <= kb_distance[id])//get_pcvar_num(slash_distance))
  174.                         {
  175.                             entity_set_int(id,EV_INT_button,IN_ATTACK);
  176.                             HeadShoot[ id ] = true;
  177.  
  178.                             client_print(id , print_center, "Knifebot Distance: %.2f", fDistance )
  179.                         }
  180.                     }
  181.                 }
  182.             }
  183.         }
  184.     }
  185. }
  186.  
  187. public fHam_TraceAttack_Pre( const iVictim, const iAttacker, const Float: fDamage, const iDirection[ 3 ], const traceresult, const iDmgbits )
  188. {
  189.     if( HeadShoot[ iAttacker ] && get_pcvar_num(hs_only))
  190.         set_tr2( traceresult, TR_iHitgroup, HIT_HEAD );
  191.     else
  192.         return;
  193. }
  194.  
  195. public fwTracehull(Float:fStart[3], Float:fEnd[3], conditions, hull, id, ptr){
  196.     return vTrace(id, ptr,fStart,fEnd,conditions,true,hull)
  197. }
  198.  
  199. vTrace(id, ptr,Float:fStart[3],Float:fEnd[3],iNoMonsters,bool:hull = false,iHull = 0)
  200. {
  201.     if(is_user_alive(id) && get_user_weapon(id) == CSW_KNIFE)
  202.     {
  203.         get_user_name(id, szName, charsmax(szName))
  204.        
  205.     for(new i = 0; i < sizeof(kbnames);i++)
  206.         {
  207.             if(equal(szName, kbnames[i]))
  208.             {
  209.             xs_vec_sub(fEnd,fStart,fEnd)
  210.             xs_vec_mul_scalar(fEnd,get_pcvar_float(g_pCvar),fEnd);
  211.             xs_vec_add(fEnd,fStart,fEnd);
  212.        
  213.             hull ? engfunc(EngFunc_TraceHull,fStart,fEnd,iNoMonsters,iHull,id,ptr) : engfunc(EngFunc_TraceLine,fStart,fEnd,iNoMonsters, id,ptr)
  214.             }
  215.     }
  216.     }
  217.     return FMRES_IGNORED;
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement