Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma semicolon 1
- #include <sourcemod>
- #include <sdktools>
- #include <cstrike>
- #include <sdkhooks>
- bool g_bIsGrabModeActivated[MAXPLAYERS + 1];
- bool g_bIsGrabbingPerson[MAXPLAYERS + 1];
- int g_iPlayerLastButtons[MAXPLAYERS + 1];
- int g_iPlayerGrabTarget[MAXPLAYERS + 1];
- float g_fDistanceGrabbing[MAXPLAYERS + 1];
- int g_iBeamSprite;
- int g_iHaloSprite;
- #define MAX_BUTTONS 26
- public Plugin myinfo =
- {
- name = "Grab",
- author = "Instinct",
- description = "Allows you to grab people",
- version = "1.0",
- url = ""
- };
- public void OnPluginStart()
- {
- RegAdminCmd("sm_grab", Command_Grab, ADMFLAG_CUSTOM3);
- HookEvent("round_end", Event_RoundEnd);
- HookEvent("player_death", Event_PlayerDeath);
- g_iBeamSprite = PrecacheModel("materials/sprites/laserbeam.vmt");
- g_iHaloSprite = PrecacheModel("materials/sprites/glow.vmt");
- }
- public Action Command_Grab(int client, int args)
- {
- if(!IsValidClient(client))
- {
- return Plugin_Handled;
- }
- if (g_bIsGrabModeActivated[client])
- {
- g_bIsGrabModeActivated[client] = false;
- PrintToChat(client, "[Grab] Turned off grabbing!");
- return Plugin_Handled;
- }
- if (!IsPlayerAlive(client))
- {
- ReplyToCommand(client, "[SM] You have to be alive in order to use this command.");
- return Plugin_Handled;
- }
- g_bIsGrabModeActivated[client] = true;
- PrintToChat(client, "[Grab] Turned on grabbing!");
- return Plugin_Handled;
- }
- 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])
- {
- if (g_bIsGrabModeActivated[client] && IsPlayerAlive(client))
- {
- for (int i = 0; i < MAX_BUTTONS; i++)
- {
- int button = (1 << i);
- if ((buttons & button))
- {
- if (!(g_iPlayerLastButtons[client] & button))
- {
- ClientOnButtonPress(client, button);
- }
- }
- }
- if (g_bIsGrabbingPerson[client])
- {
- float ClientOrigin[3];
- float ClientEyeAngles[3];
- float g_iForwardAngle[3];
- float g_iEndPos[3];
- GetClientAbsOrigin(client, ClientOrigin);
- GetClientEyeAngles(client, ClientEyeAngles);
- GetAngleVectors(ClientEyeAngles, g_iForwardAngle, NULL_VECTOR, NULL_VECTOR);
- ScaleVector(g_iForwardAngle, g_fDistanceGrabbing[client]);
- AddVectors(ClientOrigin, g_iForwardAngle, g_iEndPos);
- if (buttons & IN_DUCK)
- {
- if (buttons & IN_FORWARD)
- {
- g_fDistanceGrabbing[client] += 5.0;
- }
- if (buttons & IN_BACK)
- {
- g_fDistanceGrabbing[client] -= 5.0;
- }
- }
- SetupLaser(client, g_iPlayerGrabTarget[client]);
- TeleportEntity(g_iPlayerGrabTarget[client], g_iEndPos, NULL_VECTOR, NULL_VECTOR);
- }
- }
- g_iPlayerLastButtons[client] = buttons;
- return Plugin_Continue;
- }
- public Action GrabbedTarget_TakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
- {
- if (IsValidClient(victim))
- {
- return Plugin_Handled;
- }
- return Plugin_Continue;
- }
- public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
- {
- for (int i = 1; i < MaxClients; i++)
- {
- if (IsValidClient(i))
- {
- if (g_bIsGrabbingPerson[i])
- {
- ReleasePlayer(g_iPlayerGrabTarget[i]);
- }
- }
- }
- }
- public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
- {
- int victim = GetClientOfUserId(GetEventInt(event, "userid"));
- if (!IsValidClient(victim))
- {
- return Plugin_Handled;
- }
- if (g_bIsGrabbingPerson[victim])
- {
- ReleasePlayer(g_iPlayerGrabTarget[victim]);
- }
- return Plugin_Handled;
- }
- public void ClientOnButtonPress(int client, int button)
- {
- switch(button)
- {
- case IN_ATTACK:
- {
- char sWeapon[16], sKnife[16];
- GetClientWeapon(client, sWeapon, sizeof(sWeapon));
- GetEntityClassname(GetPlayerWeaponSlot(client, 2), sKnife, sizeof(sKnife));
- if(StrContains(sWeapon, sKnife) != -1)
- {
- if (!g_bIsGrabbingPerson[client])
- {
- int target = GetClientAimTarget(client);
- if (IsValidClient(target))
- {
- GrabPlayer(client, target);
- PrintToChat(client, "[Grab] You grabbed %N!", target);
- }
- }
- else
- {
- PrintToChat(client, "[Grab] You released %N!", g_iPlayerGrabTarget[client]);
- ReleasePlayer(client);
- }
- }
- }
- case IN_ATTACK2:
- {
- char sWeapon[16], sKnife[16];
- GetClientWeapon(client, sWeapon, sizeof(sWeapon));
- GetEntityClassname(GetPlayerWeaponSlot(client, 2), sKnife, sizeof(sKnife));
- if(StrContains(sWeapon, sKnife) != -1)
- {
- if (g_bIsGrabbingPerson[client])
- {
- float ClientOrigin[3];
- float ClientEyeAngles[3];
- float g_iForwardAngle[3];
- float g_iEndVel[3];
- GetClientAbsOrigin(client, ClientOrigin);
- GetClientEyeAngles(client, ClientEyeAngles);
- GetAngleVectors(ClientEyeAngles, g_iForwardAngle, NULL_VECTOR, NULL_VECTOR);
- ScaleVector(g_iForwardAngle, 2000.0);
- AddVectors(ClientOrigin, g_iForwardAngle, g_iEndVel);
- ReleasePlayer(client);
- TeleportEntity(g_iPlayerGrabTarget[client], NULL_VECTOR, NULL_VECTOR, g_iEndVel);
- }
- }
- }
- }
- }
- public void GrabPlayer(int client, int target)
- {
- float g_fClientOrigin[3];
- float g_fTargetOrigin[3];
- GetClientAbsOrigin(client, g_fClientOrigin);
- GetClientAbsOrigin(target, g_fTargetOrigin);
- g_fDistanceGrabbing[client] = GetVectorDistance(g_fClientOrigin, g_fTargetOrigin);
- g_iPlayerGrabTarget[client] = target;
- g_bIsGrabbingPerson[client] = true;
- SetEntityMoveType(target, MOVETYPE_NONE);
- SDKHook(target, SDKHook_OnTakeDamage, GrabbedTarget_TakeDamage);
- }
- public void ReleasePlayer(int client)
- {
- SetEntityMoveType(g_iPlayerGrabTarget[client], MOVETYPE_WALK);
- SDKUnhook(g_iPlayerGrabTarget[client], SDKHook_OnTakeDamage, GrabbedTarget_TakeDamage);
- g_iPlayerGrabTarget[client] = 0;
- g_bIsGrabbingPerson[client] = false;
- g_fDistanceGrabbing[client] = 0.0;
- }
- public void SetupLaser(int client, int target)
- {
- TE_SetupBeamLaser(client, target, g_iBeamSprite, g_iHaloSprite, 0, 30, 0.1, 6.0, 6.0, 5, 6.0, { 254, 0, 0, 125 }, 1);
- TE_SendToAll();
- }
- stock bool IsValidClient(int client)
- {
- return (client >= 1 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && !IsClientSourceTV(client));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement