Jump to content

Recommended Posts

Hello community,

 

First of all i am quiet new into scripting and actually learning by exploring the Enfusion workbench. I just opened up the SCR_ExplosionGenerator and still try to understand all those lines. My first intention was to create a script that a player can use as "Artillery support" so basically looking at a certain point and call artillery on that poing (technically that would be done my some kind of marker script that executes repeating ExplosionGenerator on that mark). That was the idea so far but this is actually quiet to difficult for me at that point.

 

Next i was trying to create IEDs out of prop-prefabs by spawning a prefab (in my example an ammo box that i named "IED"). After that i added a script via "prop properties" with the preset "On Contact", copied and pasted the SCR_ExplosionGenerator into that script and set an example explosion rounds of 4 with a time of "1" inbetween that.

 

So my kind of expectation on that is that the player model walks up to the prefab and once it got contact with the prefab ("On Contact") it triggers the SCR_ExplosionGenerator which creates 4 Explosions on the Prefab.

 

For some reason the script is corrupted and I am not able to load the game within the editor to test the script. Anyone has any ideas on that? I will post the IED-Script below:

 

 

lass IED_Class: GenericEntity

{

override void EOnContact(IEntity owner, IEntity other, Contact contact)

{

[Attribute("", UIWidgets.ResourceAssignArray, "Generated explosions will loop through the projectiles on this array", "et")]

ref array<ResourceName> m_ProjectilesToTrigger;

//Initial values

[Attribute("0", UIWidgets.EditBox, "Number of explosions to create. 0 = until time ends")]

int m_NumExplosions;

[Attribute("0", UIWidgets.EditBox, "Time until this entity creates a new explosion.")]

float m_TimeBetweenExplosions;

[Attribute("0", UIWidgets.EditBox, "Time (in seconds) until no more explosions are generated. This is not needed if Num Explosions is different to 0")]

float m_TotalDuration;

// current values

ref array<ref Resource> m_LoadedPrefabs = new array<ref Resource>();

int m_RemainingExplosions = 4;

float m_TimeUntilNextExplosion = 1;

float m_RemainingDuration = 0;

 

 

//keeps track of what explosion prefab will be used

int m_CurrentExplosionPrefab = 0;

 

//------------------------------------------------------------------------------------------------

void SCR_ExplosionGenerator(IEntitySource src, IEntity parent)

{

SetFlags(EntityFlags.ACTIVE, false);

SetEventMask(EntityEvent.FRAME);

 

for(int i = 0; i < m_ProjectilesToTrigger.Count(); i++)

{

if(m_ProjectilesToTrigger)

m_LoadedPrefabs.Insert(Resource.Load(m_ProjectilesToTrigger));

}

m_RemainingExplosions = m_NumExplosions;

m_TimeUntilNextExplosion = m_TimeBetweenExplosions;

m_RemainingDuration = m_TotalDuration;

}

 

//------------------------------------------------------------------------------------------------

override protected void EOnFrame(IEntity owner, float timeSlice) //EntityEvent.FRAME

{

//end conditions, no need to keep updating the object

if (m_NumExplosions == 0 && m_RemainingDuration < 0 || m_NumExplosions != 0 && m_RemainingExplosions <= 0)

{

ClearFlags(EntityFlags.ACTIVE, false);

ClearEventMask(EntityEvent.FRAME);

return;

}

 

m_TimeUntilNextExplosion -= timeSlice;

m_RemainingDuration -= timeSlice;

 

//no explosion

if (m_TimeUntilNextExplosion > 0)

return;

 

//added instead of assigned to ensure accuracy

m_TimeUntilNextExplosion += m_TimeBetweenExplosions;

CreateExplosion(owner);

}

 

protected void CreateExplosion(IEntity owner)

{

ref Resource prefab = m_LoadedPrefabs[m_CurrentExplosionPrefab];

AdvanceExplosionPrefab();

m_RemainingExplosions--;

if (!prefab)

return;

ref EntitySpawnParams spawnParams = new EntitySpawnParams();

spawnParams.TransformMode = ETransformMode.WORLD;

owner.GetTransform(spawnParams.Transform);

 

IEntity spawnedProjectile = GetGame().SpawnEntityPrefab(prefab, owner.GetWorld(), spawnParams);

Managed managedComp = spawnedProjectile.FindComponent(BaseTriggerComponent);

BaseTriggerComponent comp = BaseTriggerComponent.Cast(managedComp);

 

if(comp)

comp.OnUserTrigger(spawnedProjectile);

}

};

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×