Author Sticky: Post Working Scripts Here
Modal Posted: Friday, 28 June 02:45PM
It seems a "Repulsion Script" may come in handy for some people, so here's a really simple one:

NWScript:
/******************************************************************

 * Name: Simple "Repulsion Field" Script

 * Type: Trigger (OnEnter)

 * ---

 * Author: Modal

 * Date: 06/28/02

 * ---

 * This is a simple "repulsion" script which doubles as a demo

 * of using vector functions - attach this to a trigger (OnEnter)

 * to repel a PC/NPC backwards by REPEL_DISTANCE meters.

 ******************************************************************/



/* Repelling distance, in meters */

float REPEL_DISTANCE = 1.0;

void main()

{

  object oEnteringPC = GetEnteringObject();

  location lOrigin,

           lDest;

  vector vOrigin,

         vDest,

         vUnitRepel;

/* Get the starting location and vector of the PC/Mob */

lOrigin = GetLocation( oEnteringPC );

vOrigin = GetPosition( oEnteringPC );

/* Calculate the Unit Vector needed to repel the PC/Mob */

vUnitRepel = AngleToVector( GetFacingFromLocation( lOrigin ) + 180.0 );

/* Calculate Destination Vector */

vDest = vOrigin + REPEL_DISTANCE * vUnitRepel;

/* Create a new location from the destination vector */

lDest = Location( GetArea( oEnteringPC ), vDest, GetFacingFromLocation( lOrigin ) );

/* Warp PC to new location */

AssignCommand( oEnteringPC, ClearAllActions() );

AssignCommand( oEnteringPC, JumpToLocation( lDest ) );

}




-Modal