Jump to content

Need help with my trap door


BlacksunN8
 Share

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

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

Recommended Posts

hi all^^

im trying to code a trap door script. not a usual one. so since i'm quite new to scripting plus i don't really know if that what i want to do is possible at all i would need some help please.

want i want is a trap door that turns phantom when somebody is standing on that door longer than lets say 30 seconds. If the avatar moves on in less than 30 seconds it should not turn phantom. When turned to phantom it should be phantom for only 5 seconds and then turn back to non phantom.

Ok my question are, is that possible at all ? And if yes would you tell me please what i'm missing? Here is the snippet i'm currently working with.

 

default
{
    state_entry()
    {
        llSetStatus (STATUS_PHANTOM, FALSE);
    }
    collision_start(integer total_number)
    {
         llSetTimerEvent(30.0);
    }

    timer()
    {
        llSetTimerEvent(0.0);
        llSetStatus (STATUS_PHANTOM, TRUE);
        llSleep (5);
        llSetStatus (STATUS_PHANTOM, FALSE);
    }

    
}

 This just does what i want, it turns the door to phantom and back but no matter if the avatar is still standing on the door or not.
 Thanks in advance for help ^^

Link to comment
Share on other sites

Your trap door is certainly possible, but you'll need several things to make it effective.

When an avatar collides with the prim, start a timer. As I recall volume detect can also detect when an avatar stops colliding with the prim. So if the script senses that the avatar stopped colliding with the prim before the timer runs out, your script can have nothing happen. If they are still colliding, send a signal to trigger the trap.

The trap door itself can be a prim that goes phantom, as you suggested, or a door scripted prim that pivots out of the way likea real trap door. Either way, something above the avatar will need to give the avatar a downward push once the trap opens. Otherwise, a stationary avatar will just hover there, like the the characters in a Road Runner cartoon. Without that push, ans unless the trap is huge, a stationary avatar over a hole that has suddenly appeared can start walking and just step to the edge of the hole and walk away.

You may also want to have an invisible but not phantom box spring up around the shaft opening, so they can't 'leap to safety' as the trap opens. 

Link to comment
Share on other sites

This is one way to do what you´re looking for.

key av;default {    state_entry() {        llSetStatus(STATUS_PHANTOM, FALSE);    }    collision_start(integer total_number) {        if (av != llDetectedKey(0)) {            av = llDetectedKey(0);            llSetTimerEvent(30.0);        }    }        timer() {
av = ""; vector size = llGetScale(); float max = llListStatistics( LIST_STAT_MAX, [size.x, size.y, size.z] ); llSensor( "", "", AGENT, max, PI); } sensor(integer num) { llSetTimerEvent(1.0); integer i; do { vector size = llGetScale(); vector pos = llGetPos(); vector det_pos = llDetectedPos(i); if ( (det_pos.x > (pos.x - (size.x / 2)) && det_pos.x < (pos.x + (size.x / 2))) && (det_pos.y > (pos.y - (size.y / 2)) && det_pos.y < (pos.y + (size.y / 2))) ) { llSetStatus(STATUS_PHANTOM, TRUE); llSleep(.5); } else { llSetStatus(STATUS_PHANTOM, FALSE); llSetTimerEvent(.0); } } while (++i < num); } no_sensor() { llSetStatus(STATUS_PHANTOM, FALSE); llSetTimerEvent(.0); }}

 

 Editted to fix the little problem Ela spotted.

Link to comment
Share on other sites

It is not yet complete. What is going to happen when a second agent collides while the timer is ticking? Let's say it ticked 29 sec. The collision code is going to reset the timer to 30 sec again...so the door traps now after 59 sec... and so on. I believe you would know how to resolve this issue so not going to write code for you :)

 

Link to comment
Share on other sites

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