Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_VehicleSpawner.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/ScriptWizard", description: "THIS IS THE SCRIPT DESCRIPTION.", color: "0 0 255 255")]
5
6class SCR_VehicleSpawner : ScriptComponent
7{
8 static const float MIN_DISTANCE = 10;
9
10 [Attribute("", UIWidgets.ResourceNamePicker, "", "")]
11 private ref array<ResourceName> m_aPrefabs;
12
13 private IEntity m_pSpawnedEntity;
14 private IEntity m_owner;
15
16 private bool m_bSpawned = false;
17
18 //------------------------------------------------------------------------------------------------
19 override void OnPostInit(IEntity owner)
20 {
21 m_owner = owner;
22 }
23
24 //------------------------------------------------------------------------------------------------
28 ResourceName PickRandomResource(array<ResourceName> resources)
29 {
30 if (!resources)
31 return string.Empty;
32
33 int count = resources.Count();
34 if (count < 1)
35 return string.Empty;
36
37 int randomIndex = Math.RandomInt(0, count);
38 return resources[randomIndex];
39 }
40
41 //------------------------------------------------------------------------------------------------
43 void PerformSpawn()
44 {
45 if (!m_owner)
46 return;
47
48 if (m_pSpawnedEntity && vector.Distance(m_pSpawnedEntity.GetOrigin(), m_owner.GetOrigin()) < MIN_DISTANCE)
49 return;
50
51 ArmaReforgerScripted game = GetGame();
52 if (!game)
53 return;
54
55 if (!game.InPlayMode())
56 return;
57
58
59 // server only
60 if (RplSession.Mode() == RplMode.Client)
61 return;
62
63 ResourceName randomResource = PickRandomResource(m_aPrefabs);
64 if (randomResource == string.Empty)
65 {
66 Print("Resource is null or empty! Cannot spawn!", LogLevel.ERROR);
67 return;
68 }
69
70 Resource resource = Resource.Load(randomResource);
71 if (!resource)
72 return;
73
75 params.TransformMode = ETransformMode.WORLD;
76 m_owner.GetTransform(params.Transform);
77
78 m_pSpawnedEntity = game.SpawnEntityPrefab(resource, m_owner.GetWorld(), params);
79 }
80
81 //------------------------------------------------------------------------------------------------
82 // constructor
86 void SCR_VehicleSpawner(IEntityComponentSource src, IEntity ent, IEntity parent)
87 {
88 }
89
90 //------------------------------------------------------------------------------------------------
91 // destructor
92 void ~SCR_VehicleSpawner()
93 {
94 // server only
95 if (RplSession.Mode() == RplMode.Client)
96 return;
97
98 if (m_pSpawnedEntity)
99 delete m_pSpawnedEntity;
100
101 m_pSpawnedEntity = null;
102 }
103}
ref DSGameConfig game
Definition DSConfig.c:81
ArmaReforgerScripted GetGame()
Definition game.c:1398
RplMode
Mode of replication.
Definition RplMode.c:9
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
SCR_VehicleSpawnerClass MIN_DISTANCE
enum EVehicleType IEntity
proto external vector GetOrigin()
proto external BaseWorld GetWorld()
proto external void GetTransform(out vector mat[])
void EntitySpawnParams()
Definition gameLib.c:130
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute