Aller au contenu

Photo

Placeable as Area Transition


  • Veuillez vous connecter pour répondre
17 réponses à ce sujet

#1
Yawgn0r

Yawgn0r
  • Members
  • 18 messages

How do I take a placeable, say a well, and have it so when a character clicks on it, they are transported to another area, for example down the well?



#2
Tchos

Tchos
  • Members
  • 5 054 messages

Very simple.  Make it usable, and put a script in its On Used slot that calls JumpPartyToArea(oPC, oWP);

 

Here's the one I use, which I made to work on any door or placeable without alteration, getting the destination and other information from local variables on the placeable.  It also works across modules.

//////////////////////////////////////////////////////////////////////////////
//	
//	tch_door
//	by Tchos
//	
//	A script to apply to a door's On Open slot, or a placeable's On Used slot.
//	Will play a door opening sound (a default one, or one you specify),
//	and then transition the player and party there.
//	
//	If the object is a door, it will stop the door from visibly opening, and 
//	transition without requiring the user to click on the door twice.
//	
//	If there is a module specified in the local variables, it will perform a 
//	module transition.
//	
//////////////////////////////////////////////////////////////////////////////

#include "ginc_companion"

void main()
{
	object oPC = GetLastOpenedBy();
	if (oPC == OBJECT_INVALID) 
		{ 
			oPC = GetLastUsedBy();
		}
	if (oPC == OBJECT_INVALID) 
		{ 
			oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC); 
		}
	
	
	ClearAllActions(TRUE); 
	AssignCommand(OBJECT_SELF, ActionCloseDoor(OBJECT_SELF));
   
   	//tag of waypoint to travel to should be in a local string called "dest"
	string sDestWP = GetLocalString(OBJECT_SELF, "dest");
	if (sDestWP != "") 
	{
	//	SendMessageToPC(oPC, "Destination: " + sDestWP);
		object oWP = GetWaypointByTag(sDestWP);
		//name of sound to play when door opens should be in a local string called "sound"
		string sSoundName = GetLocalString(OBJECT_SELF, "sound");
		if (sSoundName == "")
			{
			// Play default door sound if none specified
			sSoundName = "drs_woodenopen_01";
			}
	//	SendMessageToPC(oPC, "Sound to play: " + sSoundName);
	
		//play door sound
		PlaySound(sSoundName);
		
		// Check if this door needs to load a new module
		string sModuleName = GetLocalString(OBJECT_SELF, "module");
		if (sModuleName != "")
			{
				// There is a module specified in the local variable, so treat
				// this door as module loading transition.
				SaveRosterLoadModule(sModuleName, sDestWP);				
			}
		else
			{
				// There is no module name specified, so treat this door as a
				// normal teleport or area transition.
				DelayCommand(0.2, AssignCommand(oPC, SetFacing(GetFacing(oWP))));
				JumpPartyToArea(oPC, oWP);
			}
	}
	else
	{
		SpeakString("No destination specified.  Aborting.");
		return;
	}

}

  • GCoyote aime ceci

#3
Yawgn0r

Yawgn0r
  • Members
  • 18 messages

Thank you very very much.



#4
Yawgn0r

Yawgn0r
  • Members
  • 18 messages

I'm hoping to transport each player in the party seprately, will this do that?



#5
Tchos

Tchos
  • Members
  • 5 054 messages

No, this transports the whole party at once.  You'd have to change JumpPartyToArea to one of the other functions.



#6
Yawgn0r

Yawgn0r
  • Members
  • 18 messages

I really do appreciate your attempt to help me, Tchos, but I'm lost. I have no scripting experience, and have no idea what you are talking about when you say "variables" and "functions".

 

I was hoping for someone to tell me, step by step, how to make a placeable teleport a single player, even if in a party with other players.

 

Sorry to have wasted your time.



#7
kevL

kevL
  • Members
  • 4 061 messages

you haven't wasted anyone's time ...
this looks pretty good : dayjo Scripting Tutorial

links are on the left. variables are Lesson 2, functions Lesson 8


no offense, but a bit of basic understanding really helps a lot.

ps. here's a simplified version

void main()
{
    object oPC = GetLastUsedBy();
    if (GetIsPC(oPC) == FALSE)
        return;

    AssignCommand(oPC, ClearAllActions(TRUE));

    object oDest = GetWaypointByTag("tag_of_destination_waypoint"); // replace w/ wp_Tag
    AssignCommand(oPC, JumpToObject(oDest));
    
    // this does not transport associates of any type, just the PC.
}

goes in onUsed of a usable placeable w/ hitpoints. Don't forget to compile.

#8
4760

4760
  • Members
  • 1 207 messages

In case variables attached to an object are not dealt with in the link above, you could also read this post.

Go straight to the second half, starting at the line 

1) In the creature's properties, at the very last line, click on the ... button at the end:

"dest", "sound" and "module" in Tchos's script are exactly this type of variables.



#9
andysks

