Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///////////////////////////////////////////////////////////////
  2. //                                                           //
  3. //   Script made by Kadai Flanagan                           //
  4. //                                                           //
  5. //   For use with the VLC Train Script 2.6.0                 //
  6. //                                                           //
  7. //   This is an experimental implementation, so be fair.     //
  8. //                                                           //
  9. //   If you come with any modification or enhancement,       //
  10. //  please share it with everyone.                           //
  11. //                                                           //
  12. //                                                           //
  13. //   Last Revised 12-January-2011                            //
  14. //                                                           //
  15. //                                                           //
  16. ///////////////////////////////////////////////////////////////
  17.  
  18.  
  19. string MACHINE_NAME = "Maquina";
  20. string FOLLOW_GUIDE = "Guide";
  21.  
  22. vector lastmachinepos = <0,0,0>;
  23. integer WE_KNOW_POS = FALSE;
  24. integer RE_RAIL_WAGON = TRUE;
  25. integer DESTINE_RAIL = FALSE;
  26. string locationrecived = "";
  27. rotation wagonrotation = ZERO_ROTATION;
  28. //vector vDestine = <0,0,0>;
  29.  
  30. LocomotiveMoveTo(vector vWaypointNext, rotation rAttitudeNext)
  31. {
  32.  
  33. //llOwnerSay((string)vWaypointNext);
  34.  
  35.     //vector vWaypointNext = vWaypointNext + <0, 0, 0.5>;
  36.  
  37.     if (llGetStatus(STATUS_PHYSICS))
  38.     {
  39.  
  40.         //llSay(0, (string)llGetVel());
  41.  
  42.         llRotLookAt(rAttitudeNext, 1 / llVecMag(llGetVel()), 1);
  43.         llMoveToTarget( vWaypointNext, 1.0);
  44.     }
  45.     else
  46.     {
  47.  
  48.         llSetLinkPrimitiveParamsFast(LINK_ROOT,
  49.             [PRIM_POSITION, vWaypointNext,
  50.             PRIM_ROTATION, rAttitudeNext]);
  51.     }
  52.  
  53. } // LocomotiveMoveTo
  54.  
  55. default
  56. {
  57.     state_entry()
  58.     {
  59.         vector pos = llGetPos();
  60.         llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE);
  61.         llSleep(0.1);
  62.  
  63.         llSensor(FOLLOW_GUIDE, NULL_KEY, PASSIVE | ACTIVE, 20.0, PI);
  64.         llListen(-16,MACHINE_NAME,"","");
  65.         llListen(-15,MACHINE_NAME,"","");
  66.  
  67.         //llGetObjectDetails();
  68.     }
  69.  
  70.     sensor(integer total_number)
  71.     {
  72.  
  73.         if (RE_RAIL_WAGON){
  74.            vector pos = llDetectedPos(0);
  75.            wagonrotation = llDetectedRot(0);
  76.            vector offset = <0,0,0.5>;
  77.            pos+=offset;
  78.            LocomotiveMoveTo(pos, wagonrotation);
  79.            //llOwnerSay((string)llDetectedPos(1));
  80.            RE_RAIL_WAGON = FALSE;
  81.         }
  82.  
  83.  
  84.     }
  85.  
  86.     listen(integer channel, string name, key id, string message)
  87.     {
  88.  
  89.         if(channel==-16){
  90.  
  91.            if(DESTINE_RAIL != FALSE){
  92.               //llOwnerSay("--Ajuste--" + (string)vDestine);
  93.               RE_RAIL_WAGON = TRUE;
  94.               llSensor(FOLLOW_GUIDE, NULL_KEY, PASSIVE | ACTIVE, 20.0, PI);
  95.            }
  96.  
  97.            //vDestine = (vector)message;
  98.            DESTINE_RAIL = TRUE;
  99.         }
  100.  
  101.         if(DESTINE_RAIL && channel==-15){
  102.            locationrecived = message;
  103.  
  104.            //vector nuevolocationrecived = (vector)locationrecived;
  105.  
  106.            if (WE_KNOW_POS == FALSE){
  107.               lastmachinepos = (vector)locationrecived;
  108.               WE_KNOW_POS = TRUE;
  109.  
  110.               //llOwnerSay("Entre");
  111.  
  112.            } else {
  113.  
  114.  
  115.               //falta = distancia-movimiento;
  116.               //vector calculateddistance = vDestine-llGetPos();
  117.               //llOwnerSay("Distancia: " + (string)distancia);
  118.  
  119.               vector movement = (vector)locationrecived-lastmachinepos;
  120.               vector newposition = llGetPos()+movement;
  121.               //vector nuevapos = distancia-movimiento;
  122.               lastmachinepos = (vector)locationrecived;
  123.  
  124.               //llOwnerSay("Movimiento: " + (string)movimiento);
  125.  
  126.               LocomotiveMoveTo(newposition, wagonrotation);
  127.  
  128.            }
  129.  
  130.         }
  131.  
  132.     }
  133.  
  134.     on_rez(integer iRezParameter)
  135.     {
  136.         llResetScript();
  137.     } // on_rez
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement