Change font size
It is currently Wed Nov 20, 2019 9:43 am

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 3 of 4   [ 34 posts ]
Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject: Re: Pointing your nose..
PostPosted: Sun Sep 04, 2011 1:24 pm 
Furious Typer
User avatar

Joined: Fri Aug 19, 2011 7:10 pm
Posts: 244
Location: UK
Glad you liked them. I agree about the chatbot script, but it's the best I could get to work with. I've tried linking in to chatterbot for responses, and whilst I can send the request to chatterbot and I can get the reply page back, actually finding the reply is proving to be more difficult simply because the reply comes back with a whole bunch of javascript which appears to write the actual reply to the served webpage after it's been served. My javascript is sketchy at the best, and I'm not too sure how to interact with the js from lsl (or even if it's possible), so I've put that script on hold for the time being. I'll probably study the js some more when I have time and see if there's anyway to write an lsl script that will do the same job. Would be nice to get it working, though. The responses from chatterbot make much more sense. The Elisa model is extremely restricted.

As for load, the NPCs are probably less of a load than real AVs, and so as long as you can handle visitor numbers they shouldn't present a problem. You are likely to introduce more of a load with your scripts, depending on what they are doing and how they do it. I'm suddenly paying a lot more attention to optimising scripts now :)

_________________
50's sim based at Rumbled on OSGrid
happily running on Debian Linux on a VPS since June 10 2013


Top
 Profile  
 
 Post subject: Re: Pointing your nose..
PostPosted: Sun Sep 04, 2011 2:09 pm 
OSG Elite
User avatar

Joined: Thu Dec 11, 2008 7:51 am
Posts: 391
Location: England UK
Roken,

