Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Lots of comments included in this script since it was written to help someone learn the basics...
- //
- key npc=NULL_KEY;
- string notecardName="NPC card to use"; // if no notecard in inventory, toucher's appearance will be cloned to this cardname and used
- string npcFirstName="Ima"; // change to whatever you like
- string npcLastName="Clone"; // ditto
- vector sitTargetPos= <0.0,0.0,0.75>; // set sit target as per any poseball (Magic Sit Kit makes it easy)
- rotation sitTargetRot= ZERO_ROTATION; // or whatever you like
- string animToPlay; // will use the 1st one if finds in inventory if blank, or the "built in" dance1 if none is found
- default
- {
- state_entry()
- {
- if (sitTargetPos==ZERO_VECTOR) sitTargetPos=<0,0,0.00001> ; // sit target cannot be zero vector
- }
- touch_start(integer num)
- {
- // ignore anyone other than the owner touching it
- if (llDetectedKey(0)!=llGetOwner()) return;
- // if an NPC is already active, touching the prim kills it and stops
- if (npc!=NULL_KEY)
- {
- osNpcRemove(npc);
- npc=NULL_KEY;
- return;
- }
- // Otherwise the touch gets things started...
- // 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
- if (!llGetInventoryNumber(INVENTORY_NOTECARD))
- {
- osOwnerSaveAppearance(notecardName);
- }
- else notecardName=llGetInventoryName(INVENTORY_NOTECARD,0);
- // 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
- if ((animToPlay=="") || (llStringLength(animToPlay)>0 && llGetInventoryType(animToPlay)!=INVENTORY_ANIMATION))
- {
- if (!llGetInventoryNumber(INVENTORY_ANIMATION)) animToPlay="dance1";
- else animToPlay=llGetInventoryName(INVENTORY_ANIMATION,0);
- }
- // now all we have to do is rez the NPC and have it sit on this prim which will trigger the changed event
- npc = osNpcCreate(npcFirstName,npcLastName,llGetPos()+<0.0,0.0,1>,notecardName,OS_NPC_SENSE_AS_AGENT);
- osNpcSit(npc, llGetKey(), OS_NPC_SIT_NOW);
- }
- changed(integer change)
- {
- // Animate our NPC when it sits down
- if (change & CHANGED_LINK)
- {
- osNpcStopAnimation(npc,"Sit");
- osNpcPlayAnimation(npc,animToPlay);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement