Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
RplTestComponentWrong.c
Go to the documentation of this file.
1
[
ComponentEditorProps
(
category
:
"GameScripted/Test"
, description:
"Test component showcasing doing the replication from script the WRONG way"
)]
2
class
SCR_RplTestComponentWrongClass
:
ScriptComponentClass
3
{
4
}
5
6
class
SCR_RplTestComponentWrong :
ScriptComponent
7
{
8
[
RplProp
(condition:
RplCondition
.NoOwner)]
9
private
int
m_iTest = 0;
10
private
int
m_iTestLast = 0;
11
12
float
m_fdelay = 0;
13
14
//------------------------------------------------------------------------------------------------
15
[
RplRpc
(
RplChannel
.Reliable,
RplRcver
.Broadcast)]
16
void
NetTestRpc(
int
testNum)
17
{
18
Print
(
"RPC RECEIVE: "
+ testNum,
LogLevel
.NORMAL);
19
}
20
21
//------------------------------------------------------------------------------------------------
22
override
void
EOnFrame
(
IEntity
owner,
float
timeSlice)
23
{
24
if
(
Debug
.KeyState(
KeyCode
.KC_P))
25
{
26
Debug
.ClearKey(
KeyCode
.KC_P);
27
int
rndRPCNum = Math.RandomIntInclusive(0, 100);
28
// WRONG:
29
// When performed on server, this is broadcast to everyone.
30
// However when executed on client, this is only performed on the client.
31
Rpc
(NetTestRpc, rndRPCNum);
32
Print
(
"RPC SEND: "
+ rndRPCNum,
LogLevel
.NORMAL);
33
}
34
35
/*
36
WRONG:
37
Never never never (unless you really have to).
38
If possible, never decide which RPC to call be checking for wheter you're
39
a client or not.
40
In general, if you need to write this condition it means your thought process is
41
not the best one and you should think things through again.
42
Instead, use proper attributes for the RPC. It takes a little bit of getting
43
used to, however, you'll end up with code which is cleaner and easier to understand.
44
This design actually enforces the right way of thinking on you.
45
*/
46
if
(RplSession.Mode() ==
RplMode
.Client)
// Client
47
{
48
/*
49
WRONG:
50
Never never never.
51
Always check for property changes on client using a callback.
52
You won't need to remeber the previous value + you'll avoid
53
cases where OnFrame isn't called for whatever reason (sometimes,
54
simulation of certain entites might turn off EOnFrame for proxies).
55
56
In this case, every time m_iTest changes on sever, OnTestChanged
57
is called on client. The moment it's called, you know the value has
58
already been updated to a new one. If you want to keep the old one (
59
which you usually don't) you need to store it e.g. m_iTestLast or
60
in an array depending on your needs.
61
*/
62
if
(m_iTestLast != m_iTest)
63
Print
(
"RPLPROP CHANGED: "
+ m_iTest,
LogLevel
.NORMAL);
64
65
m_iTestLast = m_iTest;
66
}
67
else
68
{
69
m_fdelay -= timeSlice;
70
if
(m_fdelay > 0)
71
return
;
72
73
m_fdelay += 2;
74
75
// Change the value server side
76
if
(RplSession.Mode() !=
RplMode
.Client)
77
{
78
m_iTest = Math.RandomIntInclusive(0, 100);
79
Replication.BumpMe();
80
}
81
82
Print
(
"RPLPROP CHANGE: "
+ m_iTest);
83
}
84
}
85
86
//------------------------------------------------------------------------------------------------
87
void
SCR_RplTestComponentWrong(IEntityComponentSource src,
IEntity
ent,
IEntity
parent)
88
{
89
SetEventMask
(ent,
EntityEvent
.FRAME);
90
ent.
SetFlags
(
EntityFlags
.ACTIVE,
true
);
91
}
92
}
RplMode
RplMode
Mode of replication.
Definition
RplMode.c:9
ComponentEditorProps
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
Definition
SCR_AIGroupUtilityComponent.c:12
RplProp
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
category
params category
Definition
SCR_VehicleDamageManagerComponent.c:302
IEntity
enum EVehicleType IEntity
GenericComponent::SetEventMask
proto external int SetEventMask(notnull IEntity owner, int mask)
GenericComponent::Rpc
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)
IEntity::SetFlags
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
SCR_RplTestComponentWrongClass
Definition
RplTestComponentWrong.c:3
ScriptComponentClass
Definition
ScriptComponentClass.c:8
ScriptComponent
Definition
ScriptComponent.c:24
ScriptComponent::EOnFrame
void EOnFrame(IEntity owner, float timeSlice)
Print
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
LogLevel
Enum with severity of the logging message.
Definition
LogLevel.c:14
EntityEvent
EntityEvent
Various entity events.
Definition
EntityEvent.c:14
EntityFlags
EntityFlags
Various entity flags.
Definition
EntityFlags.c:14
KeyCode
KeyCode
Definition
KeyCode.c:13
RplRpc
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition
EnNetwork.c:95
RplCondition
RplCondition
Conditional replication rule. Fine grained selection of receivers.
Definition
RplCondition.c:14
RplRcver
RplRcver
Definition
RplRcver.c:59
RplChannel
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition
RplChannel.c:14
Debug
void Debug()
Definition
Types.c:327
scripts
Game
Network
RplTestComponentWrong.c
Generated by
1.17.0