Author Topic: Quick Help  (Read 507 times)

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
Quick Help
« on: June 13, 2011, 10:01:46 pm »


               Here is what I am doing...

I have a wagon coach system from JFK. The driver inside the wagon announces when they enter a rea by a trigger.

I want to do the same thing but have it announce every area with one script.

This is what he has;

void main()
{
object oCoach = GetObjectByTag("COACH");
object oDriver = GetObjectByTag("DRIVER");
if(GetEnteringObject() == oCoach)
    {
    AssignCommand(oDriver, SpeakString("Dragonspear Castle region!"));
    }
}


He has that  as a trigger in each area he wants the man to announce it. Could I not just change it to something of the sorts?


void main()
{
object oCoach = GetObjectByTag("COACH");
object oDriver = GetObjectByTag("DRIVER");
object oArea = GetArea(oCoach);
string sName = GetName(oArea);
if(GetArea(oCoach) == sName)
    {
    AssignCommand(oDriver, SpeakString("*sName* region!"));
    }
}
               
               

               


                     Modifié par TSMDude, 13 juin 2011 - 09:06 .
                     
                  


            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Quick Help
« Reply #1 on: June 13, 2011, 10:07:05 pm »


               EDIT

I can't see why not.

    AssignCommand(oDriver, SpeakString(sName + " region!"));
               
               

               


                     Modifié par Xardex, 13 juin 2011 - 09:09 .
                     
                  


            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Quick Help
« Reply #2 on: June 13, 2011, 10:11:15 pm »


               Yup you can. The function is GetName().

AssignCommand(oDriver, SpeakString("We've arrived at " + sAreaName + "!"));
               
               

               
            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
Quick Help
« Reply #3 on: June 13, 2011, 10:17:34 pm »


               Ahhh...I see what I screwed up....why did I add stars instead of pluses? I need some sleep....lol...

Thank you guys for helping me with my cranuim flatulence.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Quick Help
« Reply #4 on: June 13, 2011, 11:31:51 pm »


               

TSMDude wrote...


void main()
{
object oCoach = GetObjectByTag("COACH");
object oDriver = GetObjectByTag("DRIVER");
object oArea = GetArea(oCoach);
string sName = GetName(oArea);
if(GetEnteringObject() == oCoach)
    {
    AssignCommand(oDriver, SpeakString("We've arrived at " + sName + "!"));
    }
}


I hope you don't take my comments her the wrong way.  This script is just a little wastfull, so thought i would comment on it. 

This script fires every time somthing enters the module.  And here is my paraphrase on what I see it doing. 

OOch,  Something just steped on me. 
Where is my to do list for this again.  
Oh here it is.  
1  object oCoach = GetObjectByTag("COACH");
    Ok everyone hod on a bit I need to search the entire face of the planet and figure out where the Coach is.  
      ( after looking at sever hundred object if not thousnad)   O found it. 
2. object oDriver = GetObjectByTag("DRIVER");
   O-boy  I get to scry the face of the planet again looking for its Driver. 
   ( Fast sucker a few milliseconds later)   Ok found it too. 
3. object oArea = GetArea(oCoach);
   Hay Coach what area are you in.   
       Coach:   I'm in area 42.
4. string sName = GetName(oArea); 
   That is nice do you happen to have the name of the area.  
       Sure it is name is.   "Way the heck out here". 
5 if(GetEnteringObject() == oCoach)
   Hay coach did you jusr roll over me ? 
      coach:  Are you kidding!! Im leagues away from you.
   Ok Im going back to sleep then.    
....

 
OOch,  Something just steped on me. 
Let see where is that coach and driver again. 
...  

**************

Would it not be better to: 

