Jump to content
Sign in to follow this  
pescadorrr

[solved] How to delete a item?

Recommended Posts

I need the code to delete a item.

I make a task with a trigger linked him and i need to delete a object when actívate.

I have achieved that a second task is activated to the players when finishing the first task and i need delete a object.

 

The code for the second task assigned is this:

 

class pista_Class: SCR_BaseFactionTriggerEntity 
{
    override void OnActivate(IEntity ent)
    {
        super.OnActivate(ent);
                
        BaseWorld world = ent.GetWorld();
        IEntity entity = world.FindEntityByName("tarea_2");
        SCR_BaseTask task = SCR_BaseTask.Cast(entity);
        
        FactionKey m_sAssignedFaction  = "US";
        Faction targetFaction = GetGame().GetFactionManager().GetFactionByKey(m_sAssignedFaction);
        task.SetTargetFaction(targetFaction);
    }

};

 

"Tarea_2" is the name of the second task.

 

Thanks for the help.

 

Share this post


Link to post
Share on other sites

One thing you could try is to get the entity's parent and remove the entity from its children.

IEntity ent = ...
ent.GetParent().RemoveChild(ent);

I doubt this is best practice and may leave the entity straggling in memory, but it should get the job done.

I haven't tested this code myself, but it should work as long as the parent isn't null for some reason.

  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)

You could try this, it deletes the entity on the server and can be called by the owner entity itself to delete it:

// Note: The entity needs an RPL component, m_Owner is the entity to be deleted.

SCR_EntityHelper.DeleteEntityAndChildren( m_Owner );
or 
SCR_EntityHelper.DeleteChildren( m_Owner );

 

Edited by joemac90
additional info
  • Like 1

Share this post


Link to post
Share on other sites

 

 

On 6/7/2022 at 9:23 PM, SovietKitKat said:

One thing you could try is to get the entity's parent and remove the entity from its children.


IEntity ent = ...
ent.GetParent().RemoveChild(ent);

I doubt this is best practice and may leave the entity straggling in memory, but it should get the job done.

I haven't tested this code myself, but it should work as long as the parent isn't null for some reason.

This option gives an error and does not work, thanks anyway

This opcion works:

IEntity docus = world.FindEntityByName("documentos");
SCR_EntityHelper.DeleteEntityAndChildren( docus );

Thanks for the anwers.

Share this post


Link to post
Share on other sites

Yes, you have to know the entity you want to delete.

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
Sign in to follow this  

×