Spawn prefab placeable group

I just made a group of a few objects, namely a lamp that consists of: a light, a lamp placeable and a candle flame effect. I exported the group and it now shows up among the placeable prefabs. Is there someway to spawn the whole group to a waypoint, so that the lamp appears with the light and effect and all, or is this impossible?

I’ve searched for functions, even within the #EC_super_include library, but I haven’t found a function that seems to be able to do this.

3 Likes

You have to save it as a “Blueprint” first, not a “prefab” and use the appropriate tag for all objects. Of course, you can always save it as a “prefab” to make it easier to access and use in another module.

EDIT: To call this “group of objects” with a precise tag created as a placeable blueprint (not prefab), you can make them appear (spawn) on a specific WP via script.

Have a nice day and take care ! :grinning:

2 Likes

@raymondsebas - Thanks for the reply! I was actually thinking that you might know something about this. Now, I’ve already done this the hard way in my module by spawning each element (except for the light that I instead just activate), but for future needs this is great to know.

A follow-up question about this: If I save these things as a blueprint, where will I find this blueprint afterwards? I mean, in this case it’s both a placeable, light and effect involved.
I tried exporting and it seemed to work, but I have no idea where to find this exported thing.

@andgalf Oh no, don’t get me wrong, you’re still forced to summon all the pieces one by one with WP. So uncheck :heavy_check_mark: the solution box.

Hmmm, I’m not sure I understand then what the point is to save the group of objects as a blueprint if you still need to summon one by one to the waypoint, and if you can’t find the group of objects anywhere unless you export it as a group and import it as a prefab.

To save your customization of these objects.
For spawning light and VFX, see “Puket” useable light prefab.

https://neverwintervault.org/project/nwn2/prefab/item/useable-lights

1 Like

@andgalf

Are you trying to make dynamic lights?

As @raymondsebas explains, prefabs are to make building easier rather than anything else. I.e. Rather than go to placeables, place a torch, go to lights, place a light and finally go to effects and place an effect … a prefab drops all three items in one go. So prefabs are designed for speed of building repetitious cluster of objects. They can also be a little fiddly to setup and use, but once established can be a time saver.

Now, if you want dynamic lights (which I nearly answered a couple of times, but thought you had marked it as solved for you), I have a slightly different approach, but still uses prefabs for speed … Anyway, I include an explanation here for you.

The important point to note is that light objects lose their tags between reloads, and referencing them becomes awkward. So, here is what I do, which I imagine you will know what to do, but ask if you need any additional explanation here.

PRE BUILD CAVEAT: The light object position is the reference for the VFX when required.

  1. Place the torch or other light placeable object. (Have TAG ref “OFF” if the source starts off.)
  2. Place the light object just above the placeable where you intend the VFX to also appear.
  3. Have a script on the placeable OnUsed that controls everything.

The script must then determine from the placeable TAG whether the light source is currently on or off for initial usage. (Thereafter it should just toggle any state.) Any light placed above the torch (also where the flame will be created) is also set matching “ON” or “OFF” at time of build placement.

The script then searches for the nearest light OBJECT to the placeable (not tag of light which breaks), and then toggles the light source object “ON” or “OFF” subject to current state, initially dictated by the placeable TAG. At the same time, the script creates or destroys the VFX you have setup as a template for the object.

My own script has grown quite large to accommodate all sorts of other lighting setups and so may only confuse matters if I posted it. I can do, but only if you think it might help you to understand some of what I wrote here.

EDIT: Actually, I found the smaller older script I use for this sort of thing … This version assumes the light source starts OFF wherever you place it at build time. i.e. No flame VFX placed and light that is placed is set “OFF”.

This script is set on the OnUsed of the light object.

//////////////////////////////////////////////////////////////////////////////////////
// LIGHT SWITCH FOR LAMPS (WILL SAVE 1) AND TORCHES (WILL SAVE 0)
// LIGHT MUST BE PLACED (FLAME IS CREATED)
//////////////////////////////////////////////////////////////////////////////////////

void StopLight(object oSelf)
{	
	object oFlame = GetNearestObjectByTag("alb_wall_torch_flame", oSelf);
	DestroyObject(oFlame);		
	
	object oLight = GetNearestObject(OBJECT_TYPE_LIGHT, OBJECT_SELF);		
	SetLightActive(oLight, FALSE);	// NEAREST LIGHT FIX APPLED	
}

