PreBeginPlay() vs PostBeginPlay()!

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Dexter13

The Coding Machine
Dec 18, 2001
111
0
0
Visit site
I was wondering, can I set a player or bot a team during prebeginplay() or postbeginplay()?

Also, I created a small mod, but for some reason, when I play it with bots, it always spawns 5 bots, no more, no less, even if I specifically choose 9 bots before starting the game!

Does anyone have any ideas or solutions?
thanks,
 

butto

Red Orchestra Coder
The PlayerReplicationInfo and GameReplicationInfo both take a little bit to be created even after PostBeginPlay I think. They update every 1/8 and every 1/4 second respectively I think. I've had a few problems accessing those in the first fraction of a second after joining the game as a client.
 

Dexter13

The Coding Machine
Dec 18, 2001
111
0
0
Visit site
no, but I have fiddled with:

'function Bot SpawnBot(out NavigationPoint StartSpot)'

but I can't see anything in there that would limit me to 5 bots, but I could be wrong! What do you think?
thanks,
 

butto

Red Orchestra Coder
Well, I just made sure that only the server can alter anything in them (the spectator state normally doesn't check if Role == ROLE_Authority before setting bIsSpectator and bWaitingPlayer for example) and made checks like if (PlayerOwner.GameReplicationInfo == None) return; in the HUD to make sure the timer I made doesn't try to draw right away.
 

Dexter13

The Coding Machine
Dec 18, 2001
111
0
0
Visit site
here it is..

O.k here's the code:

function Bot SpawnBot(out NavigationPoint StartSpot)
{
local bot NewBot;
local int BotN;
local Pawn P;
local class<bot> BotSpawnClass;
local Float F;



if ( bRatedGame )
return SpawnRatedBot(StartSpot);
Difficulty = BotConfig.Difficulty;
if ( Difficulty >= 4 )
{
bNoviceMode = false;
Difficulty = Difficulty - 4;
}
else
{
if ( Difficulty > 3 )
{
Difficulty = 3;
bThreePlus = true;
}
bNoviceMode = true;
}
BotN = BotConfig.ChooseBotInfo();
StartSpot = FindPlayerStart(None, 255);
if( StartSpot == None )
{
log("Could not find starting spot for Bot");
return None;
}


BotSpawnClass = class'JWF_Bot';
NewBot = Spawn(BotSpawnClass,,,StartSpot.Location,StartSpot.Rotation);

if ( NewBot == None )
log("Couldn't spawn player at "$StartSpot);

if ( (bHumansOnly || Level.bHumansOnly) && !NewBot.bIsHuman )
{
log("can't add non-human bot to this game");
NewBot.Destroy();
NewBot = None;
}

if ( NewBot == None )
{
NewBot = Spawn(BotSpawnClass,,,StartSpot.Location,StartSpot.Rotation);
}

if ( NewBot != None )
{
// Set the player's ID.
NewBot.PlayerReplicationInfo.PlayerID = CurrentID++;
NewBot.PlayerReplicationInfo.Team = BotConfig.GetBotTeam(BotN);
BotConfig.CHIndividualize(NewBot, BotN, NumBots);
NewBot.ViewRotation = StartSpot.Rotation;

// broadcast a welcome message.
BroadcastMessage( NewBot.PlayerReplicationInfo.PlayerName$EnteredMessage, false );

ModifyBehaviour(NewBot);
AddDefaultInventory( NewBot );
NumBots++;

if ( bRequireReady && (CountDown > 0) )
NewBot.GotoState('Dying', 'WaitingForStart');

NewBot.AirControl = AirControl;

if ( (Level.NetMode != NM_Standalone) && (bNetReady || bRequireReady) )
{
// replicate skins
for ( P=Level.PawnList; P!=None; P=P.NextPawn )
if ( P.bIsPlayer && (P.PlayerReplicationInfo != None) &&
P.PlayerReplicationInfo.bWaitingPlayer && P.IsA('PlayerPawn') )
{
if ( NewBot.bIsMultiSkinned )
PlayerPawn(P).ClientReplicateSkins(NewBot.MultiSkins[0], NewBot.MultiSkins[1], NewBot.MultiSkins[2], NewBot.MultiSkins[3]);
else
PlayerPawn(P).ClientReplicateSkins(NewBot.Skin);
}
}
}


what do you reckon?
 

2COOL4-U

New Member
Mar 17, 2001
505
0
0
37
dot NL
2cool.free.fr
Re: here it is..

Code:
function Bot SpawnBot(out NavigationPoint StartSpot)
{
local bot NewBot;
local int BotN;
local Pawn P;
local class<bot> BotSpawnClass;
local Float F;



 if ( bRatedGame )
   return SpawnRatedBot(StartSpot);
 Difficulty = BotConfig.Difficulty;
 if ( Difficulty >= 4 )
 {
   bNoviceMode = false;
   Difficulty = Difficulty - 4;
 }
 else
 {
   if ( Difficulty > 3 )
   {
     Difficulty = 3;
     bThreePlus = true;
   }
   bNoviceMode = true;
 }
 BotN = BotConfig.ChooseBotInfo();
 StartSpot = FindPlayerStart(None, 255);
 if( StartSpot == None )
 {
   log("Could not find starting spot for Bot");
   return None;
 }


 BotSpawnClass = class'JWF_Bot';
 NewBot = Spawn(BotSpawnClass,,,StartSpot.Location,StartSpot.Rotation);

 if ( NewBot == None )
   log("Couldn't spawn player at "$StartSpot);

 if ( (bHumansOnly || Level.bHumansOnly) && !NewBot.bIsHuman )
 {
   log("can't add non-human bot to this game");
   NewBot.Destroy();
   NewBot = None;
 }

 if ( NewBot == None )
 {
   NewBot = Spawn(BotSpawnClass,,,StartSpot.Location,StartSpot.Rotation);
 }

 if ( NewBot != None )
 {
  // Set the player's ID.
  NewBot.PlayerReplicationInfo.PlayerID = CurrentID++;
  NewBot.PlayerReplicationInfo.Team = BotConfig.GetBotTeam(BotN);
  BotConfig.CHIndividualize(NewBot, BotN, NumBots);
  NewBot.ViewRotation = StartSpot.Rotation;

  // broadcast a welcome message.
  BroadcastMessage( NewBot.PlayerReplicationInfo.PlayerName$EnteredMessage, false );

  ModifyBehaviour(NewBot);
  AddDefaultInventory( NewBot );
  NumBots++;

  if ( bRequireReady && (CountDown > 0) )
    NewBot.GotoState('Dying', 'WaitingForStart');

  NewBot.AirControl = AirControl;

  if ( (Level.NetMode != NM_Standalone) && (bNetReady || bRequireReady) )
  {
    // replicate skins
    for ( P=Level.PawnList; P!=None; P=P.NextPawn )
    if ( P.bIsPlayer && (P.PlayerReplicationInfo != None) &&
      P.PlayerReplicationInfo.bWaitingPlayer && P.IsA('PlayerPawn') )
    {
      if ( NewBot.bIsMultiSkinned )
        PlayerPawn(P).ClientReplicateSkins(NewBot.MultiSkins[0], NewBot.MultiSkins[1], NewBot.MultiSkins[2], NewBot.MultiSkins[3]);
      else
        PlayerPawn(P).ClientReplicateSkins(NewBot.Skin);
    }
  }
 }

Now that's readable let's see
 

Dexter13

The Coding Machine
Dec 18, 2001
111
0
0
Visit site
hmmm...

hmm, so what do you think could be wrong in any of my code?

also, how/where can I put code to make a player get a certain skin when they spawn/start a game?