So, i'm using GigaToni's original code for this tutorial and not mine.
His code causes server crashes, and they will not die (at least in my case)
So lets begin
Search for:
Below that, add:
Search for:
Below it add:
Now Search for
Below that add
Now search
Below that add
Now:
Add this below it
Now last but not least:
And below it add
And the command to spawn them in:
Heres the files you will need, remember to add in object explorer.
for all you newbs out there, any thing starting with OBJ is client, and SOBJ is server sided
Link to the files
Credits to:
m70b1jr @GigaToni
His code causes server crashes, and they will not die (at least in my case)
So lets begin
Search for:
Code:
DEFINE_PACKET_FUNC(PKT_S2C_CheatWarning);
Code:
DEFINE_PACKET_FUNC(PKT_S2C_CreateNPC);
Code:
// server notes
Code:
//NPC
PKT_S2C_CreateNPC,
PKT_S2C_NPCSetState,
// END
Code:
struct PKT_S2C_SetNoteData_s : public DefaultPacketMixin<PKT_S2C_SetNoteData>
Code:
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;
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>
{
BYTE State; // ZombieStates::EZombieStates
};
/*struct PKT_S2C_NPCAttack_s : public DefaultPacketMixin<PKT_S2C_NPCAttack>
{
gp2pnetid_t targetId;
};*/
Code:
IMPL_PACKET_FUNC(ClientGameLogic, PKT_S2C_SetNoteData)
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", "obj_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);
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;
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;
pl->CurLoadout.Thirst = 0;
pl->CurLoadout.BackpackID = 20185;
pl->CurLoadout.BackpackSize = 28;
pl->m_fPlayerRotationTarget = pl->m_fPlayerRotation = u_GetRandom(0.0f, 360.0f);
pl->OnCreate();
pl->UpdateLoadoutSlot(pl->CurLoadout);
pl->netMover.SetStartCell(n.moveCell);
}
Code:
DEFINE_PACKET_HANDLER(PKT_S2C_CheatWarning);
Code:
DEFINE_PACKET_HANDLER(PKT_S2C_CreateNPC);
Code:
#include "ObjectsCode/Zombies/sobj_Zombie.h"
Code:
#include "ObjectsCode/[B][U]DIRECTORY[/U][/B]/sobj_Guard.h"
And the command to spawn them in:
Code:
if(strncmp(cmd, "/spawnnpc", 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;
}
Heres the files you will need, remember to add in object explorer.
for all you newbs out there, any thing starting with OBJ is client, and SOBJ is server sided
Link to the files
To view the content, you need to sign in or register
Credits to:
m70b1jr @GigaToni

