Script to show/hide objects?

+
Script to show/hide objects?

Right; at the end of 'Birth, and Virgins' there's a wedding reception. I don't want the items for the wedding reception to be hanging around all through the plot, I want them to appear when it's time for the reception, and I want them to get tidied up afterwards.The script I'm trying to write goes something like this:
Code:
void main(){	PrintString( "Setting/unsetting reception scenery");	int done = FALSE;		for (int i = 0; !done; i++) {		object ob = GetObjectByTag( "bv_ob_reception", i);				if ( ob != OBJECT_INVALID) {			vector pos = GetPosition( ob);			pos[2] = 0 - pos[ 2];		} else {			done = TRUE;		}	}}
The problem is that there's no [tt]SetPosition( object, vector)[/tt] function, and the vector you get back from [tt]GetPosition( object)[/tt] is clearly a copy of the position co-ordinates of the object - you can't change the position just by changing the values.Obviously my first thought was to bury my 'reception' scenery underground when I wasn't using it by toggling the sign of it's Z position. But I don't need that to be the solution - if there was a way to hide the objects when I'm not using them, and make them visible again when I want them, that would do equally well.Any suggestions?
 
I've only just started with this D'jinni stuff, so there's probably an excellent reason why you can't do this, butCould you have a copy of the location that has everything set up for the wedding? Call that location instead of the usual one when it's time for the wedding, then send everybody back to the original location when the wedding is done?
 
Corylea said:
I've only just started with this D'jinni stuff, so there's probably an excellent reason why you can't do this, butCould you have a copy of the location that has everything set up for the wedding? Call that location instead of the usual one when it's time for the wedding, then send everybody back to the original location when the wedding is done?
Yes, that is entirely possible (and is certainly one way to do it) but seems absurdly heavyweight for what I want to do.
 
You can use "StoreCampaignObject" and "SetCampaignLocation" to store the placable and it's location, destroy the placables, then call them back with "RetrieveCampaignObject" and "GetCampaignLocation", and create new placables, but i've never used this before so this is just a guess..!
 
JSlash said:
You can use "StoreCampaignObject" and "SetCampaignLocation" to store the placable and it's location, destroy the placables, then call them back with "RetrieveCampaignObject" and "GetCampaignLocation", and create new placables, but i've never used this before so this is just a guess..!
Can you?Thanks, I'll try that!
 
You might wanna use "SetLocalObject" and "SetLocalLocation" to set the vars on an object or a character instead, sorry i didn't remember this earlier, but i think they're both gonna give similar results.
 
I do not fully understand, what exactly you want. If you have always the same place for your item, what appear and disappear you can set a waypoint there.Or you work with position-command, you prefer.The position can be changed with:Vector(float x, float y, float z)The Location can be set with:location(area, pos., facing)That are the commands, function available ...Sorry, can't help more.
 
Try this one, Simon:
Code:
void main{  object oArea = GetArea(GetObjectByTag("objects_tag"));  vector vPosition = GetPosition(GetObjectByTag("objects_tag"));  float fOrientation = GetFacing(GetObjectByTag("objects_tag"));  location lLocation = Location( oArea, vPosition, fOrientation);  DestroyObject(GetObjectByTag("objects_tag"));  object new = CreateObject(OBJECT_TYPE_PLACEABLE,"old_object",lLocation,FALSE,"new_object");}
Handwritten, don't know if it works (as Ailinon would say: Dry code) ;)
 
What I have at present is
Code:
//////////////////////////////////////////////////////////////////////////	inc_scenery// 	Set/unset the scenery////	(c) 2008 The Medusa Collective////////////////////////////////////////////////////////////////////////const string CAMPAIGN_NAME = "bv";// Scenery to be stored must be set up in the area just like any other scenery;// then, as the module starts, it must be stored using this function. Subsequently// it can be removed using ClearScenery and restored using RestoreSceneryvoid StoreScenery( string tag) {	PrintString( "Storing scenery for tag " + tag);	int i = 0;		object ob = GetObjectByTag( tag, i);			while ( ob != OBJECT_INVALID) {		PrintString( "storing object " + tag + IntToString( i));		SetCampaignLocation( CAMPAIGN_NAME, tag + IntToString( i), 			GetLocation( ob));		PrintString( "Stored location...");		StoreCampaignObject( CAMPAIGN_NAME, tag + IntToString( i), ob);		PrintString( "Stored object...");		i++;		ob = GetObjectByTag( tag, i);	}}// Clears scenery with a specific tag. If the scenery has first been stored it can// subsequently be restored; if not, not.void ClearScenery( string tag) {	PrintString( "Tearing down scenery for tag " + tag);	int i = 0;		object ob = GetObjectByTag( tag, i);			while ( ob != OBJECT_INVALID) {		PrintString( "clearing object " + tag + IntToString( i));		DestroyObject( ob);		i++ ;		ob = GetObjectByTag( tag, i);	}}// Restores previously stored and cleared sceneryvoid RestoreScenery( string tag) {	PrintString( "Setting up scenery for tag " + tag);	int i = 0;		location loc = GetCampaignLocation( CAMPAIGN_NAME, tag + IntToString( i));		object ob = RetrieveCampaignObject( CAMPAIGN_NAME, tag + IntToString( i), loc);					PrintString( "retrieved object " + tag + IntToString( i)); 			while ( ob != OBJECT_INVALID) {		i ++;				loc = GetCampaignLocation( CAMPAIGN_NAME, tag + IntToString( i));			ob = RetrieveCampaignObject( CAMPAIGN_NAME, tag + IntToString( i), loc);		PrintString( "retrieved object " + tag + IntToString( i));	}}
This isn't yet working - I get stack underflow in the loops, which seems bizarre - but I sense it isn't far off.
 
In NWN, if i remember correctly, we sometimes get a stack underflow when a function returns an invalid object, i think, if this is the case here, it may be related to the "SetCampaignLocation" and "GetCampaignLocation", according to NWNLexicon, it returns an invalid area object when the area changes. Check it hereit might be easier to use "SetLocalLocation" instead. I'm sorry about that, i didn't know! :-XEDIT: Also, stack underflow happens sometimes when you declare variables in a loop, and it misses updating the variable for some reason, but i don't think it's the case here, but i thought i'd mention it.
 
I really don't know, why you all want to do such easy stuff with such complicated scripts? ???This is what you want to do:
Right; at the end of 'Birth, and Virgins' there's a wedding reception. I don't want the items for the wedding reception to be hanging around all through the plot, I want them to appear when it's time for the reception, and I want them to get tidied up afterwards.
With my above script you can change these items from a visible one into an unvisible one. You just have to put the items into the script, that you want to disappear.Arkray made it that simple too, in her Poet's Pride Mod, she changed the banner with the mirror, that's the same funktion as you can do with an unvisible objekt.It's a simple changing of objects, but it will be the effect, that you want.Well, at last you can try out several more complicated scripts like yours, it's not my problem... :whistle:
 
HexenmeisterRaven said:
I really don't know, why you all want to do such easy stuff with such complicated scripts? ???This is what you want to do:
Right; at the end of 'Birth, and Virgins' there's a wedding reception. I don't want the items for the wedding reception to be hanging around all through the plot, I want them to appear when it's time for the reception, and I want them to get tidied up afterwards.
With my above script you can change these items from a visible one into an unvisible one. You just have to put the items into the script, that you want to disappear.Arkray made it that simple too, in her Poet's Pride Mod, she changed the banner with the mirror, that's the same funktion as you can do with an unvisible objekt.It's a simple changing of objects, but it will be the effect, that you want.Well, at last you can try out several more complicated scripts like yours, it's not my problem... :whistle:
Raven, I'm not ignoring your solution, I simply don't understand it. I don't know how to make objects invisible - if I did, that would pretty much solve my problem. Your solution of destroying objects and then creating new ones would work - but I need a means of storing what they were and where they were while they're not visible.
 
HexenmeisterRaven said:
I really don't know, why you all want to do such easy stuff with such complicated scripts? ???This is what you want to do:
Right; at the end of 'Birth, and Virgins' there's a wedding reception. I don't want the items for the wedding reception to be hanging around all through the plot, I want them to appear when it's time for the reception, and I want them to get tidied up afterwards.
With my above script you can change these items from a visible one into an unvisible one. You just have to put the items into the script, that you want to disappear.Arkray made it that simple too, in her Poet's Pride Mod, she changed the banner with the mirror, that's the same funktion as you can do with an unvisible objekt.It's a simple changing of objects, but it will be the effect, that you want.Well, at last you can try out several more complicated scripts like yours, it's not my problem... :whistle:
Actually your script is exactly what he's doing, but you just simplified it a little bit. He will probably be using different scripts, one to despawn the placeables, and another to recreate them, so he'll need to store their tags and locations somewhere.Another way to do it is like Ralf1731 said, is to move them somewhere then restore them with "Location" function, but you will still need to store the original location somewhere. Unless the placeable holds items in its inventory, it's easier to just destroy and create new ones, there's no need to crowd your RAM with objects that are not needed, plus moving all placeables to the same position, like (0,0,0), could sometimes cause crashes.
 
JSlash said:
You might wanna use "SetLocalObject" and "SetLocalLocation" to set the vars on an object or a character instead, sorry i didn't remember this earlier, but i think they're both gonna give similar results.
OK, latest update: when I use
Code:
void StoreScenery( string tag) {	PrintString( "Storing scenery for tag " + tag);	int i = 0;		object ob = GetObjectByTag( tag, i);			while ( ob != OBJECT_INVALID) {		PrintString( "storing object " + tag + IntToString( i));		SetLocalLocation( GetFirstPC(), tag + IntToString( i) + "loc", GetLocation(ob));		PrintString( "Stored location...");		StoreCampaignObject( CAMPAIGN_NAME, tag + IntToString( i), ob);		PrintString( "Stored object...");		i++;		ob = GetObjectByTag( tag, i);		PrintString( "Got next object");	}}
what gets printed in the log is:
Code:
Storing scenery for tag bv_ob_receptionstoring object bv_ob_reception0Stored location...Stored object...Script bv_unsetsc_rec, OID: 800008c5, Tag: bv_npct_rozalia, ERROR: STACK UNDERFLOW, Last Command Id: 83
The string [tt]"Got next object"[/tt] never gets printed, so it's the call to [tt]GetObjectByTag( tag, i)[/tt] which is failing when i is one. That seems to imply that whether we're setting the variables on the player or the campaign is a distraction - what's failing is simply looping through objects...However, when I do the tear down:
Code:
void ClearScenery( string tag) {	PrintString( "Tearing down scenery for tag " + tag);	int i = 0;		object ob = GetObjectByTag( tag, i);			while ( ob != OBJECT_INVALID) {		PrintString( "clearing object " + tag + IntToString( i));		DestroyObject( ob);		i++ ;		ob = GetObjectByTag( tag, i);	}}
What I get in the log is:
Code:
Tearing down scenery for tag bv_ob_receptionclearing object bv_ob_reception0clearing object bv_ob_reception1clearing object bv_ob_reception2
So in this case, looping through objects works...I'm still investigating!
 
I tried your script, the problem is the "StoreCampaignObject" function, it seems it's only used with creatures and items, i'm really sorry i haven't noticed this before. you'll have to use "SetLocalObject" instead. Again, really sorry! :-[
 
I wouldn't take the 'SetLocalObject' function, so it doesn't store the object persistant.if you destroy the object, it will be invalid in my knowledge (tell me other, if i am wrong).
@Simonbut I need a means of storing what they were and where they were while they're not visible.
Maybe we think in different ways. But you have the object as blueprint. What exactly should be changed on that object. You can store the object as blueprint and Create the first time, than destroy and if you wantcreate again. You only need to store the position of the the object. It is always the same pos., i don't seeany problem...If you set object in area, maybe that would be a suggestion (in addition to Raven):void{vector vPosition = GetPosition([object]);location Location = Location( oArea, vPosition, fOrientation);if (!GetLocalInt(GetFirstPC(),"object") == 1)
 
To use an "invisible" object, simply try to steal it's texture. I mean, place the weddingstuff somewhere, and change the texture to an completely unknown one, so that there is no "black box" then.The object itself AND the positions remain in it's place, but it is "invisible" now. But you can click it in your placeables list.You can also try the object, with which I done my wfx-list... btw, the list is here in german, simply rightclick to download it (165MB) www.hexenmeister-raven.de/downloads/Raven's WFX-Effekte.pdfthe object is a raven :) but that raven is flying some meters away from the object itself, so every effect is putting on the "middle" of the object (the position!) but you can't see the raven, because it's somewhere else away from this position. It's called "an_kruklow2", it's an mdb-file, change the model in your weddingstuffIf you use the weddingstuff in a house, there's no problem to set the object so, that the raven is "blocked" in a wall, and if you use it outside, well it's no problem because the raven will fly around there and the object-middle should be "stucked" on it's place. Like my wfx-effects.... ;)
 
Ralf1731 said:
But the object is in room, isn't it? So - is the object not blocking your moving?
No, it isn't, because the middle of this object is "not there", the effects of the object itself are at the position where the raven is. ;DOnly if you put an effect on that object, then it is at object's middle position, that also means, you can't put an effect onto the raven...That's the Djinni, isn't it nice? ;)
 
Top Bottom