Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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")]
2 class SCR_VehicleSpawnerClass : ScriptComponentClass
3 {
4 }
5 
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 
74  ref EntitySpawnParams params = new EntitySpawnParams();
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
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 }
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_bSpawned
private bool m_bSpawned
Definition: SCR_VehicleSpawner.c:16
m_aPrefabs
private ref array< ResourceName > m_aPrefabs
Definition: SCR_VehicleSpawner.c:11
m_pSpawnedEntity
private IEntity m_pSpawnedEntity
Definition: SCR_VehicleSpawner.c:13
PickRandomResource
ResourceName PickRandomResource(array< ResourceName > resources)
Definition: SCR_VehicleSpawner.c:28
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_VehicleSpawner
void SCR_VehicleSpawner(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_VehicleSpawner.c:86
m_owner
private IEntity m_owner
Definition: SCR_VehicleSpawner.c:14
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_VehicleSpawner.c:19
~SCR_VehicleSpawner
void ~SCR_VehicleSpawner()
Definition: SCR_VehicleSpawner.c:92
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
MIN_DISTANCE
SCR_VehicleSpawnerClass MIN_DISTANCE
PerformSpawn
void PerformSpawn()
Definition: SCR_VehicleSpawner.c:43
SCR_VehicleSpawnerClass
Definition: SCR_VehicleSpawner.c:2
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180