DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
ContaminatedAreaLoader.c
Go to the documentation of this file.
1// This will be used to parse and load contaminated area related data
3{
4 private static string m_Path = "$mission:cfgEffectArea.json";
5
6 static void CreateZones()
7 {
8 JsonDataContaminatedAreas effectAreaData;
9
10 // We confirm the contaminated area configuration file exists in mission folder
11 if ( !FileExist( m_Path ) )
12 {
13 // We fallback to check in data and notify user file was not found in mission
14 PrintToRPT("[WARNING] :: [EffectAreaLoader CreateZones] :: No contaminated area file found in MISSION folder, your path is " + m_Path + " Attempting DATA folder"); // If the path is invalid, we warn the user
15
16 m_Path = "";
18 m_Path = string.Format("DZ/worlds/%1/ce/cfgEffectArea.json", m_Path );
19
20 if ( !FileExist( m_Path ) )
21 {
22 PrintToRPT("[WARNING] :: [EffectAreaLoader CreateZones] :: No contaminated area file found in DATA folder, your path is " + m_Path); // If the path is invalid, we warn the user
23 return; // Nothing could be read, just end here
24 }
25 }
26
27 // We load the data from file, in case of failure we notify user
28 effectAreaData = EffectAreaLoader.GetData();
29 if ( effectAreaData )
30 {
31 // Now that we have extracted the data we go through every declared area
32 //Debug.Log("Contaminated area JSON contains : " + effectAreaData.Areas.Count());
33
34 for ( int i = 0; i < effectAreaData.Areas.Count(); i++ )
35 {
36 EffectAreaParams params = new EffectAreaParams();
37
38 // We feed in all relevant data
39 params.m_ParamName = effectAreaData.Areas.Get( i ).AreaName;
40 string areaType = effectAreaData.Areas.Get( i ).Type;
41 params.m_ParamTriggerType = effectAreaData.Areas.Get( i ).TriggerType;
42 JsonDataAreaData data = effectAreaData.Areas.Get( i ).Data;
43
44 // World level area data ( Trigger info, world particles, etc... )
45 vector pos = Vector( data.Pos[0], data.Pos[1], data.Pos[2] );
46 params.m_ParamRadius = data.Radius;
47 params.m_ParamPosHeight = data.PosHeight;
48 params.m_ParamNegHeight = data.NegHeight;
49 params.m_ParamInnerRings = data.InnerRingCount;
50 params.m_ParamInnerSpace = data.InnerPartDist;
51 params.m_ParamOuterToggle = data.OuterRingToggle;
52 params.m_ParamOuterSpace = data.OuterPartDist;
53 params.m_ParamOuterOffset = data.OuterOffset;
54 params.m_ParamVertLayers = data.VerticalLayers;
55 params.m_ParamVerticalOffset = data.VerticalOffset;
56 string particleName = data.ParticleName;
57
58 // Local level area data ( Player particles and PPE )
59 JsonDataPlayerData playerData = effectAreaData.Areas.Get( i ).PlayerData;
60 string aroundPartName = playerData.AroundPartName;
61 string tinyPartName = playerData.TinyPartName;
62 string ppeRequesterType = playerData.PPERequesterType;
63
64 // Conversion of particle name to ID for synchronization and loading
65 if (particleName != "")
66 params.m_ParamPartId = ParticleList.GetParticleID( particleName );
67
68 if (aroundPartName != "")
69 params.m_ParamAroundPartId = ParticleList.GetParticleID( aroundPartName );
70
71 if (tinyPartName != "")
72 params.m_ParamTinyPartId = ParticleList.GetParticleID( tinyPartName );
73
74 params.m_ParamPpeRequesterType = ppeRequesterType;
75
76 EffectArea newZone; // Zones MUST inherit from EffectArea
77
78 // We snap item position to ground before creating if specified Y is 0
79 if ( pos[1] == 0 )
80 {
81 pos[1] = GetGame().SurfaceRoadY( pos[0], pos[2] );
82 Class.CastTo( newZone, GetGame().CreateObjectEx( areaType, pos, ECE_PLACE_ON_SURFACE ) );
83 }
84 else
85 Class.CastTo( newZone, GetGame().CreateObjectEx( areaType, pos, ECE_NONE ) );
86
87 // We created a new zone, we feed in the data to finalize setup
88 if ( newZone )
89 newZone.SetupZoneData( params );
90 else
91 Error("[WARNING] :: [EffectAreaLoader CreateZones] :: Cast failed, are you sure your class ( 'Type:' ) inherits from EffectArea and that there are no Typos?");
92 }
93 }
94 else
95 Error("[WARNING] :: [EffectAreaLoader CreateZones] :: Data could not be read, please check data and syntax"); // Most JSON related errors should be handled, but we have an extra check in case data could not be read
96 }
97
99 {
101
102 JsonFileLoader<JsonDataContaminatedAreas>.JsonLoadFile( m_Path, data );
103
104 return data;
105 }
106}
const int ECE_NONE
const int ECE_PLACE_ON_SURFACE
proto void GetWorldName(out string world_name)
proto native float SurfaceRoadY(float x, float z)
Super root of all classes in Enforce script.
Definition EnScript.c:11
void SetupZoneData(EffectAreaParams params)
Definition EffectArea.c:104
static private string m_Path
static JsonDataContaminatedAreas GetData()
ref array< ref JsonDataContaminatedArea > Areas
static int GetParticleID(string particle_file)
Returns particle's ID based on the path (without .ptc suffix)
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
proto void PrintToRPT(void var)
Prints content of variable to RPT file (performance warning - each write means fflush!...
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
proto bool FileExist(string name)
Check existence of file.
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.