Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

AI Bandit Tutorial

Today I will be giving you the AI Bandit code to add into your server. This code still needs a lot of work
for the bandit animations but it is a starting point for you to add them into your server. Yes this will be a
copy and paste tutorial.

First you will need to extract the AI Bandit files and put them in the correct folders. I will be using my
directory for reference. Yours may be different than mine, but it should be the same end folders as
mine.

“o let’s add the first folder to e lipse studio. Navigate to your ObjectsCode folder in EclipseStudio.
Place the folder Guard in there.

These files should be in the Guard folder.

(obj_Guard.cpp, obj_Guard.h, obj_GuardSpawn.cpp, and obj_GuardSpawn.h)

Now go into your Gameplay folder in the same folder as your Guard folder. Add the following files
to this folder.

These files should be in the Gameplay folder.

(GuardStates.cpp, GuardStates.h, Guard.cpp, and Guard.h)

No let’s add the files to the ser er folder. Na igate to your ObjectsCode folder in
WO_Ga e“er er folder. Add a folder and name it Guards . In the folder Guards add the following
files.

These files should be in the Guards folder.

(GuardNavAgent.cpp, GuardNavAgent.h, sobj_Guard.cpp, sobj_Guard.h, sobj_GuardSpawn.cpp, and


sobj_GuardSpawn.h)

Now add the following files to your O je tsCode folder were you just made the Guards folder. The
following files should be added.

These files should be in the ObjectsCode folder.


AI Bandit Tutorial
Adding Folders, Files, and code to WarZ.sin
Ok o e eed to ha e “tudio see the files e just added to our ga e folders. Let’s ope up WarZ.sin
now in Microsoft Studio.

In solution explorer expand Eclipse Studio so that you can see the folder named Ga e .

Now expand the folder Ga e folder.

Now expand the folder Ga e O je ts Code .

Right click on the folder Ga eO je ts Code and navigate to add and then to New filter and add a new
filter and name it Guard .

Now you should see a folder named Guard under Ga eO je ts Code . Now we need to add the files
to the folder we just made. We will add them the same way as we added the folder.

Right click on the folder Guard and navigate to add then Existing Items. Now a window will open up
and you will need to navigate to the guard folder in EclipseStudio.

Add the following files (obj_Guard.cpp, obj_Guard.h, obj_GuardSpawn.cpp, and obj_GuardSpawn.h).

Now in the Solution Explorer you should see a folder named Guard with the files in it.

Now we can begin to add the code to the source files.

Ok so the first file we will open will be UserRe ards. pp .

Search for this code:

SetReward(2, "Super ZombieKill", 20, 20, 50, 50);

Right below this add the following code:

SetReward(3, "RWD_GuardKill", 40, 40, 80, 80);

Here is where you will set the XP for killing the bandits. I will not explain how to do that in this tutorial.

No let’s ope up UserRe ards.h .

Search for this code:

RWD_SuperZombieKill = 2,

Right below this add the following code:

RWD_GuardKill = 3,

Now lets open up Clie tGa eLogi . pp


AI Bandit Tutorial
Search for this code:

#include "ObjectsCode/Gameplay/obj_Zombie.h"

Right below this add the following code:

#include "ObjectsCode/Guard/obj_guard.h"

Search for this code:

IMPL_PACKET_FUNC(ClientGameLogic, PKT_S2C_UseNetObjectAns)

Above this add the following code:

IMPL_PACKET_FUNC(ClientGameLogic, PKT_S2C_CreateNPC)
{
//r3dOutToLog("obj_Zombie %d\n", n.spawnID);
r3d_assert(GameWorld().GetNetworkObject(n.spawnID) == NULL);

/*obj_Guard* obj = (obj_Guard*)srv_CreateGameObject("obj_Guard",


"Guard", n.spawnPos);
obj->SetNetworkID(n.spawnID);
obj->NetworkLocal = false;
//memcpy(&obj->CreateParams, &n, sizeof(n));
obj->OnCreate();
obj->netMover.SetStartCell(n.moveCell);*/

obj_Player* pl = (obj_Player *)srv_CreateGameObject("obj_Player",


"Guard", n.spawnPos); //Was obj player.. and causing crashing.

pl->NetworkLocal = false; // so it will be always in 3rd person mode.


with disabled physics

pl->SetNetworkID(n.spawnID);

pl->CurLoadout.HeroItemID = n.HeroItemID;
const HeroConfig* heroConf = g_pWeaponArmory->getHeroConfig(pl-
>CurLoadout.HeroItemID);
pl->CurLoadout.HeadIdx = n.HeadIdx;
pl->CurLoadout.BodyIdx = n.BodyIdx;
pl->CurLoadout.LegsIdx = n.LegsIdx;

pl->CurLoadout.Items[wiCharDataFull::CHAR_LOADOUT_ARMOR].itemID
= n.ArmorPart; //sfag
pl->CurLoadout.Items[wiCharDataFull::CHAR_LOADOUT_HEADGEAR].itemID
= n.HGearPart;
//pl->CurLoadout.Items[0].itemID =
WeaponConfig::ITEMID_Unarmed;
pl->CurLoadout.Items[0].itemID = n.WeaponPart;
//pl->CurLoadout.Items[1].itemID = XX;

pl->CurLoadout.Health = 100;
pl->CurLoadout.Toxic = 0;
pl->CurLoadout.Hunger = 0;
AI Bandit Tutorial
pl->CurLoadout.Thirst = 0;
pl->CurLoadout.MedFeverCold = 0;
pl->CurLoadout.BackpackID = NULL;
pl->CurLoadout.BackpackSize = 28;

pl->m_fPlayerRotationTarget = pl->m_fPlayerRotation = u_GetRandom(0.0f,


360.0f);
pl->OnCreate();
pl->UpdateLoadoutSlot(pl->CurLoadout, -1);

pl->netMover.SetStartCell(n.moveCell);
}

Search for this code:

DEFINE_PACKET_HANDLER(PKT_S2C_CreateZombie);

Right below add this code:

DEFINE_PACKET_HANDLER(PKT_S2C_CreateNPC);

Now lets open Clie tGa eLogi .h

Search for this code:

DEFINE_PACKET_FUNC(PKT_C2S_ValidateConnectingPeer);

Right above add this code:

DEFINE_PACKET_FUNC(PKT_S2C_CreateNPC);

Now lets open P PMessages.h .

Search for this code:

PKT_S2C_ZombieSprint,

Right below add this code:

PKT_S2C_GuardSprint,

Search for this code:

struct PKT_S2C_ZombieSprint_s : public


DefaultPacketMixin<PKT_S2C_ZombieSprint>
{
};

Right below add this code:

struct PKT_S2C_GuardSprint_s : public


DefaultPacketMixin<PKT_S2C_ZombieSprint>
{
AI Bandit Tutorial
};

Search for this code:

PKT_S2C_GroupNotify,

Right below add this code:

// server notes

//NPC
PKT_S2C_CreateNPC,
PKT_S2C_NPCSetState,
// END

Search for this code:

struct PKT_S2C_CreateNote_s : public DefaultPacketMixin<PKT_S2C_CreateNote>


{
gp2pnetid_t spawnID;
r3dPoint3D pos;
};

Right below add this code:

//Packets for the Bandit AI


struct PKT_S2C_CreateNPC_s : public DefaultPacketMixin<PKT_S2C_CreateNPC>
{
gp2pnetid_t spawnID;
r3dPoint3D spawnPos;
float spawnDir;
r3dPoint3D moveCell; // cell position from PKT_C2C_MoveSetCell
DWORD HeroItemID; // ItemID of base character
BYTE HeadIdx;
BYTE BodyIdx;
BYTE LegsIdx;
BYTE State; // ENPCStates
float WalkSpeed;
float RunSpeed;
float SprintMaxSpeed;
float SprintMaxTime;
float SprintSlope;
float SprintCooldownTime;

DWORD HGearPart; // HGear


DWORD ArmorPart; // Armor
DWORD BackPackPart; // Backpack
DWORD WeaponPart; // WEAPON?
};
// NPC's AI
struct PKT_S2C_NPCSetState_s : public DefaultPacketMixin<PKT_S2C_NPCSetState>
{
AI Bandit Tutorial
BYTE State; // ZombieStates::EZombieStates
};

