Jump to content

Send Regionsayto all detectect items detected by a sensor?


Altier Verwood
 Share

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

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

Recommended Posts

Hello there LSL people, I have a basic grenade I am trying to make that detect any active or agents in the area and then shoots a message to them. but I've run into a bit of a problem.

the sensor works just fine, but it only detects and sends the mssage to the first thing it sense, not all of the things it scans in range of the sensor.

I think I have to use list2key or something like that but I'm not quite sure, would someone be able to shed of light on what I'm doing wrong? here is the very simple script.

 

list explode = ["ex1","ex2","ex3","ex4"];
default
{

    on_rez(integer vIntFound)
    {
        llTriggerSound(llList2String(llListRandomize(explode,1),0),1.0);
        llSleep(.2);
        llSensorRepeat( "", "", ACTIVE | AGENT, 10, PI,1);
    }
        sensor( integer vIntFound )
    {
        integer index = 0;
        llOwnerSay("Index: "+(string)index);
        key id2 = llDetectedKey(index);
        llOwnerSay("id: "+(string)id2);
        //llOwnerSay((string)vIntFound);
        key id = llDetectedKey(0);
        integer vIntCounter = 0;
        vector pos = llDetectedPos(0);
        float dist = llVecDist(pos, llGetPos() );
        if (dist < 10)
        llRegionSayTo(id,-943, "PlasmaG");
        llDie();      
    }
        no_sensor()
    {
        llDie();
    }    
}

Edited by Altier Verwood
Link to comment
Share on other sites

  • Altier Verwood changed the title to Send Regionsayto all detectect items detected by a sensor?

Try this one - written dry and without testing if it compiles inworld, but should work. You don't need llSensorRepeat since you're using llDie right after the sensor ends its work, llSensor is sufficient. Remember, that sensor functions can only get up to 16 items max, which may be not enough and prevent from registering damage; It would be better if your grenade would do llRegionSay only and then just llDie after few seconds - and the items/receivers themselves would do the llVecDist calculation instead. This would also cut out the slow sensor call.

Or... since your grenade is scanning within 10m, you could just use llWhisper for it and start simple listeners in receivers without any calculations, as whispering has 10m range.

list explode = ["ex1", "ex2", "ex3", "ex4"];

default
{

    on_rez(integer vIntFound)
    {
        llTriggerSound(llList2String(llListRandomize(explode, 1), 0), 1.0);
        llSleep(0.2);
        llSensor("", "", ACTIVE | AGENT, 10, PI);
    }

    sensor(integer vIntFound)
    {

        vector currentPos = llGetPos();
        while(vIntFound--)
        {
            key itemFound = llDetectedKey(vIntFound)
            llOwnerSay("Index: " + (string)vIntFound);
            llOwnerSay("id: " + (string)itemFound);
            vector pos = llDetectedPos(vIntFound);
            float dist = llVecDist(pos, currentPos);
            if (dist < 10)
            {
                llRegionSayTo(itemFound, -943, "PlasmaG");
            }
        }
        llDie();      
    }

    no_sensor()
    {
        llDie();
    }

}

 

Edited by panterapolnocy
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Hey there thank you for taking time to reply to me.

So I tried using whisper first, and sadly it still goes 20 meters, from what i know LL broke the whisper command in the last update.

as for the other thing you said, I am still semi new to scripting, and I'm not exactly sure how to have a listener do the calculation instead of the one saying the message, the sensor script is also a bit long, listening for 14 different message types. I saw this as a way to shorten that.

Link to comment
Share on other sites

Try to experiment with these. Again - coded dry, and no whiles(). ;) 

integer gChannel = -943;
string gDamageMessage = "PlasmaG";
list gExplode = ["ex1", "ex2", "ex3", "ex4"];

default
{
    on_rez(integer vIntFound)
    {
        llSetMemoryLimit(llGetUsedMemory() + 5120);
        llTriggerSound(llList2String(llListRandomize(gExplode, 1), 0), 1.0);
        llSleep(0.2);
        llRegionSay(gChannel, gDamageMessage);
        llSetAlpha(0.0, ALL_SIDES);
        llSleep(3);
        llDie();
    }
}

 

integer gChannel = -943;
string gDamageMessage = "PlasmaG";
string gDamageDistance = 10;

default
{

    state_entry()
    {
        llListen(gChannel, "", NULL_KEY, "");
        llSetMemoryLimit(llGetUsedMemory() + 10240);
    }

    listen(integer channel, string name, key id, string message)
    {
        if (message == gDamageMessage)
        {
            vector pos = llList2Vector(llGetObjectDetails(id, [OBJECT_POS]), 0);
            float dist = llVecDist(pos, llGetPos());
            if (dist < gDamageDistance)
            {
                llSay(0, "Damage registered from '" + name + "'.");
            }
        }
    }

    on_rez(integer start_param)
    {
        llResetScript();
    }

}

 

Edited by panterapolnocy
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Oh my, you are on a different level than me,  while I can't use those on the main combat system, the first script you posted works perfectly after testing, I will learn much from this.
thank you very much for helping me, this explosion thing was holding up the whole project.

  • Like 2
Link to comment
Share on other sites

The integer in the sensor is the number of detected avatars.
sensor(integer vIntFound)

So to get all the avatars detected you need to use that number in a loop (while of for).
llDetectedPos(0) inside the sensor only gets the first avatar. That is what the 0 refers to.
llDetectedPos(1) would get the second avatar and so on.

 

  • Like 2
Link to comment
Share on other sites

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