Aller au contenu

Photo

Get Waypoint By Tag


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

#1
andysks

andysks
  • Members
  • 1 651 messages
Hi all. I've written a script, which is hard to test before some final playtesting, and I'm curious if it will work. It compiles and everything but that's not the point. When a local int set on the MODULE is met, a guy needs to spawn and initiate conversation with you. The local int is set through some key conversations, which you can have at random order so I'm using the + .At the end of each of these key convos, there is another NPC line, with the condition, and if met a guy is spawned at a WP and starts new convo.

Problem is, the key convos are scattered throughout a city. Will the GetWaypointByTag choose the nearest? Or do I have to call another fuction for tis to chose the nearest?

#2
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
GetNearestObjectByTag will work for you. Or just give each waypoint a unique tag.

#3
Darin

Darin
  • Members
  • 282 messages
You can use the same tag for all of the waypoints, say "wp_initiate_the_talk".

Then you'd use...

ka_spawn_the_talk

void main (string sCreature, string sWP)
{
object oWP = GetNearestObjectByTag( sWP, GetPCSpeaker() );
location lLocation = GetLocation( oWP );
object oSpeaker = CreateObject( OBJECT_TYPE_CREATURE , sCreature, lLocation );
}

(above assumes that he will have the next node of the conversation)

You could also just spawn the WayPoint based on the PC's Location, but if the speaker can't just "appear" that may not work for you.

#4
Eguintir Eligard

Eguintir Eligard
  • Members
  • 1 832 messages
Don't expect any "Get" function to return the nearest item... it shouldn't. What it should return in such a case is the first one created/loaded. Only GetNearest type functions care about actually physical distance. Always use a unique name as has been said.

Also try to use unique states rather than a + so it is self documenting as you may forget what each state is months down the road. So you could make that variable a string and use "TALKED_TO_ONCE" "TALKED_TO_TWICE" "QUEST_1_DONE" etc rather than just 1, 2, 3.

Modifié par Eguintir Eligard, 18 septembre 2013 - 04:57 .


#5
Dann-J

Dann-J
  • Members
  • 3 161 messages
If you really want to confuse yourself, you can always try to encode multiple states into the one integer by adding numbers that are powers of two (+1, +2, +4, +8, etc). Then you get to figure out all the possible combinations of states and their corresponding values, and design conversation nodes around them. I've used that system once in a module (and never again).

It has all the convenience of a single variable, combined with the mind-bending complication of interpreting said variable!

#6
andysks

andysks
  • Members
  • 1 651 messages
Ok, now I am a bit confused, so I will explain what I want a bit better.
You are in a city, performing quests. Of these 20 or so quests, there are 8 that in the starting node have a local int raised by 1. On the completion of each one of this quests, after the farewell and thank you take this reward nodes, there is one more with a conditional of the local int to be 8. If it's not met yet, you continue as nothing happened. If it's met, then there is a guy spawning to the given area that the given quest was completed(near a door, somewhere and runs to you... doesn't matter. Wherever the WP is) and from the first convo there is a jump to the spawned guy's convo in which he is like "Hey you are the one that did all these things, come with me" short of thing. Since there are 8 instances for this, giving different tags I guess require make the script a ga_* script, like EpicFetus said right? But in his script, the convo has to continue there is no jump to other convo right?
Another thing, does + and ++ even work? Or just the +1 ++1 and so on?

#7
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
To translate DannJ:

As you have it, your final variable starts at 0 and as each of the eight quests is completed, it's gets incremented one-by-one to 8. An alternative way of counting is to have each of these eight quests add a different power of 2 (1, 2, 4, 8, 16, 32, 64, 128). Imagine the number written out in binary (ones and zeros). You complete the first quest (1) and your value becomes 1. Then you complete the third quest (4) and your value becomes 101 (in binary, 4 = 100). You then do the seventh quest (64), and the value is 1000101. By the time you do them all, the value, in binary, is 11111111. In decimal that's 1+2+4+8+16+32+64+128, or 255.

The math is hard to do in your head when writing a convo, but you could instead use a script that just looks at the nth digit in the number. Say the value is 69, and you want to know whether or not they completed the third quest. You just lop off each digit's value in order. First you lop off 64, then because the result (5) is so small you skip 32, 16, and 8, lop off 4, skip 2, then take away the last 1. Since the 4 was there for you to lop off, the player must have completed the third quest.

Modifié par Lugaid of the Red Stripes, 20 septembre 2013 - 03:28 .


#8
andysks

andysks
  • Members
  • 1 651 messages
Is this method better or gives best results? Or is it just a different approach? I mean, won't the normal +s work as intended? I remember a while ago I needed to do something like that with levers, which the PC had to pull increasing a local int, and when he had all something was open. A programmer friend of mine when I explained it to him, said "Why don't you do it like binary"? like it is the best way to go. Is that true?

#9
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
It's more robust, which matters when it comes to testing and big-fixing. How does the player know which quests are left for him to do? What if there's a bug in a conversation and the integer is incremented repeatedly or not at all? What if you later decide that you want to vary NPC responses based upon which quests the player has completed?

Just adding one each time will work, but eventually you'll want to do something more complicated, and then the binary system will help you out. By all means, though, do what works for you and get back to the fun parts!

#10
I_Raps

I_Raps
  • Members
  • 1 262 messages
No need to reinvent the wheel:

 NWN2 Bitwise Math Operators

Modifié par I_Raps, 20 septembre 2013 - 08:25 .


#11
Tchos

Tchos
  • Members
  • 5 063 messages
To answer your specific question, ++ works fine. I use it often.

iCounter++;

is the same as

iCounter = iCounter + 1;

#12
Morbane

Morbane
  • Members
  • 1 883 messages
you could write a script intended to set every local int - attach it to anything - a gong for instance

you can also use the above method for practically anything: spawning companions, giving xp/items skills, feats etc -

just whack the thing in to test, delete/move when done...

#13
Morbane

Morbane
  • Members
  • 1 883 messages

Lugaid of the Red Stripes wrote...

By all means, though, do what works for you and get back to the fun parts!



your programmer friend will be able to confirm that there is always another way to juggle code

robust, brute force, elegance, simplicity - and of course cleverness and flexibility - reuseable code is always handy

- also consider just using unique tags - and the journal to keep track of variables

Modifié par Morbane, 21 septembre 2013 - 02:05 .


#14
andysks

andysks
  • Members
  • 1 651 messages
I kinda thought of another possibility here, which would be easier I guess. The OnClientOnEnter event, will it fire every time the player transits to the specific area? Or it fires only the first time? If not, I could just scatter some WPs with the same tag near the entrances, and the conditional int will be called from the script itself, spawning the NPC to the nearest WP by tag...

#15
Tchos

Tchos
  • Members
  • 5 063 messages
Yes, both On Client Enter and On Enter fire every time you enter the area.