Talk:Fixing AI in multiplayer
I'm not 100% sure, but I think this sentence was wrong (so I corrected it, I hope): "With this table NPCs won't know which entities to hate/like" --Andreasen 07:22, 26 Aug 2006 (PDT)
- You are right--dutchmega 07:36, 26 Aug 2006 (PDT)
why combine can not shoot ?? --Test 05:19, 30 Sep 2006 (PDT)
- Some more info would be nice --dutchmega 12:37, 30 Sep 2006 (PDT)
- Agree --Rookie 04:57, 4 Oct 2006 (PDT)
this Fixing AI in multiplayer cannot make a combine shoot ?? or u can post full code ? plz --Test 09:14, 1 Oct 2006 (PDT)
- Translated: "This tutorial cannot make a combine shoot. Can you explain why they can't do this, or post the neccessary code for fixing this, please?" --Andreasen 05:19, 4 Oct 2006 (PDT)
- Anyway,I want to make a combine shoot but i can't find any tutorial for my problem.Also the zombie make clash my mod when i spawn it. --Rookie 08:16, 4 Oct 2006 (PDT)
- "Make clash"? You are saying that the zombie crashes the game when it is spawned? Are you from Japan or something? --Andreasen 08:37, 4 Oct 2006 (PDT)
- Yes it crash my server but fast zombie doesn't.ONLY the zombie.(I am a hong kong secondary school student,what the clash and crash different? ) Rookie
- "Make clash"? You are saying that the zombie crashes the game when it is spawned? Are you from Japan or something? --Andreasen 08:37, 4 Oct 2006 (PDT)
- Anyway,I want to make a combine shoot but i can't find any tutorial for my problem.Also the zombie make clash my mod when i spawn it. --Rookie 08:16, 4 Oct 2006 (PDT)
I can't post the entire code.. What do the Combine do? Do they shoot with good animations but bullets don't hit? They have no animations but bullets hit? Or something else? And if you can't debug crashes, I'm not sure you should even be allowed near the HL2 modcode... :P --dutchmega 09:20, 4 Oct 2006 (PDT)
- Judging by how the article ends, in some kind of "This isn't really an article about fixing the AI in multiplayer.", I think it's more a question about finishing the article. I think he has done as the article says, but that that isn't enough to fix things. --Andreasen 01:57, 5 Oct 2006 (PDT)
- Agree AgreeRookie
Hey Thomas...
I found my way to this tutorial (and the previous one) after accomplishing the same basic thing, but I am still having trouble. I cant seem to get any of the combine soldiers use thier weapons. They hit (using meylee attack), but cannot use thier weapons. So this cant be a relationship problem. Is it a problem of them just not recognizing the HL2mp weapons or have i just not included the correct ai code??
Buddy
This problem is not actualy due to anything related to relationships or whatever: this is caused by HL2DM animations! Indeed, the issue is due to the Combine Soldiers' animations. You have to move default HL2DM players animations to an other directory then you add Half-Life 2 SP character models in the MODDIR\models folder. You eventually have to edit the HL2DM code to change the player models names.
NOTE: this fix is very hard to do, you have to Hex-edit the player models to make them work! Then everything should work. Good luck!
--Thomas
- I was not able to get models other than HL2DM to load without crashing the game. I'm sure I'm just not doing it right. I've resorted to changing the appid to 218, and then manually extracting all the HL2DM content OTHER THAN MODELS to my mod directory. It's working but I'd rather use appid 320 and override just the models as described instead if I can figure it out. Would anyone be interested in typing a more detailed (and up to date with impact of the latest SDK) explination of what needs done to get models with the correct animations for AI pulled into the mod? --Schroe2a 06:00, 1 Jul 2008 (PDT)
Didn't work
That didn't seem to work. I tried what you said, and I just repaced all the model/animation files with the right ones. That didn't work. So, I extracted all of the models from the HL2 GFC and put them in my mod's model folder. Still didn't work. Finally, I extracted all of Half-Life 2 and just left the server and client DLL in, but it still didn't work. I no longer get errors when in developer mode about missing animations on the NPC's, but the combine just stand around. The "police" will chase after me, but they won't hit me or shoot me. It could be a weapon problem, maybe an ammo problem. I think they don't know how to use thier weapons. Please help. --General Eskimo
General Eskimo
This problem is not actualy due to anything related to the code or the weapons. Metropolices won't attack you because this is a HL2DM SDK issue. Many programmers did not manage to fix it. You can make Combine Soldiers work, but Metropolices won't work! Thus I suggest you to work with others NPCs than Metropolices. Anyway, I will try to find a way to make them work! Then I'll provide you the trick! Yours.
--Thomas
No NPC's can shoot
It is not just the metropolice. All NPC's that carry weapons will not shoot. Is there some way I can make sure they have amunition? Something is definately not working other than just the Police. ^Ben
This is simply because MP code removed the NPC shot handling code...you can simply retrieve the hl2 code for the weapon and copy over the animation handling code—ts2do 17:39, 12 Feb 2006 (PST)
If anybody knows where this code is, please let us know. I have searched over the codebase but can't find any clues to where it may be. ^Ben
This code is in the singleplayer code...like I just said...what do you have a problem finding?—ts2do 16:52, 13 Feb 2006 (PST)
Well at the moment I am using the weapon code from HL2MP and I'm using it in conjunction with the HL2MP files(in the hl2mp_dll referencing all the header files for HL2MP) the NPC's run around and they "dry" fire, so they basically have the shooting animation and the muzzle flash and shells work, but no actual shots. It has me stumped. ^Ben 18:06, 13 Feb 2006 (PST)
So what I'm saying is copy over specific animation event handling stuff from the singleplayer weapon code so they do shoot..—ts2do 19:09, 13 Feb 2006 (PST)
This is where I am confused, I have got all the animation code that I can think of from single player, I am currently using the singleplayer SMG1 code, I'm also using the singleplayer combine code. Is there any other animation handling code I should belooking for.
Edit from Thomas
In have an idea. We should check if the bullet-shots are not triggered by a specific event called in the animation. I mean we could have an event called at a specific frame in the shooting animation, and then the game deals with it to make the NPC fire. What do you think about that speculation?
Yours.
(Generaleskimo)- well, why is it that the snipers in c17 will shoot at you? are they NPCs? I cant even seem to find the link between the animation in the HL2 code and the code for firing the weapon for NPCs. Under one of the "firebullet" functions it says "only the player uses this", so what shooting code does the npc use? (Generaleskimo)
The code specifically uses weapon based animations and animation handling events declared in the weapon code to fire—ts2do 11:31, 26 Feb 2006 (PST)
This is in the singleplayer SMG code.
void Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ) { switch( pEvent->event ) { case EVENT_WEAPON_SMG1: { Vector vecShootOrigin, vecShootDir; QAngle angDiscard; if ((pEvent->options == NULL) || (pEvent->options[0] == '\0') || (!pOperator->GetAttachment(pEvent->options, vecShootOrigin, angDiscard))) { vecShootOrigin = pOperator->Weapon_ShootPosition(); } CAI_BaseNPC *npc = pOperator->MyNPCPointer(); ASSERT( npc != NULL ); vecShootDir = npc->GetActualShootTrajectory( vecShootOrigin ); // FIXME: use the returned number of bullets to account for >10hz firerate WeaponSoundRealtime( SINGLE_NPC ); CSoundEnt::InsertSound( SOUND_COMBAT, pOperator->GetAbsOrigin(), SOUNDENT_VOLUME_MACHINEGUN, 0.2, pOperator ); pOperator->FireBullets( 1, vecShootOrigin, vecShootDir, VECTOR_CONE_PRECALCULATED, MAX_TRACE_LENGTH, m_iPrimaryAmmoType, 2, entindex(), 0 ); pOperator->DoMuzzleFlash(); m_iClip1 = m_iClip1 - 1; } break; /*//FIXME: Re-enable case EVENT_WEAPON_AR2_GRENADE: { CAI_BaseNPC *npc = pOperator->MyNPCPointer(); Vector vecShootOrigin, vecShootDir; vecShootOrigin = pOperator->Weapon_ShootPosition(); vecShootDir = npc->GetShootEnemyDir( vecShootOrigin ); Vector vecThrow = m_vecTossVelocity; CGrenadeAR2 *pGrenade = (CGrenadeAR2*)Create( "grenade_ar2", vecShootOrigin, vec3_angle, npc ); pGrenade->SetAbsVelocity( vecThrow ); pGrenade->SetLocalAngularVelocity( QAngle( 0, 400, 0 ) ); pGrenade->SetMoveType( MOVETYPE_FLYGRAVITY ); pGrenade->m_hOwner = npc; pGrenade->m_pMyWeaponAR2 = this; pGrenade->SetDamage(sk_npc_dmg_ar2_grenade.GetFloat()); // FIXME: arrgg ,this is hard coded into the weapon??? m_flNextGrenadeCheck = gpGlobals->curtime + 6;// wait six seconds before even looking again to see if a grenade can be thrown. m_iClip2--; } break; */ default: BaseClass::Operator_HandleAnimEvent( pEvent, pOperator ); break; } }
^Ben 12:23, 26 Feb 2006 (PST)
Edit from Thomas
Does your code fix the problem? It doesn't fix anything for me :-(
Yours
Edit from Thomas
Probem solved. NPCs can shoot now. Report tge other bugs ;o) Yours
--
Edit by dutchmega Added some little notes and 1 include. It works now here :)
--
THOMAS: OK! Thanks ;o)
One Last Problem...
There is one last problem. How do you get the ai to bleed. It works if cl_predict is 0, so it is something as simple as adding a prediction table. I when I figured that out, I thought "oh, so it's really simple, right?", but I have been having some trouble getting it to work. Help me make my ai bleed. I love the blood. It's all... good-like. --General Eskimo
EDIT FROM THOMAS: General Eskimo, I don't know how to help, sorry :-|
Metropolice with stunstick
How the hell do you fix metropolice with a stunstick? They run towards me but it can't hit me really. I also don't see the animation for it...
EDIT FROM THOMAS: Well, there is no way to fix that damn metropolice, I hope Valve will do something.
- Well, it's is fixed in the mod Synergy but it's coder isn't very helpfull.. -- dutchmega
Ts2Do's Suggestion
Thank you for your tip Ts2Do. It really helps. By the way, I can't specify that instruction
m_flexWeight[index] = value;
I must let the original one as the compiler generates errors with your code. Any idea? Yours.
--Thomas
And is the rest of the CBaseFlex class usefull? It would save more network bandwidth ;) --dutchmega
It worked for me for a couple of days, then, without changing anything (i was really tired) i recompiled and it has an error! Just leave that line alone for now, it doesn't get as much network traffic as the other one. I am not looking at the code right now, but it is just an integer right? Works fine if that transmits. --General Eskimo
The changes to the flex array sending has made certain npcs that have eyes look in the wrong direction all the time, at least from what I see in game.--Skidz 16:22, 16 May 2006 (PDT)
Thumbs up
This code works pefectly if you don't happen to make stupid misstakes like i did. :D TheSpaceMan 07:37, 24 Jun 2006 (PDT)
This article is about generally fixing AI in multiplayer. If you really want to fix all NPCs, this article gets 5-10 times longer... Anyway, if you think I've forget something, feel free to add it... --dutchmega 06:05, 5 Oct 2006 (PDT)
- "Function calls". --Rookie
- My combine in my mod have they animations but they don't shoot,just throw the flags and hit player with gun when player close to them.(not shooting but hurt,i don't know what word i should use--Rookie
Yes, it probably would be longer, but then we could divide it into sub pages if neccessary. Co-op is very, very fun once implemented, and Sven Coop 2 seems like it will take forever to finish. Of course we lack the coding skills to do this ourselves, which is why we turn to the wiki to tell us what we should add and not. If we could do this by ourselves, we wouldn't need the wiki for it. --Andreasen 07:47, 5 Oct 2006 (PDT)
- I love being a jerk. Last time I counted, there were over 3000 calls that need fixing. Anyway, about the Combine not shooting. It should work but should is a nasty word. Try my weapon_smg1.cpp. If that doesn't work, I'll look if the article misses something after doing my Java-homework --dutchmega 09:28, 5 Oct 2006 (PDT)
- 3000 calls?? Then I understand you. I thought it was under 25. --Andreasen 10:00, 5 Oct 2006 (PDT)
- I've put that last sentence in the article for a reason :) --dutchmega 12:29, 5 Oct 2006 (PDT)
- Replace the weapon_smg1.cpp with this one the combine still don't shoot. :( -- Rookie
Is it just me or is this no longer working? I have copied HL2's AIRelationships function and it compiles fine, and made sure I have the EP1 models, but not even simple zombies work. Only seconds after adding them into the game with the npc_create command, it crashes to desktop. If I load an existing map that already has zombies, it crashes to desktop before it finishes loading the level. Just trying to get zombies to work for now. Did I miss something? --Wildfire 22:16, 12 Feb 2007 (PST)
Nope it doesn't work anymore. I could imagine it being model related - the crashes. --unsigned
- This article is way too outdated and very misleading especially to new coders. Someone please either attend to it or just put a warning on top of the article. --TwL 17:08, 6 Dec 2007 (PST)
- I've got simple NPCs working, but the basic zombies crash if they take melee or physics damage still and I can't figure out why. It would be great if someone who knew what they were doing could put some work into this article, it gets linked to quite a bit from the Steam forums. --IncompetentFool 13:23, 18 Dec 2007 (PST)
Patch
Hey all, I've added a link to a .patch file that implements everything described in this article, including the hundreds of function calls that the article only mentions in passing! I've done this not to remove the need for a brain or code understanding, but to save people the bother of replacing hundreds of function calls in a consistant and sensible manner, which took me a couple of 'fun-filled' days! Feedback & suggestions appreciated. Also, I've had to upload it onto my own webspace, as the wiki won't let me upload a .patch or a .zip file, it only seems to want to accept image files for upload. It doesn't bother me as such, but does anyone have any better suggestions? --Winston 10:21, 3 Apr 2008 (PDT)
- Feedback & suggestion: This patch is very nice. I've applied this to the multiplayer source SDK based on OB engine as of 6/29/2008 and I'm having some success with it, as long as I DO NOT set the appID to 320 (HL2DM, which I really want to do) I'm confident this is because I need to do the steps under "Model animations" in the article. Those steps could not be accomplished by a patch file. I think a better explination in that area would do a lot to make this article useful to more people. I have a feeling I should understand what it means to "copy them over" from HL2, however my attempts are not working out thus far... schroe2a 29 June 2008