Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
RplTestEntity.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Test", description: "Testing entity for scripted replication", color: "0 0 255 255")]
2 class SCR_RplTestEntityClass: GenericEntityClass
3 {
4 };
5 
7 {
8  int iVal;
9  float fVal;
10  bool bVal;
11 
12  //################################################################################################
14  //------------------------------------------------------------------------------------------------
15  static void Encode(SSnapSerializerBase snapshot, ScriptCtx hint, ScriptBitSerializer packet)
16  {
17  snapshot.Serialize(packet, 9);
18  }
19 
20  //------------------------------------------------------------------------------------------------
21  static bool Decode(ScriptBitSerializer packet, ScriptCtx hint, SSnapSerializerBase snapshot)
22  {
23  return snapshot.Serialize(packet, 9);
24  }
25 
26  //------------------------------------------------------------------------------------------------
27  static bool SnapCompare(SSnapSerializerBase lhs, SSnapSerializerBase rhs, ScriptCtx hint)
28  {
29  return lhs.CompareSnapshots(rhs, 9);
30  }
31 
32  //------------------------------------------------------------------------------------------------
33  static bool PropCompare(RplTestPropType prop, SSnapSerializerBase snapshot, ScriptCtx hint)
34  {
35  return snapshot.Compare(prop.iVal, 4)
36  && snapshot.Compare(prop.fVal, 4)
37  && snapshot.Compare(prop.bVal, 1);
38  }
39 
40  //------------------------------------------------------------------------------------------------
41  static bool Extract(RplTestPropType prop, ScriptCtx hint, SSnapSerializerBase snapshot)
42  {
43  snapshot.SerializeBytes(prop.iVal, 4);
44  snapshot.SerializeBytes(prop.fVal, 4);
45  snapshot.SerializeBytes(prop.bVal, 1);
46 
47  return true;
48  }
49 
50  //------------------------------------------------------------------------------------------------
51  static bool Inject(SSnapSerializerBase snapshot, ScriptCtx hint, RplTestPropType prop)
52  {
53  snapshot.SerializeBytes(prop.iVal, 4);
54  snapshot.SerializeBytes(prop.fVal, 4);
55  snapshot.SerializeBytes(prop.bVal, 1);
56 
57  return true;
58  }
59  //################################################################################################
60 
61 };
62 
63 //------------------------------------------------------------------------------------------------
65 {
66  [RplProp(condition: RplCondition.NoOwner)]
67  private int m_iTest = 0;
68  private int m_iTestLast = 0;
69 
70  float m_fdelay = 0;
71 
72  [RplProp(onRplName: "OnRpl_CustomProp")]
73  ref RplTestPropType customProp = new RplTestPropType();
74 
75  void OnRpl_CustomProp()
76  {
77  Print("CUSTOM RPLPROP CHANGE1: " + customProp.iVal);
78  Print("CUSTOM RPLPROP CHANGE2: " + customProp.fVal);
79  Print("CUSTOM RPLPROP CHANGE3: " + customProp.bVal);
80  }
81 
82  //------------------------------------------------------------------------------------------------
83  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
84  void NetTestRpc(int testNum)
85  {
86  Print("RPC RECEIVE: " + testNum.ToString());
87  }
88 
89  //------------------------------------------------------------------------------------------------
90  override void EOnFrame(IEntity owner, float timeSlice)
91  {
92  if (Debug.KeyState(KeyCode.KC_P))
93  {
94  Debug.ClearKey(KeyCode.KC_P);
95  int rndRPCNum = Math.RandomIntInclusive(0, 100);
96  Rpc(NetTestRpc, rndRPCNum);
97  Print("RPC SEND: " + rndRPCNum.ToString());
98  }
99 
100  if (RplSession.Mode() == RplMode.Client) // Client
101  {
102  if (m_iTestLast != m_iTest)
103  {
104  Print("RPLPROP CHANGED: " + m_iTest);
105  Print("CUSTOM RPLPROP CHANGED1: " + customProp.iVal);
106  Print("CUSTOM RPLPROP CHANGED2: " + customProp.fVal);
107  Print("CUSTOM RPLPROP CHANGED3: " + customProp.bVal);
108  }
109 
111  }
112  else
113  {
114  m_fdelay -= timeSlice;
115  if (m_fdelay > 0)
116  return;
117 
118  m_fdelay += 2;
119 
120  // Change the value server side
121  if (RplSession.Mode() != RplMode.Client)
122  {
123  m_iTest = Math.RandomIntInclusive(0, 100);
124  customProp.iVal = Math.RandomIntInclusive(0, 100);
125  customProp.fVal = Math.RandomFloatInclusive(0, 100);
126  customProp.bVal = customProp.iVal > 50;
127  }
128 
129  Print("RPLPROP CHANGE: " + m_iTest);
130  Print("CUSTOM RPLPROP CHANGE1: " + customProp.iVal);
131  Print("CUSTOM RPLPROP CHANGE2: " + customProp.fVal);
132  Print("CUSTOM RPLPROP CHANGE3: " + customProp.bVal);
133  }
134  }
135 
136  //------------------------------------------------------------------------------------------------
137  void SCR_RplTestEntity(IEntitySource src, IEntity parent)
138  {
139  SetEventMask(EntityEvent.FRAME);
140  SetFlags(EntityFlags.ACTIVE, true);
141  }
142 
143  //------------------------------------------------------------------------------------------------
144  void ~SCR_RplTestEntity()
145  {
146  }
147 };
SCR_RplTestEntity
Definition: RplTestEntity.c:64
RplTestPropType
Definition: RplTestEntity.c:6
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_RplTestEntityClass
Definition: RplTestEntity.c:2
RplProp
SCR_RplTestEntityClass RplProp
Used for handling entity spawning requests for SCR_CatalogEntitySpawnerComponent and inherited classe...
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
m_iTestLast
private int m_iTestLast
Definition: RplTestComponentWrong.c:10
m_iTest
private int m_iTest
Definition: RplTestComponent.c:16
m_fdelay
float m_fdelay
Definition: RplTestComponent.c:18
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180