andysks
  • Members
  • 1 650 messages

In many cases there is a simpler way to do such a thing. I often use a conversation like "Do you wish to go down the well?" then a "Yes" option will transport you with the use of just a stock script. ga_jump_players("wp_tag",1,0) for the whole party, ga_jump_players("wp_tag",0,0) for PC alone. I think at least. If I remember correctly that's how I used it a while ago.

 

Although this script uses a variable defined on ginc_transition, where this is written: // TODO: What if oClicker is NPC?

it kinda makes you think twice before using it :D.



#10
rjshae

rjshae
  • Members
  • 4 491 messages

That's the way I'd do it; use the built-in ga functions for conversations. Possibly it could even be done as a bark string one-liner.



#11
Yawgn0r

Yawgn0r
  • Members
  • 18 messages

 

 here's a simplified version

void main()
{
    object oPC = GetLastUsedBy();
    if (GetIsPC(oPC) == FALSE)
        return;

    AssignCommand(oPC, ClearAllActions(TRUE));

    object oDest = GetWaypointByTag("tag_of_destination_waypoint"); // replace w/ wp_Tag
    AssignCommand(oPC, JumpToObject(oDest));
    
    // this does not transport associates of any type, just the PC.
}

 

This worked. Thank you.

 

What would I need to add to this to transport familiars with the character?



#12
kevL

kevL
  • Members
  • 4 061 messages
void main()
{
    object oPC = GetLastUsedBy();
    if (GetIsPC(oPC) == FALSE)
        return;

    AssignCommand(oPC, ClearAllActions(TRUE));

    object oDest = GetWaypointByTag("tag_of_destination_waypoint"); // replace w/ wp_Tag
    AssignCommand(oPC, JumpToObject(oDest));


    object oAssoc;
    int i;
    for (i = 1; i != 6; i++)
    {
        int j;
        oAssoc = GetAssociate(i, oPC, ++j);
        while (GetIsObjectValid(oAssoc))
        {
            AssignCommand(oAssoc, ClearAllActions(TRUE));

            AssignCommand(oAssoc, JumpToObject(oDest));
            oAssoc = GetAssociate(i, oPC, ++j);
        }
    }
}

// These match the values in nwscreature.h
//int ASSOCIATE_TYPE_NONE             = 0;
//int ASSOCIATE_TYPE_HENCHMAN         = 1;
//int ASSOCIATE_TYPE_ANIMALCOMPANION  = 2;
//int ASSOCIATE_TYPE_FAMILIAR         = 3;
//int ASSOCIATE_TYPE_SUMMONED         = 4;
//int ASSOCIATE_TYPE_DOMINATED        = 5;
i think that got it,

EDIT: dang better clearall actions
  • GCoyote et 4760 aiment ceci

#13
Dann-J

Dann-J
  • Members
  • 3 161 messages

That's the way I'd do it; use the built-in ga functions for conversations. Possibly it could even be done as a bark string one-liner.

 

GA_ action scripts won't run off bark strings. You need at least a second [End Dialog] node for scripts to work.

 

[EDIT: The above is a false assertion]



#14
kamal_

kamal_
  • Members
  • 5 250 messages

Scripts won't run off bark strings. You need at least a second [End Dialog] node for scripts to work.

I make my placeable area transitions with conversations, and include a "stay here" option in case of accidentally clicking on the object and starting the conversation.



#15
andysks

andysks
  • Members
  • 1 650 messages

Scripts won't run off bark strings. You need at least a second [End Dialog] node for scripts to work.

Are you certain? I was certain that I've used such a thing... but now that I read this I question my memory.

 

Edit: I know this is not the case of this thread but I checked and it is true. I have this instance where an one liner uses

ga_set_immortal

ga_sound_object_play

ga_destroy_item

All in one. Tested and working fine.


  • rjshae aime ceci

#16
rjshae

rjshae
  • Members
  • 4 491 messages

Yes, I've used scripts for triggered one-liner bark strings by intelligent swords, for example.



#17
Dann-J

Dann-J
  • Members
  • 3 161 messages

Are you certain? I was certain that I've used such a thing... but now that I read this I question my memory.

 

Edit: I know this is not the case of this thread but I checked and it is true. I have this instance where an one liner uses

ga_set_immortal

ga_sound_object_play

ga_destroy_item

All in one. Tested and working fine.

 

It used to be true years ago. Perhaps it was fixed in one of the patches? I haven't tried it in a while.

 

No doubt many of the things I avoid doing in the toolset are based on problems that have long since been fixed in subsequent patches.

 

 

Yes, I've used scripts for triggered one-liner bark strings by intelligent swords, for example.

 

That's not the same as having a one-liner bark string execute a script of its own though (which apparently works now anyway).



#18
rjshae

rjshae
  • Members
  • 4 491 messages

That's not the same as having a one-liner bark string execute a script of its own though (which apparently works now anyway).

 

Well the trigger starts a conversation, which in some cases triggers conditional tests to select a random bark string.