• 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 use function from another class (instance)

Nerus87

Member
Jul 9, 2018
8
0
36
Poland
As in topic, please look at code in line with "if(IsAdmin(NewPlayer))", IsAdmin is function from AccessControl class.

PHP:
class Test extends KFMutator;

function NotifyLogin(Controller 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)
        {
            if(IsAdmin(NewPlayer))
                Player.ClientMessage("Admin '"$NewPlayer.PlayerReplicationInfo.PlayerName"' connected");
            else
                Player.ClientMessage("Player '"$NewPlayer.PlayerReplicationInfo.PlayerName"' connected");
        }
}
 
Last edited:
If you want to call another class's function, you need a reference to an instance of it* - the same as in Java, C++, C#, etc. In this case you could do:
Code:
if(WorldInfo.Game.AccessControl.IsAdmin(NewPlayer))
Or you could even do :
Code:
if(NewPlayer.PlayerReplicationInfo.bAdmin)

* This is not required if it's a static function. In that case you would have:
Code:
class'SomeClass'.static.SomeFunction();
 
  • Like
Reactions: Nerus87
Upvote 0
Every Actor instance has a reference to the WorldInfo instance. The WorldInfo in turn has a reference to the GameInfo instance (WorldInfo.Game), and that has a reference to an AccessControl instance.

AccessControl isn't actually an inner class, and AccessControl isn't a static function. Inner classes include a 'within' clause in their class definition, and cannot be Actors. AccessControl extends Info which extends Actor, and - as you'd expect - doesn't have a 'within' clause.
 
  • Like
Reactions: Nerus87
Upvote 0