Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <dhooks>
- #include <sdktools>
- new Handle:hSequenceSet;
- new Handle:sdkDoAnim;
- static clienthook[MAXPLAYERS + 1] = -1;
- static clone[MAXPLAYERS + 1] = -1;
- #define ANIM_NICK 631
- #define ANIM_ELLIS 636
- #define ANIM_ROCH 639
- #define ANIM_ZOEY 529
- #define ANIM_LOUIS 539
- #define ANIM_FRANCIS 542
- #define ANIM_BILL 539
- static const String:MODEL_NICK[] = "models/survivors/survivor_gambler.mdl";
- static const String:MODEL_ROCHELLE[] = "models/survivors/survivor_producer.mdl";
- static const String:MODEL_COACH[] = "models/survivors/survivor_coach.mdl";
- static const String:MODEL_ELLIS[] = "models/survivors/survivor_mechanic.mdl";
- static const String:MODEL_BILL[] = "models/survivors/survivor_namvet.mdl";
- static const String:MODEL_ZOEY[] = "models/survivors/survivor_teenangst.mdl";
- static const String:MODEL_FRANCIS[] = "models/survivors/survivor_biker.mdl";
- static const String:MODEL_LOUIS[] = "models/survivors/survivor_manager.mdl";
- public Plugin:myinfo =
- {
- name = "L4D2 DHook Test",
- author = "DeathChaos25",
- description = "",
- version = "",
- url = ""
- }
- public OnPluginStart()
- {
- SetConVarInt(FindConVar("survivor_allow_crawling"), 1);
- SetConVarInt(FindConVar("survivor_crawl_speed"), 35);
- LoadOffset();
- PrepSDKCall();
- RegConsoleCmd("sm_hook", HOOKME);
- }
- public OnGameFrame()
- {
- for (new client = 1; client <= MaxClients; client++)
- {
- if (!IsClientInGame(client))return;
- new buttons = GetClientButtons(client);
- if (IsSurvivor(client) && IsPlayerAlive(client) && !IsPlayerHeld(client)
- && GetEntProp(client, Prop_Send, "m_isHangingFromLedge") != 1
- && GetEntProp(client, Prop_Send, "m_reviveOwner") == -1 && IsIncapacitated(client) && buttons & IN_FORWARD)
- {
- new String:model[128];
- GetClientModel(client, model, sizeof(model));
- if (StrEqual(model, MODEL_COACH))return;
- if (clienthook[client] != 1)
- {
- GotoThirdPerson(client);
- clienthook[client] = DHookEntity(hSequenceSet, false, client);
- SDKCall(sdkDoAnim, client, 71, 0);
- if(StrEqual(model, MODEL_ZOEY))
- {
- SetEntProp(client, Prop_Send, "m_nSequence", ANIM_ZOEY);
- }
- else if(StrEqual(model, MODEL_NICK))
- {
- SetEntProp(client, Prop_Send, "m_nSequence", ANIM_NICK);
- }
- else if(StrEqual(model, MODEL_ELLIS))
- {
- SetEntProp(client, Prop_Send, "m_nSequence", ANIM_ELLIS);
- }
- else if(StrEqual(model, MODEL_ROCHELLE))
- {
- SetEntProp(client, Prop_Send, "m_nSequence", ANIM_ROCH);
- }
- else if(StrEqual(model, MODEL_BILL))
- {
- SetEntProp(client, Prop_Send, "m_nSequence", ANIM_BILL);
- }
- else if(StrEqual(model, MODEL_FRANCIS))
- {
- SetEntProp(client, Prop_Send, "m_nSequence", ANIM_FRANCIS);
- }
- else if(StrEqual(model, MODEL_LOUIS))
- {
- SetEntProp(client, Prop_Send, "m_nSequence", ANIM_LOUIS);
- }
- }
- }
- else if (IsSurvivor(client) && IsPlayerAlive(client) && GetEntProp(client, Prop_Send, "m_isHangingFromLedge") != 1 && IsIncapacitated(client))
- {
- SDKCall(sdkDoAnim, client, 20, 0);
- if (clienthook[client] > 0)
- {
- DHookRemoveHookID(clienthook[client]);
- GotoFirstPerson(client);
- clienthook[client] = -1;
- }
- }
- }
- }
- public Action:HOOKME(client, args)
- {
- if (IsSurvivor(client))
- {
- if (clienthook[client] > 0)
- {
- DHookRemoveHookID(clienthook[client]);
- clienthook[client] = -1;
- }
- else clienthook[client] = DHookEntity(hSequenceSet, true, client);
- }
- else ReplyToCommand(client, "Must be an ingame survivor to use this command!");
- }
- public MRESReturn:OnSequenceSet(client, Handle:hParams)
- {
- return MRES_Ignored;
- }
- bool:IsSurvivor(client)
- {
- return (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2);
- }
- LoadOffset()
- {
- new Handle:temp = LoadGameConfigFile("l4d2_sequence");
- if (temp == INVALID_HANDLE)
- {
- SetFailState("Error: Gamedata not found");
- }
- new offset;
- offset = GameConfGetOffset(temp, "CTerrorPlayer::SelectWeightedSequence");
- if (offset == -1)
- {
- CloseHandle(temp);
- LogError("Unable to get offset for CTerrorPlayer::SelectWeightedSequence");
- return;
- }
- hSequenceSet = DHookCreate(offset, HookType_Entity, ReturnType_Void, ThisPointer_CBaseEntity, OnSequenceSet);
- DHookAddParam(hSequenceSet, HookParamType_Int);
- }
- stock bool:IsPlayerHeld(client)
- {
- new jockey = GetEntPropEnt(client, Prop_Send, "m_jockeyAttacker");
- new charger = GetEntPropEnt(client, Prop_Send, "m_pummelAttacker");
- new hunter = GetEntPropEnt(client, Prop_Send, "m_pounceAttacker");
- new smoker = GetEntPropEnt(client, Prop_Send, "m_tongueOwner");
- if (jockey > 0 || charger > 0 || hunter > 0 || smoker > 0)
- {
- return true;
- }
- return false;
- }
- stock bool:IsIncapacitated(client)
- {
- if (GetEntProp(client, Prop_Send, "m_isIncapacitated", 1) > 0)
- return true;
- return false;
- }
- static PrepSDKCall()
- {
- new Handle:config = LoadGameConfigFile("l4d2_sequence");
- if (config == INVALID_HANDLE)
- {
- SetFailState("Error: unable to load l4d2_sequence gamedata file");
- }
- StartPrepSDKCall(SDKCall_Player);
- if (!PrepSDKCall_SetFromConf(config, SDKConf_Virtual, "CTerrorPlayer::DoAnimationEvent"))
- {
- CloseHandle(config);
- SetFailState("Cant find CTerrorPlayer::DoAnimationEvent Signature in gamedata file");
- }
- PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
- PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
- CloseHandle(config);
- sdkDoAnim = EndPrepSDKCall();
- if (sdkDoAnim == INVALID_HANDLE)
- {
- SetFailState("Cant initialize CTerrorPlayer::DoAnimationEvent SDKCall, Signature broken");
- }
- }
- GotoThirdPerson(client)
- {
- SetEntPropFloat(client, Prop_Send, "m_TimeForceExternalView", 99999.3);
- }
- GotoFirstPerson(client)
- {
- SetEntPropFloat(client, Prop_Send, "m_TimeForceExternalView", 0.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment