Jump to content

Help with HUDs


Loki Eliot
 Share

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

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

Recommended Posts

I want to make a HUD button that when pressed activates an animation from an attached object, eg. Weapon, wizard staff, etc. I'm only a basic scripter as in I cut and paste and hope it works.

Can any script ors point me in a direction to achieve This function? What sets of actions should I be concentrating on?--||-
Link to comment
Share on other sites

Ok - let's take it step by sep - I don't know what your level is.

  1. You need communication - since it's unlinked objects, it's gonna be chat. The objects communicating have to use the same channel - best you use a big number and make it negative
  2. To keep it simple at first, I would say, just do a one way commuication HUD to object. The object needs to have a listener llListen in order to hear the HUD - and it has to listen to the channel talked about earlier
  3. The HUD needs to say or whisper (llWhisper)something at the button touch - something like "play staff anim" - again on the predfined channel
  4. the object (let's take the staff example) needs a listen event where ii checks if the messages heard is the right one:
    if(m,essage == "play staff anim")
  5. if it is the right messages, we know that it's time to play the anim. In order to do so, the staff needs the permission to play the anim. The staff could ask for permission as soon as it gets attached - so in the attached event, it could do the
    llRequestPermissions(AvatarID, PERMISSION_TRIGGER_ANIMATION)
    
  6. If successful, this will trigger the run_time_permissions event which you can use to set a flag telling you that permission has been granted.
  7. now back to our listen event - if you set a flag, you can now do a llStartAnimation after checking if the permission flag is set - or you could just try to play it at the risk that you'll get an error if there had been a problem with the permissions#

 

That's ust a simple example - the are many variations which all have different pros and cons. E.g. you could actually play the animation right from the HUD - but in this case ou might wanna check if the object an animation is associated with is attached.

Link to comment
Share on other sites

as for your first question:

there are ways to make integer dynamic but yet predictible - you can make an integer based on the owners key - e.g.:

giChan = (integer)("0x" + llGetSubString(llGetOwner(), 0, 7)) * -1;

 This way you would get an integer for the channel that is the same in the HUD and the staff but different from your friend's channel.

Additionally or alternatively, you could check for the owner's key:

listen(integer channel, string name, key id, string message) {    	if(llGetOwnerKey(id) == llGetOwner()) {    		...    	} }

 as for your other question:

Do it either in the HUD or the object. As I've said - there are advantages to both. I would prefer (in most cases) to keep as much of the scripts and stuff in one place - but there are reasons like the fact that you don#t want a animation for a staff if the staff is not attached, that are handled more easily if the playing of the animatons is left to the objects themselves

  • Like 1
Link to comment
Share on other sites

I would like if possible to have it so the HUD will work with any staff i make, so if i make a green on or a blue one, the user can use the HUD with either.

Thanks your your response although you lost me at 'here are ways to make integer dynamic but yet predictible'.

Can you point me towards any script examples already available either in script library or on market place?

Link to comment
Share on other sites

What I wanted to say in the part where I lost you is: You can calculate a channel number fom the owner's key. I will be the same. If you use smothing like:

giChan = (integer)("0x" + llGetSubString(llGetOwner(), 0, 7)) * -1;

in your objects, the integer giChan would be the same everywhere - and it would be different from that of another ava, since it is based on the key. Here is a little example for you. First the staff:

string gsAnimName = "wield staff";default {	attach(key id) {		if (id != NULL_KEY) { //check if the staff has got attached, not detached			llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION); //request permission to play an animation			integer iChan =  (integer)("0x" + llGetSubString(llGetOwner(), 0, 7)) * -1; //compute a channel number based in the key of theowner			llListen(iChan, "", "", ""); //listen for the owner		}	}		listen(integer channel, string name, key id, string message) { //message come in on the defined channel		if (message == "play staff animation") { //check if the contents is correct			if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) { //check if permission has been granted properly				llStartAnimation(gsAnimName); //play animation			} else {				llOwnerSay("There is something wrong with the permissions - animation can't be played.");			}		}	}}

 This would be the script for the HUD button

integer giChan;default {	attach(key id) {		if (id != NULL_KEY) { //check if the HUD has got attached, not detached			giChan =  (integer)("0x" + llGetSubString(llGetOwner(), 0, 7)) * -1; //compute a channel number based in the key of the owner		}	}		touch_end(integer num_detected) {		llWhisper(giChan, "play staff animation"); //say the defined comand for playing the animation	}}

 I hope that very simple example will point you in the right direction.

Link to comment
Share on other sites

Good point, Cerise.  One way to beat that would be to write

attach(key id) {		if (id != NULL_KEY) { //check if the staff has got attached, not detached                        llListenRemove(gLisn);			llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION); //request permission to play an animation			integer iChan =  (integer)("0x" + llGetSubString(llGetOwner(), 0, 7)) * -1; //compute a channel number based in the key of theowner			gLisn = llListen(iChan, "", "", ""); //listen for the owner		}	}

 remembering to declare gLisn as a global integer variable, of course. 

Link to comment
Share on other sites

Ok after playing around a bit ive discovered that if i simply GIVE someone my new HUD, im somehow able to control their HUD. If i place the HUD in a box and set it so my friends can click the box and receive a copy of the HUD, then all seems fine and i dont control their HUD. Very odd permissions thing going on.

 

Again thank you all for such amazing help :)

Link to comment
Share on other sites

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...