Summoning portal and destroyng it!

hi there all!

So I am working on my PW and t is going greatthough I am not a script master I have the desire to alter this script that I had found but I seem to hit a wall with this so I would appreciate any additional help on this!

Okay so i got this script which I believe works the moment you close the placeable (in my case a bookcase) with books with a certain letter on it.

void main()
{
object oThief = GetLastClosedBy();
object oBook = GetFirstItemInInventory(OBJECT_SELF);
object oO = GetObjectByTag("BOOK_O TAG",0);
object oP = GetObjectByTag("BOOK_P TAG",0);
object oE = GetObjectByTag("BOOK_E TAG",0);
object oN = GetObjectByTag("BOOK_N TAG",0);
location oLoc = GetLocation(GetWaypointByTag("WP_BOOKCASE_PORTAL"));
if ((oBook == oN) && (GetIsObjectValid(oBook)))
{
    oBook = GetNextItemInInventory(OBJECT_SELF);
    if ((oBook == oE) && (GetIsObjectValid(oBook)))
    {
        oBook = GetNextItemInInventory(OBJECT_SELF);
        if ((oBook == oP) && (GetIsObjectValid(oBook)))
        {
            oBook = GetNextItemInInventory(OBJECT_SELF);
            if ((oBook == oO) && (GetIsObjectValid(oBook)))
            {
            AssignCommand(oThief,ActionJumpToLocation(oLoc));
            }
        }
    }
}
}

Which if I read this correctly would teleport the user to the WP that has been specified in the top. HOWEVER I seem to be doing it either wrong or something went wrong.

So I thought of altering it slightly to create a portal at a WP that will last for like 6seconds (so long enough for people to hop in before the portal vanishes and the books being consumed by the placeable)

Would that be doable? with this script? If anyone can lend me a hand with this since I keep walking up that wall and I can tell you I do not like the wall :S

anyway thank you in advance,

DQ!

I think it should be possible. I’ll have a go at it. No promises though, but I’ll try.

1 Like

Ok, the script doesn’t work, and I have an idea why. Let me work on it some more. I think I can fix it.

Alright, I have no idea what I’m doing wrong, but I can’t get the script to work. I’ve tried several methods now. I won’t embarass myself posting my attempts here since I know they don’t work. This should be an easy script to make but… :woozy_face:

ikr? I have been having issues with that as well! I appreciate the attempt though! (thought I was going coocoo for failing)

The one thing I see is wrong in the script is for example the

GetObjectByTag(“BOOK_O TAG”,0);

You should remove the “0”.

I tried some “while-loops” which I suck at, but I thought they would work, and the script compiled, but the spawning of the portal never happens.

Wait, I have another idea. I’ll try that. I’ll get back to you. I realized I have a very similar script in the module I’m working on. Let met take a look.

Here. This works in NWN2 at least (I renamed the tags when testing, sorry about that):

int ItemsValid()
{

    int bHasBook1 = FALSE;
    int bHasBook2 = FALSE;
	int bHasBook3  = FALSE;
	int bHasBook4 = FALSE;

    string sTag;

    object oItem = GetFirstItemInInventory();
    	while (GetIsObjectValid(oItem))
    	{
        	sTag = GetTag(oItem);
        	if (sTag == "book_o")
        	{
            bHasBook1 = TRUE;
        	}
        	else if (sTag == "book_p")
        	{
            bHasBook2 = TRUE;
        	}
			else if (sTag == "book_e")
        	{
            bHasBook3 = TRUE;
        	}
			else if (sTag == "book_n")
        	{
            bHasBook4 = TRUE;
        	}


        oItem = GetNextItemInInventory();
    	}

    return bHasBook1 && bHasBook2 && bHasBook3 && bHasBook4; // All must be TRUE for the return to be TRUE
}

void DestroyTheObject()
{

object oPortal = GetObjectByTag("portal");

DestroyObject(oPortal,0.1);

}

