Code Adjustments (Formerly burp)

Moderator: Event DM

Post Reply
User avatar
Silk
Co-Founder
Posts: 6662
Joined: Fri Sep 14, 2001 6:47 pm
Contact:

Code Adjustments (Formerly burp)

Post by Silk » Tue Jul 02, 2002 12:09 pm

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;
Silk

Member of the MadK@t lover's group.
Orleron
World Advisor, Co-founder
World Advisor, Co-founder
Posts: 15149
Joined: Fri Sep 14, 2001 9:48 pm
Timezone: GMT-5
Contact:

Post by Orleron » Tue Jul 02, 2002 1:41 pm

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?
User avatar
Silk
Co-Founder
Posts: 6662
Joined: Fri Sep 14, 2001 6:47 pm
Contact:

Post by Silk » Tue Jul 02, 2002 3:14 pm

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.
Silk

Member of the MadK@t lover's group.
Orleron
World Advisor, Co-founder
World Advisor, Co-founder
Posts: 15149
Joined: Fri Sep 14, 2001 9:48 pm
Timezone: GMT-5
Contact:

Post by Orleron » Tue Jul 02, 2002 3:21 pm

Ok, I am home now, so I will work on implementing that code.
"Truth has no form."
--Idries Shah
User avatar
Silk
Co-Founder
Posts: 6662
Joined: Fri Sep 14, 2001 6:47 pm
Contact:

Post by Silk » Tue Jul 02, 2002 3:25 pm

I put my morning update in my ftp folder for you. I put an update of changes in a txt file in your folder.
Silk

Member of the MadK@t lover's group.
User avatar
Silk
Co-Founder
Posts: 6662
Joined: Fri Sep 14, 2001 6:47 pm
Contact:

Post by Silk » Tue Jul 02, 2002 3:45 pm

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!");
 }
}
User avatar
Silk
Co-Founder
Posts: 6662
Joined: Fri Sep 14, 2001 6:47 pm
Contact:

Post by Silk » Tue Jul 02, 2002 3:50 pm

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.
User avatar
Silk
Co-Founder
Posts: 6662
Joined: Fri Sep 14, 2001 6:47 pm
Contact:

Post by Silk » Tue Jul 02, 2002 3:59 pm

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!"));
    }
  }
}
User avatar
Silk
Co-Founder
Posts: 6662
Joined: Fri Sep 14, 2001 6:47 pm
Contact:

Post by Silk » Tue Jul 02, 2002 4:05 pm

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.
Silk

Member of the MadK@t lover's group.
User avatar
Silk
Co-Founder
Posts: 6662
Joined: Fri Sep 14, 2001 6:47 pm
Contact:

Post by Silk » Tue Jul 02, 2002 4:52 pm

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!");
    }
  }
}
Silk

Member of the MadK@t lover's group.
Post Reply