Advertisement
salahzar

Ima Clone (NPC)

Dec 21st, 2014
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Lots of comments included in this script since it was written to help someone learn the basics...
  2. //
  3. key npc=NULL_KEY;
  4. string notecardName="NPC card to use";          // if no notecard in inventory, toucher's appearance will be cloned to this cardname and used
  5. string npcFirstName="Ima";                      // change to whatever you like
  6. string npcLastName="Clone";                     // ditto
  7. vector sitTargetPos= <0.0,0.0,0.75>;            // set sit target as per any poseball (Magic Sit Kit makes it easy)
  8. rotation sitTargetRot= ZERO_ROTATION;           // or whatever you like
  9. string animToPlay;                              // will use the 1st one if finds in inventory if blank, or the "built in" dance1 if none is found
  10.  
  11. default
  12. {
  13.     state_entry()
  14.     {
  15.         if (sitTargetPos==ZERO_VECTOR) sitTargetPos=<0,0,0.00001> ;     // sit target cannot be zero vector
  16.     }
  17.     touch_start(integer num)
  18.     {
  19.         // ignore anyone other than the owner touching it
  20.         if (llDetectedKey(0)!=llGetOwner()) return;
  21.         // if an NPC is already active, touching the prim kills it and stops
  22.         if (npc!=NULL_KEY)
  23.         {
  24.             osNpcRemove(npc);
  25.             npc=NULL_KEY;
  26.             return;
  27.         }
  28.         // Otherwise the touch gets things started...
  29.         // first, check whether we have a notecard in inventory to use for our NPC. If none is found, clone and store the toucher's appearance, else use the first one
  30.         if (!llGetInventoryNumber(INVENTORY_NOTECARD))
  31.         {
  32.             osOwnerSaveAppearance(notecardName);
  33.         }
  34.         else notecardName=llGetInventoryName(INVENTORY_NOTECARD,0);
  35.        
  36.         // next, if an animation has been specified make sure it's in inventory - otherwise see if we can find one to play or use fallback of dance
  37.         if ((animToPlay=="") || (llStringLength(animToPlay)>0 && llGetInventoryType(animToPlay)!=INVENTORY_ANIMATION))
  38.         {
  39.             if (!llGetInventoryNumber(INVENTORY_ANIMATION)) animToPlay="dance1";
  40.             else animToPlay=llGetInventoryName(INVENTORY_ANIMATION,0);
  41.         }
  42.        
  43.         // now all we have to do is rez the NPC and have it sit on this prim which will trigger the changed event
  44.         npc = osNpcCreate(npcFirstName,npcLastName,llGetPos()+<0.0,0.0,1>,notecardName,OS_NPC_SENSE_AS_AGENT);
  45.         osNpcSit(npc, llGetKey(), OS_NPC_SIT_NOW);
  46.     }
  47.     changed(integer change)
  48.     {
  49.     // Animate our NPC when it sits down
  50.         if (change & CHANGED_LINK)
  51.         {
  52.             osNpcStopAnimation(npc,"Sit");
  53.             osNpcPlayAnimation(npc,animToPlay);
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement