Ukill Posted February 28, 2017 Share Posted February 28, 2017 (edited) The script below is working as expected, all variables get replicated to player in game on change, except that the default variables get replicated to users that join the game, instead of the current ones. I think that i need to create a function that is executed on the clients from new players, so it will get the variables from the server, but have no idea how to do it. Does anybody have an idea how to complete this replication ? The variables are :var RepNotify string RefArrayStatus [4];var RepNotify int RefArrayAccessLevel [4]; // ***************************************************************************** // * * * * * * * * * * Rx_Mutator_AdminTool_Controller * * * * * * * * * * * * // Written by Ukill, Supported by ........................................... // ***************************************************************************** class Rx_Mutator_AdminTool_Controller extends Rx_Controller; //General var var string RefArrayName [4]; //ReferenceNameArray var string RefArrayDescription [4]; //ReferenceDescriptionArray var RepNotify string RefArrayStatus [4]; //ReferenceStatusArray var RepNotify int RefArrayAccessLevel [4]; //ReferenceAccessLevelArray var bool OSA; //OneStepAuthentication var int ArrayLength; var bool DebugMode; replication { if (bNetDirty && Role == ROLE_Authority) RefArrayStatus,RefArrayAccessLevel; } exec function AdminTool(string sToggleName, optional string sStatus, optional string iAccessLevel) { local string sStatusOut; local string iAccessLevelOut; local int x; local int y; //Filter bad sToggleName for (x = 0; x < ArrayLength ; x++) { if (RefArrayName[x] != sToggleName) { y=y++; if (y == ArrayLength) { sToggleName=""; sStatus=""; iAccessLevel=""; } } } // Swap if order is different if ( Len(sStatus) == 1 && Len(iAccessLevel) == 0 ) { iAccessLevel=(sStatus); sStatus="Skip"; } else if ( Len(iAccessLevel) > Len(sStatus) ) { sStatusOut=(iAccessLevel); (iAccessLevelOut)=(sStatus); iAccessLevel=(iAccessLevelOut); sStatus=(sStatusOut); } // Do status stuff if ( Len(iAccessLevel) == 0 && Len(sStatus) == 0 || "true" == sStatus || "false" == sStatus ) { ServerAdminToolStatus(sToggleName, sStatus); } //Do AccessLevel stuff if ( Len(iAccessLevel) == 1 && int(iAccessLevel) != 0 && int(iAccessLevel) > 0 && int(iAccessLevel) < 6) { ServerAdminToolAccessLevel(sToggleName, int(iAccessLevel)); } // Show summary if ( DebugMode == true ) { AdminToolInfo(); } } reliable server function ServerAdminToolStatus(string sToggleName, optional string sStatus) { local Rx_Mutator_AdminTool_Controller C; if ( DebugMode == true ) { ClientMessage("Started function ServerAdminToolAccessLevel with variables sToggleName: " $ sToggleName $ " sStatus: " $ sStatus); } /* * * * * * * * * * * * * * * * * * * * */ // DONT CHANGE - Start Authentication Check AdminToolAccessLevelAuth(RefArrayAccessLevel[0]); if (OSA == true && (RefArrayStatus[0]) == "true" ) { OSA=false; // DONT CHANGE - Stop Authentication Check /* * * * * * * * * * * * * * * * * * * * */ foreach WorldInfo.AllControllers(class'Rx_Mutator_AdminTool_Controller', C) { C.ServerAdminToolStatusDo(sToggleName, sStatus); } } else { foreach WorldInfo.AllControllers(class'Rx_Mutator_AdminTool_Controller', C) { ClientMessage(PlayerReplicationInfo.PlayerName $ " : You must be admin to use the ToggleStatus function"); } } } reliable server function ServerAdminToolAccessLevel(string sToggleName, int iAccessLevel) { local Rx_Mutator_AdminTool_Controller C; if ( DebugMode == true ) { ClientMessage("Started function ServerAdminToolAccessLevel with variables sToggleName: " $ sToggleName $ " iAccessLevel: " $ iAccessLevel); } /* * * * * * * * * * * * * * * * * * * * */ // DONT CHANGE - Start Authentication Check AdminToolAccessLevelAuth(RefArrayAccessLevel[0]); if (OSA == true && (RefArrayStatus[0]) == "true" ) { OSA=false; // DONT CHANGE - Stop Authentication Check /* * * * * * * * * * * * * * * * * * * * */ foreach WorldInfo.AllControllers(class'Rx_Mutator_AdminTool_Controller', C) { C.ServerAdminToolAccessLevelDo(sToggleName, iAccessLevel); } } else { foreach WorldInfo.AllControllers(class'Rx_Mutator_AdminTool_Controller', C) { ClientMessage(PlayerReplicationInfo.PlayerName $ " : You must be admin to use the ToggleAccessLevel function"); } } } exec function AdminToolInfo() { local int x; local string Msg; /* * * * * * * * * * * * * * * * * * * * */ // DONT CHANGE - Start Authentication Check AdminToolAccessLevelAuth(RefArrayAccessLevel[0]); if (OSA == true && (RefArrayStatus[0]) == "true" ) { OSA=false; // DONT CHANGE - Stop Authentication Check /* * * * * * * * * * * * * * * * * * * * */ ClientMessage(" "); ClientMessage(" Info: function AdminToolInfo"); ClientMessage(" "); ClientMessage(" Level: Status: Name: Description:"); ClientMessage(" "); for (x = 0; x < ArrayLength ; x++) { Msg = " " $ RefArrayAccessLevel[x] $ " " $ RefArrayStatus[x] $ " " $ RefArrayName[x] $ " " $ RefArrayDescription[x]; ClientMessage(Msg); } ClientMessage(""); } } function ServerAdminToolStatusDo(string sToggleName, optional string sStatus) // ToggleStatus Option: true,false,empty(autotoggle) { local int x; if ( DebugMode == true ) { ClientMessage("Started function ServerAdminToolStatusDo with variables sToggleName: " $ sToggleName $ " sStatus: " $ sStatus); } if ( DebugMode == true ) { ClientMessage("Jump in array with variable sToggleName: " $ sToggleName); } for (x = 0; x < ArrayLength ; x++) { if(sToggleName == RefArrayName[x] ) { if (sStatus == "true") { RefArrayStatus[x] = ("true"); if ( DebugMode == true ) ClientMessage( RefArrayStatus[x] $ " Found!" $ sToggleName ); } else if (sStatus == "false") { RefArrayStatus[x] = ("false"); if ( DebugMode == true ) ClientMessage( RefArrayStatus[x] $ " Found!" $ sToggleName ); } else if ("true" == RefArrayStatus[x] ) { RefArrayStatus[x] = ("false"); if ( DebugMode == true ) ClientMessage( RefArrayStatus[x] $ " Found!" $ sToggleName ); } else if ("false" == RefArrayStatus[x] ) { RefArrayStatus[x] = ("true"); if ( DebugMode == true ) ClientMessage( RefArrayStatus[x] $ " Found!" $ sToggleName ); } else { if ( DebugMode == true ) ClientMessage( RefArrayStatus[x] $ " None found!" $ sToggleName ); } } } } function ServerAdminToolAccessLevelDo(string sToggleName, int iAccessLevel){ local int x; if ( DebugMode == true ) { ClientMessage("Started function AdminToolAccessLevel with variables sToggleName: " $ sToggleName $ " iAccessLevel: " $ iAccessLevel); } for (x = 0; x < ArrayLength ; x++) { if( sToggleName == RefArrayName[x] ) { RefArrayAccessLevel[x] = (iAccessLevel); } } } function AdminToolAccessLevelAuth(int iAccessLevel) { local string GroupName; OSA=false; switch (iAccessLevel) { case 0: break; case 1: Groupname="None"; if (PlayerReplicationInfo.PlayerName == "") { OSA=true; } break; case 2: GroupName="All Users"; if (PlayerReplicationInfo.PlayerName != "") { OSA=true; } break; case 3: GroupName="Administrators"; if (PlayerReplicationInfo.bAdmin && PlayerReplicationInfo.PlayerName != "") { OSA=true; } break; case 4: GroupName="Developers"; if (PlayerReplicationInfo.PlayerName != "" && bIsDev) { OSA=true; } break; case 5: GroupName="Administrators or Developers"; if (PlayerReplicationInfo.bAdmin || bIsDev) { OSA=true; } break; } if ( OSA == true ) { ClientMessage( GroupName $ " Accepted with Level : " $ iAccessLevel ); } else if ( OSA == false ) { ClientMessage( GroupName $ " Denied with Level : " $ iAccessLevel ); } // Maybe later add here the modename in the clientmessage } defaultproperties { //General OSA=false DebugMode=false; //AuthMode=false; // AccessLevel 0 for None ArrayLength=4; // AccessLevel 1 for All Users // AccessLevel 2 for Administrators //ModeNames // AccessLevel 3 for Developers RefArrayName[0]="allmode"; RefArrayName[1]="mode1"; // RefArrayName (string) RefArrayName[2]="mode2"; // ModeNames : this variable is used to set the default Name for any Mode RefArrayName[3]="mode3"; // RefArrayStatus (string) //Modedescription // ModeStatus : This variable is used to set the default Status for any Mode. (false and False) RefArrayDescription[0]="All modes"; RefArrayDescription[1]="FutureSoldier"; // RefArrayAccessLevel (int) RefArrayDescription[2]="SandboxSpawn"; // Modesnames : This variable is used to set the default AccessLevel for any Mode. (0-4) RefArrayDescription[3]="SandboxGimme"; // TODO: create accesslevels that are static to users, for use in subfunctions //ModeStatus RefArrayStatus[0]="true"; RefArrayStatus[1]="true"; RefArrayStatus[2]="true"; RefArrayStatus[3]="true"; //ModeAccessLevel RefArrayAccessLevel[0]=2; RefArrayAccessLevel[1]=0; RefArrayAccessLevel[2]=0; RefArrayAccessLevel[3]=0; } Edited March 2, 2017 by Ukill add "if (bNetDirty && Role == ROLE_Authority)" to the script Quote Link to comment Share on other sites More sharing options...
Totem Arts Staff yosh56 Posted March 1, 2017 Totem Arts Staff Share Posted March 1, 2017 if(bNetDirty || bNetInitial) Pretty sure.... I don't know the full context. Quote Link to comment Share on other sites More sharing options...
Ukill Posted March 2, 2017 Author Share Posted March 2, 2017 I did try to add the replication block below: replication { if ( bNetDirty && Role == ROLE_Authority ) RefArrayStatus,RefArrayAccessLevel; } More info about the replication block : Spoiler replication { // To actually replicate a function call from the server to a client you have to use a replication statement like the following: reliable if ( Role == ROLE_Authority ) FunctionName; // This will replicate function calls for FunctionName to the client this actor belongs to. If the actor is either owned by the // server's player or Owner is None the function will be executed on the server like a regular function. // To replicate a function call from a client to the server you have to use a replication statement like the following: reliable if ( Role < ROLE_Authority ) FunctionName; // This replicated function calls for FunctionName to the server if the actor is owned by this client's player. } /* Things that may go wrong when replication functions: Client -> Server replication will not work if the actor is owned by the server player (on a listen server) or by a client other than the one trying to replicate something or when the actor has no owner. Server -> Client replication will be useless if the replicated function isn't a simulated function (unless the actor's Role on that client is ROLE_AutonomousProxy, which it usually isn't). */ I did use "( bNetDirty && Role == ROLE_Authority )" in the script, because in other scripts this gave me the most accurate replication. In the end the problem is still here, it is impossible for me to replicate a static array (Only for players that join an existing game) I also found some errors in the server-log : RefArrayStatus: [0249.49] ScriptWarning: Accessed array 'Rx_Mutator_AdminTool_Controller_0.RefArrayStatus' out of bounds (6/6) Rx_Mutator_AdminTool_Controller CNC-Walls_Flying.TheWorld:PersistentLevel.Rx_Mutator_AdminTool_Controller_0 Function Rx_Mutator_AdminTool.Rx_Mutator_AdminTool_Controller:AdminToolNotifyServerAccessLevel:002D RefArrayAccessLevel: [0249.49] ScriptWarning: Accessed array 'Rx_Mutator_AdminTool_Controller_0.ServerRefArrayAccessLevel' out of bounds (6/6) Rx_Mutator_AdminTool_Controller CNC-Walls_Flying.TheWorld:PersistentLevel.Rx_Mutator_AdminTool_Controller_0 Function Rx_Mutator_AdminTool.Rx_Mutator_AdminTool_Controller:AdminToolNotifyServerAccessLevel:004E I do also saw the output of the "simulated event ReplicatedEvent(name VarName)", this means in my opinion that the replication at least runs/starts for the array variables. T see the output below when I Toogle mode 4 to level 2: Server current values Rx_Mutator_AdminTool_Controller.ServerRefArrayAccessLevel to ( [1] = 2, [2] = 2, [3] = 3, [4] = 4, [5] = 1) Function ReplicatedEvent touched with VarName: ServerRefArrayAccessLevel Server updated Rx_Mutator_AdminTool_Controller.ServerRefArrayAccessLevel to ( [1] = 2, [2] = 2, [3] = 3, [4] = 2, [5] = 1) I think i got a dirty solution to get the replication working, because it is possible for me to replicate "normal" variables. I am thinking about that i could create some "normal" variables that will do the replication, whereby after the replication i push those value's from the normal variables to the "array variables", as far as i can see now this will get my script working but gives me a couple of disadvantages : my script will grow in size, and a lot of variables will have duplicated value's. I will try to get it to work like described above, but i am still searching for that "better way", and have no idea what to think about or what i can do to solve the "out of bounds (6/6)" error Quote Link to comment Share on other sites More sharing options...
Ukill Posted March 2, 2017 Author Share Posted March 2, 2017 1 hour ago, Ukill said: I also found some errors in the server-log : RefArrayStatus: [0249.49] ScriptWarning: Accessed array 'Rx_Mutator_AdminTool_Controller_0.RefArrayStatus' out of bounds (6/6) Rx_Mutator_AdminTool_Controller CNC-Walls_Flying.TheWorld:PersistentLevel.Rx_Mutator_AdminTool_Controller_0 Function Rx_Mutator_AdminTool.Rx_Mutator_AdminTool_Controller:AdminToolNotifyServerAccessLevel:002D RefArrayAccessLevel: [0249.49] ScriptWarning: Accessed array 'Rx_Mutator_AdminTool_Controller_0.ServerRefArrayAccessLevel' out of bounds (6/6) Rx_Mutator_AdminTool_Controller CNC-Walls_Flying.TheWorld:PersistentLevel.Rx_Mutator_AdminTool_Controller_0 Function Rx_Mutator_AdminTool.Rx_Mutator_AdminTool_Controller:AdminToolNotifyServerAccessLevel:004E I will try to get it to work like described above, but i am still searching for that "better way", and have no idea what to think about or what i can do to solve the "out of bounds (6/6)" error Meanwhile the "out of bounds (6/6)" problem disappear. Quote Link to comment Share on other sites More sharing options...
Agent Posted March 2, 2017 Share Posted March 2, 2017 You could try adding code to PostBeginPlay in the controller. Quote Link to comment Share on other sites More sharing options...
Ukill Posted March 2, 2017 Author Share Posted March 2, 2017 (edited) Thanks @Agent, but i really don't know what to add there. Because i really dont know what to change in my existing script i decided to start over again, and put my focus on the replication, whereby i build my script around itSo i started first to do just a simple replication. class Rx_Mutator_CountDown_Controller extends Rx_Controller; var repnotify int Count; replication { if (bNetDirty && (Role==ROLE_Authority)) Count; } simulated event ReplicatedEvent(name VarName) { if (VarName == 'Count') { Count=(Count); } else { super.ReplicatedEvent(VarName); } } exec function DoCountDown() { ServerCountIt(); } reliable server function ServerCountIt() { local Rx_Mutator_CountDown_Controller C; foreach WorldInfo.AllControllers(class'Rx_Mutator_CountDown_Controller', C) { C.Count=(Count); C.CountIt(); } } simulated function CountIt() { local int TimeSec, TimeTenSec; Count--; TimeSec = Count % 10; TimeTenSec = (Count / 10); ClientMessage( " TimeTenSecTimeSec: " $ TimeTenSec $ TimeSec); SetTimer(2, false, 'ServerCountIt'); } defaultproperties { Count=180.0 } and extended this with my arrayvariable, now it is finally possible to replicate string/int-array // ***************************************************************************** // * * * * * * * * * * Rx_Mutator_AdminTool_Controller * * * * * * * * * * * * // Written by Ukill, Supported by ........................................... // ***************************************************************************** class Rx_Mutator_AdminTool_Controller extends Rx_Controller; var repnotify string MyText; var repnotify int Cycle; var repnotify string RefArrayStatus[2]; var repnotify int RefArrayAccessLevel[2]; var int ArrayLength; replication { if (bNetDirty && (Role==ROLE_Authority)) RefArrayAccessLevel,RefArrayStatus,MyText,Cycle; } simulated event ReplicatedEvent(name VarName) { local int x; if (VarName == 'MyText') { MyText=(MyText); } else if (VarName == 'Cycle') { Cycle=(Cycle); } else if (VarName == 'RefArrayStatus') { for (x = 0; x < ArrayLength ; x++) { RefArrayStatus[x]=(RefArrayStatus[x]); } } else if (VarName == 'RefArrayAccessLevel') { for (x = 0; x < ArrayLength ; x++) { RefArrayAccessLevel[x]=(RefArrayAccessLevel[x]); } } else { super.ReplicatedEvent(VarName); } } simulated event PreBeginPlay() { SetTimer(5, true, 'ServerReplicate'); } exec function DoReplicate() { ServerReplicate(); } reliable server function ServerReplicate() { local Rx_Mutator_AdminTool_Controller C; local int x; foreach WorldInfo.AllControllers(class'Rx_Mutator_AdminTool_Controller', C) { C.Cycle=(Cycle); C.MyText=(MyText); for (x = 0; x < ArrayLength ; x++) { C.RefArrayStatus[x]=(RefArrayStatus[x]); C.RefArrayAccessLevel[x]=(RefArrayAccessLevel[x]); } C.Replicate(); } } simulated function Replicate() { local string MyString; local int x; Cycle++; MyString = MyText $ Cycle; for (x = 0; x < ArrayLength ; x++) { if (RefArrayStatus[x] == "true") { RefArrayStatus[x]="false"; } else { RefArrayStatus[x]="true"; } RefArrayAccessLevel[x]--; } for (x = 0; x < ArrayLength ; x++) { ClientMessage( MyString $ " - RefArrayStatus[" $ x $ "]=" $ RefArrayStatus[x]); ClientMessage( MyString $ " - RefArrayAccessLevel[" $ x $ "]=" $ RefArrayAccessLevel[x]); } //ClientMessage( MyString $ " - RefArrayStatus[0]=" $ RefArrayStatus[0] $ " RefArrayStatus[1]=" $ RefArrayStatus[1] ); } defaultproperties { ArrayLength=2; MyText="Replication #"; Cycle=0; RefArrayStatus[0]=""; RefArrayStatus[1]=""; RefArrayAccessLevel[0]=1000; RefArrayAccessLevel[1]=100000; } But i am still searching for the fault in my existing script : Why will it not replicate to new users, and what exactly needs to be modified ? I did find the issue that is responsible for the players that are not in game yet. after an other try of search and compare. Foreach WorldInfo.AllControllers(class'Rx_Mutator_AdminTool_Controller', C) { -> for (x = 0; x < ArrayLength ; x++) -> { -> C.RefArrayStatus[x]=(RefArrayStatus[x]); -> } C.ServerAdminToolStatusDo(sToggleName, sStatus); } But finally, it works !!!! Edited March 2, 2017 by Ukill Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.