• 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/

Code Couple of mutator coding questions

Justbleed

FNG / Fresh Meat
Jul 7, 2015
2
0
Hello,

I am new to UE3 mutator coding, but with UE3 online docs and some posts here on this forum, I think I was able to figure out the basics. Atm, I have couple of questions. Please see example code below.


class MyMutator extends Mutator;

simulated function PreBeginPlay()
{

local ROMapInfo MyMapInfo;
MyMapInfo = ROMapInfo(WorldInfo.GetMapInfo());

//do something with MyMapInfo here

SetTimer(2, true);

}

function Timer()
{

local ROGameInfo MyGameInfo;
local ROMapInfo MyMapInfo;
local Controller MyController;
local ROPlayerReplicationInfo MyPlayerInfo;

MyMapInfo = ROMapInfo(WorldInfo.GetMapInfo());
MyGameInfo = ROGameInfo(WorldInfo.Game);

for (MyController = WorldInfo.Controllerlist; MyController != None; MyController = MyController.NextController)
{
MyPlayerInfo = ROPlayerReplicationInfo(MyController.PlayerReplicationInfo);

//do something with MyPlayerInfo, MyGameInfo and MyMapInfo here

}

}


Does it matter if MyMutator extends Mutator or ROMutator?
Do I need to do some destroying, now when Timer() is executed every 2 seconds?
If PreBeginPlay() needs to be executed both client and server side, is it ok to have it as simulated function here, now when Timer() is executed only server side? If I have understood docs correctly, this is what happens with this mutator.
 
Hello!

Hello,
Does it matter if MyMutator extends Mutator or ROMutator?

Strictly speaking, no it does not. However, ROMutator does provide the interface for the in-game configuration menu and a couple other features. There's no reason you wouldn't want to use it, I don't think.

Do I need to do some destroying, now when Timer() is executed every 2 seconds?

No, you shouldn't need to. However, I would recommend you iterate this way:

Code:
foreach (WorldInfo.AllControllers(class'Controller',MyController)
{
   MyPlayerInfo = ROPlayerReplicationInfo(MyController.PlayerReplicationInfo);
//....
}

Some more info on iterators: http://udn.epicgames.com/Three/UnrealScriptIterators.html

If PreBeginPlay() needs to be executed both client and server side, is it ok to have it as simulated function here, now when Timer() is executed only server side?
Making it simulated is necessary, but you must also modify the RemoteRole of your Mutator so that client-side execution of simulated functions is allowed. Details here: http://wiki.tripwireinteractive.com/index.php?title=Multiplayer_Mutators
Also it is usually better to use PostBeginPlay() for this purpose, because most Actors perform their initialization here anyway.

After all that, your timer function will not be executed on clients (which I gather is intended). However a timer will be set on clients, and the client will attempt to call Timer() every 2 seconds. To prevent this kind of waste, enclose the SetTimer in this:

Code:
if(Role == ROLE_Authority)
{
    SetTimer(2,true);
}

The mutator's Role is ROLE_Authority on the server and will be ROLE_SimulatedProxy on the clients (in your case. It's ROLE_None by default). I hope that was helpful :)
 
Upvote 0