DMH-Online

Dungeon Masters Helper · Est. 2005

Triggers Scripts

NWN Script: repulsion_script_003.htm

Author Sticky: Post Working Scripts Here
Deadphyre Posted: Monday, 08 July 08:00AM
For the life of me I can't remember who made the force field v2 script, but with some modifications I have enabled it to repel alignment only instead of everyone. The script that is gonna be posted will allow evil characters to pass but blocking anyone else from passing.
I would like to thank the original creator for making the original script, because this wouldn't have been possible without him/ or her.

Instructions:
1. Copy this script and create a new one with a name like align_field or something like that.
2. Create a waypoint with the tag "force_bouncer"
3. Create a trigger around that waypoint. And apply this script to the OnEnter event of that trigger.

Tips: If your going to make a large non passable area, you should probably place several waypoints down, all with the same tag, then create a giant trigger around them, as it gets the closest waypoint to the current pc entering the field.

Warning: If you have 2 fields across from each other, like a wallway, a pc can pass through one force field through the one across from it. It's a problem with the code I think. Well last I checked anyways. Not sure if this is fixed, but watch out for that.

NWScript:
void bounce_player(location loc) {
    ClearAllActions();
    JumpToLocation(loc);
    ActionDoCommand( SetCommandable(TRUE) );
    SetCommandable(FALSE);
}
void main()
{
    // obtain the player and his nearest bouncer
    object player = GetEnteringObject();
    object bouncer = GetNearestObjectByTag( "force_bouncer", player );
    int nAlign = GetAlignmentGoodEvil(player);
    if (nAlign == ALIGNMENT_GOOD)
    {
        // find the location of player and bouncer
        location player_location = GetLocation(player);
        location bouncer_location = GetLocation(bouncer);
        // extract position vectors
        vector player_position = GetPositionFromLocation( player_location );
        vector bouncer_position = GetPositionFromLocation( bouncer_location );
        // extract other location components
        object player_area = GetAreaFromLocation( player_location );
        float player_ori   = GetFacingFromLocation( player_location );
        // calculate vector away from bouncer through player_point
        vector displacement = player_position - bouncer_position;
        // ensure that the magnitude of the vector is greater than 0
        // otherwise use the inverse of the player's orientation as the vector
        if( VectorMagnitude( displacement ) <= 0.0 ){
        displacement = -1.0 * AngleToVector( player_ori );
        }
        // normalize the displacement vector
        displacement = VectorNormalize( displacement );
        // multiply displacement by force strength
        float bounce_strength = 3.5;
        displacement = displacement * bounce_strength;
        // calculate new player position by adding displacement to current position
        player_position = displacement + player_position;
        player_location = Location( player_area, player_position, player_ori );
        // Play a neat visual effect
        effect bounce_flash = EffectVisualEffect( VFX_IMP_SUNSTRIKE );
        ApplyEffectAtLocation( DURATION_TYPE_INSTANT, bounce_flash, bouncer_location);
        // Jump the player there
        AssignCommand(player, bounce_player(player_location));
        // Apply a knockdown effect
        //effect knock_down = EffectKnockdown();
        //ApplyEffectToObject( DURATION_TYPE_TEMPORARY, knock_down, player, 3.0);
        //AssignCommand(player, ApplyEffectToObject( DURATION_TYPE_TEMPORARY, knock_down, player, 3.0));
    }
    else if (nAlign == ALIGNMENT_NEUTRAL)
    {
        // find the location of player and bouncer
        location player_location = GetLocation(player);
        location bouncer_location = GetLocation(bouncer);
        // extract position vectors
        vector player_position = GetPositionFromLocation( player_location );
        vector bouncer_position = GetPositionFromLocation( bouncer_location );
        // extract other location components
        object player_area = GetAreaFromLocation( player_location );
        float player_ori   = GetFacingFromLocation( player_location );
        // calculate vector away from bouncer through player_point
        vector displacement = player_position - bouncer_position;
        // ensure that the magnitude of the vector is greater than 0
        // otherwise use the inverse of the player's orientation as the vector
        if( VectorMagnitude( displacement ) <= 0.0 ){
        displacement = -1.0 * AngleToVector( player_ori );
        }
        // normalize the displacement vector
        displacement = VectorNormalize( displacement );
        // multiply displacement by force strength
        float bounce_strength = 3.5;
        displacement = displacement * bounce_strength;
        // calculate new player position by adding displacement to current position
        player_position = displacement + player_position;
        player_location = Location( player_area, player_position, player_ori );
        // Play a neat visual effect
        effect bounce_flash = EffectVisualEffect( VFX_IMP_SUNSTRIKE );
        ApplyEffectAtLocation( DURATION_TYPE_INSTANT, bounce_flash, bouncer_location);
        // Jump the player there
        AssignCommand(player, bounce_player(player_location));
        // Apply a knockdown effect
        //effect knock_down = EffectKnockdown();
        //ApplyEffectToObject( DURATION_TYPE_TEMPORARY, knock_down, player, 3.0);
        //AssignCommand(player, ApplyEffectToObject( DURATION_TYPE_TEMPORARY, knock_down, player, 3.0));
    }
}



Again thank the original creater for the Force Field v2 Script.

Deadphyre out
Email deadphyre@charter.net

⌂ 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