/*struct PKT_S2C_NPCAttack_s : public DefaultPacketMixin<PKT_S2C_NPCAttack>


{
gp2pnetid_t targetId;
};*/

Now that everything is added we can now compile WarZ.si .

Once you are done compiling WarZ.si you can close out this solution and open WarZ_“er er.si

Adding Folders, Files, and code to WarZ_Server.sin

Now we will add the files to the WarZ_“er er.si just like we did in WarZ.si . In the solutions
Explorer navigate to the folder WarZ Ga e “er er and expand it then scroll down and expand :
“er er and then scroll down and then finally expand the folder Ga eO je ts Code .

Now add the following folder and files just like we did in WarZ.si .

Right li k o Ga eo je ts Code folder a d add e filter. Name the new filter Guard.

Now right click on the new filter and add the following files to it.

Add the following files (GuardNavAgent.cpp, GuardNavAgent.h, sobj_Guard.cpp, sobj_Guard.h,


sobj_GuardSpawn.cpp, and sobj_GuardSpawn.h)

Ok now that it is all do e a d o er ith let’s starts addi g the ode to the sour e.

Ok so the first file we will open will be o j_“er erPlayer. pp

Search for the following code:

#include "../EclipseStudio/Sources/ObjectsCode/Gameplay/ZombieStates.h"

Right below it we will add the following code:

#include "../EclipseStudio/Sources/ObjectsCode/Gameplay/GuardStates.h"

Search for the following code:

Right below it we will add the following code:


AI Bandit Tutorial
No let’s ope up “er erGa eLogi . pp

Search for the following code:

#include "ObjectsCode/Zombies/sobj_Zombie.h"

Right below add the following code:

#include "ObjectsCode/Guards/sobj_GuardSpawn.h"
#include "ObjectsCode/Guards/sobj_Guard.h"

Now scroll down the page and should come to this include:

#include "../EclipseStudio/Sources/ObjectsCode/Gameplay/ZombieStates.h"

Right below add the following code:

#include "../EclipseStudio/Sources/ObjectsCode/Gameplay/GuardStates.h"

Search for the following code:

#ifdef VEHICLES_ENABLED
bool ServerGameLogic::ApplyDamageToVehicle(GameObject* fromObj, GameObject*
targetVehicle, const r3dPoint3D& dmgPos, float damage, bool forceDamage,
STORE_CATEGORIES damageSource, uint32_t damageItemId)

Right above it you will add the following code:

bool ServerGameLogic::ApplyDamageToNPC(GameObject* fromObj, GameObject*


targetNPC, const r3dPoint3D& dmgPos, float damage, int bodyBone, int
bodyPart, bool force_damage, STORE_CATEGORIES damageSource)
{
r3d_assert(fromObj);
r3d_assert(targetNPC && targetNPC->isObjType(OBJTYPE_NPC));

// relay to zombie logic


obj_Guard* z = (obj_Guard*)targetNPC;
bool killed = z->ApplyDamage(fromObj, damage, bodyPart, damageSource);
if(IsServerPlayer(fromObj) && killed)
{
IsServerPlayer(fromObj)->loadout_->Stats.KilledZombies++;
}

return true;
}

Search for the following code:

#ifdef MISSIONS
if(strncmp(cmd, "/resetmd", 8) == 0 && plr-
>profile_.ProfileData.isDevAccount & wiUserProfile::DAA_DEV_ICON)
return Cmd_ResetMissionData(plr, cmd);
AI Bandit Tutorial
Right below this code add the following code:

#endif
if(strncmp(cmd, "/createai", 9) == 0 && plr-
>profile_.ProfileData.isDevAccount)
{
r3dPoint3D pos = plr->GetPosition();
pos.x += 15;
pos.z += u_GetRandom(0, 1) == 1 ? 15.0f : 0.0f;

obj_Guard* g = (obj_Guard*)srv_CreateGameObject("obj_Guard",
"Guard", pos);
g->spawnObjPos = plr->GetPosition();
g->spawnObjRad = 150.0f;
g->SetNetworkID(GetFreeNetId());
g->NetworkLocal = true;
g->DetectRadius = u_GetRandom(0, 1);
g->SetRotationVector(r3dVector(u_GetRandom(0, 360), 0, 0));
return 0;
}

Just a few lines down you will see the following code:

