Jump to content

script to detect nearby avatars and turn off hud by speaking as owner


Ryuhei Chiung
 Share

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

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

Recommended Posts

hi i want to create a script that when placed in a object on my hud will scan for avatars within a set distance if there are any there then the script will issue a command on channel 9 to turn off another hud

this is what i have so far and it doesnt work

any help apprechiated

 

integer SomebodyNear = 0;

default
{
state_entry()
{
llSetTimerEvent(5.0);
}

timer()
{
llSensor("",NULL_KEY,AGENT,100,PI);
}

sensor(integer num_detected)
{
if (SomebodyNear == 0)
{
llWhisper(9, "off"); // Turn off the hud
llSay(9, "off");
SomebodyNear = 1;
}
}

no_sensor()
{
llWhisper(9, "on"); // Turn on the hud
SomebodyNear = 0;
}
}

Link to comment
Share on other sites

hi i want to create a script that when placed in a object on my hud will scan for avatars within a set distance if there are any there then the script will issue a command on channel 9 to turn off another hud

this is what i have so far and it doesnt work

any help apprechiated

 

integer SomebodyNear = 0;

default
{
state_entry()
{
llSetTimerEvent(5.0);
}

timer()
{
llSensor("",NULL_KEY,AGENT,100,PI);
}

sensor(integer num_detected)
{
if (SomebodyNear == 0)
{
llWhisper(9, "off"); // Turn off the hud
llSay(9, "off");
SomebodyNear = 1;
}
}

no_sensor()
{
llWhisper(9, "on"); // Turn on the hud
SomebodyNear = 0;
}
}

Link to comment
Share on other sites

Many scripts are designed to prevent control by other scripts or non-authoritive avatars.

If you're trying to tell someone elses object to do something, there's a good chance that they don't want you to do this - the script will simply discard your command. You cannot pretend to be the owner of another persons objects, and there is no reason that another persons objects should listen to commands by non-authoritive objects. If this is only talking to scripts that you have built, then see the advice below.

 

  • The maximum range of llSensor is 96.0m, not 100.0m
  • llWhisper only has a radius of 10.0m and llSay has a radius of 20.0m, if you're looking to address objects further away (such as those up to 96.0m away - the maximum of the sensor), you should use either llRegionSay or llShout.

 I'd recommend using the 'Add Code' button in future, allowing it to be more easily read. It is the fifth button from the left in the edit window.

 AddCode.jpg

Link to comment
Share on other sites

Think about the logic.


Sending the on command in the no_sensor event makes no sense since there is nobody.

The script will send the off command in a 20m range if someone arrives in 96m range. It will send the command once. so a 2nd avatar approaching will not receive it. At 1st - everyone has to leave the (96m) area then it will send another off command to the next arrival. Is it supposed to work like this?

 

Link to comment
Share on other sites

yes thats exactly how it it supposed to work and the script compiles, however the problem is that i cannot get the other hud to hear what the sensor is saying e.g. if i set it to standard channel it will come out Object: /9 off

i need the script to speak as me , however my scripting is not advanced enough to achieve this yet, i was hoping to have a little help getting the listener to recognise the sensor hud as owner

Link to comment
Share on other sites

i dont think you get what im saying

 

i have a hud that when i type /9off it turns off

im trying to make a script that will keep the hud on untill another avatar enters a certain range then the script will turn off the hud with the above command

the standard llsay or llwhisper doesnt work

as you can see from my code in OP

Link to comment
Share on other sites

OK, so you have a two-part problem.

To get the other HUD to hear your "on" or "off" message on channel 9, it has to have a listen handle that opens that channel (llListen(9,"","","") ) and it has to have a listen event in which the receiving HUD interprets the message and does something (presumably turns one of its functions on or off).  Unless the second HUD has those two components, the first one (your "sensor" HUD) will just be whispering into the wind.  

