ValveSoftware / source-sdk-2013

The 2013 edition of the Source SDK
https://developer.valvesoftware.com/wiki/SDK2013_GettingStarted
Other
3.7k stars 1.99k forks source link

Zombines never pull their grenades out - zombine.cpp #425

Open Ethorbit opened 7 years ago

Ethorbit commented 7 years ago

Been tampering with this for a bit now, for the life of me I can't get the zombines to pull their grenades out. Just wanna say that they never pulled their grenades out before and after my tampering. I believe this is broken.

NicolasDe commented 7 years ago

Everything works fine on my end, make sure you haven't changed some AI or grenade code.

Ethorbit commented 7 years ago

Just reset it and zombines (Z)ombines not combine still don't pull their grenades out, I'm trying this in Half-Life 2: Deathmatch

Ethorbit commented 7 years ago

Just tested this with a fresh install of source-sdk-2013, and still NO GRENADE. This is an official issue, not a bug on my part.

neico commented 7 years ago

tried to manually trigger the grenade via ent_fire input to see if it fires at all?

Ethorbit commented 7 years ago

I manually forced them to pull out grenades in the code, but now the grenades only hurt the zombine that pulled the grenade.

An example, a zombine pulls a grenade out by a player and 2 other zombines. The zombine that pulled the grenade out dies, the 2 zombines and the player untouched.

neico commented 7 years ago

Forcing it from the code isn't really the same as using the input, and the input test is quickly doable...

Since you're trying them on hl2mp, did you put a HL2_EPISODIC define in the vpc file? Did you fix the AI_GetSinglePlayer() behavior to work with multiplayer? Did you fix the relationships?

See https://developer.valvesoftware.com/wiki/Fixing_AI_in_multiplayer

Ethorbit commented 7 years ago

Can you provide the fixes since you know so much about it? I mean these are fixes they need to implement. Even then, I don't think AI_GetSinglePlayer() is the cause for the grenades not popping out or the grenades not dealing any damage.

I also used one of the forks which already fixed the zombie AI, every other zombie is working fine.

neico commented 7 years ago

Well without a relationship neither the grenade nor the zombine know who is hurtable (neutral's can't hurt each other which is the default)

And the code here checks using AI_GetSinglePlayer() if there's a player nearby, and only then tries to throw a grenade

You basically need to move a lot of singleplayer code over to multiplayer, making AI more difficult to use. The fork that's linked in the wiki page seems rather outdated and is probably only useful if you want to see the diff.

Technically adding the code is rather easy, you just need to make sure that HL2MP_GameRules HL2MPPlayer etc. derive from their HL2 variants as those already contain the needed code for relationship.

The next step is adding / using UTIL_GetLocalHost / UTIL_GetLocalPlayer & UTIL_GetClosestPlayer and adjusting the AI_GetSinglePlayer() references. (can be easily done with tools like Notepad++)

And then some other small misc fixes, which are irrelevant for your issue though.

This fork might also be worth looking through as tony was originally assigned with maintaining the Source SDK (back with the 2007 branch an before): https://github.com/tonysergi/source-sdk-2013

PS: I can't really share "my" code with you, since the only code base I have access to which has similar changes implemented is in Obsidian Conflict (which isn't open source).
Though I plan to eventually create a repo on the above mentioned GitLab group with a proper base for both sp and mp mods, in which I might actually add those changes as well, but I can't really tell whenever this will happen...

Ethorbit commented 7 years ago

Just to get it straight, I have fastzombies working normally in my server, but IT even has AI_GetSinglePlayer() in it, you're saying to use UTIL_GetLocalHost / UTIL_GetLocalPlayer & UTIL_GetClosestPlayer and adjusting the AI_GetSinglePlayer() references, but are you saying I can use any of these?

I'd suspect UTIL_GetClosestPlayer() is what I'd want for a zombine. PS: I've already converted the HL2 stuff to HL2MP.

Either way, I'll mess with these and see if it fixes my issue, thank you for the very detailed reply.

Ethorbit commented 7 years ago

