Ukill Posted February 5, 2017 Share Posted February 5, 2017 (edited) Howto set replicated variable with unrealscript: Goals : (Create a var, that i can use to enable\disable functions ) 1. Set the "var (bool) bTestMode" 2. Change it with exec function 3. If "var (bool) bTestMode" changed on client\server -> replicate value to server\all other clients 4. (optional) Keep the "var (bool) bTestMode" alive between MapChange and when notQuestions: 1. Are my goals possible\logical ? 2. Do I extend the class to the right class? (or can i better choose others ?)Content: The scripts does what i did planned, except that it does not change the same variable on other clients. For my question i created 2 files : - Rx_Mutator_TestMode.uc - Rx_Mutator_TestMode_Controller.uc File: Rx_Mutator_TestMode.uc (content) Spoiler // *************************************************************************************************************** // * * * * * * * * * * * * * * * * * * * * * * Rx_Mutator_TestMode * * * * * * * * * * * * * * * * * * * * * * * * // *************************************************************************************************************** class Rx_Mutator_TestMode extends UTMutator; var RepNotify Bool bTestMode; replication { if (bNetDirty) bTestMode; } function InitMutator(string Options, out string ErrorMessage) { if (Rx_Game(WorldInfo.Game) != None) { } super.InitMutator(Options, ErrorMessage); } function bool CheckReplacement(Actor Other) { if(Other.IsA('Rx_TeamInfo')) { Rx_Game(WorldInfo.Game).PlayerControllerClass = class'Rx_Mutator_TestMode_Controller'; } return true; } File: Rx_Mutator_Controller.uc (content) Spoiler // *************************************************************************************************************** // * * * * * * * * * * * * * * * * * * * * * * Rx_Mutator_Controller * * * * * * * * * * * * * * * * * * * * * * * // *************************************************************************************************************** class Rx_Mutator_TestMode_Controller extends Rx_Controller; var RepNotify Bool bTestMode; replication { if (bNetDirty) bTestMode; } exec function TestModeCheck() { if (bTestMode) { ClientMessage("TestMode activated",,1); } else { ClientMessage("TestMode deactivated",,1); } } // Check TestMode simulated function TestModeStart() { if ( (PlayerReplicationInfo.bAdmin) == true ) { bTestMode = true; TestModeCheck(); } else { ClientMessage("First login as admin",,1); } } // Start TestMode simulated function TestModeStop() { if ( (PlayerReplicationInfo.bAdmin) == true ) { bTestMode = false; TestModeCheck(); } else { ClientMessage("First login as admin",,1); } } // Stop TestMode exec function TestModeToggle() { if ((PlayerReplicationInfo.bAdmin) == true ) { if (bTestMode) { TestModeStop(); } else { TestModeStart(); } } else { ClientMessage("First login as admin",,1); } } // Toggle (stop/start) TestMode I would appriciate any solution. Edited February 7, 2017 by Ukill Quote Link to comment Share on other sites More sharing options...
Totem Arts Staff yosh56 Posted February 6, 2017 Totem Arts Staff Share Posted February 6, 2017 Exec functions are usually simulated and called on the client themselves. You would have to call either a reliable, or unreliable 'server' function from one command (The command on the client), then in the actual server command is where you would take that action. Like: exec function ToggleTestMode() { //Just call for server to try and toggle ServerToggleTestMode() } reliable server function ServerToggleTestMode() { if ((PlayerReplicationInfo.bAdmin) == true ) //Only ever do admin checks on the actual server. { if (bTestMode) { TestModeStop(); } else { TestModeStart(); } } else { ClientMessage("First login as admin",,1); } } You also don't need TestModeStop(), and TestModeStart() to be simulated, since they should always be toggled on the server or in a realm where they have ROLE_AUTHORITY. Quote Link to comment Share on other sites More sharing options...
Ukill Posted February 6, 2017 Author Share Posted February 6, 2017 (edited) Thanks @yosh56, but i did not succeed, it does set the value, but does not replicate it, i dont know what i am doing wrong. I also did try to change the TesetModeStart function : function TestModeStart() { if( Role < Role_Authority ) { // if we're a client, Notify/synchronize server ServerToggleTestMode(); } bTestMode = true; TestModeCheck(); } // Start TestMode I got now the following 2 files below : File: Rx_Mutator.uc (content) Spoiler // ***************************************************************************** // * * * * * * * * * * * * * * * * Rx_Mutator * * * * * * * * * * * * * * * * * // ***************************************************************************** class Rx_Mutator_TestMode extends Rx_Mutator; function InitMutator(string Options, out string ErrorMessage) { if (Rx_Game(WorldInfo.Game) != None) { } super.InitMutator(Options, ErrorMessage); } function bool CheckReplacement(Actor Other) { if(Other.IsA('Rx_TeamInfo')) { Rx_Game(WorldInfo.Game).PlayerControllerClass = class'Rx_Mutator_TestMode_Controller'; } return true; } defaultproperties { } File: Rx_Mutator_Controller.uc (content) Spoiler // ***************************************************************************** // * * * * * * * * * * * * * Rx_Mutator_Controller * * * * * * * * * * * * * * // ***************************************************************************** class Rx_Mutator_TestMode_Controller extends Rx_Controller; var RepNotify Bool bTestMode; replication { if (bNetDirty) bTestMode; } exec function TestModeCheck() { if (bTestMode) { ClientMessage("TestMode activated",,1); } else { ClientMessage("TestMode deactivated",,1); } } // Check TestMode /* You also don't need TestModeStop(), and TestModeStart() to be simulated, since they should always be toggled on the server or in a realm where they have ROLE_AUTHORITY. */ function TestModeStart() { bTestMode = true; TestModeCheck(); } // Start TestMode function TestModeStop() { bTestMode = false; TestModeCheck(); } // Stop TestMode exec function TestModeToggle() { if ((PlayerReplicationInfo.bAdmin) == true ) { if (bTestMode) { TestModeStop(); } else { TestModeStart(); } } else { ClientMessage("First login as admin",,1); } } // Toggle (stop/start) TestMode exec function ToggleTestMode() { ServerToggleTestMode(); } //Just call for server to try and toggle reliable server function ServerToggleTestMode() { if ((PlayerReplicationInfo.bAdmin) == true ) { if (bTestMode) { TestModeStop(); } else { TestModeStart(); } } else { ClientMessage("First login as admin",,1); } } //Only ever do admin checks on the actual server. defaultProperties { bTestMode=false; } What do i need to add or remove ? Edited February 7, 2017 by Ukill Quote Link to comment Share on other sites More sharing options...
Totem Arts Staff yosh56 Posted February 6, 2017 Totem Arts Staff Share Posted February 6, 2017 How are you confirming that it actually sets it on the server? Quote Link to comment Share on other sites More sharing options...
Ukill Posted February 6, 2017 Author Share Posted February 6, 2017 I check it with an other client or i reconnect to the game and do TestModeCheck Quote Link to comment Share on other sites More sharing options...
Totem Arts Staff yosh56 Posted February 6, 2017 Totem Arts Staff Share Posted February 6, 2017 So what clients doesn't it replicate to? Quote Link to comment Share on other sites More sharing options...
Ukill Posted February 6, 2017 Author Share Posted February 6, 2017 None, it does not matter from which client i try, but it will change the variable local Quote Link to comment Share on other sites More sharing options...
Agent Posted February 6, 2017 Share Posted February 6, 2017 Are you trying to set bTestMode on every Controller? If so then you're not having a replication issue; you have to iterate through every controller and set the variable on the server, which then replicates to the client for their respective controller. Every player has a separate Controller. I'm sure you can find an example of iterating through AllControllers in Rx_Game somewhere. 1 Quote Link to comment Share on other sites More sharing options...
Ukill Posted February 6, 2017 Author Share Posted February 6, 2017 Thanks! @Agent, i am gonna search and try it out. Quote Link to comment Share on other sites More sharing options...
Ukill Posted February 7, 2017 Author Share Posted February 7, 2017 (edited) Successful File: Rx_Mutator_Controller.uc (content) Spoiler // ***************************************************************************** // * * * * * * * * * * * * * Rx_Mutator_Controller * * * * * * * * * * * * * * // ***************************************************************************** class Rx_Mutator_TestMode_Controller extends Rx_Controller; var RepNotify Bool bTestMode; replication { if(bNetDirty) // if(bNetDirty && ROLE == ROLE_Authority) bTestMode; } exec function TestModeCheck() { // Check TestMode if (bTestMode) { ClientMessage("TestMode activated",,1); } else { ClientMessage("TestMode deactivated",,1); } } function TestModeToggleSet() { // Stop TestModeSet if (bTestMode) { bTestMode=false; //false } else { bTestMode=true; //true } } exec function TestModeToggle() { //Just call for server to try and toggle ServerTestModeToggle(); } reliable server function ServerTestModeToggle() { local Rx_Mutator_TestMode_Controller C; if (PlayerReplicationInfo.bAdmin) { foreach WorldInfo.AllControllers(class'Rx_Mutator_TestMode_Controller', C) { C.TestModeToggleSet(); C.TestModeCheck(); } } else { ClientMessage("First login as admin",,1); } } //Only ever do admin checks on the actual server. DefaultProperties { bTestMode=false; } Now i like to find out how i do Keep the variable alive between Map Changes ? Do i need then to extend to an other class ? Any idea's @yosh56 or @Agent ? Edited February 7, 2017 by Ukill Quote Link to comment Share on other sites More sharing options...
Totem Arts Staff yosh56 Posted February 11, 2017 Totem Arts Staff Share Posted February 11, 2017 You would have to use seamless loading which RenX hasn't used since the days of crashing every single game. I think Agent had an alternative at some point, but I don't know if you can tap into that with a mutator 1 Quote Link to comment Share on other sites More sharing options...
Agent Posted February 11, 2017 Share Posted February 11, 2017 Other than seamless travel, it is absolutely impossible to transfer anything that extends from Actor between levels, because an Actor exists on the level itself. I've been passing certain non-Actor variables such as the connection to the server list through Rx_GameEngine lately, but this isn't at all intended to be used by modders since including an Actor in there literally crashes the game client. I'm sure I could create some sort of interface for this though if it's genuinely useful -- just be aware that however I implement it, it wouldn't accept Actors in any way. The options available to you are: Write variables to a config file -- this is probably the most straight forward way to do what you want Pass variables as a server travel parameter -- this requires extending Rx_Game and using a config file would generally be cleaner Use seamless travel -- this is not recommended or supported in any way, and could have screwy results since we haven't tested anything with it in a very long time. 1 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.