Jump to content

trying to write a script to work a script i bought


MishkaKatyusha
 Share

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

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

Recommended Posts

bit of an odd one,im trying to make an unguided rocket battery that will spew one rocket in the direction the object is facing when the owner says "fire_missile"

but im having a very difficult time here.see i bought a missile script that came with a free missile,im trying to figure out what phrase spoken over the linkset will trigger it

 

integer fireable;
integer ccc = 0;
default
{
    state_entry()
    {
        llListen(1, "", "", "");
//        llListen(2, "", "", "");        
    }

    on_rez(integer params)
    {
        llListen(1, "", "", "");
//        llListen(2, "", "", "");        
    }
    sensor(integer num_targets)
    {
            vector pos;
            rotation rot;
            rot = <0.00000, 0.70711, 0.00000, 0.70711>;
            rot *= llGetRot();
            pos = llGetPos();            
            llRezObject("Missile", pos + <0,0,2>, ZERO_VECTOR, rot, 1);
//            llMessageLinked(LINK_SET, 0, "sensor", NULL_KEY);
            llSleep(0.2);
            if(llDetectedKey(0) != llGetOwner())
            {
                llShout(2000, llDetectedName(0));
                llSay(0, "Locked onto target: " + llDetectedName(0));
            }
            else if(llDetectedKey(1) != NULL_KEY)
            {
                llShout(2000, llDetectedName(1));
                llSay(0, "Locked onto target: " + llDetectedName(1));
            }
            else
            {
                llSay(0, "No Targets to Lock On To.");
            }
            fireable = 0;
        
    }
    no_sensor()
    {
        llSay(0, "No Targets to Lock On To.");
        fireable = 0;
    }
    listen(integer chan, string name, key id, string msg)
    {
        if (llToLower(msg) == "arm" && id == llGetOwner() && ccc == 1)
        {
            llOwnerSay("Missile Armed");
            fireable = 1;
            llMessageLinked(LINK_SET, 0, "arm", "");
        }
        else if (llToLower(msg) == "arm2" && id == llGetOwner() && ccc == 1)
        {
            llOwnerSay("AG Missile Armed");
            fireable = 2;
            llMessageLinked(LINK_SET, 0, "arm", "");
        }
        
    }
    link_message(integer sender, integer number, string msg, key id)
    {
//        vector pos;
//        rotation rot;
 //       llOwnerSay(msg);

        if(msg == "fire_missile" && fireable == 1 && ccc == 1)
        {
            llSensor("", "", AGENT, 96.0, (12 * DEG_TO_RAD));
//            rot = <0.00000, 0.70711, 0.00000, 0.70711>;
//            rot *= llGetRot();
//            pos = llGetPos();            
//            llRezObject("Missile", pos + <0,0,2>, ZERO_VECTOR, rot, 1);
//            llMessageLinked(LINK_SET, 0, "sensor", NULL_KEY);
//            fireable = 0;
        }
        else if(msg == "fire_missile" && fireable == 2 && ccc == 1)
        {
            vector pos;
            vector vel;
            rotation rot;
            rot = llGetRot();
            vel = llRot2Fwd(rot); 
            pos = llGetPos();               
            pos += <0,0,-2>;
            vel = vel * 40.0;
//            pos = llGetPos();            
            rot = <0.00000, 0.70711, 0.00000, 0.70711>;
            rot *= llGetRot();

            llRezObject("AGMissile", pos, vel, rot, 1);

        }
        else if(msg == "ccc_on")
        {
            ccc = 1;
        }
        else if(msg == "ccc_off")
        {
            ccc = 0;
            fireable = 0;
        }

    }
}

now,im trying to guess what will work,and thus have tried to make a script by modifying something i got off the wiki.my attempt has gone very badly

//  Opens two listen handles upon touch_start and
//  stops listening whenever something heard passes either filter


string fireable;
string  ccc;
integer listenHandle_a;
integer listenHandle_b;

