|
Katoomi Yoshikawa
Registered User
Join date: 17 May 2007
Posts: 22
|
01-13-2008 06:04
I am looking for a script that will allow me to activate a particle effect when a key is pressed down, but stop it when the key is released. I want to use this script on the movement keys WAS and D. The only way I know how to make something happen is from voice commands using.. if(message=="command name"  I assume there must be something along the lines of.... if(keydown=="w" Or better still... while(keydown=="w"  etc... Is there anything like that??? Thanks!!! ^^KAT IM Katoomi Yoshikawa PS... I would also like to know how to do the same thing with a HUD button, so that someone can click a button to get the script to run rather than having to say something in chat.
|
|
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
|
01-13-2008 06:17
You want to take a look at the control() event. Unfortunately this is a bit more complicated than listen(), but it's not too hard. You will have to obtain permission to take controls first.
Hold on and I will write you a quick example.
_____________________
http://ordinalmalaprop.com/forum/ - visit Ordinal's Scripting Colloquium for scripting discussion with actual working BBCode!
http://ordinalmalaprop.com/engine/ - An Engine Fit For My Proceeding, my Aethernet Journal
http://www.flickr.com/groups/slgriefbuild/ - Second Life Griefbuild Digest, pictures of horrible ad griefing and land spam, and the naming of names
|
|
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
|
01-13-2008 06:21
integer WASD = 0; integer gRunning = FALSE;
default { state_entry() { // This bit is just a shortcut to save time later // since we don't care exactly which control was pressed WASD = CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_RIGHT; // Ask for permission to take controls if (llGetAttached()) { llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS); } }
on_rez(integer p) { llResetScript(); }
run_time_permissions(integer perms) { if (perms & PERMISSION_TAKE_CONTROLS) { // We have permission, so take controls // but let them also act normally to move the av llTakeControls(WASD, TRUE, TRUE); } }
control(key id, integer level, integer edge) { // This event will fire whenever we have taken controls // and the owner presses or releases WASD if (level & edge & WASD && !gRunning) { // Started pressing a control, effect not running llSay(0, "Particle effect starting"); gRunning = TRUE; } else if (~level & edge & WASD && gRunning) { // Stopped pressing controls, effect running llSay(0, "Particle effect stopping"); gRunning = FALSE; } } }
_____________________
http://ordinalmalaprop.com/forum/ - visit Ordinal's Scripting Colloquium for scripting discussion with actual working BBCode!
http://ordinalmalaprop.com/engine/ - An Engine Fit For My Proceeding, my Aethernet Journal
http://www.flickr.com/groups/slgriefbuild/ - Second Life Griefbuild Digest, pictures of horrible ad griefing and land spam, and the naming of names
|
|
Katoomi Yoshikawa
Registered User
Join date: 17 May 2007
Posts: 22
|
THANKS!!! it works! 
01-13-2008 06:41
Wow.. that was much more complicated than I expected.. I thought it would be a single line and actually felt silly asking!! I just tried it and it works I want something different to happen depending on which key is pressed.. but I think i can figure that out just by splitting it up for each key! Thank you so much that's really helped my new build look much more realistic  And that was a seriously fast reply too!! Nice one!!
|
|
Katoomi Yoshikawa
Registered User
Join date: 17 May 2007
Posts: 22
|
How do I use a different key?
01-13-2008 13:50
Everythign on thw script is working great and i have made all the adjustment I need for my build so far...
But.... I also want to make something happen when the R key is pressed down. I've been trying to find how to use keys which are not on the standard CONTROL command and can't find any reference to it or figure it out. I did try to guess at the value and use that.. i found a few responces from various keys but not the one i wanted.
Is there some kind of keyboard map to do this with each key being assigned a specific value? If not.. how do I make an event happen on other keys, that do not usually control anything in game.
Thanks!
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
01-13-2008 14:36
From: Katoomi Yoshikawa ...how do I make an event happen on other keys, that do not usually control anything in game. You can't, really. Choices are pretty limited. You can use the standard up, down, forward, backward, rotate left, rotate right, left, and right controls. You can detect whether always run (CTRL-R) and/or fly (F) is on, and change behavior based on that. You can use gestures to translate F-key combinations into chat commands (though you don't get the granularity of control input--in particular, you can't detect when the keys are released unless maybe holding down the keys repeats the gesture, which I'm not sure of). You can use the mouse buttons. You can use mouse touches on HUD controls as further inputs or to change the state of the key input behaviors. But so far as I know you cannot use arbitrary key presses unless you have a custom viewer. A custom viewer could translate any key press/release into a chat command. But it's not likely a solution that will work well for most applications. 
|
|
Katoomi Yoshikawa
Registered User
Join date: 17 May 2007
Posts: 22
|
01-13-2008 22:10
Thanks for the info.. I guess i can simply put the other actions I want into a listen command and use the chat channel. At least that way the item will not keep asking for permission! ...or on a hud button. I should stick to building.. it's much much easier than trying to get my head around scripting... I know a little javascript and its so frustrating knowing how easy what i want to do would be in that!
Thanks again, KAT^^
|