scripts/3_Game/Entities/EntityAI.c
//! Called when entity is part of "connected system" and being restored after load
Called when entity is part of "connected system" and being restored after load
Called when entity is part of " connected system " and being restored after load
void EEOnAfterLoad()
	{
		if ( HasEnergyManager()  &&  GetCompEM().GetRestorePlugState() )
		{
			int low = GetCompEM().GetEnergySourceIDLow();
			int high = GetCompEM().GetEnergySourceIDHigh();
			EntityAI potential_energy_source = GetGame().GetEntityByPersitentID(low, high); 
			bool IsAttachment = false;
			if (potential_energy_source)
				IsAttachment = GetInventory().HasAttachment(potential_energy_source);
			if ( !IsAttachment	&&	potential_energy_source )
				IsAttachment = potential_energy_source.GetInventory().HasAttachment(this);
			if ( potential_energy_source  &&  potential_energy_source.HasEnergyManager()  &&  !IsAttachment )
			{
				GetCompEM().PlugThisInto(potential_energy_source); 
			}
		}
	}
void EEOnAfterLoad ( ) { if ( HasEnergyManager ( ) && GetCompEM ( ) . GetRestorePlugState ( ) ) { int low = GetCompEM ( ) . GetEnergySourceIDLow ( ) ; int high = GetCompEM ( ) . GetEnergySourceIDHigh ( ) ; EntityAI potential_energy_source = GetGame ( ) . GetEntityByPersitentID ( low , high ) ; bool IsAttachment = false ; if ( potential_energy_source ) IsAttachment = GetInventory ( ) . HasAttachment ( potential_energy_source ) ; if ( ! IsAttachment && potential_energy_source ) IsAttachment = potential_energy_source . GetInventory ( ) . HasAttachment ( this ) ; if ( potential_energy_source && potential_energy_source . HasEnergyManager ( ) && ! IsAttachment ) { GetCompEM ( ) . PlugThisInto ( potential_energy_source ) ; } } }
Called when entity is part of "connected system" and being restored after load
Called when entity is part of " connected system " and being restored after load
// ENERGY MANAGER // Restore connections between devices which were connected before server restart // get pointer to EntityAI based on this ID // This function is available only in this event! // IMPORTANT! // Object IDs acquired here become INVALID when electric devices are transfered to another server while in plugged state (like Flashlight plugged into its attachment 9V battery) // To avoid issues, these items must be excluded from this system of restoring plug state so they don't unintentionally plug to incorrect devices through these invalid IDs. // Therefore their plug state is being restored withing the EEItemAttached() event while being excluded by the following 'if' conditions... // restore connection