[ EDIT:  Ah!  OK, I missed seeing what you were getting at. So the other script already has that stuff in it.  Good.  In that case, try simplifying your sensor and no_sensor events to

sensor(integer num_detected){    llWhisper(9, "off"); // Turn off the hud}no_sensor(){    llWhisper(9, "on"); // Turn on the hud}

 Your variable named SomebodyNear isn't serving any useful purpose that I can see, and you don't need the extra llSay statements.  ]

BTW, it usually wise to use a high negative channel number when you have objects talking to each other. Avatars cannot communicate on negative channels, and the high number reduces to possibility of crosstalk.

As Dora says, you cannot make an object impersonate an avatar.  You can almost do that, though, by changing the HUD's name. 

llSetObjectName(llGetDisplayName(llGetOwner()));

When the HUD "speaks" in chat, the name next to the messge will be yours.  Any vaguely smart person receiving it will see that the message is in a different color, though, so it's clearly NOT coming from you. Still, it might fool an occasional person for a few seconds.

[More Edit --  I think you're not really talking about getting the HUD to impersonate you at all,  You just want the second HUD to listen to you, personally.  It should do that now unless it is set to listen to owner only.  Unfortunately, if that's the case you're stuck because that script is probably no-mod, so you can't change it.

  • Like 1
Link to comment
Share on other sites

integer SomebodyNear = 0;default{state_entry(){llSetTimerEvent(5.0);}timer(){llSensor("",NULL_KEY,AGENT,95,PI);}sensor(integer num_detected){    llWhisper(9, "off"); // Turn off the hud}no_sensor(){    llWhisper(9, "on"); // Turn on the hud}SomebodyNear = 0;}}

 this doesnt seem to work either

its something to do with the avatar key but really need help to script such a thing

yes yes i see however the hud responds to

/9 off in local , and will not respond to other avatars who use the same command so im thinking it has some kind of key specific to the owner how would i script this into what i have

 

riiight im sure then its set to listen to owner only, im a complete noob at this so thankyou for your help :)

Link to comment
Share on other sites


Ryuhei Chiung wrote:

[ .... ]

/9 off in local , and will not respond to other avatars who use the same command so im thinking it has some kind of key specific to the owner how would i script this into what i have

 

riiight im sure then its set to listen to owner only, im a complete noob at this so thankyou for your help
:)

Sorry.  In that case you really are out of luck.  Your best shot is to replace the script in the receiving HUD.  When you do that, you can build your sensor capability into it and save having an extra HUD.

Link to comment
Share on other sites

ok let me clarify ive been thinking about it again

so what im trying to do is set up a sensor HUD (HUD1)so if a avatar walks with set distance the sensor puts out a message in chat of /9off

the message would be going straight to a meter above the avatars head 

this meter is also controlled by a seperate hud (hud 2) that has a button on it that does the same thing /9off and the meter switches off

 

so therefore it cannot be scripted as listen to avatar only because it responds to the same command from HUD 2

any other ideas how i can solve this problem?

Link to comment
Share on other sites

How much is known about HUD2? Is it open source or something, such that we know it's simply chatting on channel 9 (and not doing anything tricky such as responding to a challenge from the meter)?

Is the meter only controlled by the HUD2 worn by the meter-wearer, specifically, and nobody else? (The meter could listen but then check the owner of the message-sending HUD2.) Or does anybody wearing a HUD2 already get to control every meter in the vicinity -- and if that, then we're just trying to add a sensor here?

Link to comment
Share on other sites

A simple DEMO ......  Create two plywood boxes

Script for Box A (name it "Sender"):

default{    touch_start(integer num)    {        llSay(9,"This is a message");    }}

 Script for Box B (name it "Receiver"):

default{    state_entry()    {        llListen(9,"",llGetOwner(),"");    }    listen (integer channel, string name, key id, string msg)    {        llSay(0,msg);    }}

 Click Box A.  Observe that nothing happens.  That's because the "Sender" is not the owner of Box B.  If you want Box B to repond, YOU have to type "/9 This is a message." in your own chat.  Then Box B will respond, because the message is coming from you.  There is nothing that you can do to Box A to make Box B listen.  The only way to make Box B listen (other than typing the message yourself) is to change its script to

default{    state_entry()    {        llListen(9,"","","");    }    listen (integer channel, string name, key id, string msg)    {        llSay(0,msg);    }}

 As I said earlier, though, you can't change Box B's script if it's no-mod. Your only option is to delete that script entirely and replace it with something else.  In the context of your immediate problem, something similar to this would work....

integer gSense = TRUE;default{    state_entry()    {        llListen(9,"",llGetOwner(),"");    }    listen (integer channel, string name, key id, string msg)    {        if (llToLower(msg) == "on")        {            llSetTimerEvent(5.0); //Turn timer on/off        }        else if (llToLower(msg) == "off")        {             llSetTimerEvent(0.0);        }    }    timer()    {        llSensor("","",AGENT_BY_LEGACY_NAME,96.0,PI);    }    sensor (integer num)    {        if (gSense)        {            gSense = FALSE;  // The variable in your original script does make sense here            // Do whatever your second HUD does now        }    }    no_sensor()    {        gSense = TRUE;        // Stop doing whatever your second HUD does now    }}

 That assumes you know what your second HUD does today and can duplicate that function where I left room for it above.  One of the nice things about being a scripter is that you can usually figure out your own way to do what some other scripter has already shown to be possible.  :smileywink:

 

 

 

Link to comment
Share on other sites

Am I correct in thinking that you are wearing two huds, a scanner/sender and a receiver, and you want your scanner/sender to communicated with your receiver hud and only that hud?

If that is the case,  there's two ways to do this.   The older way would be to have the receiver script listen on a channel and check that the id of whoever/whatever it heard from is that of its owner or something belonging to its owner.   Like this:

default{	state_entry()	{		llListen(9,"","","");  // listen on 9 for messages from anyone	}	listen(integer channel, string name, key id, string message)	{		if (id == llGetOwnerKey(id)){//if id is that of my owner or of something belonging to my owner,			// do stuff		}	}}

 The newer and better way is to use the function llRegionSayTo(id,channel, message).   This newish function has the advantage that messages you send with it to an avatar (id) are heard by anything that avatar is wearing, or sitting on, that is listening on that channel, and only items that avatar is wearing or sitting on.   Other objects listening on the channel don't hear the messages at all.

So if you did it this way, you would say, in the scanner/sender,

 

integer SomebodyNear = 0;key owner;default{	state_entry()	{		llSetTimerEvent(5.0);	}	attach(key attached)	{		owner = attached;	}	timer()	{		llSensor("",NULL_KEY,AGENT,100,PI);	}	sensor(integer num_detected)	{		if (SomebodyNear == 0)		{			llRegionSayTo(owner,9,"off");			SomebodyNear = 1;		}	}	no_sensor()	{		llRegionSayTo(owner,9,"on"); // Turn on the hud		SomebodyNear = 0;	}}

 

 However, I don't really see why you need two huds in that case.   I am a bit confused, still, having read this thread, what exactly is supposed to be happening and who is wearing what hud(s).

 

Link to comment
Share on other sites

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