Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SupplyContainerValueAttribute.c
Go to the documentation of this file.
3{
4 override SCR_BaseEditorAttributeVar ReadVariable(Managed item, SCR_AttributesManagerEditorComponent manager)
5 {
7 if (!editableEntity)
8 return null;
9
10 GenericEntity entity = editableEntity.GetOwnerScripted();
11 if (!entity)
12 return null;
13
14 SCR_ResourceComponent resourceComponent;
15 SCR_ResourceContainer supplyContainer = GetContainer(entity, resourceComponent);
16 if (!supplyContainer)
17 return null;
18
19 float currentValue = supplyContainer.GetResourceValue();
20 float maxValue = supplyContainer.GetMaxResourceValue();
21
22 if (maxValue == 0)
23 return null;
24
25 return SCR_BaseEditorAttributeVar.CreateFloat((currentValue / maxValue) * 100);
26 }
27
28 override void WriteVariable(Managed item, SCR_BaseEditorAttributeVar var, SCR_AttributesManagerEditorComponent manager, int playerID)
29 {
31 if (!editableEntity)
32 return;
33
34 GenericEntity entity = editableEntity.GetOwnerScripted();
35 if (!entity)
36 return;
37
38 SCR_ResourceComponent resourceComponent;
39 SCR_ResourceContainer supplyContainer = GetContainer(entity, resourceComponent);
40 if (!supplyContainer)
41 return;
42
43 float percentage = var.GetFloat();
44 float maxValue = supplyContainer.GetMaxResourceValue();
45 float newValue = maxValue * (percentage / 100);
46
47 supplyContainer.SetResourceValue(newValue);
48 }
49
50 SCR_ResourceContainer GetContainer(notnull IEntity entity, out SCR_ResourceComponent component)
51 {
52 component = SCR_ResourceComponent.Cast(entity.FindComponent(SCR_ResourceComponent));
53 SCR_ResourceContainer container;
54
55 if (component)
56 {
57 container = component.GetContainer(EResourceType.SUPPLIES);
58 if (container)
59 return container;
60 }
61
62 IEntity iteratedEntity = entity.GetChildren();
63 while (iteratedEntity)
64 {
65 component = SCR_ResourceComponent.Cast(iteratedEntity.FindComponent(SCR_ResourceComponent));
66 if (component)
67 {
68 container = component.GetContainer(EResourceType.SUPPLIES);
69 if (container)
70 return container;
71 }
72
73 iteratedEntity = iteratedEntity.GetSibling();
74 }
75
76 return null;
77 }
78}
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
proto external Managed FindComponent(typename typeName)
proto external IEntity GetChildren()
proto external IEntity GetSibling()
static SCR_BaseEditorAttributeVar CreateFloat(float value)
bool SetResourceValue(float value, bool notifyChange=true)