Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_UserActionWithOccupancy.c
Go to the documentation of this file.
2{
3 protected IEntity m_Occupant;
5 //------------------------------------------------------------------------------------------------
6 bool IsOccupied()
7 {
8 return m_Occupant != null;
9 }
10
11 //------------------------------------------------------------------------
13 {
14 if (!ent)
15 return false;
16
17 if (m_Occupant)
18 return m_Occupant == ent;
19
21 }
22
23 //------------------------------------------------------------------------
25 {
26 m_Occupant = null;
27 m_OccupantRplId = RplId.Invalid();
28 }
29
30 //------------------------------------------------------------------------------------------------
31 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
32 {
33 if (m_Occupant && m_Occupant != pUserEntity)
34 return;
35
36 if (!m_Occupant)
37 {
38 m_Occupant = pUserEntity;
40 StartAction(pUserEntity);
41 }
42 else
43 {
45 StopAction(pUserEntity);
46 }
47 }
48 //------------------------------------------------------------------------------------------------
49 void StartAction(IEntity pUserEntity);
50 //------------------------------------------------------------------------------------------------
51 void StopAction(IEntity pUserEntity);
52 //------------------------------------------------------------------------------------------------
53 // Writes the occupant and returns true if a valid occupant was written
54 protected bool SaveOccupant(ScriptBitWriter writer)
55 {
56 if (!m_Occupant)
57 {
58 writer.WriteBool(false);
59 return false;
60 }
61
63 if (!rplComp)
64 {
65 writer.WriteBool(false);
66 return false;
67 }
68
69 writer.WriteBool(true);
70 writer.WriteRplId(rplComp.Id());
71 return true;
72 }
73 //------------------------------------------------------------------------------------------------
74 // Reads the occupant and returns true if occupant data exists (but occupant may be null due to not being streamed in)
75 protected bool LoadOccupant(ScriptBitReader reader)
76 {
78 bool occupantExists = false;
79
80 reader.ReadBool(occupantExists);
81 if (!occupantExists)
82 return false;
83
84 RplId rplId;
85 reader.ReadRplId(rplId);
86 m_OccupantRplId = rplId;
88 return true;
89 }
90
91 //------------------------------------------------------------------------------------------------
92 protected override bool OnRplSave(ScriptBitWriter writer)
93 {
94 if (!super.OnRplSave(writer))
95 return false;
96
97 SaveOccupant(writer);
98 return true;
99 }
100
101 //------------------------------------------------------------------------------------------------
102 protected override bool OnRplLoad(ScriptBitReader reader)
103 {
104 if (!super.OnRplLoad(reader))
105 return false;
106
107 LoadOccupant(reader);
108 return true;
109 }
110}
Replication item identifier.
Definition RplId.c:14
static IEntity RplIdToEntity(RplId id)
static RplId EntityToRplId(IEntity ent)
static RplComponent GetEntityRplComponent(notnull IEntity entity)
void StartAction(IEntity pUserEntity)
override bool OnRplSave(ScriptBitWriter writer)
override bool OnRplLoad(ScriptBitReader reader)
bool LoadOccupant(ScriptBitReader reader)
void StopAction(IEntity pUserEntity)
bool SaveOccupant(ScriptBitWriter writer)
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
@ StartAction