1
0

KanEd-Test10.lsl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. vector startPosition;
  2. float groundLevel;
  3. default
  4. {
  5. state_entry()
  6. {
  7. llListen( 0, "", llGetOwner(), "");
  8. startPosition = llGetPos();
  9. groundLevel = llGround( startPosition );
  10. llSay( 0, "Control this object with chat commands like:" );
  11. llSay( 0, "'up' or 'down' followed by a distance." );
  12. }
  13. listen( integer channel, string name, key id, string message )
  14. {
  15. // separate the input into blank-delmited tokens.
  16. list parsed = llParseString2List( message, [ " " ], [] );
  17. // get the first part--the "command".
  18. string command = llList2String( parsed, 0 );
  19. // get the second part--the "distance".
  20. string distance_string = llList2String( parsed, 1 );
  21. float distance = ( float )distance_string;
  22. vector position = llGetPos();
  23. if( command == "up" )
  24. {
  25. if( ( position.z + distance ) < (startPosition.z + 10.0 ) )
  26. {
  27. llSetPos( llGetPos() + < 0, 0, distance > ); // move up
  28. llSetText( "Went up " + (string)distance, < 1, 0, 0 >, 1 );
  29. }
  30. else
  31. {
  32. llSetText( "Can't go so high.", < 1, 0, 0 >, 1 );
  33. }
  34. }
  35. else if( command == "down" )
  36. {
  37. if( ( position.z - distance ) > groundLevel )
  38. {
  39. llSetPos( llGetPos() + < 0, 0, -distance > ); // move down
  40. llSetText( "Went down " + (string)distance, < 1, 0, 0 >, 1 );
  41. }
  42. else
  43. {
  44. llSetText( "Can't go so low.", < 1, 0, 0 >, 1 );
  45. }
  46. }
  47. }
  48. }