Script Bot NPC
Categories
Scripts | OpenSim Script Language
Mode
Compat
Langage
Les Fonctions NPC ont été récement implémentées dans OpenSim. Voici quelques scripts d'exemples d'utilisation.
Les fonctions NPC n'étant pas implémentées dans Aurora-Sim, ces scripts ne fonctionneront donc pas sur ce type de server. Heureusement sur Aurora-Sim nous avons les BotFunctions (exclusives).
NpcBot simple
NpcBot simple | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
// touch to create a NPC clone of the toucher in front of this emitter // NPC will move to the toucher, then will greet them. // Touch again to remove the NPC // Referencia NPCs http://opensimulator.org/wiki/OSSL_Implemented key npc; vector toucherPos; vector npcPos; string ObjectName; default { state_entry(){ ObjectName = llGetInventoryName(INVENTORY_SCRIPT,0); llSetObjectName(ObjectName); } touch_start(integer number){ npcPos = llGetPos() + <(integer)llFrand(3),(integer)llFrand(3),0>; osAgentSaveAppearance(llDetectedKey(0),llKey2Name(llDetectedKey(0))); // coud use avatar UUID directly in osNpcCreate, but then NPC appearance is not persisted //npc = osNpcCreate("ImYour", "Clone", npcPos, "appearance"); list user = llParseString2List(llKey2Name(llGetOwner()), [" "], []); string nombre = llList2String(user, 0); string apellido = llList2String(user, 1); npc = osNpcCreate(nombre,apellido, npcPos,llKey2Name(llDetectedKey(0))); toucherPos = llDetectedPos(0); state hasNPC; } } state hasNPC { state_entry(){ osNpcMoveTo(npc, toucherPos + <(integer)llFrand(3),(integer)llFrand(3),0>); osNpcSay(npc, "Hi there! My name is " + llKey2Name(npc)); llSleep(5); llSay(512,"ResetNpcBot"); // para resetear el AO } touch_start(integer number){ osNpcSay(npc, "Goodbye!"); osNpcRemove(npc); npc = NULL_KEY; state default; } } |
NpcBot Random Movement
NpcBot Random Movement | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
// touch to create a NPC clone of the toucher in front of this emitter // NPC will move to the toucher, then will greet them. // Touch again to remove the NPC // Referencia NPCs http://opensimulator.org/wiki/OSSL_Implemented key npc; vector toucherPos; vector npcPos; float metrosRegion = 512.0; // 256.0 para region simple, 512.0 para region de 2x2, 1024.0 para region de 4x4, etc // DE MOMENTO NO FUNCIONA CON MEGARREGION, SOLO REGIONES DE 256, pero el valor debe ser de 512 para que los bots puedan recorrer toda la region de 256 (vaya saberse el porque, mas para la dimensión desconocida). Si soltamos un bot en una megarregion mas alla de las coordenadas 256x256y se dirigira al 1er sim del SO en la megarregion y luego quedara alli dando vueltas float alturaMaxima = 100.0; // altura maxima a la que puede llegar el boot float tiempo = 3.0; // tiempo maximo entre cada nueva coordenada de destino. El tiempo variara de forma aleatorea entre 0 y el valor estipulado string ObjectName; default { state_entry(){ ObjectName = llGetInventoryName(INVENTORY_SCRIPT,0); llSetObjectName(ObjectName); } touch_start(integer number){ npcPos = llGetPos() + <(integer)llFrand(3),(integer)llFrand(3),0>; osAgentSaveAppearance(llDetectedKey(0),llKey2Name(llDetectedKey(0))); // coud use avatar UUID directly in osNpcCreate, but then NPC appearance is not persisted //npc = osNpcCreate("ImYour", "Clone", npcPos, "appearance"); list user = llParseString2List(llKey2Name(llGetOwner()), [" "], []); string nombre = llList2String(user, 0); string apellido = llList2String(user, 1); npc = osNpcCreate(nombre,apellido, npcPos,llKey2Name(llDetectedKey(0))); toucherPos = llDetectedPos(0); state hasNPC; } } state hasNPC { state_entry(){ osNpcMoveTo(npc, toucherPos + <(integer)llFrand(3),(integer)llFrand(3),0>); osNpcSay(npc, "Hi there! My name is " + llKey2Name(npc)); llSetTimerEvent(llFrand(tiempo)); llSleep(5); llSay(512,"ResetNpcBot"); // para resetear el AO } timer(){ // OS_NPC_FLY - Fly the avatar to the given position. The avatar will not land unless the OS_NPC_LAND_AT_TARGET option is also given. // OS_NPC_NO_FLY - Do not fly to the target. The NPC will attempt to walk to the location. If it's up in the air then the avatar will keep bouncing hopeless until another move target is given or the move is stopped. // OS_NPC_LAND_AT_TARGET - If given and the avatar is flying, then it will land when it reaches the target. If OS_NPC_NO_FLY is given then this option has no effect. // OS_NPC_FLY and OS_NPC_NO_FLY are options that cannot be combined - the avatar will end up doing one or the other. If you want the avatar to fly and land at the target, then OS_NPC_LAND_AT_TARGET must be combined with OS_NPC_FLY. osNpcMoveToTarget(npc,<(integer)llFrand(metrosRegion),(integer)llFrand(metrosRegion),(integer)llFrand(alturaMaxima)>,OS_NPC_NO_FLY); llSetTimerEvent(llFrand(tiempo)); } touch_start(integer number){ osNpcSay(npc, "Goodbye!"); osNpcRemove(npc); npc = NULL_KEY; state default; } } |
NpcBot FollowOwner
Npc Follower v0.1 | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
// Npc Follower v0.1 key npc; vector toucherPos; vector npcPos; vector MasterPos; rotation MasterRot; key masterKey; string ObjectName; vector Separator = <2, 2, 0>; default { state_entry() { llSetText("NPC DEMO v0.1\nCliquez moi!",<1,1,1>, 1.0); ObjectName = llGetScriptName(); llSetObjectName(ObjectName); } touch_start(integer number) { npcPos = llGetPos() + <(integer)llFrand(3),(integer)llFrand(3),0>; osAgentSaveAppearance(llDetectedKey(0),llKey2Name(llDetectedKey(0))); list user = llParseString2List(llKey2Name(llGetOwner()), [" "], []); string First = llList2String(user, 0); string Last = llList2String(user, 1); npc = osNpcCreate(First,Last, npcPos,llKey2Name(llDetectedKey(0))); toucherPos = llDetectedPos(0); osNpcMoveTo(npc, toucherPos + <(integer)llFrand(3),(integer)llFrand(3),0>); osNpcSay(npc, "Hello! Mon nom est " + llKey2Name(npc)); state follow; } } state follow { state_entry() { masterKey = llGetOwner(); llSensorRepeat("",masterKey,AGENT,96.0,PI,1.0); llSetText("NPC DEMO v0.1\nReady to Follow!",<1,1,1>, 1.0); } sensor(integer num_detected) { MasterPos = llDetectedPos(0); MasterRot = llDetectedRot(0); osNpcMoveToTarget(npc,MasterPos-Separator,OS_NPC_NO_FLY); osNpcSetRot(npc,MasterRot); } touch_start(integer number) { osNpcSay(npc, "Goodbye!"); osNpcRemove(npc); npc = NULL_KEY; state default; } } |
NpcBot Ao
NpcBot Ao | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
// Script OpenSIM-AO v2.0 // LowLag AO Quick and Dirty Script // (c) Akira Sonoda // Modificado por Mentolyptus Destiny el 7/5/2010 // Se agrega la posibilidad de multiples stands para darle algo mas de color al AO // Pueden agregarse tantas animaciones stand como se desee, pero solo puede establecerse un walk // Instrucciones: meter las animaciones en contenidos y resetear el script del objeto. El nombre de la animacion walk debe escribirse en la descripcion del objeto. list animations; integer number_stands; string add_stand; integer time_stand = 10; string anim_Standing; string anim_Walking; key aoOwner; initialize() { aoOwner = llGetOwner(); llRequestPermissions(aoOwner, PERMISSION_TRIGGER_ANIMATION); // obtenemos nombre animacion walk de la descripcion del ao anim_Walking = llGetObjectDesc(); // Sacamos el numero de animaciones stand number_stands = llGetInventoryNumber(INVENTORY_ANIMATION)-1; // creamos la lista de animaciones para standing integer i; for(i=0;i < llGetInventoryNumber(INVENTORY_ANIMATION);i++){ add_stand = llGetInventoryName(INVENTORY_ANIMATION,i); if(add_stand != anim_Walking){ animations += add_stand; } } } default { state_entry() { initialize(); state Standing; } on_rez(integer start_param){ llResetScript(); } changed( integer change ) { if(change & CHANGED_OWNER){ llResetScript(); } } } state NonOverride { changed( integer change ) { if (change & CHANGED_ANIMATION) { string anim = llGetAnimation(aoOwner); if (anim == "Standing") state Standing; if (anim == "Walking") state Walking; } } } state Standing { state_entry() { llSetTimerEvent(time_stand); llListen(512,"","","ResetNpcBot"); } listen(integer channel,string name,key id,string message){ if(message == "ResetNpcBot"){ llResetScript(); } } timer(){ // recuperamos al azar una animacion de la lista de stands anim_Standing = llList2String(animations,(integer)llFrand(number_stands)); llStartAnimation(anim_Standing); } changed( integer change ) { if (change & CHANGED_ANIMATION) { string anim = llGetAnimation(aoOwner); if (anim == "Walking") state Walking; state NonOverride; } } state_exit() { llStopAnimation(anim_Standing); } } state Walking { state_entry() { llStartAnimation(anim_Walking); llListen(512,"","","ResetNpcBot"); } listen(integer channel,string name,key id,string message){ if(message == "ResetNpcBot"){ llResetScript(); } } changed( integer change ) { if (change & CHANGED_ANIMATION) { string anim = llGetAnimation(aoOwner); if (anim == "Standing") state Standing; state NonOverride; } } state_exit() { llStopAnimation(anim_Walking); } } |
NpvBot CauseDamage (Sensor)
NpvBot CauseDamage (Sensor) | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
// Npc Bot Damage float damage = 5.0; // daño provocado float distancia = 3.0; // metros float tiempo = 3.0; string mensaje1 = "pierde"; string mensaje2 = "de vida"; string ObjectName; default { state_entry(){ ObjectName = llGetInventoryName(INVENTORY_SCRIPT,0); llSetObjectName(ObjectName); llSensorRepeat("","",AGENT,distancia,PI,tiempo); llSetPrimitiveParams([PRIM_SIZE,<0.1,0.1,0.1>,PRIM_COLOR,ALL_SIDES,<1.0,0.0,0.0>,0.0]); } sensor(integer num_detected){ integer i; for(i = 0;i<num_detected;i++){ if(llDetectedKey(i) != llGetOwner()){ osCauseDamage(llDetectedKey(0),damage); llInstantMessage(llDetectedKey(i),llKey2Name(llDetectedKey(i))+" "+mensaje1+" "+(string)llRound(damage)+"% "+mensaje2); } } } } |
NpcBot CauseHealing (Sensor)
NpcBot CauseHealing (Sensor) | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
// Npc Bot Damage float healing = 5.0; // daño provocado float distancia = 3.0; // metros float tiempo = 6.0; // doble de tiempo para sanarse string mensaje1 = "recupera"; string mensaje2 = "de vida"; string ObjectName; default { state_entry(){ ObjectName = llGetInventoryName(INVENTORY_SCRIPT,0); llSetObjectName(ObjectName); llSensorRepeat("","",AGENT,distancia,PI,tiempo); llSetPrimitiveParams([PRIM_SIZE,<0.1,0.1,0.1>,PRIM_COLOR,ALL_SIDES,<0.0,1.0,0.0>,0.0]); } sensor(integer num_detected){ integer i; for(i = 0;i<num_detected;i++){ if(llDetectedKey(i) != llGetOwner()){ osCauseHealing(llDetectedKey(0),healing); llInstantMessage(llDetectedKey(i),llKey2Name(llDetectedKey(i))+" "+mensaje1+" "+(string)llRound(healing)+"% "+mensaje2); } } } } |
HealButton
HealButton | |
1 2 3 4 5 6 |
default { touch_start(integer num_detected){ osCauseHealing(llDetectedKey(0),10.0); } } |
npc = osNpcCreate(nombre,apellido, npcPos,llKey2Name(llDetectedKey(0)));
npc = osNpcCreate("Nombre", "Apellido", npcPos, "appearance");