if (strncmp(cmd, "/szspawn", 8) == 0 && plr-


>profile_.ProfileData.isDevAccount & wiUserProfile::DAA_DEV_ICON)
return Cmd_ZombieSpawn(plr, cmd, true);

Right below it we will add the following code:

if (strncmp(cmd, "/mguard", 9) == 0 && plr-


>profile_.ProfileData.isDevAccount) //Specific command for spawning in new
guard :p
return Cmd_MeleeGuardSpawn(plr, cmd, true);

NOTE: This is the code for DEVs to spawn a AI Bandit in game!

Search for the following code:

void ServerGameLogic::SendSystemChatMessageToPeer(DWORD peerId, const


obj_ServerPlayer* fromPlr, const char* msg)

Right above this code add the following code:

int ServerGameLogic::Cmd_MeleeGuardSpawn(obj_ServerPlayer* plr, const char*


cmd, bool isMeleeGuard)
{
char buf[128];
int GuardCount = 0;

if(sscanf(cmd, "%s %d", buf, &GuardCount) != 2)


GuardCount = 1;

if (GuardCount > 50)


GuardCount = 50;
AI Bandit Tutorial
else if (GuardCount < 1)
GuardCount = 1;

if (isMeleeGuard)
GuardCount = 1;

obj_GuardSpawn* spawnObject = obj_GuardSpawn::GetClosestToPosition(plr-


>GetPosition());

r3dVector centerPosition = plr->GetPosition();


r3dVector position = centerPosition;
position.x += 3.0f;

for (int i = 0; i < GuardCount; ++i)


{
if (GuardCount > 1)
{
position.x = u_GetRandom(centerPosition.x - 5.0f,
centerPosition.x + 5.0f);
position.z = u_GetRandom(centerPosition.z - 5.0f,
centerPosition.z + 5.0f);

if (Terrain3)
position.y = Terrain3->GetHeight(position);
}

char name[28];
sprintf(name, "Guard_%d_%p", spawnObject->numSpawnedGuards++,
this);

obj_Guard* z = (obj_Guard*)srv_CreateGameObject("obj_Guard",
name, position);
z->SetNetworkID(gServerLogic.GetFreeNetId());
z->NetworkLocal = true;
z->spawnObject = spawnObject;
z->DetectRadius = 0;
z->SetRotationVector(r3dVector(u_GetRandom(0, 360), 0, 0));
// z->CanCallForHelp = false;
z->isMeleeGuardForced = isMeleeGuard;

spawnObject->Guards.push_back(z);
}

//LogCheat(plr->peerId_, PKT_S2C_CheatWarning_s::CHEAT_AdminGiveItem, 0,
"Admin Spawn Guard", "%d (%s) spawned %d Guard\n", plr->profile_.CustomerID,
plr->userName, zombieCount);

return 0;
}
AI Bandit Tutorial
No let’s ope up “er erGa eLogi .h

Search for this code:

int Cmd_ZombieSpawn(obj_ServerPlayer* plr, const char* cmd, bool


isSuperZombie);

Right below it we will add the following code:

int Cmd_MeleeGuardSpawn(obj_ServerPlayer* plr, const char*


cmd, bool isMeleeGuard)

No let’s ope up Vars.h

Search for this code:

REG_VAR( g_enable_zombie_sprint, true, 0 );

Right below it we will add the following code:

REG_VAR_C( r_sector_keep_alive_coef, 1.0f, 0.25f, 1.0f, 0 );

Ok now that all the code for the server side is added you can compile WarZ_“er er.si

While our server is compiling we need to edit one more file. We need to edit our O je ts.dat file in
our data folder.

You will need to go into this location to find this file:


(C:WarZ/bin/data/ObjectsDepot/GAMEPLAY/Objects.dat)

Open the file in Notepad++ and at the bottom you will see this:

<object name="Zombie Dummy" type="obj_ZombieDummy"/>

Right below that we will need to add this:

<object name="Bandit AI" type="obj_GuardSpawn"/>

Now all you need to do is to go into your Infestation Studio and add the spawn on whatever map you
want it on.

That should be it. If there are any errors please send me a message on Skype. I know there might be a
few things missing. Not sure. I am in no way shape or form taking credit for this code.

Written By:

You might also like