Jump to content

How to get trigger this script with chat msg


TrinityReclusive
 Share

You are about to reply to a thread that has been inactive for 398 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

How to get this script to trigger on a text chat message. What to trigger it by using chat window. I am stuck i tried different things but i can not get it right.

Is it possible to do this? I been searching for a way but can not find a clear answer for this.

The click on touch works fine. But wish to active this script on a chat command such as the word fire.

I appreciate you help. Thank you.

default
 {
     touch_start(integer total_number)
     { if(llDetectedKey(0)== llGetOwner())
      {
         vector rootRot = llRot2Euler(llGetRootRotation());
         vector mod = <llFrand(-0.2), llFrand(0.2), 0> + <0, -0.1, 0>;
         rotation rot = llEuler2Rot( rootRot + mod );
         
         integer n = llGetInventoryNumber( INVENTORY_OBJECT );
         integer choice = llFloor( llFrand(n) );
         string name = llGetInventoryName(INVENTORY_OBJECT,choice);
         llRezObject(name, llGetPos(), <0,0,15>*rot, ZERO_ROTATION, 12);
     }
 }
 }

 

 

Link to comment
Share on other sites

Rather than using a touch_start event, you want to place your code within a listen event. And in order to make a script actually trigger listen events, you must set up a listen handler/filter with the command llListen.

The llListen command requires several parameters which will act as a filter. This is important because you want to filter out as much chatter as possible so as to not accidentally trigger the event - similar to how your original code checks if the owner was the person who touched the object.

The wiki pages I linked above can give you the full details on how to set this up, but for a quick example, the following code can set up a listen which will trigger when the object's owner speaks the word "command" in local chat and is within hearing range of the object.

llListen( 0, "", llGetOwner(), "command" );	//sets up a listener filter for when the owner says "command" on channel 0

 

Link to comment
Share on other sites

Sorry have to admit i an not to bright. Tried reading about llListen could not make heads or tails of it.

Tried to add that command to it but it didn't work.

This is what i tried to add i know its wrong have error on line..10 9

integer handle;
default
{
    state_entry()
    {
        handle = llListen( 0, "", llGetOwner(), "fire" );    
        
    (integer )
    
         
         vector rootRot = llRot2Euler(llGetRootRotation());
         vector mod = <llFrand(-0.2), llFrand(0.2), 0> + <0, -0.1, 0>;
         rotation rot = llEuler2Rot( rootRot + mod );
         
         integer n = llGetInventoryNumber( INVENTORY_OBJECT );
         integer choice = llFloor( llFrand(n) );
         string name = llGetInventoryName(INVENTORY_OBJECT,choice);
         llRezObject(name, llGetPos(), <0,0,15>*rot, ZERO_ROTATION, 12);
 
        
        }     
    }
 
    listen(integer channel, string name, key id, string message)
    {
        llSay(0, name + " just said " + message);
    }
}

 

I Admit i am new to understand some of this never did a listen command before.

Link to comment
Share on other sites

Well i took out the (integer ) line but now it gives me error on line 23, 4.

integer handle;
default
{
    state_entry()
    {
        handle = llListen( 0, "", llGetOwner(), "fire" );    
        
    
    
         
         vector rootRot = llRot2Euler(llGetRootRotation());
         vector mod = <llFrand(-0.2), llFrand(0.2), 0> + <0, -0.1, 0>;
         rotation rot = llEuler2Rot( rootRot + mod );
         
         integer n = llGetInventoryNumber( INVENTORY_OBJECT );
         integer choice = llFloor( llFrand(n) );
         string name = llGetInventoryName(INVENTORY_OBJECT,choice);
         llRezObject(name, llGetPos(), <0,0,15>*rot, ZERO_ROTATION, 12);
 
        
        }     
    }
 
    listen(integer channel, string name, key id, string message)
    {
        llSay(0, name + " just said " + message);
    }
}

 

This is giving me  headache lol

error 1.jpg

Link to comment
Share on other sites

If you're new to scripting in general, it may be beneficial to go through some of the introductory tutorials on the wiki.

But as for your latest code, do as Love Zhaoying suggest and remove that lone (integer) statement. It's not doing anything good there. I believe that should get the script to compile.

Edit: oops, I missed the mismatched braces that KT Kingsley points out below. That'll definitely cause issues.

Now consider what the goal of your script is. You had some code that originally was triggered when the owner clicked the object. Said code was contained inside a touch_start event. You wanted to make the trigger instead happen when the script "hears" a specific command spoken by the owner. You've already got the llListen and listen event setup, so all that remains is to move the code into the listen event.

For reference, the state_entry is only triggered once, automatically when the script enters a given state. Your script only has one state (the default state) so that means its state_entry event will automatically trigger when the script starts up. That's why it's good to do your setup there, like setting the llListen handler. But after that, you want to just deal with the listen event.

Does that make sense?

Edited by Fenix Eldritch
Link to comment
Share on other sites

14 hours ago, TrinityReclusive said:

How to get this script to trigger on a text chat message. What to trigger it by using chat window. I am stuck i tried different things but i can not get it right.

Is it possible to do this? I been searching for a way but can not find a clear answer for this.

The click on touch works fine. But wish to active this script on a chat command such as the word fire.

I appreciate you help. Thank you.

default
 {
     touch_start(integer total_number)
     { if(llDetectedKey(0)== llGetOwner())
      {
         vector rootRot = llRot2Euler(llGetRootRotation());
         vector mod = <llFrand(-0.2), llFrand(0.2), 0> + <0, -0.1, 0>;
         rotation rot = llEuler2Rot( rootRot + mod );
         
         integer n = llGetInventoryNumber( INVENTORY_OBJECT );
         integer choice = llFloor( llFrand(n) );
         string name = llGetInventoryName(INVENTORY_OBJECT,choice);
         llRezObject(name, llGetPos(), <0,0,15>*rot, ZERO_ROTATION, 12);
     }
 }
 }

 

 

i don't know if you got a working script going but this worked for me.

 

default
{
    state_entry()
    {
       llListen( 0, "", llGetOwner(), "fire" );

 vector rootRot = llRot2Euler(llGetRootRotation());
         vector mod = <llFrand(-0.2), llFrand(0.2), 0> + <0, -0.1, 0>;
         rotation rot = llEuler2Rot( rootRot + mod );
         
         integer n = llGetInventoryNumber( INVENTORY_OBJECT );
         integer choice = llFloor( llFrand(n) );
         string name = llGetInventoryName(INVENTORY_OBJECT,choice);
         llRezObject(name, llGetPos(), <0,0,15>*rot, ZERO_ROTATION, 12);
        
    }
}

hope it helps.

Link to comment
Share on other sites

  • 3 years later...
You are about to reply to a thread that has been inactive for 398 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...