You should take a look at Pandora bots (http://www.pandorabots.com/botmaster/en/home). They have a nice ALICE chatbot that you can train online. I have a rather crude script I have been working on (thanks to Juicy Babii for the original script). It didn't work when I got the original, but after some footering I managed to get it to work, roughly. The issues I have are special characters, though I suspect this can be sorted easily, I just haven't gotten round to parsing the output yet. Anyway the script is below and also a short conversation between ALICE and myself so you get a feel for its capabilities.

{L_QUOTE}:
[18:53] Adelle Fitzgerald: hello
[18:53] ALICE chatbot: Hello there.
[18:53] Adelle Fitzgerald: how are you?
[18:53] ALICE chatbot: Everything is going extremely well.
[18:54] Adelle Fitzgerald: that is great to hear
[18:54] ALICE chatbot: Are you a student?
[18:54] Adelle Fitzgerald: no, I am an avatar
[18:54] ALICE chatbot: What is your profession?. What is avatar, your job?
[18:55] Adelle Fitzgerald: my profession is super hero. avatar is a manifestation of a deity in bodily form on earth
[18:55] ALICE chatbot: Where did you get your profession is super hero? Aren't all manifestation of a deity in bodily form on earth avatar?
[18:55] Adelle Fitzgerald: are you stupid?
[18:55] ALICE chatbot: No Om I certainly am not stupid.
[18:56] Adelle Fitzgerald: are you clever>?
[18:56] ALICE chatbot: I am highly intelligent. I have many intellectual functions.
[18:56] Adelle Fitzgerald: what are some of your intellectual functions?
[18:56] ALICE chatbot: Thought, reason, intelligence, logic and deduction.
[18:56] Adelle Fitzgerald: ooooh, logic is good. Spock is very logical
[18:56] ALICE chatbot: I think ooooh logic is a lot of things. And logical is Spock.
[18:57] Adelle Fitzgerald: can you please calculate something for me?
[18:57] ALICE chatbot: I think I can, don't you?. Not by any means.
[18:57] Adelle Fitzgerald: what is the square root of 13254635?
[18:57] ALICE chatbot: Do I look like a calculator? I think you already know the answer anyways.
[18:58] Adelle Fitzgerald: you said you have logic and deduction, surely that means that you can calculate for me?
[18:58] ALICE chatbot: What makes you think I have it?
[18:58] Adelle Fitzgerald: you said so
[18:58] ALICE chatbot: I say a lot of silly things.
[18:58] Adelle Fitzgerald: ahh so you are silly hehe. silly is also good.
[18:58] ALICE chatbot: Ah hah.. Thanks for telling me that I am silly he. And good is silly.
[18:59] Adelle Fitzgerald: no, good is not silly. silly is good.
[18:59] ALICE chatbot: Hey.. Glad to hear it. Are they exactly the same?
[18:59] Adelle Fitzgerald: no they are not. I think you are stupid yanno.
[18:59] ALICE chatbot: What is the difference?. Why not? Thanks for telling me that I am stupid yanno.
[18:59] Adelle Fitzgerald: thats fine
[18:59] ALICE chatbot: " Thanks for telling me that I am stupid yanno." is fine with me too.
[19:00] Adelle Fitzgerald: cool, anyway I must go now
[19:00] ALICE chatbot: I'm glad you like it. Tell your friends.
[19:00] Adelle Fitzgerald: i will! bye!
[19:00] ALICE chatbot: Go ahead. Too much recursion in AIML.
[19:01] Adelle Fitzgerald: hrm, here we go again with that recursion thing.... what is recursion in AIML?
[19:01] ALICE chatbot: Saying that " hrm here we go again with that recursion thing" is such a nonsensical position that I refuse to waste my time on it. You threw my brain through a loop.
[19:01] Adelle Fitzgerald: oh ok... cya!
[19:01] ALICE chatbot: Hmm. TTYL, Om.




{L_CODE}:
key requestId;
integer listening;
string custid;
string message;

string botId="f0487cf9de347543";
string botURL="http://www.pandorabots.com/pandora/talk-xml";

    string strReplace(string str, string search, string replace) {
        return llDumpList2String(llParseStringKeepNulls((str = "") + str, [search], []),                replace);
    }   
   
default
{
   state_entry()
   {
       listening = llListen( 0, "", NULL_KEY, "" );
       custid = "";
   }

   touch_start(integer total_number)
   {
       llWhisper(0, "Talk to me in Local Chat.");
   }
 
   listen(integer channel, string name, key id, string msg)
   {
       custid=name;
       llListenRemove(listening);
        llSetTimerEvent(5.0);
        message = msg;
   }
   

   
   timer()
   {
       requestId = llHTTPRequest(botURL,[HTTP_METHOD,"POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"],"input="+message+"&botid="+botId+"&custid="+custid);
        llSetTimerEvent(0.0);
       listening=llListen( 0, "", NULL_KEY, "" );
    }
 
    http_response(key request_id, integer status, list metadata, string body) {
     
       if (request_id == requestId) {
         
           if(body == "error") {
               llWhisper(0, "An error occurred. Please try again later");
           } else {
               //llSay(0,body);
            integer start = llSubStringIndex(body, "<that>");
            integer end   = llSubStringIndex(body, "</that>");
            list lines;
            if (start != -1 && end != -1) {
                string msglines = llGetSubString(body, start+6, end-1);
                lines = llParseString2List(msglines, ["&lt;br&gt;"],[""]);
                integer i;
                string s;
                llSay(0,msglines);



//Below here is not working properly. Needs fixing!!!!

                for (i=0; i< llGetListLength(lines); i++) {
                    //llSay(0,(string)i);
                    if (i>=0) s = s + "\n";
                    s = s + strReplace(llList2String(lines, i), "&quot;", "\"");

                  }
                //llSay(0, s);
                }
           }

       } else {
           llWhisper(0, "An error occurred. Please try again later");
       }
   }     
}


Please note the botId string is for an account registered to myself. If anyone does use this script then please register your own account and change the botId string :)

_________________
"Nothing lasts forever; It's scientific"
~David Byrne (Talking Heads)


Top
 Profile  
 
 Post subject: Re: Pointing your nose..
PostPosted: Sun Sep 04, 2011 6:18 pm 
Furious Typer
User avatar

Joined: Fri Aug 19, 2011 7:10 pm
Posts: 244
Location: UK
I tried Pandora - but had problems with "Server not found" ( tried in my browser with the same problem).

Maybe I just caught it at a bad time.

I'm not so sure I have time to work on this (I'm going to be out of the country from Tuesday) so maybe I'll earmark it for my return to the UK.

I'm really starting to get a feel for how NPCs can be used, and I'd love to pull together a script (or suite of scripts) suitably modified (or written from scratch) that will maximise their use. Something for me to work on :)

