@@ -3,95 +3,65 @@ class SQW_ColorChangerClass : ScriptComponentClass
33{
44}
55
6-
6+ //------------------------------------------------------------------------------------------------
7+ /* SIMPLE REPLICATION IMPLEMENTATION TUTORIAL BASED ON THE FOLLOWING TUTORIALS:
8+ https://community.bistudio.com/wiki/Arma_Reforger:Multiplayer_Scripting
9+ https://www.youtube.com/watch?v=4Tnbf44NjXo&list=PLxwrIHk2cX5t4vQMdHDwtJvJ1ngACyyDO&index=7&t=320s
10+ */
711//------------------------------------------------------------------------------------------------
812class SQW_ColorChanger : ScriptComponent
913{
10-
11- /*
12- You totally can change materials via script, you can use ParametricMaterialInstanceComponent component
13- for basic emat attributes or if you want something a bit more advanced then you can use
14- SCR_CustomMaterialAnimatorEntity (check the docs of this entity in the file where it is defined at)
15- or you can implement your own if you need a bit more control.
16- All of these will change the material for a specific entity instance, so it's not global
17- */
18-
1914 protected BaseWorld m_World ;
15+ protected ref RandomGenerator m_pRandomGenerator ;
2016
2117 //Cube
2218 protected GameEntity m_Cube ;
2319 ParametricMaterialInstanceComponent m_ParametricMaterialinstanceComponent ;
24-
25-
26- //location: X,Y,Z
27- vector m_vOrigin = {60 , 1 , 70 };
20+
2821
2922 //Replication
30- // [RplProp(onRplName: "OnColorChanged")] // this value is to be updated by the authority, not set locally by proxies (even owner)
31- protected int m_Color ; // if it is set locally, the change will not broadcast and there will be a difference between the proxy and the authority
32- // this state discrepancy will last until authority's next update broadcast
33- protected ref RandomGenerator m_pRandomGenerator ;
23+ [RplProp (onRplName : "OnColorChanged" )] // m_Color: this value is to be updated by the authority, not set locally by proxies (even owner)
24+ protected int m_Color ; // if it is set locally, the change will not broadcast and there will be a difference between the proxy and the authority
25+ // this state discrepancy will last until authority's next update broadcast
26+
3427
3528
3629 // Attached component.
3730 protected RplComponent m_pRplComponent ;
3831
39- /*
40- protected SQW_EditableCommentEntity m_pComment;
4132
42- //HUD
43- protected SCR_EditableCommentComponent m_NLoCTextBox;
44- protected bool m_bNetLoadOnClient;
45- protected SCR_EditableCommentComponent m_RplTextBox;
46- protected bool m_bReplicated;
47- protected SCR_EditableCommentComponent m_ColorTextBox;
48- */
49-
5033
5134 //------------------------------------------------------------------------------------------------
5235 [RplRpc (RplChannel .Reliable , RplRcver .Server )]
53- protected void RpcAsk_Authority_Method (bool turningOn )
54- {
55- }
56-
57- /*
58- //------------------------------------------------------------------------------------------------
59- // Called on the authority when an entity gets streamed
60- override bool RplSave(ScriptBitWriter writer)
61- {
62- writer.Write(m_Color, 32); //write 32 bits of m_Color - int is 32 bits in size
63- return true;
36+ protected void RpcAsk_Authority_Method ()
37+ {
38+ Print ("authority-side code" );
39+ //Change Color
40+ m_Color = GetRandomColor ();
41+ m_ParametricMaterialinstanceComponent .SetColor (m_Color );
42+ Replication .BumpMe ();
6443 }
6544
6645 //------------------------------------------------------------------------------------------------
67- // Called on the streamed proxy
68- override bool RplLoad(ScriptBitReader reader)
69- {
70-
71- if (!reader.Read(m_Color, 32)) // read 32 bits of data - the authority wrote m_Color first, so it needs to be read first
72- {
73- return false;
74- }
75-
76-
77- return true;
46+ // T
47+ protected void OnColorChanged ()
48+ {
49+ //Change Color
50+ //m_Color = GetRandomColor();
51+ Print ("proxy-side code" );
52+ m_ParametricMaterialinstanceComponent .SetColor (m_Color );
7853 }
79- */
80-
81-
82-
8354
8455 //------------------------------------------------------------------------------------------------
8556 protected void OnTriggerActivate ()
8657 {
87- //Change Color
88- m_Color = GetRandomColor ();
89- m_ParametricMaterialinstanceComponent .SetColor (m_Color );
58+ //Request Server Change Color
59+ Rpc (RpcAsk_Authority_Method );
9060 }
9161
9262 //------------------------------------------------------------------------------------------------
9363 // Gets Random color as int with 100% alpha
94- int GetRandomColor ()
64+ protected int GetRandomColor ()
9565 {
9666 if (!m_pRandomGenerator )
9767 {
@@ -143,6 +113,12 @@ class SQW_ColorChanger : ScriptComponent
143113 }
144114
145115 //cube material Component
116+ /*You can change materials via ParametricMaterialInstanceComponent component
117+ for basic emat attributes or if you want something a bit more advanced then you can use
118+ SCR_CustomMaterialAnimatorEntity (check the docs of this entity in the file where it is defined at)
119+ or you can implement your own if you need a bit more control.
120+ All of these will change the material for a specific entity instance, so it's not global
121+ */
146122 m_ParametricMaterialinstanceComponent = ParametricMaterialInstanceComponent .Cast (m_Cube .FindComponent (ParametricMaterialInstanceComponent ));
147123
148124 if (!m_ParametricMaterialinstanceComponent )
@@ -157,11 +133,13 @@ class SQW_ColorChanger : ScriptComponent
157133 }
158134
159135 //------------------------------------------------------------------------------------------------
136+ //Constructor
160137 void SQW_ColorChanger (IEntityComponentSource src , IEntity ent , IEntity parent )
161138 {
162139 }
163140
164141 //------------------------------------------------------------------------------------------------
142+ //Destructor
165143 void ~SQW_ColorChanger ()
166144 {
167145 }
0 commit comments