Changing CBasePlayer *pPlayer = AI_GetSinglePlayer(); to CBasePlayer *pPlayer = UTIL_GetNearestPlayer(GetAbsOrigin()); around line 417 throws this huge error at me. I've already tried the other ones you listed, but they don't change anything. I've already set the relationships right and have already manually gone through each valve fixing AI tutorial there ever is. I don't know what to add in a vpc file that will fix a zombine not deploying their grenades.

npc_zombine.obj : error LNK2019: unresolved external symbol "class CBasePlayer * cdecl UTIL_GetNearestPlayer(class Vector const &)" (?UTIL_GetNearestPlayer@@YAPAVCBasePlayer@@ABVVector@@@Z) referenced in function "public: void thiscall CNPC_Zombine::GatherGrenadeConditions(void)" (?GatherGrenadeConditions@CNPC_Zombine@@QAEXXZ)

I hope you can respond again, you've helped, but the problem still remains.

neico commented 7 years ago

The error sounds like you're missing the actual function implementation in util.cpp

starting with this line are those useful UTIL's: https://gitlab.com/source1/2013/sdk/blob/mp-src/game/server/util.cpp#L560

you will want to add UTIL_GetNearestPlayer below UTIL_GetListenServerHost, see https://github.com/stephsch/Fixing_AI_In_Multiplayer/blob/master/mp/src/game/server/util.cpp#L637

Though I'd probably use this variant instead:

CBasePlayer* UTIL_GetClosestPlayer( const Vector &vOrigin, void* pFilter = NULL )
{
    CBasePlayer* pClosestPlayer = NULL;
    float fMinDistance = MAX_TRACE_LENGTH * MAX_TRACE_LENGTH;

    for( int i = 1; i <= gpGlobals->maxClients; i++ )
    {
        CBasePlayer* pPlayer = UTIL_PlayerByIndex( i );
        if( !pPlayer || !pPlayer->IsConnected() ) continue;

        float fDistance = ( pPlayer->GetAbsOrigin() - vOrigin ).LengthSqr();
        if( fDistance < fMinDistance && ( pFilter ? pFilter( pPlayer, fDistance ) : true ) )
        {
            fMinDistance = fDistance;
            pClosestPlayer = pPlayer;
        }
    }

    return pClosestPlayer;
}

PS: the filter part could be probably done better, but I don't have the right tools at me to do so currently...

Ethorbit commented 7 years ago

I got the UTIL_GetClosestPlayer to work after applying the util.cpp stuff, but the zombine still doesn't pull out its grenade, I'm actually gonna stop here and give up as my zombie mod is just a remake and zombines were never originally in it so I don't really have to go through all of this hard work just to get a zombine to pull out a grenade and hurt players.

If anyone gets a working zombine on multiplayer feel free to share your fixes here.

neico commented 7 years ago

I've gone over the zombine code again within OC as they work fine there, and there really isn't anything else to it beside the AI_GetSinglePlayer change that's related to your issue.

You did mention a fix inside BaseZombie, so I checked that file as well, there isn't even a change related to AI present, so maybe that's another point to take a look at? I at least don't know of a fix that should be applied there...

Also you asked about the VPC earlier:

game\server\server_obsidian.vpc / game\client\client_obsidian.vpc

...

$Configuration
{
    $Compiler
    {
        $AdditionalIncludeDirectories   "$BASE;$SRCDIR\game\shared\hl2,.\hl2,.\hl2mp,$SRCDIR\game\shared\hl2mp,.\episodic,$SRCDIR\game\shared\episodic"
        $AdditionalIncludeDirectories   "$BASE;.\obsidian,$SRCDIR\game\shared\obsidian,$SRCDIR\game\shared\Multiplayer"
        $PreprocessorDefinitions        "$BASE;HL2MP;HL2_DLL"
        $PreprocessorDefinitions        "$BASE;HL2_EPISODIC;OBSIDIAN"
    }
}

...

In case you never worked with VPC: You should take a look at the hl2mp files to get a glimpse in how to make those files (in fact copy the file for your mod)
Just make sure to also adjust vpc_scripts\default.vgc and vpc_scripts\projects.vgc to include your mod specific define (again, look at the hl2mp variant and see how it works) as well as the build scripts in the src root