SHARE
TWEET

Untitled

a guest Aug 23rd, 2017 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma semicolon 1
  2.  
  3. #include <sourcemod>
  4. #include <sdktools>
  5. #include <cstrike>
  6. #include <sdkhooks>
  7.  
  8. bool g_bIsGrabModeActivated[MAXPLAYERS + 1];
  9. bool g_bIsGrabbingPerson[MAXPLAYERS + 1];
  10. int g_iPlayerLastButtons[MAXPLAYERS + 1];
  11. int g_iPlayerGrabTarget[MAXPLAYERS + 1];
  12. float g_fDistanceGrabbing[MAXPLAYERS + 1];
  13.  
  14. int g_iBeamSprite;
  15. int g_iHaloSprite;
  16.  
  17. #define MAX_BUTTONS 26
  18.  
  19. public Plugin myinfo =
  20. {
  21.     name = "Grab",
  22.     author = "Instinct",
  23.     description = "Allows you to grab people",
  24.     version = "1.0",
  25.     url = ""
  26. };
  27.  
  28. public void OnPluginStart()
  29. {
  30.     RegAdminCmd("sm_grab", Command_Grab, ADMFLAG_CUSTOM3);
  31.    
  32.     HookEvent("round_end", Event_RoundEnd);
  33.     HookEvent("player_death", Event_PlayerDeath);
  34.    
  35.     g_iBeamSprite = PrecacheModel("materials/sprites/laserbeam.vmt");
  36.     g_iHaloSprite = PrecacheModel("materials/sprites/glow.vmt");
  37. }
  38.  
  39. public Action Command_Grab(int client, int args)
  40. {
  41.     if(!IsValidClient(client))
  42.     {
  43.         return Plugin_Handled;
  44.     }
  45.    
  46.     if (g_bIsGrabModeActivated[client])
  47.     {
  48.         g_bIsGrabModeActivated[client] = false;
  49.         PrintToChat(client, "[Grab] Turned off grabbing!");
  50.         return Plugin_Handled;
  51.     }
  52.  
  53.     if (!IsPlayerAlive(client))
  54.     {
  55.         ReplyToCommand(client, "[SM] You have to be alive in order to use this command.");
  56.         return Plugin_Handled;
  57.     }
  58.    
  59.     g_bIsGrabModeActivated[client] = true;
  60.     PrintToChat(client, "[Grab] Turned on grabbing!");
  61.    
  62.     return Plugin_Handled;
  63. }
  64.  
  65. public Action OnPlayerRunCmd(int client,int &buttons,int &impulse, float vel[3], float angles[3],int &weapon,int &subtype,int &cmdnum,int &tickcount,int &seed,int mouse[2])
  66. {
  67.     if (g_bIsGrabModeActivated[client] && IsPlayerAlive(client))
  68.     {
  69.         for (int i = 0; i < MAX_BUTTONS; i++)
  70.         {
  71.             int button = (1 << i);
  72.        
  73.             if ((buttons & button))
  74.             {
  75.                 if (!(g_iPlayerLastButtons[client] & button))
  76.                 {
  77.                     ClientOnButtonPress(client, button);
  78.                 }
  79.             }
  80.         }
  81.        
  82.         if (g_bIsGrabbingPerson[client])
  83.         {
  84.             float ClientOrigin[3];
  85.             float ClientEyeAngles[3];
  86.             float g_iForwardAngle[3];
  87.             float g_iEndPos[3];
  88.            
  89.             GetClientAbsOrigin(client, ClientOrigin);
  90.             GetClientEyeAngles(client, ClientEyeAngles);
  91.             GetAngleVectors(ClientEyeAngles, g_iForwardAngle, NULL_VECTOR, NULL_VECTOR);
  92.             ScaleVector(g_iForwardAngle, g_fDistanceGrabbing[client]);
  93.             AddVectors(ClientOrigin, g_iForwardAngle, g_iEndPos);
  94.            
  95.             if (buttons & IN_DUCK)
  96.             {
  97.                 if (buttons & IN_FORWARD)
  98.                 {
  99.                     g_fDistanceGrabbing[client] += 5.0;
  100.                 }
  101.                 if (buttons & IN_BACK)
  102.                 {
  103.                     g_fDistanceGrabbing[client] -= 5.0;
  104.                 }
  105.             }
  106.            
  107.             SetupLaser(client, g_iPlayerGrabTarget[client]);
  108.             TeleportEntity(g_iPlayerGrabTarget[client], g_iEndPos, NULL_VECTOR, NULL_VECTOR);
  109.         }
  110.    }
  111.     g_iPlayerLastButtons[client] = buttons;
  112.  
  113.     return Plugin_Continue;
  114. }
  115.  
  116. public Action GrabbedTarget_TakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
  117. {
  118.     if (IsValidClient(victim))
  119.     {
  120.         return Plugin_Handled;
  121.     }
  122.    
  123.     return Plugin_Continue;
  124. }
  125.  
  126. public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
  127. {
  128.     for (int i = 1; i < MaxClients; i++)
  129.     {
  130.         if (IsValidClient(i))
  131.         {
  132.             if (g_bIsGrabbingPerson[i])
  133.             {
  134.                 ReleasePlayer(g_iPlayerGrabTarget[i]);
  135.             }
  136.         }
  137.     }
  138. }  
  139.  
  140. public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
  141. {
  142.     int victim = GetClientOfUserId(GetEventInt(event, "userid"));
  143.    
  144.     if (!IsValidClient(victim))
  145.     {
  146.         return Plugin_Handled;
  147.     }
  148.    
  149.     if (g_bIsGrabbingPerson[victim])
  150.     {
  151.         ReleasePlayer(g_iPlayerGrabTarget[victim]);
  152.     }
  153.    
  154.     return Plugin_Handled;
  155. }
  156.  
  157. public void ClientOnButtonPress(int client, int button)
  158. {
  159.     switch(button)
  160.     {
  161.         case IN_ATTACK:
  162.         {
  163.             char sWeapon[16], sKnife[16];
  164.             GetClientWeapon(client, sWeapon, sizeof(sWeapon));
  165.             GetEntityClassname(GetPlayerWeaponSlot(client, 2), sKnife, sizeof(sKnife));
  166.                    
  167.             if(StrContains(sWeapon, sKnife) != -1)
  168.             {
  169.                 if (!g_bIsGrabbingPerson[client])
  170.                 {
  171.                     int target = GetClientAimTarget(client);
  172.                
  173.                     if (IsValidClient(target))
  174.                     {
  175.                         GrabPlayer(client, target);
  176.                         PrintToChat(client, "[Grab] You grabbed %N!", target);
  177.                     }
  178.                 }
  179.                 else
  180.                 {
  181.                     PrintToChat(client, "[Grab] You released %N!", g_iPlayerGrabTarget[client]);
  182.                     ReleasePlayer(client);
  183.                 }
  184.             }
  185.         }
  186.         case IN_ATTACK2:
  187.         {
  188.             char sWeapon[16], sKnife[16];
  189.             GetClientWeapon(client, sWeapon, sizeof(sWeapon));
  190.             GetEntityClassname(GetPlayerWeaponSlot(client, 2), sKnife, sizeof(sKnife));
  191.                    
  192.             if(StrContains(sWeapon, sKnife) != -1)
  193.             {
  194.                 if (g_bIsGrabbingPerson[client])
  195.                 {
  196.                     float ClientOrigin[3];
  197.                     float ClientEyeAngles[3];
  198.                     float g_iForwardAngle[3];
  199.                     float g_iEndVel[3];
  200.                    
  201.                     GetClientAbsOrigin(client, ClientOrigin);
  202.                     GetClientEyeAngles(client, ClientEyeAngles);
  203.                     GetAngleVectors(ClientEyeAngles, g_iForwardAngle, NULL_VECTOR, NULL_VECTOR);
  204.                     ScaleVector(g_iForwardAngle, 2000.0);
  205.                     AddVectors(ClientOrigin, g_iForwardAngle, g_iEndVel);
  206.                    
  207.                     ReleasePlayer(client);
  208.                     TeleportEntity(g_iPlayerGrabTarget[client], NULL_VECTOR, NULL_VECTOR, g_iEndVel);
  209.                 }              
  210.             }
  211.         }
  212.     }
  213. }
  214.  
  215. public void GrabPlayer(int client, int target)
  216. {
  217.     float g_fClientOrigin[3];
  218.     float g_fTargetOrigin[3];
  219.    
  220.     GetClientAbsOrigin(client, g_fClientOrigin);
  221.     GetClientAbsOrigin(target, g_fTargetOrigin);
  222.    
  223.     g_fDistanceGrabbing[client] = GetVectorDistance(g_fClientOrigin, g_fTargetOrigin);
  224.     g_iPlayerGrabTarget[client] = target;
  225.     g_bIsGrabbingPerson[client] = true;
  226.    
  227.     SetEntityMoveType(target, MOVETYPE_NONE);
  228.      
  229.     SDKHook(target, SDKHook_OnTakeDamage, GrabbedTarget_TakeDamage);
  230. }
  231.  
  232. public void ReleasePlayer(int client)
  233. {
  234.     SetEntityMoveType(g_iPlayerGrabTarget[client], MOVETYPE_WALK);
  235.    
  236.     SDKUnhook(g_iPlayerGrabTarget[client], SDKHook_OnTakeDamage, GrabbedTarget_TakeDamage);
  237.    
  238.     g_iPlayerGrabTarget[client] = 0;
  239.     g_bIsGrabbingPerson[client] = false;
  240.     g_fDistanceGrabbing[client] = 0.0;
  241. }
  242.  
  243. public void SetupLaser(int client, int target)
  244. {
  245.     TE_SetupBeamLaser(client, target, g_iBeamSprite, g_iHaloSprite, 0, 30, 0.1, 6.0, 6.0, 5, 6.0, { 254, 0, 0, 125 }, 1);
  246.     TE_SendToAll();
  247. }
  248.  
  249. stock bool IsValidClient(int client)
  250. {
  251.     return (client >= 1 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && !IsClientSourceTV(client));
  252. }
RAW Paste Data
Top