void Ignite(object oSelf)
{	
	object oLight = GetNearestObject(OBJECT_TYPE_LIGHT, OBJECT_SELF);	
	SetLightActive(oLight, TRUE); // NEAREST LIGHT FIX APPLED	
	
	location lFlame = GetLocation(oLight);
	
	if(GetWillSavingThrow(oSelf) == 0)
	{
		CreateObject(OBJECT_TYPE_PLACED_EFFECT, "alb_wall_torch_flame", lFlame);
	}
	
	else
	{
		object oLampFlame = CreateObject(OBJECT_TYPE_PLACED_EFFECT, "alb_candle_light", lFlame);	
		SetTag(oLampFlame, "alb_wall_torch_flame");
	}
}


void main()
{
    object oPlayer = GetLastUsedBy();

    AssignCommand(oPlayer,ClearAllActions());
    AssignCommand(oPlayer, ActionMoveToObject(OBJECT_SELF,FALSE,0.5));
    AssignCommand(oPlayer, ActionPlayAnimation(ANIMATION_LOOPING_GET_MID,1.0,0.5));

    object oSelf = OBJECT_SELF;

    // LIGHT IS CURRENTLY OFF (TURN ON) ////////////////////////////////////////
	
	object oFlame = GetNearestObjectByTag("alb_wall_torch_flame", oSelf);
	float fDis = 0.0;
	
	if(oFlame != OBJECT_INVALID)
	{
		fDis = GetDistanceBetween(oFlame, oSelf);
		//SendMessageToAllPCs(" >>> " + FloatToString(fDis));
	}

	if(fDis == 0.0 || fDis > 2.0)
    {       
		// IGNITE EFFECT (TORCHES ONLY)
		if(GetWillSavingThrow(OBJECT_SELF) == 0)
		{
			effect eFlame = EffectNWN2SpecialEffectFile("IgniteTorch");
	        DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT,eFlame,OBJECT_SELF));
		}
		
		DelayCommand(1.0, Ignite(oSelf));

        DelayCommand(0.5, AssignCommand(OBJECT_SELF, PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE)));
    }

    // LIGHT IS CURRENTLY ON (TURN OFF) ////////////////////////////////////////

	else if(fDis > 0.0 && fDis <= 2.0)	
    {
        DelayCommand(1.0, StopLight(oSelf));		

        AssignCommand(OBJECT_SELF, PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));
    }
}
1 Like

No. I don’t think I’ve ever said that here.

What I wanted initially, but that doesn’t seem to be possible, is to spawn a lantern on a waypoint that has both a light and a candle effect on it.

Yes, I know that. But as stated here:

This what it’s all about, nothing else. Since I can save both the lantern, candle light effect and light as a blueprint, but I can’t find it afterwards (I don’t understand the purpsoe of this unless it’s only using placeables and not effects and lights too), or even spawn all three of them as one object, then I will just continue with the tedious approach with having two waypoints (one for the lantern and one for the candellight just a bit above it) and having the light at the waypoint (only deactivated), then spawn in the lantern and the candlelight separately and activate the light through a script. It looks quite ok, but I would have really wanted to be able to spawn all three of them as a single object to a waypoint.

I hope it’s clearer now what I’m after.

EDIT: Further explanation: The situation is that the party picks up a lantern and then places it on the ground, and there I want both the light and candle light effect to be seen, not just a lantern that’s dark (since it wasn’t dark when they picked it up from another place).

1 Like

@andgalf

Ah! A total different “kettle of fish”. :+1:

However, if it is dependent upon player positioning, won’t the light vary according to where the player has their PC drop it … or is there a specific location you adjudicate for them? i.e. Your WP settings are the only place they can drop it, I’m assuming by this …

OK, I get what you are after now … :slight_smile:

What I said above may still apply for you then, if you wanted to reduce WPs usage…

  1. Place WP for item drop to create placeable.
  2. Above that WP place the light object (initially off) where the VFX will also be created.
  3. Have the drop script manage the lighting and VFX creation.

This requires only a single WP unless you have other criteria/lighting differences required? Basically, use the location of the light object for the location to spawn the VFX.

But, if what you have works, that’s cool… this was just to help alleviate WPs if you wanted to. If you ever wanted to get really fancy (and not rely on any WPs), you could probably do this based on scripting alone … but I appreciate the exact location may be required for you.

1 Like

Mmm, ok. The only thing I’ve done differently from your suggestion is that I have one more WP. I guess I could have used the light as the second WP, I don’t know.

1 Like