User:Talarus Luan/WarpPosModule - Second Life Wiki

DOWNTIME ANNOUNCEMENT - Maintenance will be performed from 1AM-3AM Pacific Time on 2010-03-20 (tonight). Please do not edit any pages during this time.

Looking for Viewer 2 Beta help? Right this way!

User:Talarus Luan/WarpPosModule

From Second Life Wiki

Second Life Wiki > User:Talarus Luan > User: Talarus Luan/WarpPosModule
Jump to: navigation, search

Here ya go, folks: Havok4 WarpPos Module Script. Just drop into your object and call it like so:

 
llMessageLinked(LINK_SET,0x3E00,(string)vDestinationPos,"");
 

 
//********************************************************************************
// Name  : WarpPos Module Script
// Author: Talarus Luan
// Description:
//   This script implements WarpPos called via link_message.
// Use:
//   Function Codes: Call with (giModuleID << 8 + FuncCode) to llMessageLinked integer param
//     0 = In-sim WarpPos, string parameter is a fully-formatted vector
//   Responds via LM with Response code in upper 16 bits of integer param to link_message
// License:
//   Public Domain
//   If ya like it, use it. Share it. Charge for it. Whatever. Everyone else will, too!
// Disclaimer:
//   Everything, especially how nasty the code looks. LSL Optimization 4TL!
//********************************************************************************
// Update History:
//   2006/06/03 - Initial Implementation                                    - v0.0
//   2007/12/06 - Cleaned up                                                - v1.0
//   2008/03/26 - Optimized memory usage for up to 4096m Warps              - v1.1
//********************************************************************************
 
//================================================================================
// Global Variables
//================================================================================
 
//--------------------------------------------------------------------------------
// Control Constant Defaults - modify these to change the behavior of the script
//--------------------------------------------------------------------------------
 
//string   gsStartup          = "WarpPos Module v1.1 by Talarus Luan";
//integer  giDebugFlags       = 0;    // Sets script debug flags
integer  giModuleID         = 0x3E;
 
//--------------------------------------------------------------------------------
// Variables
//--------------------------------------------------------------------------------
 
//================================================================================
// User-defined Functions
//================================================================================
 
//--------------------------------------------------------------------------------
// WarpPos function - Move to destination position instantly
//
// Credits:
//  Original Discovery by Keknehv Psaltery
//  Cleanup/Optimization by Strife Onizuka, Talarus Luan
//  Havok4 modularization by Talarus Luan
//--------------------------------------------------------------------------------
WarpPos(vector pvDestPos) {
    integer liJumps = (integer)(llVecDist(pvDestPos, llGetPos()) / 10.0) + 1;
    // Try and avoid stack/heap collisions
    if (liJumps > 410)
        liJumps = 410;                              // Farthest for H4
    list laRules = [ PRIM_POSITION, pvDestPos ];    // The start for the rules list
    integer liCount = 1;
    while ( ( liCount = liCount << 1 ) < liJumps)
        laRules = (laRules=[]) + laRules + laRules;   //should tighten memory use.
    llSetPrimitiveParams( (laRules=[]) + laRules + llList2List( laRules, (liCount - liJumps) << 1, liCount) );
}
 
//********************************************************************************
// Script States
//********************************************************************************
 
//================================================================================
// State default
//================================================================================
 
default {
    //--------------------------------------------------------------------------------
    // link_message event
    //--------------------------------------------------------------------------------
    link_message(integer piSender, integer piData, string psData, key pkID) {
        integer liModule = (piData >> 8) & 0xFF;
        integer liCommand = piData & 0xFF;
        if (liModule == giModuleID)
            if (liCommand == 0) {
                WarpPos((vector)psData);
                llMessageLinked(LINK_SET,(piData >> 16) & 0xFFFF,"","");
            }
    }
}
 
//********************************************************************************
// End
//********************************************************************************
// Notes on hungarian notation used for identifiers in my scripts:
//   First letter indicates scope
//     g - global
//     l - local
//     p - function parameter
//   Second letter indicates type
//     i - integer
//     f - float
//     v - vector
//     r - rotation
//     s - string
//     k - key
//     a - array (list, actually, but local list names may conflict with library
//         function identifiers (eg, "llListen") )
//********************************************************************************