I'll keep posting - if I make any significant headway I'll open a new thread (I'm eminently conscious of the fact that I seem to have hi-jacked this one).

_________________
50's sim based at Rumbled on OSGrid
happily running on Debian Linux on a VPS since June 10 2013


Top
 Profile  
 
 Post subject: Re: Pointing your nose..
PostPosted: Mon Sep 05, 2011 12:46 am 
Furious Typer
User avatar

Joined: Mon Aug 10, 2009 11:53 pm
Posts: 258
Ok so me being the ever tinkerer and not being able to let something go... here is the solution to the 'face your target' problem with the NPC...
{L_CODE}:
if (vecTo_targ.x > 5){      // Backup check. Make sure target is not at edge of sim or out of range.                                             
    if (llFabs(llVecDist(vecTo_targ, nPos)) > 5){  // Distance before action
      osAvatarPlayAnimation(npc,"walk");                                             
      osNpcSetRot(npc, llRotBetween(<PI,PI,0>,llVecNorm(vecTo_targ - osNpcGetPos(npc))));
                                                               // ^^ Face target pos
      osNpcMoveToTarget(npc, vecTo_targ, OS_NPC_NO_FLY);                                 
    }
    else {
      llSleep(1); // Stop animation buffer - no duck walking last couple of feet.
      osAvatarStopAnimation(npc,"walk");                                           
    }
}

NOTE: The major change is the <PI,PI,0> in:
{L_CODE}:
osNpcSetRot(npc, llRotBetween(<PI,PI,0>,llVecNorm(vecTo_targ - osNpcGetPos(npc))));

Why does this work? I have no idea since in reality it is not really supposed to - however NPCs are more like objects than avatars. Then again you can do all sorts of avatar things to them so there you are lol. I took a chance after working on some particle systems and just took a random guess thinking 'hrmmm you know...'

This also eliminates the need for the stop rotation check at the end. It is a very smooth follow. You can turn zig-zags, circles, swerves, and strafes and this will just keep going right after you. It always faces your direction no matter how you are facing.

I've been testing it like crazy and I THINK there may be the tiniest little twitch to the NPC's right but mostly using run speeds. Either way if you want to mess with it I am sure you can get it absolutely perfect as you can see that changing the values got me to where I'm at now.

Hope this helps someone out, I know it just gave me a big boost in some of the 'face me when I'm talking to you dangit!' quest giver stoofs I'm working on :D

Take care,
- Hap

_________________
Sorry, I was just thinking upon the immortal words of Socrates who said ... "I drank what?? ... "
- Real Genius


Top
 Profile  
 
 Post subject: Re: Pointing your nose..
PostPosted: Mon Sep 05, 2011 7:17 am 
Furious Typer
User avatar

Joined: Fri Aug 19, 2011 7:10 pm
Posts: 244
Location: UK
@ Adele

You can fix the special characters by changing the strReplace function (which doesn't work). Add a new function:

{L_CODE}:
string str_replace(string src, string from, string to)
{//replaces all occurrences of 'from' with 'to' in 'src'.
    integer len = (~-(llStringLength(from)));
    if(~len)
    {
        string  buffer = src;
        integer b_pos = -1;
        integer to_len = (~-(llStringLength(to)));
        @loop;
        integer to_pos = ~llSubStringIndex(buffer, from);
        if(to_pos)
        {
            b_pos -= to_pos;
            src = llInsertString(llDeleteSubString(src, b_pos, b_pos + len), b_pos, to);
            b_pos += to_len;
            buffer = llGetSubString(src, (-~(b_pos)), 0x8000);
//            buffer = llGetSubString(src = llInsertString(llDeleteSubString(src, b_pos -= to_pos, b_pos + len), b_pos, to), (-~(b_pos += to_len)), 0x8000);
            jump loop;
        }
    }
    return src;
}


and then just before your llSay:

{L_CODE}:
msglines = str_replace(msglines, "&quot","'");


(This will replace, for example, &quotyou&quot with 'you')

If you are using this on a bot you may also want to add a variable declaration at the top:
{L_CODE}:
key npc = "npc's UUID";


Then in the listen loop put a test:

{L_CODE}:
if (name !="NPC's name")
    {
      ..................
    }


This stops the NPC replying to itself.

And replace llSay(0,msglines); with
{L_CODE}:
osNpcSay(npc, msglines);


There also appear to be some statements that will cause the bot to speak the source, for example say "How often what" to it. To change the output to something more meaningful, immediately before the llSay (or osNpcSay) add:

{L_CODE}:
if (llSubStringIndex(msglines, botId) != -1)
                {
                    msglines = "Oops, something went wrong. Please try again";
                }

_________________
50's sim based at Rumbled on OSGrid
happily running on Debian Linux on a VPS since June 10 2013


Top
 Profile  
 
 Post subject: Re: Pointing your nose..
PostPosted: Mon Sep 05, 2011 2:30 pm 
OSG Elite
User avatar

Joined: Thu Dec 11, 2008 7:51 am
Posts: 391
Location: England UK
Excellent Roken and Haplo!

Thanks Roken for looking at the chatbot script, and great Haplo that you fix0red the NPC facing problem.

*runs off to go and make a walking, talking clone of me!" :D

_________________
"Nothing lasts forever; It's scientific"
~David Byrne (Talking Heads)


Top
 Profile  
 
 Post subject: Re: Pointing your nose..
PostPosted: Mon Sep 05, 2011 3:55 pm 
OSG Elite
User avatar

Joined: Thu Dec 11, 2008 7:51 am
Posts: 391
Location: England UK
Hokay.... I think I misunderstood the original issue with the avatar not facing the correct direction. I thought the issue was when the NPC was stood still that it didn't face the target (I never seemed to experience the NPC facing the wrong direction when walking, that I noticed anyway).

So, I took the line of code
{L_CODE}:
osNpcSetRot(npc, llRotBetween(<PI,PI,0>,llVecNorm(vecTo_targ - osNpcGetPos(npc))));
and placed this in the 'else' statement so that when the NPC is stood still it will always face the target, such as when the target walked around the NPC in say, circles. This is what I haven't been able to make work properly. Even taking code from a script in a prim that does face the target properly it doesn't seem to work.

As what I know about LSL rotation is nothing, I'm really struggling with it :(

_________________
"Nothing lasts forever; It's scientific"
~David Byrne (Talking Heads)


Top
 Profile  
 
 Post subject: Re: Pointing your nose..
PostPosted: Tue Sep 06, 2011 7:29 am 
Furious Typer
User avatar

Joined: Mon Aug 10, 2009 11:53 pm
Posts: 258
Adelle Fitzgerald {L_WROTE}:
Hokay.... I think I misunderstood the original issue with the avatar not facing the correct direction. I thought the issue was when the NPC was stood still that it didn't face the target (I never seemed to experience the NPC facing the wrong direction when walking, that I noticed anyway).

So, I took the line of code
{L_CODE}:
osNpcSetRot(npc, llRotBetween(<PI,PI,0>,llVecNorm(vecTo_targ - osNpcGetPos(npc))));
and placed this in the 'else' statement so that when the NPC is stood still it will always face the target, such as when the target walked around the NPC in say, circles. This is what I haven't been able to make work properly. Even taking code from a script in a prim that does face the target properly it doesn't seem to work.

As what I know about LSL rotation is nothing, I'm really struggling with it :(


Ok I see. Well the original issue was that when the NPC comes to a halt after walking, running whatever. The NPC always 'settles in' at about 90 degrees to one side or the other if you do not use the PI,PI,0 method.

If you want the NPC to constantly face you while at a standstill you need to have it at some point during the constant update so it is checking the av position at all times... try commenting out the one in the 'else' statement (shouldn't need that one anymore anyway) and replace the one in the main if - check loop - and see what you get. If nobody has you fixed up by the time I get home I'll see what I can do.

Take care,
- Hap

_________________
Sorry, I was just thinking upon the immortal words of Socrates who said ... "I drank what?? ... "
- Real Genius


Top
 Profile  
 
 Post subject: Re: Pointing your nose..
PostPosted: Tue Sep 06, 2011 2:35 pm 
OSG Elite
User avatar

Joined: Thu Dec 11, 2008 7:51 am
Posts: 391
Location: England UK
Thanks for your reply Haplo.

I have tried and tried to get this working (the avatar facing the target when stood still) but it seems the NPC is always at about 90 degrees off the target. I would love to just be able to 'add' or 'subtract' 90 degrees from the set rot, but I just don't understand rotation in LSL (never have done, but hopefully will one day!)

Anyway, based on your script I have stripped out the movement part so it is just rotation to make it easier for fixing this. The script I have is below. I have also placed this into a prim (changing the various parts from NPC get/set to regular 'll' get/set and it seems that the prim faces strangly too. I did notice the prim is moving on all axis so maybe that is the issue (remembering what I read on the wiki about only rotating on a certain axis otherwise strange behavious occurs).

If anyone could take a look at this I would extreamly appreciate it :)

{L_CODE}:
key npc;
vector curPos;
vector vecTo_targ;
vector nPos;
integer destX;
integer destY;
integer target_x;


default
{
    state_entry()
    {
        llListen(10,"",NULL_KEY,""); // Uhm. Yeah
    }
   
    touch_start(integer num)
    {
        llOwnerSay("\n\nNPC Block:\nType /10 (command) to control your NPC.\ncreate - spawn NPC\nremove - despawn NPC\nreload - reload NPC appearance\nstart - start NPC watchdog\nstop - stop and remove the NPC watchdog");
        // What? Nifty little instruction toucher. Every little script needs one *pat pat*.
    }   

    listen(integer channel, string name, key id, string msg)
    {
        if (msg != "")
        {
            if (msg == "create")
            {
                osOwnerSaveAppearance("appearance");    // Saves object owner's appearance
                destX = (integer) llFrand (10)-5;      // Creates random X coord around center
                destY = (integer) llFrand (10)-5;      // Creates random Y coord around center
                npc = osNpcCreate ("Luke", "Endemirror", llGetPos()+<destX, destY, 0>, "appearance");
               
            }
            else if (msg == "start")
            {
                osSetSpeed(npc, 2);
                osAvatarPlayAnimation(npc,"VISTARUN");
                llSensorRepeat("","",AGENT,92.0,PI*2,0.8); // Kick off the watchdog   
               
            }
            else if (msg == "stop")
            {
                osNpcRemove(npc);
                llResetScript();                           // Stop all processes. Kill all NPCs.
            }
            else if (msg == "remove")
            {
                osNpcRemove(npc);                          // Kill the NPC
            }
            else if (msg == "reload")
            {
                osNpcLoadAppearance(npc, "appearance");    // Load appearance notecard in prim
            }
            else
            {
                llOwnerSay("Nope");                        // Unknown command basket
            }
        }
    }
   
    sensor (integer _det) // -----------> Watchdog Rotation and Movement Sensor <---------------
    //Movement part removed from this script to concentrate on the NPC facing the avatar
    {
        integer x;
        for (x = _det - 1; x >= 0; x--) {                                // Grab incoming avatars
            if (llDetectedKey(x) != npc && llDetectedKey(x) != ""){      // Filter for target
                target_x = x;
                vecTo_targ = llList2Vector(llDetectedPos(target_x),0);   // Grab vector to target
                nPos = osNpcGetPos(npc);       
                }
        }
       
        osNpcSetRot(npc, llRotBetween(<PI,PI,0>,llVecNorm(vecTo_targ - osNpcGetPos(npc))));
    }                   // ------------> End of Watchdog Movement Block <------------------------
}



P.S. Anyone know where I can get some lessons in LSL rotation? hehe ;)

_________________
"Nothing lasts forever; It's scientific"
~David Byrne (Talking Heads)


Top
 Profile  
 
 Post subject: Re: Pointing your nose..
PostPosted: Tue Sep 06, 2011 8:45 pm 
Furious Typer
User avatar

Joined: Mon Aug 10, 2009 11:53 pm
Posts: 258
Well first of all your script seems to work very well for me. Be sure to reduce the sensor to around .1 and you will notice a dramatic difference in how well the NPC tracks you. Remember that its movements are based loosely on MoveTo iterations which aren't that spiffy unless you crank on the system a bit.

Also I have noticed that if you keep your right shoulder to the NPC and walk in a circle... it seems to track nearly perfectly. Keep your left shoulder to it and it tracks, but at about 45-90 degrees off.

I believe this something is happening akin to a 'mini-grid' between the avatar and the NPC, but I do not know how to correct the calculations.

I've so far tried breaking down both vectors and making them absolute values, applying all sorts of conditional filters one way or the other, and I always end up back to the original single line statement being the better of them all.

I'm missing something somewhere, but surely someone that understand this better may have the answer.

Also consider that Opensim has never quite gotten all of the rotation stuff down imho. Where as a standard angle pattern in a particle system would be 1.55, 1.55 for a flat plane of particles - in OS it is more like 1.689, 1.689 or something like that.

Also, NPCs being relatively new it could possibly even be a bug. I will talk to some people and find out just what the end result of some of these functions are supposed to be versus what we are seeing.

Take care,
- Hap

_________________
Sorry, I was just thinking upon the immortal words of Socrates who said ... "I drank what?? ... "
- Real Genius


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 3 of 4   [ 34 posts ]
Go to page Previous  1, 2, 3, 4  Next


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net