Advertisement
Dorex

Simple Elevator

Feb 12th, 2016
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // ##################################################################################
  3. //
  4. // Simple Elevator
  5. //
  6. // Dorex Delicioso 2015-10-30 'Happy Halloween'
  7. //
  8. // To use, add script to a prim.
  9. // Set 'DistanceBetweenFloors' to the number of meters between each floor (distance to move)
  10. // Set 'MetersPerSecond' to how many meters you want to move per second. (less is slower)
  11. // Set 'ListenChannel' to what ever channel you want this to listen on
  12. //
  13. // *****  If you reposition the prim, you must reset the script so it knows where the bottom floor is
  14. //
  15. // Stand on the prim
  16. // type /3 {floor} in local chat
  17. //
  18. // Using an open listen channel is a really bad way of doing this, but it is for
  19. // example only and this is meant to be part of a larger build.
  20. // A better way would be Link_Message, linked to a prim with floor selectors on it.
  21. //
  22. // ##################################################################################
  23. //
  24. float MetersPerSecond=2.0;       // how fast it moves in meters per second
  25. float DistanceBetweenFloors=2.0;  // how far between floors
  26. integer ListenChannel=3;        // what channel do we listen on
  27.  
  28. vector Floor1;
  29.  
  30. doMove(string floor)
  31. {
  32.     //
  33.     // only try to move on floor numbers that are positive integers
  34.     //
  35.     if ((string)((integer)floor)==floor){        
  36.         //
  37.         // if floor is an integer
  38.         //
  39.         integer floorNumber=(integer)floor;
  40.         if(floorNumber>0){                    
  41.             //
  42.             // if floor > 0
  43.             //
  44.             floorNumber--;        
  45.             vector pos=llGetPos();
  46.             //
  47.             // what is the distance between the floor we want and where we are?
  48.             //
  49.             float distance = Floor1.z + floorNumber*DistanceBetweenFloors - pos.z;
  50.             //
  51.             // how long should it take us to get there
  52.             //
  53.             float time=llFabs(distance/MetersPerSecond);
  54.             llSetKeyframedMotion( [<0.0,0.0,distance>, <0.0,0.0,0.0,1.0>, time], [KFM_MODE ,KFM_FORWARD]);
  55.         }    
  56.     }
  57. }
  58.  
  59. default{
  60.  
  61.     on_rez( integer start_param)
  62.     {
  63.         llResetScript();
  64.     }
  65.    
  66.     state_entry()
  67.     {
  68.         llSetText("Simple Elevator", ZERO_VECTOR,1.0);
  69.         //
  70.         // remember the first floor position
  71.         //
  72.         Floor1=llGetPos();          
  73.         llSetPrimitiveParams([PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]);
  74.        
  75.         llListen(ListenChannel,"", NULL_KEY, "");      
  76.     }
  77.    
  78.     listen(integer channel, string name, key id, string message) {
  79.         doMove(message);    
  80.     }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement