Page 1 of 1

NPC's in multiplayer

PostPosted: Thu Feb 15, 2007 10:22 pm
by Wildfire
Here's the deal: I've been trying to get simple NPCs into HL2DM. After searching around the VERC forums and the VDC, it seems that people have been able to get at least zombies to work fine in MP by copying hl2_gamerules.cpp's InitDefaultAIRelationships function into hl2mp_gamerules.cpp.

Now I was almost certain that this was going to work, but apparently the SDK has changed since other people have done this, and zombie NPCs still crash my game to desktop a few seconds after I add one in-game with ent_create (or during map load if I try to load a map with existing zombies).

I'm pretty sure the function I copied works fine, I have all the latest zombie models from the EP1 gcf, and my skills.cfg has the proper stuff. I am using VC++2005 Express, if that matters. Any ideas?

PostPosted: Fri Feb 16, 2007 6:12 pm
by steven_m64
AI in hl2 is designed for SP play only, changing it so it works well in a multiplayer game without causing lag or crashing will not be easy unless you know the SDK well and are proficient at C++.

you should look into what is causing the crash care of visual studios debugger, then work off and backtrack where the crash is caused to help fix the problem.

PostPosted: Sat Feb 17, 2007 11:07 pm
by Wildfire
Alright, so InitDefaultAIRelationships was set to return nothing in gamerules.h.

So now that they work without actually crashing, there are more complications. The zombie walk animations are jerky, but I don't mind that for now. Hitting the zombies with the crowbar or stunstick does so much damage that it splits them in half, but they stay alive and turn invisible (fixed that by just stopping them from splitting in half altogether.)

The one problem that makes it unplayable though, is that for some reason, the map simply ends a few seconds after spawning zombies (the map just changes as if the timelimit ran out).

I have no idea what would make it do that, but I'm trying to look into it. All I changed was the AI relationship stuff. How can I find out what's causing the game to change maps? Any ideas or help would be appreciated.

PostPosted: Sun Feb 18, 2007 12:11 am
by steven_m64
check into the time limit cvars and see what the defaults are initialized to and what thay are set to via cfg.

also check the usage of the cvars to see if there being used incorrectly (cvar is meant to be set as minutes but is used as seconds in code)

PostPosted: Sun Feb 18, 2007 12:26 am
by Wildfire
The wierd thing is that the timelimit works exactly as it should if I don't mess with NPC's.

This map change problem occurs only when I add zombies. Sometimes it changes the map 2 seconds after adding a zombie, sometimes 10. It seems random, but there have also been several occasions where it changed the map on the very instant I switched to a new weapon or shot a zombie (before I fixed the AIRelationships thing, it actually seemed to crash at the same moments, so I'm thinking that whatever was happening to make it crash, it now causes it to change levels instead).

I haven't tried loading a map that already has NPC's on it since fixing the AIRelationships thing, so I will probably try that and see if there's any difference.

EDIT: Loading a map with existing zombie NPC's just makes it change the map at the very moment it finishes loading. :(

PostPosted: Sun Feb 18, 2007 12:52 pm
by steven_m64
sounds like you screwed up some code.

PostPosted: Sun Feb 18, 2007 2:08 pm
by Wildfire
There was nothing to screw up.

In HL2DM, the game will crash after a few seconds if you add a zombie to the game.
For my mod, I copied the InitDefaultAIRelationships function from hl2_gamerules.cpp into hl2mp_gamerules.cpp. It compiles and runs fine, except now the map changes a few seconds after a zombie is added instead of crashing.
If I comment out the new function, the mod becomes exactly like HL2DM again. I didn't mess with anything else.

There's some code already there that's causing it to change maps when I add a zombie.

Is there any way to find out why the game decides to change maps at that point? How can I find the part of the code that is causing it to change levels when it shouldn't?

PostPosted: Sun Feb 18, 2007 5:31 pm
by steven_m64
place a breakpoint for the debugger on the changelevel code and backtrack to where it was called.

PostPosted: Mon Feb 26, 2007 11:04 pm
by Wildfire
Got it working.

The function GoToIntermission was being called to change the map. Even if I commented out all the calls to that function, it still for some reason seemed to get called anyway.
I solved it by basically copying GoToIntermission into a new function, GoToIntermission2, then commenting GoToIntermission's contents, and finally changing the calls to GoToIntermission into calls to my GoToIntermission2. Works great now.

Also, zombie co-op is fun. 8)

PostPosted: Mon Feb 26, 2007 11:36 pm
by Bob
Looks good!

Should be fun. Keep posting if you need further help.