Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 30th, 2012  |  syntax: C  |  size: 2.29 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. script ROPE_HOLD (int ropeTID, int length, int strength)
  2. {
  3.     int myX;   int myY;   int myZ;
  4.     int ropeX; int ropeY; int ropeZ;
  5.     int velX;  int velY;  int velZ;
  6.     int normX; int normY; int normZ;
  7.     int pullX; int pullY; int pullZ;
  8.     int rPullX; int rPullY; int rPullZ;
  9.     int mag; int mode;
  10.    
  11.     strength = (strength << 16) / 100;
  12.     strength = FixedMul(strength, strength);
  13.  
  14.     if (length == -1)
  15.     {
  16.         myX   = GetActorX(0);    myY   = GetActorY(0);    myZ   = GetActorZ(0);
  17.         ropeX = GetActorX(ropeTID); ropeY = GetActorY(ropeTID); ropeZ = GetActorZ(ropeTID);
  18.         velX  = myX - ropeX;        velY  = myY - ropeY;        velZ  = myZ - ropeZ;
  19.  
  20.         length = magnitudeThree(velX >> 16, velY >> 16, velZ >> 16);
  21.     }
  22.  
  23.     int playerTID = ActivatorTID();
  24.  
  25.     if ((playerTID != 0) || (ThingCount(0, playerTID) != 1))
  26.     {
  27.         playerTID = unusedTID(5000, -1);
  28.         Thing_ChangeTID(0, playerTID);
  29.     }
  30.  
  31.     while (ThingCount(0, ropeTID) == 1)
  32.     {
  33.  
  34.         myX   = GetActorX(0);    myY   = GetActorY(0);    myZ   = GetActorZ(0);
  35.         ropeX = GetActorX(ropeTID); ropeY = GetActorY(ropeTID); ropeZ = GetActorZ(ropeTID);
  36.         velX  = myX - ropeX;        velY  = myY - ropeY;        velZ  = myZ - ropeZ;
  37.  
  38.         // this is where precision goes down the drain
  39.         mag = magnitudeThree(velX >> 16, velY >> 16, velZ >> 16);
  40.    
  41.         normX = velX / mag;   normY = velY / mag;   normZ = velZ / mag;
  42.  
  43.         if (mag > length)
  44.         {
  45.             rPullX = ropeX + (normX * length);
  46.             rPullY = ropeY + (normY * length);
  47.             rPullZ = ropeZ + (normZ * length);
  48.  
  49.             pullX = -(velX - (normX * length));
  50.             pullY = -(velY - (normY * length));
  51.             pullZ = -(velZ - (normZ * length));
  52.  
  53.             pullX = FixedMul(pullX, strength);
  54.             pullY = FixedMul(pullY, strength);
  55.             pullZ = FixedMul(pullZ, strength);
  56.  
  57.             SetActorPosition(0, rPullX, rPullY, rPullZ, 0);
  58.             SetActorVelocity(0, pullX, pullY, pullZ, 1, 0);
  59.         }
  60.  
  61.         ACS_ExecuteAlways(ROPE_DRAWLINE, 0, ropeTID, playerTID, 24);
  62.         Delay(1);
  63.     }
  64.  
  65.     if (ThingCount(0, ropeTID) > 1)
  66.     {
  67.         Log(s:"Error: more than one object with tid ", d:ropeTID, s:" (is used for rope)");
  68.     }
  69. }