Jump to content

Having a script do something when exitting mouselook


Tash Navarathna
 Share

Recommended Posts

I did check the wiki, the only example there is for telling you if you're in mouselook by touching it, which is not what I want. I also tried info = llGetAgentInfo(llGetOwner()); in timer, but no matter where I place the if (info & AGENT_MOUSELOOK), like changed, state_entry, it returns once and never again.

Link to comment
Share on other sites

You could learn more about llSetTimerEvent. It won't trigger the timer() event just the once when used correctly. E.g.:

default{    state_entry()    {        llSetTimerEvent(0.5);    }    timer()    {        integer buf;        buf = llGetAgentInfo(llGetOwner());        string out;        if(buf & AGENT_FLYING)            out += "The agent is flying.\n";        else            out += "The agent is not flying.\n";         if(buf & AGENT_ATTACHMENTS)        {            if(buf & AGENT_SCRIPTED)                out += "The agent has scripted attachments.\n";            else                out += "The agent's attachments are unscripted.\n";        }        else            out += "The agent does not have attachments.\n";         if(buf & AGENT_MOUSELOOK)            out += "the agent is in mouselook.";        else            out += "the agent is in normal camera mode.";        llWhisper(0, out);    }}

 Other than this, I don't know what you expect from this thread.

Link to comment
Share on other sites

Doing it that way causes it to spam the returns every .5 seconds,

 

I'm trying to have it do a return only once, so it doesn't play a holster noise every .5 seconds after you exit mouselook.

 

 

This is the most I could come up with, but it doesn't work.

 

 

integer info;default{    state_entry()    {        llSetTimerEvent(1);    }    changed(integer info)    {            if(info & !AGENT_MOUSELOOK)        {        llSay(0, "Touched.");    }    }    timer()    {        info = llGetAgentInfo(llGetOwner());    }}

 

Link to comment
Share on other sites

Firstly, use the Code button.

AddCode.jpg

Secondly, that was the intended purpose of the code - to repeat every 0.5s. It's not spam if it's relevant, but you will want to swap your sound for the local chat function.

What you want to do is detect when TRUE turns to FALSE, you can use a global variable type integer to do this.

Thirdly, in your code, you've split the if between timer and changed events  for reasons I can't understand. You don't need to use changed at all. Follow the nesting of the script example when modifying the example, and don't introduce new events that aren't necessary.

You might want to learn more about if statements and events.

Link to comment
Share on other sites

I did it with states.

 

integer info;key owner;    default{    state_entry()    {        llSetTimerEvent(.5);        owner = llGetOwner();    }                timer()    {        info = llGetAgentInfo(owner);            if(info & AGENT_MOUSELOOK)        state mouselook;        else        state notmouselook;    }    }state mouselook{    state_entry()    {        llSetTimerEvent(0.5);    }    timer()    {        info = llGetAgentInfo(owner);            if(info & AGENT_MOUSELOOK);            else state notmouselook;        }    }state notmouselook{    state_entry()    {        llSetTimerEvent(0.5);        llTriggerSound("foxblast2", 1);}        timer()    {        info = llGetAgentInfo(owner);            if(info & AGENT_MOUSELOOK)        state default;    }}

 

 

Also Freya, you might be more helpful if you didn't assume who you were helping was completely braindead when it comes to scripting.

Link to comment
Share on other sites

Assigning a single variable would be cleaner and less work than initialising three timer functions - it will also reduce the size of your code.

I assume nothing, all replies to posts are built up from the image conveyed. That said, I'm glad you've come up with a functional solution regardless of whether or not my bedside manner matched your expectations.

Best o' luck!

Link to comment
Share on other sites

you could use flags? (Freya's suggestion)

something like ....

integer mouseFlag = TRUE;    default{    state_entry()    {   llSetTimerEvent(0.5);        owner = llGetOwner();    }     timer()    {           info = llGetAgentInfo(owner);        if(info & AGENT_MOUSELOOK)        mouseFlag = TRUE;        else        {            if(mouseFlag == TRUE)           {  llTriggerSound("foxblast2", 1);               mouseFlag = FALSE;           }         }    }}

         this should change the flag when you switch to mouselook, and change it again when you leave mouselook...

Link to comment
Share on other sites

There are many ways to do it.  The less complicated the better.  Freya's works, so does Xijia's.  So does the OP's last shot at it.  We don't write scripts to order in this forum usually, only schematic examples or snippets.  It's up to the OP to do the actual scripting.  :smileywink:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...