Jump to content

llSetClickAction: Disable touch_start


testgenord1
 Share

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

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

Recommended Posts

Hi!
I've made a script enabling the user to teleport to different stations according to the name of the particular station.
For example, when you write the number "1" into the chat, you are teleported to "station 1" etc.

The script is in an object the user has to attach to him/herself.
It listens for the numbers and uses them for the respective teleport destinations.

After a certain time the script is switched off entirely, to prevent that teleporting option from being infinite.

There is one problem I couldn't solve, though, and that is, in theory, a second avatar could touch the attachment and type a number into the chat.
Thereby the avatar wearing the attachment would be teleported to the respective undesired destination.
So there is the possibility of griefing in this.

I tried  llSetClickAction(8); to disable the clicking of the attachment which has worked in other examples but not in this one.

Do you maybe see how that possibility could be stopped?
I'm posting the script below.
I'm sure it contains some more flaws, so feel free to make any kind of suggestions of improvement.
Thank you very much in advance.
 

key user;
key caller;
string message;

default
{
    attach(key id)
    {
        if (id)     // is a valid key and not NULL_KEY
        {
        llSetClickAction( CLICK_ACTION_TOUCH );
        llSay(0,"Click the attachment at your hand.");
        }
    }
        touch_start(integer number)
    {
        llSetClickAction(8); 
        user = llDetectedKey(0);
        llRegionSayTo(user,0,"You have 15 minutes time.");
        llSetTimerEvent(900.0); 
    }
    timer()
    {
        llRegionSayTo(user,0,"Your time is up.");
        llSetTimerEvent(0);
        llSetScriptState(llGetScriptName(),FALSE); 
    }
    touch_end(integer num_detected)
    {
     caller = llDetectedKey(0);
     llListen(PUBLIC_CHANNEL, "", caller, "");  
    }
    listen(integer channel, string name, key id, string message)
    {
        message = llStringTrim(message, STRING_TRIM);
        if(message)
        {
            llSensor ("station "+message,"",PASSIVE | ACTIVE,96.0,PI);
        }
    }
    sensor(integer number)
    {
        vector det_pos = llDetectedPos(0)+<0.0,-5.0,-2.0>;
        llTeleportAgent(user,"", det_pos, <0.0,1.0,0.0>);
    } 
}

 

Link to comment
Share on other sites

The two standard methods:

1. Set a global flag ( integer iTouched ) that is FALSE by default but becomes TRUE as soon as the item is touched.  If the touch_start event is set to respond only if (iTouched == TRUE), then no futher touches will do anything until you reset iTouched (in a timer or by some subsequent action).

2.  Make the final action in the touch_start event move execution to a new state that has no touch_start event in it.  Do all your important stuff in the new state and only returtn to state default when you are ready to allow more touches.

  • Like 2
Link to comment
Share on other sites

A third approach is record the uuid of the avatars, so that a touch from avatar 1 is associated with the listen also from avatar 1, avatar 2 touches and the listen then checks which uuid is has heard the command from and takes appropriate action. Both touch and listen events always supply the uuid of the initiator of the event.

Edited by Profaitchikenz Haiku
  • Like 2
Link to comment
Share on other sites

Thank you very much for your ideas.
I certainly learned a lot today.

@Qie Niangao: I'm on Opensim mostly, and that does not seem to be a problem here. Is this maybe more a Second Life issue?

@Rolig Loon: For whatever reason, the toggle switch works in other script versions I tried,
but not in this one.
This seems to have to do with the fact that it's an attachment.
Does an attachment maybe count as an implicit touch_start?

So I ended up using Profaitchikenz Haiku's idea.
The script only reacts to the new owner.
If it's not the owner touching it, the script is reset, and so the owner has to touch again,
which is a bit clumsy. So if you have better ideas, you're welcome to comment.

The script has worked so far.
I'm posting it below.
There is always room for improvement, so feel free to comment further.
Thank you very much again!

// Target Sensor Teleporter v0.1 by djphil (CC-BY-NC-SA 4.0)
key user;
string message;

default
{
    attach(key id) 
    {
        if (id)     // is a valid key and not NULL_KEY
        {
        //llSetClickAction( CLICK_ACTION_TOUCH );
        llRegionSayTo(id,0,"You have 15 minutes time.\n \n Click on the teleporter in your hand.");
        llSetTimerEvent(900.0);
        }
        } 
    touch_start(integer num)
    {
     user = llDetectedKey(0);
     if(llGetOwner()==user)
     {
     llRegionSayTo(user,0,"\n \n Write the number of your destination station into the chat and press 'enter'.");
     llListen(PUBLIC_CHANNEL, "", user, "");
    }
    else
    {
        llResetScript();
    }
    }
    listen(integer channel, string name, key id, string message)
    {
        message = llStringTrim(message, STRING_TRIM);
        if(message)
        {
            llSensor ("station "+message,"",PASSIVE | ACTIVE,96.0,PI);
        }
    }
    sensor(integer number)
    {
        vector det_pos = llDetectedPos(0)+<0.0,-5.0,-2.0>;
        llTeleportAgent(user,"", det_pos, <0.0,1.0,0.0>);
    }
    timer()
    {
        llRegionSayTo(user,0,"Your time is up.");
        llSetTimerEvent(0);
        llSetScriptState(llGetScriptName(),FALSE); 
    }
}
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1607 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...