void main()
{
 object oCoach = GetEnteringObject();
 if ( GetTag(oCoach) != "COACH") return;
 
object oDriver = GetNearestObjectByTag("DRIVER");// Does not search the entire world.
 string sName = GetName(GetArea(oCoach));
 AssignCommand(oDriver, SpeakString("We've arrived at " + sName + "!"));



Paraphrase.

 Ouch.
1  object oCoach = GetEnteringObject();
  Hay man you just stepped on me.
2  if ( GetTag(oCoach) != "COACH") return;
  Are you the Coach,  No Then let me sleep...
.
 ouch. 
1  object oCoach = GetEnteringObject();
  Hay that wheel hurts. Carfull Im taking names.
2  if ( GetTag(oCoach) != "COACH") return; 
  Hay man I have been wating for you.
3. object oDriver = GetNearestObjectByTag("DRIVER"); 
  I needed to talk to your driver.  
4  string sName = GetName(GetArea(oCoach));
   What is the name of this area again. 
5 AssignCommand(oDriver, SpeakString("We've arrived at " + sName + "!"));
   Hay driver I was tolt to remind yoou to anounce your arivial in sName.

**** 

Hope you dont mind may paraphrasing here. 
I have just noticed way to many people lately insisting on searching the entire module for an object, when all they care about is the one that just stepped on them.

This method also has the advantage of being able to handle more then one coach and driver in the module.    With the first script you would never know if the coach you just searched for and found was the one that just stepped on you or not.

And yes I do know that you where just modifing a script that someone else wrote.  
It was just a short enough example that I could not resist.
               
               

               
            

Legacy_Axe_Murderer

  • Full Member
  • ***
  • Posts: 199
  • Karma: +0/-0
Quick Help
« Reply #5 on: June 15, 2011, 12:22:25 am »


               [nwscript]
// Trigger or Area OnEnter script
void main()
{ object oCoach = GetEnteringObject();
  if( GetTag( oCoach ) == "COACH" )
  { string sMsg = "We've arrived at " +GetName( GetArea( OBJECT_SELF ) ) +"!"; 
    AssignCommand( GetNearestObjectByTag( "DRIVER", oCoach ), SpeakString( sMsg ) );
  }
}
[/nwscript]
  • find the entering object.
  • if the entering object has it's TAG set to "COACH"
  • then
    • build a string containing the driver's dialogue by inserting the current area's

      name inside some hard-coded text.



      Note: if OBJECT_SELF is the trigger, when used as the trigger's OnEnter event script,

      GetArea( OBJECT_SELF ) will be the area the trigger is in.

      if OBJECT_SELF is the area, when used as the area's OnEnter event script,

      GetArea( OBJECT_SELF ) will be the area being entered (an area's area is itself).

      It would also work on a door, but that would be on the way out of the area not on the way in.



      In either case GetName( GetArea( OBJECT_SELF )) will be the name of the area

      being entered or the name of the area the trigger being entered resides in. And that's

      what the driver should say.
    • Make the object closest to the entering COACH whose TAG is set to "DRIVER" speak the message.
  • otherwise it's not a COACH so do nothing

               
               

               


                     Modifié par Axe_Murderer, 14 juin 2011 - 11:55 .
                     
                  


            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
Quick Help
« Reply #6 on: June 15, 2011, 01:29:32 am »


               

Lightfoot8 wrote...

I hope you don't take my comments her the wrong way.  This script is just a little wastfull, so thought i would comment on it. 

This script fires every time somthing enters the module.  And here is my paraphrase on what I see it doing. 

OOch,  Something just steped on me. 
Where is my to do list for this again.  
Oh here it is.  
1  object oCoach = GetObjectByTag("COACH");
    Ok everyone hod on a bit I need to search the entire face of the planet and figure out where the Coach is.  
      ( after looking at sever hundred object if not thousnad)   O found it. 
2. object oDriver = GetObjectByTag("DRIVER");
   O-boy  I get to scry the face of the planet again looking for its Driver. 
   ( Fast sucker a few milliseconds later)   Ok found it too. 
3. object oArea = GetArea(oCoach);
   Hay Coach what area are you in.   
       Coach:   I'm in area 42.
4. string sName = GetName(oArea); 
   That is nice do you happen to have the name of the area.  
       Sure it is name is.   "Way the heck out here". 
5 if(GetEnteringObject() == oCoach)
   Hay coach did you jusr roll over me ? 
      coach:  Are you kidding!! Im leagues away from you.
   Ok Im going back to sleep then.    
....

 
OOch,  Something just steped on me. 
Let see where is that coach and driver again. 
...  

**************

Would it not be better to: 

void main()
{
 object oCoach = GetEnteringObject();
 if ( GetTag(oCoach) != "COACH") return;
 
object oDriver = GetNearestObjectByTag("DRIVER");// Does not search the entire world.
 string sName = GetName(GetArea(oCoach));
 AssignCommand(oDriver, SpeakString("We've arrived at " + sName + "!"));



Paraphrase.

 Ouch.
1  object oCoach = GetEnteringObject();
  Hay man you just stepped on me.
2  if ( GetTag(oCoach) != "COACH") return;
  Are you the Coach,  No Then let me sleep...
.
 ouch. 
1  object oCoach = GetEnteringObject();
  Hay that wheel hurts. Carfull Im taking names.
2  if ( GetTag(oCoach) != "COACH") return; 
  Hay man I have been wating for you.
3. object oDriver = GetNearestObjectByTag("DRIVER"); 
  I needed to talk to your driver.  
4  string sName = GetName(GetArea(oCoach));
   What is the name of this area again. 
5 AssignCommand(oDriver, SpeakString("We've arrived at " + sName + "!"));
   Hay driver I was tolt to remind yoou to anounce your arivial in sName.

**** 

Hope you dont mind may paraphrasing here. 
I have just noticed way to many people lately insisting on searching the entire module for an object, when all they care about is the one that just stepped on them.

This method also has the advantage of being able to handle more then one coach and driver in the module.    With the first script you would never know if the coach you just searched for and found was the one that just stepped on you or not.

And yes I do know that you where just modifing a script that someone else wrote.  
It was just a short enough example that I could not resist.


Honestly no offense was taken and normally your spot on but ummm....I do not understand this in the slightest...have you been drinking and posting again? 'Image

Why is anyone stepping on anyones toes? 'Image

Not a onModule event but a trigger event though I dig Axe's version way better than the little quick change I did. A lot smarter than mine fer surseys...

(PS Glad to have you back here Axe as you been missed.)
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Quick Help
« Reply #7 on: June 15, 2011, 03:14:23 am »


               I think Lightfoot's main point was the wastefulness of Getting by Tag, which is modwide. We don't use that function at all - there is ALWAYS a better way (often GetNearest, which only loops a single area). When I need to get something in a completely different area, I'll typically use a waypoint in the area and then GetNearest to it, unless I'm getting that thing a lot, in which case I'll set it as a LocalObject on the module.

FWIW, Lightfoot's and Axe's versions are essentially the same.

Funky
               
               

               


                     Modifié par FunkySwerve, 15 juin 2011 - 02:20 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Quick Help
« Reply #8 on: June 15, 2011, 04:30:13 am »


               

TSMDude wrote...

Honestly no offense was taken and normally your spot on but ummm....I do not understand this in the slightest...have you been drinking and posting again? 'Image


Does Diet Coke count as drinking.   Or perhaps my lack of sleep has just twisted my brain. 

Why is anyone stepping on anyones toes? 'Image

 
'Image Just my way of saying that something fired the script on the trigger.


Not a onModule event but a trigger event though I dig Axe's version way better than the little quick change I did. A lot smarter than mine fer surseys...

True not a module event.  but like funky said, the original script does a search through every object in the game twice.  Once for the coach and once for the driver.  The GetEnteringObject function only has to return the value of a single memory location with no search.   So why search through all them objects.  

Yes I like Axe's version better also,  mainly because the script uses fewer varaiables and has only one exit point.  


(PS Glad to have you back here Axe as you been missed.)

I think we are all glad to see Axe back around.  He was sorely missed during his absance. 
Wellcome back Axe.


Sorry, that my attempt at a humorous explanation did not explain things as well as I had hoped.   Explaining thins never was my strong suit.  I hpoe you at least got a good laugh at me making a fool of myself. 'Image


L8
               
               

               


                     Modifié par Lightfoot8, 15 juin 2011 - 03:31 .
                     
                  


            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
Quick Help
« Reply #9 on: June 15, 2011, 04:37:50 am »


               No worries as I just did not understand is all...lol...
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Quick Help
« Reply #10 on: June 15, 2011, 05:03:20 am »


               

Lightfoot8 wrote...

Sorry, that my attempt at a humorous explanation did not explain things
as well as I had hoped.   Explaining thins never was my strong suit. 
I hpoe you at least got a good laugh at me making a fool of myself. ../../../../images/forum/emoticons/surprised.png


I sure liked it. It's explanations like this that helped me learn how to script. I need stuff explained in "Layman's Terms" sometimes. '<img'>
               
               

               


                     Modifié par GhostOfGod, 15 juin 2011 - 04:03 .