DMH-Online

Dungeon Masters Helper · Est. 2005

Triggers Scripts

NWN Script: repulsion_script.htm

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

⌂ All Scripts ← PreviousNext → 👁 Category List

All Triggers Scripts

📄 boss_room 📄 falling_trap 📄 finger 📄 giev_xp_disarm 📄 giev_xp_disarm_002 📄 giev_xp_disarm_003 📄 giev_xp_disarm_004 📄 laughing_trap 📄 random_enc_high 📄 repulsion_script 📄 repulsion_script_002 📄 repulsion_script_003 📄 repulsion_script_004 📄 set_variable 📄 shut_lock_door 📄 spiked_corridor 📄 traps_that _trigger