Loki Eliot Posted July 2, 2011 Share Posted July 2, 2011 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 More sharing options...
Ciaran Laval Posted July 2, 2011 Share Posted July 2, 2011 You're going to want to look at starting and stopping animations, a good starting point is llStartAnimation: http://lslwiki.net/lslwiki/wakka.php?wakka=llStartAnimation Take note of the good practice of using llGetPermissions and there's a link to an example there too. Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted July 2, 2011 Share Posted July 2, 2011 Ok - let's take it step by sep - I don't know what your level is. 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 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 The HUD needs to say or whisper (llWhisper)something at the button touch - something like "play staff anim" - again on the predfined channel 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") 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 thellRequestPermissions(AvatarID, PERMISSION_TRIGGER_ANIMATION) 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. 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 More sharing options...
Loki Eliot Posted July 2, 2011 Author Share Posted July 2, 2011 Thanks for that. Looking at your approach, what would stop the HUD controlling someone else's staff. As in if i give a copy of my staff to a friend, would my HUD control his staff as well? Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted July 2, 2011 Share Posted July 2, 2011 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 1 Link to comment Share on other sites More sharing options...
Loki Eliot Posted July 2, 2011 Author Share Posted July 2, 2011 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 More sharing options...
Darkie Minotaur Posted July 2, 2011 Share Posted July 2, 2011 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 More sharing options...
Qie Niangao Posted July 2, 2011 Share Posted July 2, 2011 I haven't tried this, so it may be all wrong, but shouldn't llRegionSayTo(llGetOwnerKey(), ...) be useful for messaging between attachments of the same agent? Link to comment Share on other sites More sharing options...
Loki Eliot Posted July 3, 2011 Author Share Posted July 3, 2011 Thank you SO SO much for your help. I have managed to apply your example to my objects to get exactly what i've desired Link to comment Share on other sites More sharing options...
Loki Eliot Posted July 7, 2011 Author Share Posted July 7, 2011 an odd behaviour has occurred. Other people can use my HUD fine without effecting each others weapons.... but when i use the HUD i end up controlling EVERYONEs weapons. Its very odd. Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted July 7, 2011 Share Posted July 7, 2011 are you using the scripts postd here? Link to comment Share on other sites More sharing options...
Rolig Loon Posted July 7, 2011 Share Posted July 7, 2011 If yopu used the scripts that Darkie posted, they should be creating a listen channel that's based on the owner's UUID. That should therefore be different for each person who's wearing a device. Link to comment Share on other sites More sharing options...
Cerise Sorbet Posted July 7, 2011 Share Posted July 7, 2011 I do not see where the posted scripts release old listeners or get reset. Are they piling up on every attach, listening to old and new owners alike, waiting for "too many listens" errors to happen? Link to comment Share on other sites More sharing options...
Rolig Loon Posted July 7, 2011 Share Posted July 7, 2011 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 More sharing options...
Darkie Minotaur Posted July 7, 2011 Share Posted July 7, 2011 That's exactly what I was aiming at - the two little scripts were intended to demonstrate one point - and not as ready to use scripts Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted July 8, 2011 Share Posted July 8, 2011 Depending on what Loki does in the rest of the script, it may even be to just reset the script on attach. Link to comment Share on other sites More sharing options...
Loki Eliot Posted July 8, 2011 Author Share Posted July 8, 2011 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 More sharing options...
Darkie Minotaur Posted July 8, 2011 Share Posted July 8, 2011 What Cerise said is still true - if you have taken my example as it is and used it as the basis of your HUD, you night run into problems. Im may be a good idea to post the code (for the object) here to have it fixed. Link to comment Share on other sites More sharing options...
Recommended Posts
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