Page 1 of 1

Code Adjustments (Formerly burp)

PostPosted: Tue Jul 02, 2002 12:09 pm
Author: 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;

PostPosted: Tue Jul 02, 2002 1:41 pm
Author: 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?

PostPosted: Tue Jul 02, 2002 3:14 pm
Author: 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.

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

PostPosted: Tue Jul 02, 2002 3:25 pm
Author: 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.

PostPosted: Tue Jul 02, 2002 3:45 pm
Author: Silk
This:
[code]
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!");
}
}
[/code]

PostPosted: Tue Jul 02, 2002 3:50 pm
Author: 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.

PostPosted: Tue Jul 02, 2002 3:59 pm
Author: 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!"));
    }
  }
}

PostPosted: Tue Jul 02, 2002 4:05 pm
Author: 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.

PostPosted: Tue Jul 02, 2002 4:52 pm
Author: 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!");
    }
  }
}