Hello. I was searching for random functions to test with orpheu and got curious about func_tanks. They have auto aiming and shooting functionality but it doesn't work out of the box in CS so I tried to unlock it. The process is easy: we just have to make them think, have basic flags, and override its search for players because it's code inherited from halflife searches for players in PVS but it seems that they don't have one in CS
.
The code:
Code:
public plugin_precache()
{
RegisterHam(Ham_Spawn,"func_tank","spawnTank",1)
OrpheuRegisterHook(OrpheuGetEngineFunction("pfnFindClientInPVS","FindClientInPVS"),"OnFindClientInPVS")
}
public spawnTank(id)
{
set_pev(id,pev_spawnflags, SF_TANK_ACTIVE | SF_TANK_PLAYER | SF_TANK_HUMANS | SF_TANK_CANCONTROL | SF_TANK_SOUNDON)
dllfunc(DLLFunc_Think,id)
}
public OrpheuHookReturn:OnFindClientInPVS(id)
{
OrpheuSetReturn(find_ent_by_class(0,"player"))
return OrpheuSupercede
}
Arkshine told me that the only flag really needed is SF_TANK_ACTIVE and you can see more about them in hlsdk.
If you want to use this code in a zombie server or something like that just change the function
OnFindClientInPVS and use on it an algorithm of yours to find a player to shoot at (like the closer zombie or whatever).
Final notes:
It almost could be made without orpheu because fakemeta also provides hooking for FindClientInPVS but I tested it and it didn't get called.
Offsets for CFuncTank -
http://wiki.amxmodx.org/CFuncTank_%28CS%29
FindClientInPVS can be also called in more situations for other entities (though is unusual) so you might want to add it's hook an extra check to see if it is a func_tank using it.
Thanks to Capostrike for testing with me
Example map:
http://www.fpsbanana.com/maps/1080