AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   Automatic func_tanks in Counter Strike (https://forums.alliedmods.net/showthread.php?t=126074)

joaquimandrade 05-05-2010 07:26

Automatic func_tanks in Counter Strike
 
1 Attachment(s)
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 :P.

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 :D

Example map: http://www.fpsbanana.com/maps/1080

capostrike93 05-05-2010 07:48

Re: Automatic func_tanks in Counter Strike
 
Demonstration video: ...

http://www.xfire.com/video/29f364/

please see 2:25 minutes

here useful example:

PHP Code:

#include <amxmodx>
#include <orpheu>
#include <orpheu_stocks>
#include <fakemeta>
#include <hamsandwich>
#include <xs>

#define KILL_ONLYT // Kill only Terrorist Team...
// #define KILL_ONLYCT // Kill only Counter-Terrorist Team...
// #define ZOMBIEPLAGUE // For zombie plague mod...

#if defined ZOMBIEPLAGUE
#include <zombieplague>
#elseif defined KILL_ONLYT || defined KILL_ONLYCT
#include <cstrike>
#endif

public plugin_precache()
{
    
register_plugin("Example Advanced Spawn Tank","1.0","capostrike93/joaquim")
    
RegisterHam(Ham_Spawn,"func_tank","spawnTank",1)    
    
OrpheuRegisterHook(OrpheuGetEngineFunction("pfnFindClientInPVS","FindClientInPVS"),"OnFindClientInPVS")
}

public 
spawnTank(id)
{
    
set_pev(id,pev_spawnflagsSF_TANK_ACTIVE SF_TANK_PLAYER SF_TANK_HUMANS SF_TANK_CANCONTROL SF_TANK_SOUNDON)
    
dllfunc(DLLFunc_Think,id)
    
set_pdata_float(id,41,360.0,4)
}

public 
OrpheuHookReturn:OnFindClientInPVS(id)
{
    
OrpheuSetReturn(findCloserPlayer(id))
    return 
OrpheuSupercede
}

findCloserPlayer(id)
{
    new 
Float:originFTank[3]
    
pev(id,pev_origin,originFTank)
    
    static
    
Float:originFPlayer[3],
    
Float:Distance,
    
Float:CloserDistance;

    
// Reset Distance
    
CloserDistance 999999.0;
    
    new 
CloserPlayer
    
    
for(new i;i<33;i++)
    {
        if(!
is_user_alive(i)) continue
        
#if defined ZP
        
if(!zp_get_user_zombie(i)) continue
        
#endif
        #if defined KILL_ONLYT
        
if(cs_get_user_team(i) != CS_TEAM_T) continue
        
#endif
        #if defined KILL_ONLYCT
        
if(cs_get_user_team(i) != CS_TEAM_CT) continue
        
#endif
        
        
pev(i,pev_origin,originFPlayer)
        
        
Distance get_distance_f(originFTank,originFPlayer)
        if(
CloserDistance Distance)
        {
            
CloserPlayer i;
            
CloserDistance Distance;
        }
    }
    
    return 
CloserPlayer;


set_pdata_float(id,41,360.0,4) // For full rotation (360º)

fezh 05-05-2010 13:01

Re: Automatic func_tanks in Counter Strike
 
Good stuff, gonna test it.

capostrike93 05-05-2010 19:36

Re: Automatic func_tanks in Counter Strike
 
set_pdata_float(id,41,360.0,4) // For full rotation (360º)

AntiBots 05-05-2010 20:44

Re: Automatic func_tanks in Counter Strike
 
Caostrike, you example they will only shoot people with the last index in the Radio.

You understand me?

joropito 05-05-2010 21:41

Re: Automatic func_tanks in Counter Strike
 
It works using fakemeNta too

(I'm using random 1-32 because I'm too lazy to make it better :P)

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

public plugin_init()
{
        
register_forward(FM_FindClientInPVS"findclientinpvs")
}

public 
plugin_precache()
{
        
RegisterHam(Ham_Spawn,"func_tank","spawnTank",1)
}

public 
spawnTank(id)
{
        
set_pev(id,pev_spawnflagsSF_TANK_ACTIVE SF_TANK_PLAYER SF_TANK_HUMANS SF_TANK_CANCONTROL SF_TANK_SOUNDON)
        
dllfunc(DLLFunc_Think,id)
}

public 
findclientinpvs(id)
{
        static class[
32]
        if(
pev_valid(id))
        {
                
pev(idpev_classname, class, charsmax(class))
                if(
equal(class, "func_tank"))
                {
                        
forward_return(FMV_CELLrandom_num(132))
                        return 
FMRES_SUPERCEDE
                
}
        }
        return 
FMRES_IGNORED



joaquimandrade 05-05-2010 21:47

Re: Automatic func_tanks in Counter Strike
 
But have you tested? When I tested, FM_FindClientInPVS didn't get called.

joropito 05-05-2010 21:48

Re: Automatic func_tanks in Counter Strike
 
Yes, I have tested.

Maybe you miss using forward_return or you use findentityinpvs instead of clientinpvs, I don't know but it's working.

joaquimandrade 05-05-2010 21:51

Re: Automatic func_tanks in Counter Strike
 
Quote:

Originally Posted by joropito (Post 1172098)
Yes, I have tested.

Maybe you miss using forward_return or you use findentityinpvs instead of clientinpvs, I don't know but it's working.

I remember testing the right forward but anyway, if it works, it works.

joropito 05-05-2010 21:52

Re: Automatic func_tanks in Counter Strike
 
Here's the key name/values used for func_tank
(cs_rats2_final example values)

Code:

model *174
origin -35 576 -198
rotatesound ambience/turretrot1.wav
rendermode 0
renderfx 0
spriteflash sprites/muzzleflash2.spr
bullet 3
maxRange 0
minRange 0
firespread 1
persistence 1
bullet_damage 15
firerate 15
spritescale 1
barrelz 7
barrely 0
barrel 66
pitchtolerance 5
pitchrange 75
pitchrate 500
yawtolerance 15
yawrange 55
yawrate 500
target boom
rendercolor 0 0 0
renderamt 0
targetname gunny
spawnflags 32



All times are GMT -4. The time now is 17:39.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.