Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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")]
2class 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//------------------------------------------------------------------------------------------------
64class SCR_RplTestEntity : GenericEntity
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
110 m_iTestLast = m_iTest;
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 {
140 SetFlags(EntityFlags.ACTIVE, true);
141 }
142
143 //------------------------------------------------------------------------------------------------
144 void ~SCR_RplTestEntity()
145 {
146 }
147};
RplMode
Mode of replication.
Definition RplMode.c:9
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
Definition Debug.c:13
void Rpc(func method, void p0=NULL, void p1=NULL, void p2=NULL, void p3=NULL, void p4=NULL, void p5=NULL, void p6=NULL, void p7=NULL)
void IEntity(IEntitySource src, IEntity parent)
protected script Constructor
proto external EntityEvent SetEventMask(EntityEvent e)
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
Definition Math.c:13
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
KeyCode
Definition KeyCode.c:13
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplCondition
Conditional replication rule. Fine grained selection of receivers.
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14