Guest

Untitled

By: a guest on Aug 18th, 2011  |  syntax: None  |  size: 1.66 KB  |  hits: 131  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. // touch to create an NPC at a random position in your region.
  2. // The NPC will be created at 100m up in the air, just for dramatic effect :-)
  3. // Set npcNum to how many NPCs you want.
  4.  
  5. key npc;
  6. vector toucherPos;
  7. integer n;
  8. integer i;
  9. float X = 112;
  10. float Y = 112;
  11. float Z = 22;
  12. float spacing = 2;
  13. integer npcNum = 10;
  14. integer wait = 10000;
  15. string toucher;
  16. key toucherkey;
  17.  
  18. default
  19. {
  20.     state_entry()
  21.     {
  22.         llSetText("Populate this region",<1,1,1>,1);
  23.     }
  24.  
  25.     touch_start(integer number)
  26.     {
  27.         toucher = llKey2Name(llDetectedKey(0));
  28.         toucherkey = llDetectedKey(0);
  29.         state raise;
  30.     }
  31. }
  32.  
  33. state raise
  34. {
  35.     state_entry()
  36.     {
  37.         for (n=0;n<npcNum;++n)
  38.         {
  39.             llSetText("Creating NPC #"+(string)(n+1)+"...",<1,1,1>,1);
  40.             vector npcPos = < X, Y, Z >;
  41.             osNpcCreate(toucher, "", npcPos, toucherkey);
  42.             Y = Y + spacing;
  43.  
  44.             if (wait)
  45.             {
  46.                 for (i=wait;i>0;--i)
  47.                 {
  48.                     llSetText("Creating NPC #"+(string)(n+2)+" in "+(string)i+"...",<1,1,1>,1);
  49.                 //    llSleep(1);                
  50.                 }
  51.             }
  52.         }
  53.         llSetText("Done",<1,1,1>,1);
  54.     }
  55.  
  56.     touch_start(integer number)
  57.     {
  58.         llSay(0,"Removing all NPCs from this scene!");
  59.         list avies = osGetAvatarList();
  60.         for(n=0;n<llGetListLength(avies);n=n+3)
  61.         {
  62.             llOwnerSay("Attempting to remove "+llList2String(avies,n+2)+" with UUID "+llList2String(avies,n+0));
  63.             osNpcRemove((key)llList2Key(avies,n));
  64.         }
  65.  
  66.         llResetScript();
  67.     }
  68. }