void main()
{
object oThief = GetLastClosedBy();

location lLoc = GetLocation(GetWaypointByTag("WP_BOOKCASE_PORTAL"));

	if(ItemsValid())
		{

		CreateObject(OBJECT_TYPE_PLACEABLE,"portal",lLoc);
		
		DelayCommand(6.0, DestroyTheObject());
        }

}

Sigh, so the function ginc_object is not available in NWN1. Ok, I’ll try and fix it.

Are you sure spaces (" ") are allowed in tags? What happens if you try with "BOOK_O_TAG" instead.

Maybe this will work (it works like a charm in NWN2, don’t know about using the teleporter, if that interupts the destroy but…EDIT: Tested that too in NWN2 and it works too):

int ItemsValid()
{

    int bHasBook1 = FALSE;
    int bHasBook2 = FALSE;
	int bHasBook3  = FALSE;
	int bHasBook4 = FALSE;

    string sTag;

    object oItem = GetFirstItemInInventory();
    	while (GetIsObjectValid(oItem))
    	{
        	sTag = GetTag(oItem);
        	if (sTag == "book_o")
        	{
            bHasBook1 = TRUE;
        	}
        	else if (sTag == "book_p")
        	{
            bHasBook2 = TRUE;
        	}
			else if (sTag == "book_e")
        	{
            bHasBook3 = TRUE;
        	}
			else if (sTag == "book_n")
        	{
            bHasBook4 = TRUE;
        	}
			

        oItem = GetNextItemInInventory();
    	}

    return bHasBook1 && bHasBook2 && bHasBook3 && bHasBook4; // All must be TRUE for the return to be TRUE
}

void DestroyTheObject()
{

object oPortal = GetObjectByTag("portal");

DestroyObject(oPortal,0.1);

}

void main()
{

object oThief = GetLastClosedBy();
location lLoc = GetLocation(GetWaypointByTag("WP_BOOKCASE_PORTAL"));

	if(ItemsValid())
		{
		
		CreateObject(OBJECT_TYPE_PLACEABLE,"portal",lLoc);		
		DelayCommand(6.0, DestroyTheObject());
        }

}

At least now it compiled in NWN1.

nothing seems to happen here when I try it? 0.0

Have you changed the tags? As I said, I happened to change the tags when trying different things, so you would want to change them back to what you had. OR it might be as @4760 says that you shouldn’t have a space in the tag name.

Since I only have NWN “somewhat” installed on this computer (I’ve actually just copied my previous folders from an old harddrive) and even though I can open the toolset, it says (understandably) that there’s no key for the game, so I probably wouldn’t be able to test this. And it takes to long if I were to install the whole game from my old discs (I own the NWN Deluxe Edition), sorry. Plus, I don’t know my way around the NWN1 Toolset. I know how to write a script there, but that’s it.

EDIT: Have you put my script on the OnClosed of the placeable you use?

I did and I even took your script over completely and changed their tags to see if that changed anything. it didnt

Did the script compile for you?

it did

I’m trying with the NWN1 toolset myself now. Have no idea if the game will start…It will take a while for me to set this up, being so unfamiliar with this toolset, but I’ll try.

Hmmm, it actually worked. The game runs, and everything except teleporting from the portal works (but that’s because I don’t know how to write a normal jump to object script in NWN1, while I know exactly how this is done in NWN2). Such nostalgia to run old NWN1 again.

So I have no idea why it doesn’t work for you. I have the old NWN1 so maybe it’s got something to do with NWN:EE if you’re using that?

On what handle you put it? on closed right?

Yep

Try ClearAllActions() before jumping.

If you only want to know if someone has a specific item you can use GetItemPossessedBy() to simplify the script (no loop).

Does that work for placeables too?

@Dragonqueeny - I now successfully created a jumping script. Everything now works on my end in both NWN1 and NWN2.