|
Great Tester of Whatever
|
12-28-2020
, 03:27
Re: [L4D2] Witch target override in better way?
|
#3
|
My old practices, they work but as far as I remember the server will crash if you change the target when the witch is not scared yet
You can also literally change the target to any entity and patch the WitchAttack::IsValidEnemy function so the witch can run after anyone and not just survivors
Spoiler
PHP Code:
#pragma semicolon 1 #pragma newdecls required
#include <sourcemod> #include <sdktools>
static const int byte[] = { 0x1CC8, 0x1C, 0x8, 0x10, 0x10 }; public void OnPluginStart() { RegConsoleCmd("sm_insult", sm_insult); }
public Action sm_insult ( int client, int args ) { int client = GetClientAimTarget(client); if ( client == -1 ) return; int witch = MaxClients + 1, target; while ( (witch = FindEntityByClassname(witch, "witch")) && IsValidEntity(witch) ) { target = GetCurrentWitchTarget(witch); if ( target == -1 ) /* So the witch had lost her target or didn't have one yet */ continue; PrintToChatAll("Current target is %i changing to %i", target, client); ChangeWitchTarget(witch, client); } }
int GetCurrentWitchTarget (int witch) { Address behavior = GetEntityAddress(witch); for ( int i; i < sizeof byte; i++ ) { if ( behavior == Address_Null ) return -1; behavior = view_as<Address>(LoadFromAddress(behavior + view_as<Address>(byte[i]), NumberType_Int32)); } for ( int i = 1; i <= MaxClients; i++ ) { if ( !IsValidEntity(i) ) continue; if ( LoadFromAddress(GetEntityAsRef(i), NumberType_Int32) == LoadFromAddress(behavior + view_as<Address>(0x34), NumberType_Int32) ) return i; } return -1; }
bool ChangeWitchTarget (int witch, int target) { Address behavior = GetEntityAddress(witch);
for ( int i; i < sizeof byte; i++ ) { if ( behavior == Address_Null ) return false; behavior = view_as<Address>(LoadFromAddress(behavior + view_as<Address>(byte[i]), NumberType_Int32)); } StoreToAddress(behavior + view_as<Address>(0x34), LoadFromAddress(GetEntityAsRef(target), NumberType_Int32), NumberType_Int32); StoreToAddress(behavior + view_as<Address>(56), 8, NumberType_Int32); return true; }
Address GetEntityAsRef (int entity) { static Handle call; if ( !call ) { StartPrepSDKCall(SDKCall_Entity); PrepSDKCall_SetAddress(view_as<Address>(LoadFromAddress(view_as<Address>(LoadFromAddress(GetEntityAddress(entity), NumberType_Int32) + 8), NumberType_Int32))); PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain); call = EndPrepSDKCall(); } return view_as<Address>(SDKCall(call, entity)); }
Note:
If this still works then I might try to make a more advanced version and this is for windows only
__________________
Last edited by BHaType; 12-28-2020 at 03:29.
|
|
|
|