- Joined
- Aug 14, 2009
- Messages
- 2,308
- Reaction score
- 1,207
Restored tutorial:
Hello Everyone
Im Worked On Get BattleRoyale V.2 Work On V3 Sources Work And Add New Features Like Gas , Reward System And Fixed Many Bugs / Crashes.
And It Works %80 , I Dont Want To Work On Thıs **** Again Without Any Help.
WarZ_Server.sln / ServerGameLogic.h
Search
Add Below
Search
Add
Search
Add
Look Few Lines Down And Change giveloadout variable to this
Search
Add in
Add This Functions Above ServerGameLogic::Tick()
If You Dont Have Add This On ServerGameLogic.h
Search
Add Below
Add Below void ServerGameLogic::GetSpawnPositionNewPlayer
Search in ServerGameLogic.h
Add Below
Add This in ServerGameLogic::OnNetPeerConnected
Add This in ServerGameLogic::OnNetPeerDisconnected
Add this in ServerGameLogic:
oKillPlayer
Add This in ServerGameLogic::ApplyDamage
Open WarZ.sln
Find This
Add
Search
Add
I Will Add Reward System Tomorrow 
Credits : @Burak DatLife @m70b1jr CodeX Source(For Reward System)
Hello Everyone
Im Worked On Get BattleRoyale V.2 Work On V3 Sources Work And Add New Features Like Gas , Reward System And Fixed Many Bugs / Crashes.
And It Works %80 , I Dont Want To Work On Thıs **** Again Without Any Help.
WarZ_Server.sln / ServerGameLogic.h
Search
Code:
void GiveDevEventLoadout(DWORD peerId);
Add Below
Code:
//==============
// Battle Royale
//==============
// Battle royale main tick function
void BattleRoyaleTick();
// Battle royale bool variable
bool isBattleRoyale;
bool hasMatchStarted;
bool isCountingDown;
float preGameTime; // Time before match starts
float safezoneTime; // Time before safezone enables
float shrinkTime; // Time safezone shrinks
int lastNumber;
float canCheckPlayers;
float gastimer;
int gasint;
int playersLeft;
bool canFinishMatch;
float finishMatch;
obj_ServerPlayer* winningPlr /*= NULL*/;
bool haveWinningPlayer;
bool playersTeleported;
//bool justTeleported;
float teleportTimer;
void RestartBattleRoyale();
void StartCountdown();
void StartMatch();
void GiveBattleRoyaleLoadout(obj_ServerPlayer* plr);
Search
Code:
ServerGameLogic::Init ( Function)
Add
Code:
isBattleRoyale = true;
hasMatchStarted = false;
isCountingDown = false;
canFinishMatch = false;
haveWinningPlayer = false;
playersTeleported = false;
canCheckPlayers = r3dGetTime();
gastimer = r3dGetTime();
Search
Code:
ServerGameLogic::CreateNewPlayer(
Code:
if (gServerLogic.isBattleRoyale)
wipeInventory = true;
Look Few Lines Down And Change giveloadout variable to this
Code:
if (giveLoadout)
GiveDevEventLoadout(peerId);
Search
Code:
ServerGameLogic::Tick()
Add in
Code:
BattleRoyaleTick();
GasScanner();
Add This Functions Above ServerGameLogic::Tick()
Code:
void ServerGameLogic::BattleRoyaleTick()
{
if (isCountingDown)
{
float diff = preGameTime - r3dGetTime();
int iDiff = (int)diff; // Time left util we start the game
if (iDiff == 60 || iDiff == 30 || iDiff == 15 || iDiff <= 10)
{
// Chat message to all players
if (diff > 1)
{
if (lastNumber != iDiff) // Check so that we send this message once every second
{
// Tell the players how much time we have left before we start the match
PKT_C2C_ChatMessage_s n2;
n2.msgChannel = 1; // global
n2.userFlag = 2;
r3dscpy(n2.gamertag, " Battle Royale :");
char buffer[256];
sprintf_s(buffer, "The match will start in %i seconds", iDiff);
r3dscpy(n2.msg, buffer);
p2pBroadcastToAll(&n2, sizeof(n2), 1);
lastNumber = iDiff;
}
}
else if (iDiff == 0) // If the time left to start the match is smaller than or equal to 0
{
// We start the match
StartMatch();
// And send a message to all players that the match has started
PKT_C2C_ChatMessage_s n2;
n2.msgChannel = 1; // global
n2.userFlag = 2;
r3dscpy(n2.gamertag, " Battle Royale :");
char buffer[256];
sprintf_s(buffer, "The match has started!", diff);
r3dscpy(n2.msg, buffer);
p2pBroadcastToAll(&n2, sizeof(n2), 1);
}
}
}
if (r3dGetTime() > canCheckPlayers) // Timer to check all players for something
{
if (!hasMatchStarted && curPlayers_ > 0) // If the match hasn't started yet check all the players and teleport them back into their safezone if they get out of range.
{
if (!isCountingDown || !hasMatchStarted) //fixed player count while running round
{
PKT_C2C_ChatMessage_s n2;
n2.msgChannel = 2; // global
n2.userFlag = 1;
r3dscpy(n2.gamertag, " Battle Royale :");
char buffer[256];
int playersNeeded = (int)(ginfo_.maxPlayers * 0.5f);
int stillNeeded = playersNeeded - curPlayers_;
if (stillNeeded > 0) //only shows +1 now
{
sprintf_s(buffer, "%i more %s needed to start the match!", stillNeeded, stillNeeded == 1 ? "player" : "players");
r3dscpy(n2.msg, buffer);
p2pBroadcastToAll(&n2, sizeof(n2));
}
}
// Check all players
for (int i = 0; i < curPlayers_; i++)
{
obj_ServerPlayer* pl = plrList_[i];
float minDist = FLT_MAX;
int szNumber = 0;
// Get closest safezone to players
for (int j = 0; j < gPostBoxesMngr.numPostBoxes_; j++)
{
float dist = (pl->GetPosition() - gPostBoxesMngr.postBoxes_[j]->GetPosition()).LengthSq();
if (dist < minDist)
{
szNumber = j;
minDist = dist;
}
}
// If player distance to safezone is larger than radius - 1, teleport player back inside
float rad = gPostBoxesMngr.postBoxes_[szNumber]->useRadius - 1;
float radSq = rad * rad;
if (minDist > radSq)
{
ResetPositionBattleRoyale(pl, szNumber);
}
}
// Add 10 seconds to the timer
canCheckPlayers = r3dGetTime() + 10.0f;
}
}
}
void ServerGameLogic::RestartBattleRoyale()
{
// reset variables
hasMatchStarted = false;
isCountingDown = false;
canFinishMatch = false;
haveWinningPlayer = false;
winningPlr = NULL;
lastNumber = 0;
canCheckPlayers = r3dGetTime();
gastimer = r3dGetTime();
int gasattack = 0;
playersLeft = 100;
// Reset player position and inventory
for (int i = 0; i < curPlayers_; i++)
{
obj_ServerPlayer* plr = plrList_[i];
for (int j = 0; j < plr->loadout_->BackpackSize; j++)
{
const wiInventoryItem& wi = plr->loadout_->Items[j];
if (wi.itemID > 0)
{
//r3dOutToLog("%s removed item: %d in slot: %i\n", plr->loadout_->Gamertag, wi.itemID, j);
plr->BackpackRemoveItem(wi);
}
}
}
}
void ServerGameLogic::StartCountdown()
{
isCountingDown = true;
preGameTime = r3dGetTime() + 120.0f;
lastNumber = 0;
PKT_C2C_ChatMessage_s n2;
n2.msgChannel = 1; // global
n2.userFlag = 2;
r3dscpy(n2.gamertag, " Battle Royale :");
char buffer[256];
sprintf_s(buffer, "The match will start in 120 seconds");
r3dscpy(n2.msg, buffer);
p2pBroadcastToAll(&n2, sizeof(n2), 1);
}
void ServerGameLogic::StartMatch()
{
isCountingDown = false;
hasMatchStarted = true;
canFinishMatch = false;
int gasint = 0;
safezoneTime = 60.0f;
playersLeft = curPlayers_;
// Set occupied false for all spawns
BasePlayerSpawnPoint* curSpawn;
int numSpawns = 0;
for (int i = 0; i < gCPMgr.numControlPoints_; i++)
{
curSpawn = gCPMgr.controlPoints_[i];
for (int j = 0; j < curSpawn->m_NumSpawnPoints; j++)
{
curSpawn->m_SpawnPoints[j].isOccupied = false;
numSpawns++;
}
}
r3dOutToLog("Resetted %i spawns\n", numSpawns);
// Teleport players to their start positions
for (int i = 0; i < curPlayers_; ++i)
{
obj_ServerPlayer* pl = plrList_[i];
GiveBattleRoyaleLoadout(pl);
pl->justTeleported = true;
GetStartPositionBattleRoyale(pl);
playersTeleported = true;
teleportTimer = r3dGetTime() + 2.5f;
}
r3dOutToLog("Teleported and equipped %i players\n", curPlayers_);
}
void ServerGameLogic::GiveBattleRoyaleLoadout(obj_ServerPlayer* plr)
{
// Pistol
wiInventoryItem pistol;
pistol.InventoryID = 0;
pistol.itemID = 101115;
pistol.quantity = 1;
//plr->loadout_->Items[1] = pistol;
plr->AddItemToBackpackSlot(1, pistol);
// Mags
wiInventoryItem pistolMag;
pistolMag.InventoryID = 1;
pistolMag.itemID = 400071;
pistolMag.quantity = 2;
//plr->loadout_->Items[8] = pistolMag;
plr->AddItemToBackpackSlot(8, pistolMag);
// Food
wiInventoryItem food;
food.InventoryID = 2;
food.itemID = 101284;
food.quantity = 1;
//plr->loadout_->Items[9] = food;
plr->AddItemToBackpackSlot(9, food);
}
If You Dont Have Add This On ServerGameLogic.h
Code:
#include "ObjectsCode/obj_ServerPostBox.h"
Search
Code:
float dir;
Code:
bool isOccupied;
Add Below void ServerGameLogic::GetSpawnPositionNewPlayer
Code:
void ServerGameLogic::GetSpawnPositionBattleRoyale(const r3dPoint3D& GamePos, r3dPoint3D* pos, float* dir)
{
// Get random safezone position
srand((unsigned int)r3dGetTime());
int randNum = rand() % gPostBoxesMngr.numPostBoxes_;
r3dPoint3D postboxPoint = gPostBoxesMngr.postBoxes_[randNum]->GetPosition();
float radius = (gPostBoxesMngr.postBoxes_[randNum]->useRadius - 1);
// Get point within radius
bool pointFound = false;
r3dPoint3D tempSpawn;
while (!pointFound)
{
float posX = u_GetRandom(-radius, radius);
float posZ = u_GetRandom(-radius, radius);
tempSpawn = postboxPoint;
tempSpawn.x += posX;
tempSpawn.z += posZ;
if ((tempSpawn - postboxPoint).LengthSq() < (radius * radius))
pointFound = true;
}
// Raycast down from very high to determine y coordinate
PxRaycastHit hit;
PxSceneQueryFilterData filter(PxFilterData(COLLIDABLE_STATIC_MASK, 0, 0, 0), PxSceneQueryFilterFlag::eSTATIC);
tempSpawn.y = hit.impact.y;
if (!g_pPhysicsWorld->raycastSingle(PxVec3(tempSpawn.x, 1000.0f, tempSpawn.z), PxVec3(0, -1, 0), 2000.0f, PxSceneQueryFlag::eIMPACT, hit, filter))
{
r3dOutToLog("Unable to spawn player near safezone, falling back to old method\n");
return GetSpawnPositionAfterDeath(GamePos, pos, dir);
}
// Set player position
*pos = AdjustPositionToFloor(tempSpawn);
}
void ServerGameLogic::GasScanner()
{
if (gasint > 100)
{
for (int i = 0; i < curPlayers_; i++)
{
obj_ServerPlayer* pl = plrList_[i];
float minDist = FLT_MAX;
int szNumber = 0;
// Get Safezone
for (int j = 0; j < gPostBoxesMngr.numPostBoxes_; j++)
{
float dist = (pl->GetPosition() - gPostBoxesMngr.postBoxes_[j]->GetPosition()).LengthSq();
if (dist < minDist)
{
szNumber = j;
minDist = dist;
}
}
// Gas Check
float rad = gPostBoxesMngr.postBoxes_[szNumber]->useRadius - 1;
float radSq = rad * rad;
if (minDist > radSq)
{
pl->loadout_->MedBleeding = 10000.0f;
pl->loadout_->MedBloodInfection = 100.0f;
}
else
{
pl->loadout_->MedBleeding = 0.0f;
pl->loadout_->MedBloodInfection = 0.0f;
}
}
}
if (r3dGetTime() > gastimer && gasint < 110)
{
if (hasMatchStarted && curPlayers_ > 0) // check for someone living
{
PKT_C2C_ChatMessage_s n2;
n2.msgChannel = 2; // global
n2.userFlag = 2; // administrator
r3dscpy(n2.gamertag, " Battle Royale :");
char buffer[256];
sprintf_s(buffer, "Gas Planes Prepearing %i",gasint);
r3dscpy(n2.msg, buffer);
p2pBroadcastToAll(&n2, sizeof(n2));
gasint++;
gasint++;
gasint++;
gasint++;
gasint++;
gasint++;
gasint++;
gasint++;
gasint++;
gasint++;
gastimer = r3dGetTime() + 10.0f;
}
}
}
void ServerGameLogic::GetGasPositionBattleRoyale()
{
if (gasint > 100)
{
for (int i = 0; i < curPlayers_; i++)
{
obj_ServerPlayer* pl = plrList_[i];
float minDist = FLT_MAX;
int szNumber = 0;
for (int j = 0; j < gPostBoxesMngr.numPostBoxes_; j++)
{
float dist = (pl->GetPosition() - gPostBoxesMngr.postBoxes_[j]->GetPosition()).LengthSq();
if (dist < minDist)
{
szNumber = j;
minDist = dist;
}
}
float rad = gPostBoxesMngr.postBoxes_[szNumber]->useRadius - 1;
float radSq = rad * rad;
if (minDist > radSq)
{
pl->loadout_->MedBleeding = 5000.0f;
}
else
{
pl->loadout_->MedBleeding = 0.0f;
}
}
}
}
void ServerGameLogic::GetStartPositionBattleRoyale(obj_ServerPlayer* plr)
{
float posX, posZ;
// Right now we teleport players to the first empty spawn
BasePlayerSpawnPoint* curSpawn;
while (true)
{
srand((unsigned int)r3dGetTime());
int i = rand() % gCPMgr.numControlPoints_;
curSpawn = gCPMgr.controlPoints_[i];
int j = rand() % curSpawn->m_NumSpawnPoints;
if (!curSpawn->m_SpawnPoints[j].isOccupied)
{
curSpawn->m_SpawnPoints[j].isOccupied = true;
posX = curSpawn->m_SpawnPoints[j].pos.x;
posZ = curSpawn->m_SpawnPoints[j].pos.z;
admin_TeleportPlayer(plr, posX, posZ);
break;
}
}
return;
}
void ServerGameLogic::ResetPositionBattleRoyale(obj_ServerPlayer* plr, int szNum)
{
// Closest safezone
r3dPoint3D postboxPoint = gPostBoxesMngr.postBoxes_[szNum]->GetPosition();
float radius = (gPostBoxesMngr.postBoxes_[szNum]->useRadius - 1);
// Get point within radius
bool pointFound = false;
r3dPoint3D tempSpawn;
while (!pointFound)
{
tempSpawn = postboxPoint;
float posX = u_GetRandom(-radius, radius);
float posZ = u_GetRandom(-radius, radius);
tempSpawn.x += posX;
tempSpawn.z += posZ;
if ((tempSpawn - postboxPoint).LengthSq() < (radius * radius))
pointFound = true;
}
admin_TeleportPlayer(plr, tempSpawn.x, tempSpawn.z);
}
Code:
void GetSpawnPositionAfterDeath
Code:
void GetSpawnPositionBattleRoyale(const r3dPoint3D& GamePos, r3dPoint3D* pos, float* dir);
void GetGasPositionBattleRoyale();
void GasScanner();
void GetStartPositionBattleRoyale(obj_ServerPlayer* plr);
void ResetPositionBattleRoyale(obj_ServerPlayer* plr, int szNum);
Add This in ServerGameLogic::OnNetPeerConnected
Code:
if (isBattleRoyale)
{
int startPlayers = (int)(ginfo_.maxPlayers * 0.5f);
if (curPlayers_ >= startPlayers && !hasMatchStarted && !isCountingDown)
{
r3dOutToLog("Minimum required players achieved, starting match\n");
StartCountdown();
}
}
Add This in ServerGameLogic::OnNetPeerDisconnected
Code:
if (isBattleRoyale)
playersLeft--;
return;
Add this in ServerGameLogic:
Code:
if (isBattleRoyale)
{
playersLeft--;
PKT_C2C_ChatMessage_s n;
char buffer[128] = { 0 };
sprintf(buffer, "%i players left!", playersLeft);
r3dscpy(n.gamertag, "<Battle Royale>");
r3dscpy(n.msg, buffer);
n.msgChannel = 1;
n.userFlag = 1;
p2pBroadcastToAll(&n, sizeof(n), true);
}
Add This in ServerGameLogic::ApplyDamage
Code:
if (isBattleRoyale && !hasMatchStarted) damage = 0;
Open WarZ.sln
Find This
Code:
IMPL_PACKET_FUNC(ClientGameLogic, PKT_S2C_CreatePlayer)
Add
Code:
if (m_gameInfo.mapId==GBGameInfo::MAPID_WZ_BRMAPNAME)
wipeInventory=true;
Search
Code:
int CJobUpdateChar::Exec()
Code:
if(gServerLogic.ginfo_.mapId==GBGameInfo::MAPID_WZ_BRMAP)
updateCharEnable=false;
Credits : @Burak DatLife @m70b1jr CodeX Source(For Reward System)

