• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

How to handle (use) override events

Nerus87

Member
Jul 9, 2018
8
0
36
Poland
I have problems with creating/compiling simple mutator.

1) How to handle PostLogin event in my mutator?
2) Error occurred in "local Controller Player;" - 'Controller': Bad command or expression
PHP:
class Test extends KFMutator;

event PostLogin(PlayerController NewPlayer)
{
super.PostLogin(NewPlayer);

/// Send welcome message to the connected player
NewPlayer.ClientMessage("Welcome to the server.");

/// Broatcast message to all of players on the server
local Controller Player;
foreach WorldInfo.AllControllers(class'Controller', Player)
if (Player.bIsPlayer && !Player.IsA('PlayerController') && Player != NewPlayer)
Player.ClientMessage("Player '"$NewPlayer.PlayerReplicationInfo.PlayerName"' connected");
}
 
Last edited:
Locals have to be declared at the start of functions (local block) before any other code. Also, I'd recommend wrapping foreach in braces (even for a single line of code like you have), as it can prevent a few rare crashes which will give you a headache later trying to solve. Not wrapping single line if statements should be fine though, never seen that cause a crash.
 
  • Like
Reactions: Pharrahnox
Upvote 0
Kavoh;n2323004 said:
Locals have to be declared at the start of functions (local block) before any other code. Also, I'd recommend wrapping foreach in braces (even for a single line of code like you have), as it can prevent a few rare crashes which will give you a headache later trying to solve. Not wrapping single line if statements should be fine though, never seen that cause a crash.

OK,

another bunch of code with error on compiling:

PHP:
class Test extends KFMutator;

event PostLogin(PlayerController NewPlayer)
{
    local Controller Player;

    super.PostLogin(NewPlayer);
    NewPlayer.ClientMessage("Welcome to the server.");
    
    foreach WorldInfo.AllControllers(class'Controller', Player)
    {
        if (Player.bIsPlayer && !Player.IsA('PlayerController') && Player != NewPlayer)
        {
            Player.ClientMessage("Player '"$NewPlayer.PlayerReplicationInfo.PlayerName"' connected");
        }
    }
}

Code:
Error, Unknown Function 'PostLogin' in 'Class KFGame.KFMutator'
 
Last edited:
Upvote 0