Page 1 of 1

Code Adjustments (Formerly burp)

Posted: Tue Jul 02, 2002 12:09 pm
by Silk
I will write about this later... just storing this code here for now.

Code: Select all

void main()
{
   int nUser = GetUserDefinedEventNumber();

   if (nUser == 1001)  // This is a heartbeat triggered script.
   {
   // Go to night post

        if (GetIsNight() || GetIsDusk())
        {
            string sMobName = GetTag(OBJECT_SELF);
            string sPostName = "NP_   ";
            string sPostTag = InsertString (sPostName, sMobName, 3);

            object oPost = GetObjectByTag(sPostTag);

            if (GetIsObjectValid(oPost))
           {
                ActionMoveToObject(oPost);
           }
        }
    }

    return;

Posted: Tue Jul 02, 2002 1:41 pm
by Orleron
looks like you put in a little check at the end to see if the object is a valid post. Did that fix the problem?

Posted: Tue Jul 02, 2002 3:14 pm
by Silk
Yeah. I looked at those scripts that you use for the Night changeover stuff. Alot of them are using objects assuming that they were ok.

This might be the problem. I added the Validity checks this morning, so I wasn't able to test it yet.

Whenever you use an object, make sure you verify that it is a valid object before you use it.

Posted: Tue Jul 02, 2002 3:21 pm
by Orleron
Ok, I am home now, so I will work on implementing that code.

Posted: Tue Jul 02, 2002 3:25 pm
by Silk
I put my morning update in my ftp folder for you. I put an update of changes in a txt file in your folder.

Posted: Tue Jul 02, 2002 3:45 pm
by Silk
This:

Code: Select all

void main()
{
    // shoppers picking random waypoints to walk to

 int iRandom = d12();
 int nUser =  GetUserDefinedEventNumber();
 float fWait = IntToFloat(d10());


 if (nUser == 1001)
 {

 switch (iRandom)
 {

   case 1:

        ActionMoveToObject(GetWaypointByTag("WP_SHOPPER_001"));
        break;

   case 2:

        ActionMoveToObject(GetWaypointByTag("WP_SHOPPER_002"));
        break;

   case 3:

        ActionMoveToObject(GetWaypointByTag("WP_SHOPPER_003"));
        break;

   case 4:

        ActionMoveToObject(GetWaypointByTag("WP_SHOPPER_004"));
        break;

   case 5:

        ActionMoveToObject(GetWaypointByTag("WP_SHOPPER_005"));
        break;

   case 6:

        ActionMoveToObject(GetWaypointByTag("WP_SHOPPER_006"));
        break;

   case 7:

        ActionMoveToObject(GetWaypointByTag("WP_SHOPPER_007"));
        break;

   case 8:

        ActionMoveToObject(GetWaypointByTag("WP_SHOPPER_008"));
        break;

   case 9:

        ActionMoveToObject(GetWaypointByTag("WP_SHOPPER_009"));
        break;

   case 10:

        ActionMoveToObject(GetWaypointByTag("WP_SHOPPER_010"));
        break;

   case 11:

        ActionMoveToObject(GetWaypointByTag("WP_SHOPPER_011"));
        break;

   case 12:

        ActionMoveToObject(GetWaypointByTag("WP_SHOPPER_012"));
        break;

    return;
     }

  ActionPlayAnimation(ANIMATION_FIREFORGET_HEAD_TURN_LEFT);

  ActionPlayAnimation(ANIMATION_FIREFORGET_HEAD_TURN_RIGHT);

  ActionWait(fWait);

  ActionSpeakString("Alms! Alms for the poor!");
   }
}
[\code]

Should Be This:
[code]
void main()
{
    // shoppers picking random waypoints to walk to

 int iRandom = d12();
 int nUser =  GetUserDefinedEventNumber();
 float fWait = IntToFloat(d10());
 
 object oWaypoint;

 if (nUser == 1001)
 {

	 switch (iRandom)
	 {

		 case 1:

					oWaypoint = GetWaypointByTag("WP_SHOPPER_001");
					break;

		 case 2:

					oWaypoint = GetWaypointByTag("WP_SHOPPER_002");
					break;

		 case 3:

					oWaypoint = GetWaypointByTag("WP_SHOPPER_003");
					break;

		 case 4:

					oWaypoint = GetWaypointByTag("WP_SHOPPER_004");
					break;

		 case 5:

					oWaypoint = GetWaypointByTag("WP_SHOPPER_005");
					break;

		 case 6:

					oWaypoint = GetWaypointByTag("WP_SHOPPER_006");
					break;

		 case 7:

					oWaypoint = GetWaypointByTag("WP_SHOPPER_007");
					break;

		 case 8:

					oWaypoint = GetWaypointByTag("WP_SHOPPER_008");
					break;

		 case 9:

					oWaypoint = GetWaypointByTag("WP_SHOPPER_009");
					break;

		 case 10:

					oWaypoint = GetWaypointByTag("WP_SHOPPER_010");
					break;

		 case 11:

					oWaypoint = GetWaypointByTag("WP_SHOPPER_011");
					break;

		 case 12:

					oWaypoint = GetWaypointByTag("WP_SHOPPER_012");
					break;
	}

		if (GetIsObjectValid(oWaypoint))
		{
			ActionMoveToObject(oWaypoint);
		}

		ActionPlayAnimation(ANIMATION_FIREFORGET_HEAD_TURN_LEFT);
		ActionPlayAnimation(ANIMATION_FIREFORGET_HEAD_TURN_RIGHT);

		ActionWait(fWait);
		ActionSpeakString("Alms! Alms for the poor!");
 }
}

Posted: Tue Jul 02, 2002 3:50 pm
by Silk
A Small Correction to the above.
This :

ActionMoveToObject(oWaypoint);

Should actually be this:

AssignCommand(OBJECT_SELF, ActionMoveToObject(oWaypoint));

If I understand this correctly, The second code here assignes the action to the action queue. Tell me what you think.

Posted: Tue Jul 02, 2002 3:59 pm
by Silk
Even Better, How about this code:

Code: Select all

void main()
{
  // shoppers picking random waypoints to walk to

  int nUser =  GetUserDefinedEventNumber();
  float fWait = IntToFloat(d10());

  if (nUser == 1001)
  {
    string sWaypoint = "WP_SHOPPER_" + IntToString(d12());
    object oWaypoint = GetWaypointByTag(sWaypoint);

    if (GetIsObjectValid(oWaypoint))
    {
      AssignCommand(OBJECT_SELF, ActionMoveToObject(oWaypoint));
      AssignCommand(OBJECT_SELF, ActionPlayAnimation(ANIMATION_FIREFORGET_HEAD_TURN_LEFT));
      AssignCommand(OBJECT_SELF, ActionPlayAnimation(ANIMATION_FIREFORGET_HEAD_TURN_RIGHT));
      AssignCommand(OBJECT_SELF, ActionWait(fWait));
      AssignCommand(OBJECT_SELF, ActionSpeakString("Alms! Alms for the poor!"));
    }
  }
}

Posted: Tue Jul 02, 2002 4:05 pm
by Silk
Of course if you used that last bit of code, you're going to ahve to remove the "000" format of the waypoints to just be the number.

Instead of "WP_SHOPPER_001" you need to use "WP_SHOPPER_1" instead.

Posted: Tue Jul 02, 2002 4:52 pm
by Silk
I was wrong, you don't need to use AssignCommand unless you wanted to add to the queue of another object other than object_self.

so the code is like this:

Code: Select all

void main()
{
  // shoppers picking random waypoints to walk to

  int nUser =  GetUserDefinedEventNumber();
  float fWait = IntToFloat(d10());

  if (nUser == 1001)
  {
    string sWaypoint = "WP_SHOPPER_" + IntToString(d12());
    object oWaypoint = GetWaypointByTag(sWaypoint);

    if (GetIsObjectValid(oWaypoint))
    {
      ActionMoveToObject(oWaypoint);
      ActionPlayAnimation(ANIMATION_FIREFORGET_HEAD_TURN_LEFT);
      ActionPlayAnimation(ANIMATION_FIREFORGET_HEAD_TURN_RIGHT);
      ActionWait(fWait);
      ActionSpeakString("Alms! Alms for the poor!");
    }
  }
}