Jump to content

Recommended Posts

Posted (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 not


Questions:
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)
 

  Reveal hidden contents

File: Rx_Mutator_Controller.uc (content)
 

  Reveal hidden contents

 

I would appriciate any solution.

Edited by Ukill
  • Totem Arts Staff
Posted

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. 

 

 

Posted (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 : 

  1. function TestModeStart()
  2. {
  3.     if( Role < Role_Authority )
  4.     {
  5.         // if we're a client, Notify/synchronize server
  6.         ServerToggleTestMode();
  7.     }
  8.  
  9.     bTestMode = true;
  10.     TestModeCheck();
  11.  
  12. }   // Start TestMode

 

I got now the following 2 files below :

File: Rx_Mutator.uc (content)

  Reveal hidden contents

 

File: Rx_Mutator_Controller.uc (content)

  Reveal hidden contents

What do i need to add or remove ?

Edited by Ukill
Posted

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.

  • Like 1
Posted (edited)

 

Successful :)


File: Rx_Mutator_Controller.uc (content)

  Reveal hidden contents

 

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 by Ukill
  • Totem Arts Staff
Posted

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

  • Like 1
Posted

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.
  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...