remove_listen_handles()
{
    llListenRemove(listenHandle_a);
    llListenRemove(listenHandle_b);
}
 
default
{
    touch_start(integer num_detected)
    {
        key    id   = llDetectedKey(0);
        string name = llDetectedName(0);
 
        listenHandle_a = llListen(5, "", id, "");
        listenHandle_b = llListen(6, "", NULL_KEY, "");
 
        llSay(0, "Listening now to '" + name + "' on channel 5.");
        llSay(0, "Listening now to anybody/anything on channel 6.");
    }
 
    listen(integer channel, string ccc, key id, string fireable)
    {
       
 
        
        //Modification by MishkaKatyusha,January 22,2016 at 5:32 A.M. CST,United States
        if (channel == 6){
            llMessageLinked(LINK_SET,0,"fire_missile" + (string)  fireable,1 + (string)  ccc);
        }
        remove_listen_handles();
    }
}

aside from the fact that i keep on getting function call errors and type mismatch when i try to save this.it may very well be that im not doing this properly

now please.im not trying to be annoying or disrespectful.i just want to write a little dolty thing where i can say "/6 fire_missile" and it will shoot the thing

 

Link to comment
Share on other sites

default{    state_entry()    {       // llSay(0, "Hello, Avatar!");    }    touch_start(integer total_number)    {        llMessageLinked(0,0,"ccc_on",NULL_KEY);       // llMessageLinked( integer link, integer num, string str, key id );            }}

http://wiki.secondlife.com/wiki/LlMessageLinked

ADDED. https://code.google.com/p/lsl-code-library/source/browse/trunk/weapons/Missile+Script.lsl?r=11

Its old, rubbish and a mess.

Link to comment
Share on other sites

Instead of trying to rewrite scripts that you find lying around on the Internet -- most of which are poorly written or at least inappropriate for your own needs -- I suggest writing your own from scratch. There is some advantage to looking at other people's scripts for motivation and as examples (good or bad), but retrofitting someone else's work is an exercise in frustration.  No two scripters will approach a project with exactly the same logic in mind, or with the same experiences to draw on.  Your own work will be better in the end if you do it yourself.

in this case, all you really need to know is how to use llRezAtRoot.  Study the LSL wiki briefly. You rez a physical object at ground zero ( llGetPos() ) and then use the velocity parameter to give it a shove in the direction that you want it to go.  If you always want the rezzed object to move in the direction that the object is facing (it's own +X direction), then your velocity vector is <X, 0.0,0.0>*llGetRot(), where X is as big as you need it to be to get the object moving at the speed you want. The object's initial rotation parameter can be ZERO_ROTATION.  Put that llRezAtRoot statement in a listen event, where it will be triggered when it hears your secret launch message, and you're all done. (Don't forget to open the listener with a llListen statement in your state_entry event.)  If you write those few simple commands, you will have a basic launcher in fewer than 15 lines of code.  Then you can start adding bells and whistles to make it pretty if you want.

Link to comment
Share on other sites


steph Arnott wrote:

No dissrespect, but those things need a self deleting code. Nothing more annoying than filling a sim with junk.

Quite true, Steph.  The easy, no-script solution is to make the projectiles temp_on_rez so that they vanish within a minute.  If you want to get fancier, you can put a little time in the object that starts on rez and kills the thing a few seconds later. Neither of those solutions affects the basic rezzer script, of course, although they are smart cleanup steps. :smileywink:

Link to comment
Share on other sites

:D:D:D

well well,i did what you said,

had very little idea of what a listen event was,so i tryed looking at the wiki

everything was going well until i attempted to add your "rezatroot" thing

and then it said that the "Default" was "syntax error" when i tryed to put it all together

fast foward afew hours later and my futile attempts to fix and this is what i have at the moment

 

default       {    state_entry()    {          listen_handle = llListen(5, "", llGetOwner(), "");    }     listen( integer channel, string name, key id, string message )    {    }       link_message( integer number, integer name, string target, key id )           if(number == 0){         llRezAtRoot(object, rezPos, rezVel, rezRot, startParam);                llListenRemove(listen_handle);    }     changed(integer mask)    {   //Triggered when the object containing this script changes owner.        if(mask & CHANGED_OWNER)        {            llResetScript();   // This will ensure the script listens to the new owner, and doesn't continue listening to the creator.        }    }}

i cant fathom how default could be syntax error

Link to comment
Share on other sites

Nice try.  OK, you have some extra stuff that got in there from somewhere, like

   }       link_message( integer number, integer name, string target, key id )           if(number == 0){

right in the middle of your listen event.  And

       llListenRemove(listen_handle);

,  which you probably don't want to do, unless you only plan to listen to the trigger message one time. That extra bit of stuff not only doesn't belong in your script in the first place, but it also messed up your matching brackets { }, which is why the compiler said that default was the error. Removing those things will go a long way toward clearing up the syntax errors, but not all the way.  Next, you need to tackle the llRezAtRoot statement.  Look back at what I wrote in my post.  You have

         llRezAtRoot(object, rezPos, rezVel, rezRot, startParam);

but you haven't defined what any of those parameters in the parentheses are yet.  Fortunately, you know what they are, because I put them in that post.  "object" is the name of whatever you plan to rez.  "rexPos" is the location where you plan to rez it.  "rezVel" is the velocity you want to give it when it rezzes.  "RezRot" is the rotation you want it to have.  And "startParam" is any number you want to send the object as it rezzes (You don't really care, because you won't use it, so pick any number.).  Once you fix those missing bits of information, your script should work.

The only other thing I might suggest is that you pick a trigger word you want it to listen for.  Otherwise, it will respond to any word you send on channel 5 (which may be exactly what you want).  There are a couple of ways to listen for that specific word.  Perhaps the simplest is to add it to the llListen statement in your state_entry event:

        listen_handle = llListen(5, "", llGetOwner(), "SecretWord");

 

So there's your working script. Now you can start adding things to make it pretty.  BTW, that changed event is a nice touch if you plan to give the script to someone else, but not necessary otherwise.

  • Like 1
Link to comment
Share on other sites

very good,

 

i understand the idea of "mutually exclusive"

much appreciation

that link message was written by me.see,i had no idea at first the way the script was would respond without the other script

had no idea this was an "all in one punch" thing,ill get right to work on that after my coffee

this is another reason why i like SL,i can see how you earned you rank,and my respect

Link to comment
Share on other sites

hmm.things are going well with the redesign so far,no script errors yet (thought its going a wee bit slow)

but,i decided to check out the script of the missile object itself *which came with the erstwhile garbage script that steph pointed out)

and im abit worried,because it looks quite similar to the script that it came with

 

does this have to be rewritten to?

string name;integer chan = 2000;vector tgt;integer blah;integer lstn;Launch(){      llLoopSound("rocket-transit", 2.0);    llParticleSystem([        PSYS_PART_FLAGS, PSYS_PART_INTERP_COLOR_MASK | PSYS_PART_INTERP_SCALE_MASK,                PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_DROP,                PSYS_PART_START_COLOR, <1, 1, 1>,        PSYS_PART_START_ALPHA, 1.0,        PSYS_PART_START_SCALE, <.1, .1, 0>,        PSYS_PART_END_SCALE, <.25, .25, 0>,        PSYS_PART_END_ALPHA, 0.0,                PSYS_SRC_BURST_RATE, .01,        PSYS_SRC_BURST_PART_COUNT, 150,                PSYS_SRC_TEXTURE, "smoke",                PSYS_PART_MAX_AGE, 3.0    ]);}explode(){    llTriggerSound("exp1", 10.0);    llTriggerSound("exp2", 10.0);    llTriggerSound("exp3", 10.0);    llTriggerSound("qwk1", 10.0);    llRezObject("flareburst", llGetPos() + <0,0,0>, ZERO_VECTOR, ZERO_ROTATION, 1);    llRezObject("smoker", llGetPos() + <0,0,0>, ZERO_VECTOR, ZERO_ROTATION, 1);    llRezObject("lineplasma", llGetPos() + <0,0,0>, ZERO_VECTOR, ZERO_ROTATION, 1);    llRezObject("smoke1", llGetPos() + <0,0,0>, ZERO_VECTOR, ZERO_ROTATION, 1);    llRezObject("smoke2", llGetPos() + <0,0,0>, ZERO_VECTOR, ZERO_ROTATION, 1);    llRezObject("Glow", llGetPos() + <0,0,0>, ZERO_VECTOR, ZERO_ROTATION, 1);    llRezObject("smoke3", llGetPos() + <0,0,0>, ZERO_VECTOR, ZERO_ROTATION, 1);    llTriggerSound("qwk1", 10.0);    llTriggerSound("qwk1", 10.0);    llDie();}default{    state_entry()    {        llSetBuoyancy(1.0);//        lstn = llListen(chan, "", "", "");    }    on_rez(integer start_params)    {        llSetBuoyancy(1.0);        lstn = llListen(chan, "", "", "");        llSetTimerEvent(5);    }    listen(integer channel, string name, key id, string msg)    {        if(llGetOwner() == llGetOwnerKey(id))        {                llSetTimerEvent(0);                llSetStatus(STATUS_PHYSICS, TRUE);                Launch();                llSensorRepeat(msg, "", AGENT, 96.0, TWO_PI, 0.5);                llListenRemove(lstn);                                llSetTimerEvent(0);        }    }    timer()    {        llDie();    }       sensor(integer total_number)    {        integer hits;        tgt = llDetectedPos(0);        llSetPos(tgt);        if(llVecDist(llGetPos(), tgt) > 4.0)        {            llLookAt(tgt, 1.0, 0.1);            llMoveToTarget(tgt, 0.2);        }        else        {            for(hits = 0; hits < 4; hits++)            {                llShout(393939, "ccc_hit" + llDetectedName(0));                llShout(532254, llDetectedKey(0));                llShout(696969, llDetectedKey(0));            }            llStopMoveToTarget();            llSetStatus(STATUS_PHYSICS, FALSE);            llStopSound();            llParticleSystem([]);            llSensorRemove();            explode();        }    }    collision_start(integer numtimes)    {        integer type = llDetectedType(0);        integer hits;        if(type & SCRIPTED)        {            for(hits = 0; hits < 4; hits++)            {                llShout(532254, llDetectedKey(0));            }        }    }}

 

just tell me which parts to remove 

Link to comment
Share on other sites

o.O that is seriously above my skillgrade

things are going ok,and i determined (by removing the missile object,trying the fire command,and getting the script error) that the script ive got is most definitly receiving the fire command

what i cant figure out yet is where exactly i need to insert the various little tidbits of code that rolig gave me in that post,everytime i try and insert them into the llrezatroot line,i get errors all over the place

i suspect it has something to do with the little orange bits of text that sit above the llrezatroot line in the same listen block,like the vector lines and so on

but my efforts to create those have been going very slowly so far

i even made my own "missile" as it were,basically just a round glowing sphere (im trying to make it look like its made of plasma,turns out that wasnt hard to do)

being unsure as to whether the previous "missile" that i indicated was compatible or not,i made the glowing sphere to replace it.

anywho,while i appreciate that big script you made.and it does look beautiful to my eyes.quite frankly it looks more complicated than heiroglyphics.this might seem annoying or idiotic to you,but look at it from my point of veiw,i am not even by the wildest exxageration an experienced scripter,you however are.and so what would seem trivial or common sense to you would make hardly any sense to the new-comers

 

Link to comment
Share on other sites

Fin

EDITED. some logic. Help if i remember it 2016 and not 2015, lol

//untested, writen by Steph Arnott 23/01/2016 tested and functions as expected. 0.0005ms idle 0.001 running//Mak a HUD, put script in, call your missile "whatever" without the "". //write the impulse script to go in the missileinteger menu_chan;integer menu_chan_handle;list options = ["Rezz missile", "Fire"];key owner_id;integer my_chan = 5;//vector vel    = <10, 0.0,0.0>;string msg2 = "whatever";vector offSet = <2.0, 0.0, 0.0>;//change to were you want it to rezz to be 2meters away at thisdefault{	changed(integer ch)	{		if(ch&CHANGED_OWNER)		{			llResetScript();		}	}	state_entry()	{		llSetObjectName("Main");		menu_chan =(integer)llFrand(-10000)-100;		owner_id  = llGetOwner();			}	touch_start(integer total_number)//as HUD 	{		menu_chan_handle = llListen(menu_chan, "", owner_id, "");		llDialog(owner_id, "Choose an option ", options, menu_chan);		llSetTimerEvent(20.0);	}	listen( integer channel, string name, key id, string msg )	{		if(msg == "Rezz missile" || msg == "Fire")		{			if(msg == "Rezz missile")			{				//info();				llOwnerSay("test 1");				vector sumPos       =     llGetPos();				rotation sumRot     =     llGetRot();				vector agent        =     llGetAgentSize(owner_id);				vector test         =     sumPos - agent / 2;//will rezz at feet hight.				vector Adjpos       =     test + offSet * sumRot;//ADDED 2.0 m offSet				vector speed        =     ZERO_VECTOR;				rotation rot        =     sumRot * llEuler2Rot(<0.0,0.0,PI>);//need adjusting for angle, also can angle the missile				integer startParam  =     llGetStartParameter();				llRezAtRoot(msg2, Adjpos, speed, rot, startParam);			}			else if(msg == "Fire")			{				llSay(my_chan,"go");			}		}		llListenRemove(menu_chan_handle);	}	timer()	{		llListenRemove(menu_chan_handle);		llSetTimerEvent(0.0);		llResetScript();	}}//end

. Personaly i thought that i wrote the math easy to understand.

Link to comment
Share on other sites

YAY!!!!!!!!!!!!!!

i could hug and kiss you you brilliant person you

you have my eternal grattitude

looking at your script for about half an hour,i realized what mine was missing,but i put in some snippets based on how yours looked,and it worked like magic,i set the velocity number abit too low (but thats easy to fix,love math,not so good at programming xD)

here is this beauty (or simple minded curmudgeon,but im quite happy)

string object = "Missile"; vector placement = <2.0, 0.0, 0.0>;vector velocity = <1.0, 0.0,0.0>; rotation spin = ZERO_ROTATION; integer startParam = 10;integer listen_handle;   //Completed by MishkaKatyusha(Grace Ann Ashcraft) on january 23,2016 
at 3:37 a.m. CST,United States. Major Thanks to Steph Arnott,Rollig Loon,
and all others who contributed to this workdefault{ state_entry() { //Registers the listen to the owner of the object at the moment of the call. This does not automatically update when the owner changes. // Change 0 to another positive number to listen for '/5 hello' style of chat. listen_handle = llListen(5, "", llGetOwner(), "fire"); } listen( integer channel, string name, key id, string message ) { llOwnerSay("Firing"); vector velocity = ZERO_VECTOR; vector placement = llGetPos(); rotation spin = llGetRot(); integer startParam = llGetStartParameter(); llRezAtRoot("Missile", placement, velocity, spin, startParam); } changed(integer mask) { //Triggered when the object containing this script changes owner. if(mask & CHANGED_OWNER) { llResetScript(); // This will ensure the script listens to the new owner, and doesn't continue listening to the creator. } }}

here is the screenshot



 

Link to comment
Share on other sites

Congratulations!  You have written the script that I described.

Now:

1. Throw away that script you got from the Internet.

2. Start doing the tutorials.

3. Write your next script from scratch, not by rewriting someone else's script.  Try something nice and simple.

:smileywink:

Link to comment
Share on other sites

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