• 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/
  • Weve updated the Tripwire Privacy Notice under our Policies to be clearer about our use of customer information to come in line with the EU General Data Protection Regulation (GDPR) rules that come into force today (25th May 2018). The following are highlights of our changes:


    We've incorporated the relevant concepts from the GDPR including joining the EU and Swiss Privacy Shield framework. We've added explanations for why and how Tripwire processes customer data and the types of data that we process, as well as information about your data protection rights.



    For more information about our privacy practices, please review the new Privacy Policy found here: https://tripwireinteractive.com/#/privacy-notice

Couple of mutator coding questions

Justbleed

FNG / Fresh Meat
Jul 7, 2015
2
0
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.
 

dibbler67

FNG / Fresh Meat
Sep 4, 2011
654
6
0
Texas
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 :)