Innula Zenovka Posted December 3, 2013 Share Posted December 3, 2013 AgEnTHuskey wrote: Explains what a state is fairly well, but it doesnt really give much help to someone who really doesnt know what they are doing. Im assuming I would need 2-3 states from what this says 1 as the default not doing anything but listening for command stage 1 in action phase to know when the collision can go off 1 turning off phase to return it to default? No clue how I would even start with that though. Let's start by looking at what you want to happen. As I understand it, you want to make a device that turns on and off. When it's off, nothing happens if you collide with it. When it's on, then if someone collides with it, it spits out steam for 15 seconds and then stops. That being the case, here's a possible basic skeleton for you, with lots of comments. You'll need to fill in the particle effects and so forth. integer chan = 3; //channel to listen onfloat interval = 15.0;//how long to steam for//nb I'm putting the numbers up here because it's easier to change them that way, rather than go looking for them in the script.key owner;default{ state_entry() { owner = llGetOwner(); // no need to keep on calling llGetOwner llListen(chan,"",owner,"");//listen to my owner on channel 3 //do stuff to stop steam, make object invisible and so on } listen(integer channel, string name, key id, string message) { message = llToLower(message);//so we're not worried about case if ("on" == message){ //if the message is "on" (or "ON" or "On") state running; // go to state running } } changed(integer change) { if (change & CHANGED_OWNER){ // if my owner changes owner = llGetOwner(); // you could call llResetScript but I try not to unless I want to clear all variables. llListen(chan,"",owner,""); } }}state running { state_entry() { llListen(chan,"",owner,"");//one of the drawbacks of using states is that listeners //don't survive state changes, so you have to re-declare it //also do stuff to stop steam, turn off glow and so on, because we'll be coming back here from state steaming //could turn them off in the timer event at the end of state steaming -- up to you } listen(integer channel, string name, key id, string message) { message = llToLower(message); if ("off" == message){ //if the message is "off" state default; // go to state default } } changed(integer change) { if (change & CHANGED_OWNER){ state default; // same effect as llResetScript for these purposes -- just getting the uuid of the new owner and changing the listener } } collision_start(integer total_number) { if (llDetectedType(0)&AGENT){//if it was an avatar who collided with me state steaming; // go to state steaming } }}state steaming { state_entry() { //it's showtime -- do particle stuff and whatever else you want llSetTimerEvent(interval); } timer() { llSetTimerEvent(0.0);//turn off timer state running; // go back to state running }} 1 Link to comment Share on other sites More sharing options...
AgEnTHuskey1488304671 Posted December 3, 2013 Author Share Posted December 3, 2013 Ok with some advice of friends and some stuff I learned so far here I made some changes to the script. integer active;integer has_permissions;string animation = "Lightning blade Animation";trigger(){ if(has_permissions)llStopSound(); llTriggerSound("Chidori Sound effects",1); }explosion(){ active = TRUE; if(has_permissions)llStartAnimation(animation); llSleep(0.4); llParticleSystem([PSYS_PART_FLAGS, PSYS_PART_EMISSIVE_MASK | PSYS_PART_INTERP_COLOR_MASK | PSYS_PART_INTERP_SCALE_MASK | PSYS_PART_FOLLOW_VELOCITY_MASK,PSYS_PART_START_COLOR, <1.0, 1.0, 1.0>,PSYS_PART_END_COLOR, <1.0, 1.0, 1.0>,PSYS_PART_START_SCALE, <.2,0.4,.3>,PSYS_PART_END_SCALE, <.4,1.0,.3>,PSYS_PART_MAX_AGE, .1,PSYS_SRC_ACCEL, <0.0,0.0,0.0>,PSYS_SRC_TEXTURE,"79936d24-b4dc-15a8-991d-b59e2b5c5019",PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE,PSYS_SRC_BURST_RATE, 0.01,PSYS_SRC_BURST_PART_COUNT, 13,PSYS_SRC_BURST_RADIUS, 0.0,PSYS_SRC_BURST_SPEED_MIN, 3.01,PSYS_SRC_BURST_SPEED_MAX, 3.01,PSYS_SRC_MAX_AGE, 0.0,PSYS_SRC_OMEGA, <0,0,0>,PSYS_SRC_ANGLE_BEGIN, PI_BY_TWO,PSYS_SRC_ANGLE_END, PI_BY_TWO]);llOwnerSay("Raikiri Activated"); llLoopSound("Chidori Looping Sound shorter", 1.0); llSleep(15.0); stopsteam();}stopsteam(){ active = FALSE; llParticleSystem([]); if(has_permissions)llStopAnimation(animation); llStopSound(); llResetScript();}default{ on_rez(integer t) { llResetScript();//reset so if the owner changes it will listen to the new one } attach(key id) { if(id == llGetOwner()) { llResetScript();//reset so if the owner changes it will listen to the new one } } state_entry() { llListen(3,"",llGetOwner(),""); llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION); } run_time_permissions(integer perm) { has_permissions = ((perm & PERMISSION_TRIGGER_ANIMATION) == PERMISSION_TRIGGER_ANIMATION); } listen(integer c, string n, key id, string m) { if(m == "raik") { explosion(); } } collision_start(integer t) { if(active == TRUE)//is active { if(llDetectedType(0) & AGENT) // is an avatar { trigger(); stopsteam(); } } }} Its scripted to only trigger if the collision is with an avatar and only if "TRUE" I'm assuming something is wrong with the way its done but I just cant seem to find the error /3raik should start it and send it to explosion() which is set as active = TRUE; then it will do a messload of other things and after 15 seconds it will go to stopsteam() which is set to active = FALSE; and does things needed to turn it off. my only problem is when I type that command the collision ability isnt starting up with the rest of it (it should be turned on when everything goes on and turned off after the 15 seconds like everything else) and the entire script works exactly the way I want it to beside the collision. Anyone possibly able to point out where I went wrong? Link to comment Share on other sites More sharing options...
Rolig Loon Posted December 3, 2013 Share Posted December 3, 2013 Aha. The problem is subtle, but one that we discuss here fairly often. Your script is a good example of why we should avoid using llSleep unless absolutely necessary. That function does exactly what it says: it puts the entire script to sleep for the period that you have designated -- 15 seconds. During that time, the script will not respond to anything -- messages, touches, collisions, ... anything. There are times when you may actually want to do that, but they are pretty rare and this is definitely not one of them. Usually, you simply want to have a clock ticking away in the background and then triggering some action when it reaches a target time. You use a timer event for that. So, instead of ending your eplosion function with llOwnerSay("Raikiri Activated"); llLoopSound("Chidori Looping Sound shorter", 1.0); llSleep(15.0); stopsteam();} Try writing llOwnerSay("Raikiri Activated"); llLoopSound("Chidori Looping Sound shorter", 1.0); llSetTimerEvent(15.0);} And then adding a timer event in state default that says timer(){ llSetTimerEvent(0.0); //turn the timer off stopsteam();} The little 0.4 second llSleep in your explosion function is less problematic, because in this case you don't expect anything to happen during that tiny interval. Personally, I would get rid of it, because I can't see that it's doing anything useful, but it's not harming anything either. 1 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