Advertisement
Guest User

Untitled

a guest
Aug 4th, 2017
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
LScript 26.40 KB | None | 0 0
  1. // Pistol Script (Open Source) v1.0.0
  2. // Author: Code Slacker
  3. // Description: This script operates a normal pistol with single fire and burst fire modes.
  4.  
  5. // ==== NOTES ====
  6. // - The reason this script will require slave scripts is because it will be more responsive on fast mouse clicks. Otherwise there would be a 0.1 second delay, which bugs me. :p
  7.  
  8. // - Linked Message number will correspond to the following: -1 for the animation script and casing scripts, 0 for the bullet name, velocity and distance settings, and any number higher will be the number of the bullet slave script
  9.  
  10. // - Linked Messages:   "f" is fire for the slave and casing scripts
  11. //                      "f" on -2 is for any muzzle flash scripts to start
  12. //                      "nf" on -2 is for any muzzle flash scripts to stop
  13. //                      "r" is reload for the animation script
  14. //                      "stop" is for the animation script to stop if running
  15. //                      "reset" is for resetting the animation and casing scripts (animation script will start)
  16. //                      "crouch" is for the animation script to start the crouching animation
  17. //                      "nocrouch" is for the animation script to stop the crouching animation
  18. //                      "effectsoff" is for setting the casing scripts to not eject shell casings
  19. //                      "effectson" is for setting the casing scripts to eject shell casings
  20.  
  21.  
  22.  
  23.  
  24. // ==== FORMAT ====
  25. // - All global variables will have a "g_" at the beginning of their name
  26. // - All global variables will be in camelcasing (eg. g_thisVar)
  27. // - All constants will be all in uppercase, excluding the beginning "g_"
  28. // - All local variables will be in lowercase and have underscores ("_") to separate words (eg. integer local_variable;)
  29. // - Subprocedures will be in camelcasing and exclude a "g_" at the beginning of their name
  30. // - All functions - subprocedures that require input or return output, will be in camelcasing, exclude the "g_" but instead have a "func" at the beginning of their name to distinguish them from normal subprocedures (eg. funcFunkTown)
  31.  
  32.  
  33.  
  34. // ==== CONSTANTS ====
  35.  
  36. integer g_COMMCHAN = 19;             // public command channel
  37. integer g_MENUCHAN = -25;           // menu command channel
  38.  
  39. integer g_NUMOFSLAVES = 0;          // number of slaves (update in run_time_permissions)
  40.  
  41. float g_DELAYRELOAD = 3.0;          // number of seconds for reloading
  42.  
  43.  
  44.  
  45. string g_HELPNOTE = "help";      // the notecard to give when the user says "help"
  46.  
  47. // SOUNDS
  48. string g_SNDFIRE = "Fire";    // name of the firing sound
  49. string g_SNDRELOAD = "Reload";    // name of the reloading sound
  50. string g_SNDNOAMMO = "b38bdcc9-3a98-8875-da60-b4d1e6805796";  // name of the no ammo sound (the clicking noise)
  51. string g_SNDDRAW = "";              // this is an optional sound for drawing (won't play if it's empty)
  52. string g_SNDSLING = "";             // this is an optional sound for slinging (won't play if it's empty)
  53.  
  54. key g_OWNER;                    // store the owner's key to reduce llGetOwner() calls
  55.  
  56.  
  57. // ==== VARIABLES ====
  58. integer g_magazineSize = 15;        // default size of bullets per magazine (can be changed through command)
  59.  
  60. integer g_bulletsLeft = g_magazineSize; // the number of bullets currently left in the magazine
  61.  
  62. integer g_stopFire = FALSE;            // flag to trigger when reloading or in safe mode (stops firing ability)
  63.  
  64. integer g_safeMode = FALSE;             // safe mode flag (this is only used for the gun's display text)
  65.  
  66. integer g_effectsOn = TRUE;             // effects to eject casings when firing and magazine when reloading
  67.  
  68. integer g_burstFire = FALSE;            // flag for burst fire or single fire mode
  69.  
  70. integer g_txtOn = TRUE;                 // display text above gun or not
  71.  
  72. integer g_slaveNum = 1;         // the current bullet slave number to call upon
  73.  
  74. float g_delayFire = 0.03;       // number of seconds to delay between firing (can be changed through command)
  75.  
  76. float g_velocity = 150.0;       // default bullet velocity in meters per second
  77. float g_velocityLimit = 250.0;  // the limit for bullet velocity to be set
  78. float g_distance = 6.0;         // default rez distance roughly meters from camera position
  79.  
  80.  
  81. vector g_TXTCOLOR = <1.0, 1.0, 1.0>;    // gun text color (default is green)
  82. string g_txt = "";                      // the gun's display text
  83.  
  84. string g_bulletName = "Phantom";         // the currently loaded bullet
  85.  
  86.  
  87.  
  88. // ==== SUBPROCEDURES ====
  89. // updateTxt()      - updates the gun display text
  90. // reload()         - reloads the gun
  91.  
  92. updateTxt()
  93. {
  94.     // escape if the gun text feature isn't on
  95.     if (g_txtOn == FALSE)
  96.     {
  97.         llSetText("", <0.0, 1.0, 0.0>, 1.0);
  98.         return;
  99.     }
  100.    
  101.     // display "[ Safe ]" on the gun if safety is on
  102.     if (g_safeMode == TRUE)
  103.     {
  104.         g_txt = "[ Safe ]\n[ " + g_bulletName + " ]";
  105.        
  106.         // display burst or single fire
  107.         if (g_burstFire == TRUE)
  108.         {
  109.             g_txt += "\n[ Burst Fire ]";
  110.         }
  111.         else
  112.         {
  113.             g_txt += "\n[ Single Fire ]";
  114.         }
  115.     }
  116.    
  117.     // if safety is off, display normally
  118.     else
  119.     {
  120.         g_txt = "[ " + g_bulletName + " ]\n";
  121.        
  122.         // display burst or single fire
  123.         if (g_burstFire == TRUE)
  124.         {
  125.             g_txt += "[ Burst Fire ]";
  126.         }
  127.         else
  128.         {
  129.             g_txt += "[ Single Fire ]";
  130.         }
  131.        
  132.     }
  133.    
  134.    
  135.     // add bullets remaining + magazine size
  136.     g_txt += "\n[ " + (string)g_bulletsLeft + "/" + (string)g_magazineSize + " ]";
  137.  
  138.   //  llSetText(g_txt, g_TXTCOLOR, 1.0);
  139.    
  140. }
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148. reload()
  149. {
  150.     g_stopFire = TRUE;      // make sure the gun can't fire during reload
  151.    
  152.     llMessageLinked(LINK_SET, -2, "nf", "");        // tell any muzzle flash scripts to stop
  153.    
  154.     if (g_txtOn == TRUE)
  155.     {
  156.       llSetText("", g_TXTCOLOR, 1.0); // "Reloading" text
  157.     }
  158.    
  159.     llTriggerSound(g_SNDRELOAD, 1.0);
  160.     llMessageLinked(LINK_THIS, -1, "r", "");    // trigger reload animation in animation script
  161.    
  162.    
  163.     if (g_effectsOn == TRUE)
  164.     {
  165.         vector pos = llGetPos();
  166.         rotation rot = llGetRot();
  167.         vector fwd = llRot2Fwd(rot)*0.2;
  168.        
  169.         llRezObject("Magazine", pos+fwd, ZERO_VECTOR, rot, 1);
  170.     }
  171.    
  172.    
  173.    
  174.     g_bulletsLeft = g_magazineSize;
  175.    
  176.     llSetTimerEvent(g_DELAYRELOAD); // delay the reload for an amount of time
  177.    
  178. }
  179.  
  180.  
  181.  
  182. // ==== FUNCTIONS ====
  183. //  genMenu(integer menu_num)   - generates a menu or submenu depending upon the number passed to it
  184.  
  185. genMenu(integer menu_num)
  186. {
  187.     list buttons = [];
  188.     string menu_txt = "";
  189.    
  190.     // main menu
  191.     if (menu_num == 0)
  192.     {
  193.         buttons = ["Bullet", "Other", "Help", "Firing Mode"];
  194.         menu_txt = "[Select Option]";
  195.        
  196.         if (g_safeMode == TRUE)
  197.         {
  198.             buttons += "Nosafe";
  199.         }
  200.         else
  201.         {
  202.             buttons += "Safe";
  203.         }
  204.        
  205.         buttons += "Sling";
  206.        
  207.     }
  208.    
  209.     // firing mode submenu
  210.     else if (menu_num == 1)
  211.     {
  212.         buttons = ["Single", "Burst", "Main"];
  213.         menu_txt = "[Firing Modes]\n\nSingle Fire - Fires a single round\nBurst Fire - Fires 3-rounds per shot";
  214.  
  215.     }
  216.    
  217.     // bullet selection submenu
  218.     else if (menu_num == 2)
  219.     {
  220.         buttons = ["Damage", "Training", "Phantom", "Main"];
  221.         menu_txt = "[Bullet Types]\n\nDamage - 100% Linden Combat Damage\nTraining - 0% Linden Combat Damage\nPhantom - Penetrates walls and objects; 100% Damage";
  222.  
  223.     }
  224.    
  225.     // other submenu
  226.     else if (menu_num == 3)
  227.     {
  228.         buttons = ["Reset"];
  229.  
  230.         if (g_effectsOn == TRUE)
  231.         {
  232.             buttons += "Effects Off";
  233.         }
  234.         else
  235.         {
  236.             buttons += "Effects On";
  237.         }
  238.        
  239.       //  if (g_txtOn == TRUE)
  240.        // {
  241.          //   buttons += "Textoff";
  242.       //  }
  243.        // else
  244.         // {
  245.           //  buttons += "Texton";
  246.        // }
  247.        
  248.         buttons += ["Mem", "Main"];
  249.        
  250.         menu_txt = "[Other]\n\nReset - Resets all scripts\nEffects On - Turns case ejection on\nEffects Off - Turns case ejection off\nMem - Displays available memory";
  251.  
  252.        
  253.     }
  254.    
  255.        
  256.     llDialog(g_OWNER, menu_txt, buttons, g_MENUCHAN);
  257.    
  258.     buttons = [];
  259. }
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266. default
  267. {
  268.    
  269.     state_entry()
  270.     {
  271.         g_OWNER = llGetOwner();
  272.        
  273.         // make the gun visible and set text
  274.         llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES);
  275.         llSetText("", g_TXTCOLOR, 1.0);     // clear the text incase text is off (it will just return in updateTxt
  276.  
  277.  
  278.         llListen(g_COMMCHAN, "", g_OWNER, "");
  279.         llListen(g_MENUCHAN, "", g_OWNER, "");
  280.        
  281.        
  282.         // check if attached
  283.         if (llGetAttached() > 0)
  284.         {
  285.             llRequestPermissions(g_OWNER, PERMISSION_TAKE_CONTROLS);
  286.         }
  287.        
  288.     }
  289.    
  290.    
  291.     touch_start(integer num_detected)
  292.     {
  293.         if (llDetectedKey(0) == g_OWNER)
  294.         {
  295.             genMenu(0);
  296.         }
  297.        
  298.     }
  299.    
  300.    
  301.     run_time_permissions(integer perms_granted)
  302.     {
  303.         // if permissions are granted
  304.         if (perms_granted & PERMISSION_TAKE_CONTROLS)
  305.         {
  306.             llTakeControls(CONTROL_ML_LBUTTON | CONTROL_FWD | CONTROL_BACK | CONTROL_DOWN | CONTROL_UP, TRUE, TRUE);
  307.  
  308.             // play draw sound if it exists
  309.             if (g_SNDDRAW != "")
  310.             {
  311.                 llTriggerSound(g_SNDDRAW, 1.0);
  312.             }
  313.  
  314.             g_NUMOFSLAVES = 0;      // reset number of slaves
  315.            
  316.             llMessageLinked(LINK_THIS, -1, "reset", "");    // reset animation and casing scripts
  317.            
  318.             updateTxt();        // incase text is on, set it
  319.  
  320.             // get number of slave scripts there are
  321.             integer num_of_scripts = llGetInventoryNumber(INVENTORY_SCRIPT)+1;
  322.             integer i;
  323.            
  324.             for (i=1; i<num_of_scripts; i++)
  325.             {
  326.                 // check if the script "os_pistol.Slave + i" exists
  327.                 integer find_slave = llGetInventoryType("os_pistol.Slave" + (string)i);
  328.                
  329.                 // it exists! add to number of slaves
  330.                 if (find_slave == INVENTORY_SCRIPT)
  331.                 {
  332.                     g_NUMOFSLAVES++;
  333.                 }
  334.                
  335.                 // none, stop the loop
  336.                 else
  337.                 {
  338.                     i = num_of_scripts;
  339.                 }
  340.                    
  341.             }
  342.            
  343.            
  344.             // check if there are enough slaves (there must be at least one)
  345.             if (g_NUMOFSLAVES < 1)
  346.             {
  347.                 llOwnerSay("/me - [ERROR] You have no bullet slave scripts!");
  348.             }
  349.            
  350.             llSleep(0.2);   // delay incase the scripts are slow at initiating
  351.            
  352.             llMessageLinked(LINK_THIS, 0, g_bulletName + ":" + (string)g_velocity + ":" + (string)g_distance, (string)g_burstFire);
  353.            
  354.         }
  355.        
  356.         // permissions denied
  357.         else
  358.         {
  359.             llOwnerSay("/me - [ERROR] Permissions Denied.");
  360.         }
  361.        
  362.     }
  363.    
  364.    
  365.     attach(key id)
  366.     {
  367.         // if detached
  368.         if (id == NULL_KEY)
  369.         {
  370.             // release controls for good practice
  371.             if (llGetPermissions() & PERMISSION_TAKE_CONTROLS)
  372.             {
  373.                 llReleaseControls();
  374.  
  375.             }
  376.            
  377.             llMessageLinked(LINK_THIS, -1, "stop", ""); // tell animation script to stop
  378.            
  379.         }
  380.        
  381.         // reset script to update owner
  382.         else if (id != g_OWNER)
  383.         {
  384.             // Delay to reduce the stupid "SlaveX" not found error
  385.             llSleep(0.2);
  386.             llResetScript();
  387.         }
  388.        
  389.        
  390.         // normal attach
  391.         else
  392.         {
  393.             // Delay to reduce the stupid "SlaveX" not found error
  394.             llSleep(0.2);
  395.             llRequestPermissions(g_OWNER, PERMISSION_TAKE_CONTROLS);
  396.         }        
  397.        
  398.        
  399.     }
  400.    
  401.    
  402.    
  403.    
  404.     // check for any new added bullet slave scripts
  405.     changed(integer change)
  406.     {
  407.         if (~change & CHANGED_INVENTORY)
  408.         {
  409.             return;
  410.         }
  411.        
  412.         integer next_slave = g_NUMOFSLAVES+1;
  413.         integer find_slave = llGetInventoryType("os_pistol.Slave" + (string)next_slave);
  414.        
  415.         if (find_slave == INVENTORY_SCRIPT)
  416.         {
  417.             g_NUMOFSLAVES++;
  418.             llSetScriptState("os_pistol.Slave" + (string)next_slave, TRUE);            
  419.             llResetOtherScript("os_pistol.Slave" + (string)next_slave);
  420.            
  421.             llOwnerSay("/me - [Bullet Slave Added]");
  422.         }
  423.        
  424.         llSleep(0.2);   // delay incase the scripts are slow at initiating
  425.        
  426.         // set the bullet settings to the new slave (will also go to the others)
  427.         llMessageLinked(LINK_THIS, 0, g_bulletName + ":" + (string)g_velocity + ":" + (string)g_distance, (string)g_burstFire);
  428.        
  429.     }
  430.    
  431.    
  432.    
  433.    
  434.    
  435.    
  436.     // This is where all of the firing is controlled
  437.     control(key id, integer held, integer level)
  438.     {
  439.         if (g_stopFire == TRUE)     // stops gun from firing if reloading or in safe mode
  440.         {
  441.             return;
  442.         }
  443.        
  444.                
  445.        
  446.                
  447.        
  448.         // mouse button pressed
  449.         if (level & held & CONTROL_ML_LBUTTON)
  450.         {
  451.             if (g_burstFire == TRUE)
  452.             {
  453.                
  454.                 llMessageLinked(LINK_ALL_OTHERS, -2, "f", "");     // tell any muzzle flash scripts to start
  455.                 // loop three times
  456.                 integer i;
  457.                 for (i=0; i<3; i++)         // lol <3
  458.                 {
  459.                     // check if there is any ammo left
  460.                     if (g_bulletsLeft <= 0)
  461.                     {
  462.                         llTriggerSound(g_SNDNOAMMO, 1.0);
  463.                     }
  464.                    
  465.                     // there are bullets left
  466.                     else
  467.                     {
  468.                         llMessageLinked(LINK_THIS, g_slaveNum, "f", "");    // fire bullet
  469.                        
  470.                         llTriggerSound(g_SNDFIRE, 1.0);
  471.                        
  472.                         g_bulletsLeft--;
  473.                         g_slaveNum++;
  474.                        
  475.                         // line up next slave
  476.                         if (g_slaveNum > g_NUMOFSLAVES)
  477.                         {
  478.                             g_slaveNum = 1;
  479.                         }
  480.                        
  481.                         llSleep(g_delayFire);
  482.                        
  483.                     }   // end of checking if bullets are left
  484.                    
  485.                    
  486.                 }   // end of for loop
  487.                
  488.                 llMessageLinked(LINK_ALL_OTHERS, -2, "nf", "");        // tell any flash muzzles to stop
  489.                
  490.                
  491.             }   // end of burst mode
  492.            
  493.            
  494.             // single fire mode
  495.             else
  496.             {
  497.                 llTriggerSound(g_SNDFIRE, 1.0);
  498.                 llMessageLinked(LINK_THIS, g_slaveNum, "f", "");
  499.                
  500.                 llMessageLinked(LINK_ALL_OTHERS, -2, "f", "");        // tell any muzzle flash scripts to start
  501.                
  502.                 g_bulletsLeft--;
  503.                 g_slaveNum++;
  504.                
  505.                 if (g_slaveNum > g_NUMOFSLAVES)
  506.                 {
  507.                     g_slaveNum = 1;
  508.                 }
  509.                
  510.                 llMessageLinked(LINK_ALL_OTHERS, -2, "nf", "");        // tell any flash muzzles to stop
  511.                 llSleep(g_delayFire);
  512.                
  513.             }
  514.            
  515.             updateTxt();
  516.            
  517.         }
  518.        
  519.         // mouse button released
  520.         else if (level & ~held & CONTROL_ML_LBUTTON)
  521.         {
  522.             llMessageLinked(LINK_SET, -2, "nf", "");        // tell any muzzle flash scripts to stop
  523.            
  524.             // check if reload is needed
  525.             if (g_bulletsLeft <= 0)
  526.             {
  527.                 reload();
  528.                 return;
  529.             }
  530.            
  531.         }
  532.        
  533.         // W+S (forward+back) reload
  534.         else if ((level & ~held & CONTROL_FWD) && (level & ~held & CONTROL_BACK))
  535.         {
  536.             reload();
  537.         }
  538.        
  539.  
  540.         // not crouching
  541.         else if (level & held & CONTROL_UP)
  542.         {
  543.             llMessageLinked(LINK_THIS, -1, "nocrouch", "");     // tell animation script to play normal standing animation
  544.         }        
  545.        
  546.  
  547.         // crouch
  548.         else if (level & held & CONTROL_DOWN)
  549.         {
  550.             llMessageLinked(LINK_THIS, -1, "crouch", "");       // tell animation script to play crouch animation
  551.  
  552.         }
  553.        
  554.     }
  555.    
  556.    
  557.    
  558.    
  559.     timer()
  560.     {
  561.         llSetTimerEvent(0.0);
  562.         updateTxt();
  563.         g_stopFire = FALSE;
  564.        
  565.         llOwnerSay("/me - [Reloaded]");
  566.     }
  567.    
  568.    
  569.    
  570.    
  571.    
  572.    
  573.    
  574.    
  575.    
  576.    
  577.    
  578.    
  579.     // HERE IS WHERE ALL OF THE COMMANDS ARE
  580.     listen(integer channel, string name, key id, string msg)
  581.     {
  582.         // check if message is longer than necessary
  583.         if (llStringLength(msg) > 11)
  584.         {
  585.             return;
  586.         }
  587.        
  588.        
  589.         msg = llToLower(msg);       // make case-insensitive
  590.        
  591.         // do a simple parse for the : commands (velocity, distance, and rounds)
  592.         list parsed = llParseString2List(msg, [":", " "], []);
  593.         string command = llList2String(parsed, 0);      // reduces llList2String calls
  594.        
  595.         // Go in order from most used commands to least used (by assumption)
  596.         // Use a return at each clause to exit the listen event immediately
  597.        
  598.         if (msg == "r" || msg == "reload")      // reload command
  599.         {
  600.             reload();
  601.         }
  602.        
  603.         else if (msg == "sf" || msg == "single")        // single fire command
  604.         {
  605.             g_burstFire = FALSE;
  606.             updateTxt();
  607.            
  608.             llMessageLinked(LINK_THIS, 0, g_bulletName + ":" + (string)g_velocity + ":" + (string)g_distance, (string)g_burstFire);
  609.            
  610.             llOwnerSay("/me - [Firing mode switched to Single Fire]");
  611.         }
  612.        
  613.         else if (msg == "bf" || msg == "burst")     // burst fire command
  614.         {
  615.             g_burstFire = TRUE;
  616.             updateTxt();
  617.            
  618.             llMessageLinked(LINK_THIS, 0, g_bulletName + ":" + (string)g_velocity + ":" + (string)g_distance, (string)g_burstFire);
  619.            
  620.             llOwnerSay("/me - [Firing mode switched to Burst Fire]");
  621.         }
  622.        
  623.         else if (msg == "damage")           // damage bullet command
  624.         {
  625.             g_bulletName = "Damage";
  626.             updateTxt();
  627.            
  628.             llMessageLinked(LINK_THIS, 0, g_bulletName + ":" + (string)g_velocity + ":" + (string)g_distance, (string)g_burstFire);
  629.            
  630.             llOwnerSay("/me - [Bullet switched to Damage]");
  631.            
  632.             reload();
  633.         }
  634.        
  635.        
  636.         else if (msg == "training")         // training bullet command
  637.         {
  638.             g_bulletName = "Training";
  639.             updateTxt();
  640.            
  641.             llMessageLinked(LINK_THIS, 0, g_bulletName + ":" + (string)g_velocity + ":" + (string)g_distance, (string)g_burstFire);
  642.  
  643.             llOwnerSay("/me - [Bullet switched to Training]");
  644.            
  645.             reload();
  646.         }
  647.        
  648.         else if (msg == "phantom")          // phantom bullet command
  649.         {
  650.             g_bulletName = "Phantom";
  651.             updateTxt();
  652.            
  653.             llMessageLinked(LINK_THIS, 0, g_bulletName + ":" + (string)g_velocity + ":" + (string)g_distance, (string)g_burstFire);
  654.  
  655.             llOwnerSay("/me - [Bullet switched to Phantom]");
  656.            
  657.             reload();
  658.  
  659.         }
  660.        
  661.        
  662.         else if (msg == "safe")             // safe mode command
  663.         {
  664.             g_safeMode = TRUE;
  665.             g_stopFire = TRUE;
  666.             updateTxt();
  667.            
  668.             llOwnerSay("/me - [Safe mode set to ON]");
  669.         }
  670.        
  671.         else if (msg == "nosafe" || msg == "arm")       // nosafe/arm command
  672.         {
  673.             g_safeMode = FALSE;
  674.             g_stopFire = FALSE;
  675.             updateTxt();
  676.            
  677.             llOwnerSay("/me - [Safe mode set to OFF]");
  678.         }
  679.        
  680.        
  681.         else if (msg == "sling")            // sling command
  682.         {
  683.              llSay(19, "sling");
  684.             llReleaseControls();
  685.             state sling;
  686.         }
  687.        
  688.        
  689.         else if (command == "vel")     // velocity command
  690.         {
  691.             // check if velocity is over or under the limit
  692.             float tmp = (float)llList2String(parsed, 1);
  693.             if (tmp > g_velocityLimit || tmp < 0)
  694.             {
  695.                 llOwnerSay("/me - [Bullet velocity must be set between 0 and " + (string)g_velocityLimit + "m/s]");
  696.  
  697.                 return;
  698.             }
  699.  
  700.            
  701.             // if the velocity is in range            
  702.             g_velocity = tmp;
  703.            
  704.             llMessageLinked(LINK_THIS, 0, g_bulletName + ":" + (string)g_velocity + ":" + (string)g_distance, (string)g_burstFire);
  705.  
  706.             llOwnerSay("/me - [Bullet velocity set to " + (string)g_velocity + "m/s]");
  707.            
  708.         }
  709.        
  710.        
  711.         else if (command == "dist")    // distance command
  712.         {
  713.            
  714.             // check if distance is over or under the limit
  715.             float tmp = (float)llList2String(parsed, 1);
  716.             if (tmp > 10 || tmp < 0)
  717.             {
  718.                 llOwnerSay("/me - [Bullet rez distance must set between 0 and 10 meters]");
  719.  
  720.                 return;
  721.             }
  722.            
  723.  
  724.             g_distance = tmp;
  725.            
  726.             llMessageLinked(LINK_THIS, 0, g_bulletName + ":" + (string)g_velocity + ":" + (string)g_distance, (string)g_burstFire);
  727.  
  728.             llOwnerSay("/me - [Bullet rez distance set to " + (string)g_distance + " meters]");
  729.            
  730.         }
  731.        
  732.         else if (command == "rounds")      // rounds command
  733.         {
  734.             integer tmp = (integer)llList2String(parsed, 1);
  735.            
  736.             if (tmp < 1)
  737.             {
  738.                 llOwnerSay("/me - [Number of rounds cannot be set lower than 1]");
  739.                 return;
  740.             }
  741.            
  742.             g_magazineSize = tmp;
  743.            
  744.             llOwnerSay("/me - [Number of rounds set to " + (string)g_magazineSize + "]");
  745.             reload();
  746.            
  747.         }
  748.        
  749.        
  750.         else if (msg == "effects off")
  751.         {
  752.             g_effectsOn = FALSE;
  753.             llMessageLinked(LINK_THIS, -1, "effectsoff", "");
  754.            
  755.             llOwnerSay("/me - [Effects turned OFF. Shell casings and magazines will not be rezzed]");
  756.         }
  757.        
  758.         else if (msg == "effects on")
  759.         {
  760.             g_effectsOn = TRUE;
  761.             llMessageLinked(LINK_THIS, -1, "effectson", "");
  762.            
  763.             llOwnerSay("/me - [Effects turned ON. Shell casings and magazines will be rezzed.]");
  764.         }
  765.        
  766.         else if (msg == "texton")
  767.         {
  768.             g_txtOn = TRUE;
  769.             updateTxt();
  770.            
  771.             llOwnerSay("/me - [Display text turned ON]");
  772.         }
  773.        
  774.         else if (msg == "textoff")
  775.         {
  776.             g_txtOn = FALSE;
  777.             updateTxt();
  778.            
  779.             llOwnerSay("/me - [Display text turned OFF]");
  780.         }
  781.        
  782.         else if (msg == "reset")
  783.         {
  784.             llMessageLinked(LINK_THIS, -1, "reset", "");     // tell animation script to reset
  785.             llResetScript();
  786.         }
  787.        
  788.        
  789.         else if (msg == "menu" || (msg == "main" && channel == g_MENUCHAN))     // main menu
  790.         {
  791.             genMenu(0);
  792.         }
  793.        
  794.         else if (msg == "firing mode" && channel == g_MENUCHAN)          // firing mode submenu
  795.         {
  796.             genMenu(1);
  797.         }
  798.        
  799.         else if (msg == "bullet" && channel == g_MENUCHAN)      // bullet selection submenu
  800.         {
  801.             genMenu(2);
  802.         }
  803.        
  804.         else if (msg == "other" && channel == g_MENUCHAN)       // other submenu
  805.         {
  806.             genMenu(3);
  807.         }
  808.            
  809.         else if (msg == "help")
  810.         {
  811.             llGiveInventory(g_OWNER, g_HELPNOTE);
  812.         }
  813.        
  814.         else if (msg == "mem")
  815.         {
  816.             llOwnerSay("/me - [Memory Available: " + (string)llGetFreeMemory() + " bytes]");
  817.         }
  818.  
  819.         // incase garbage collection sucks
  820.         parsed = [];
  821.        
  822.     }   // end of listen event
  823.  
  824. }
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832. //*************************************************************************************************
  833. // SLING STATE
  834. //*************************************************************************************************
  835. state sling
  836. {
  837.     on_rez(integer param)
  838.     {
  839.         llResetScript();
  840.     }
  841.    
  842.     state_entry()
  843.     {
  844.        
  845.         llMessageLinked(LINK_SET, -2, "nf", "");        // tell any muzzle flash scripts to stop
  846.        
  847.         // play sling sound if it exists
  848.         if (g_SNDSLING != "")
  849.         {
  850.             llTriggerSound(g_SNDSLING, 1.0);
  851.         }
  852.        
  853.         llMessageLinked(LINK_THIS, -1, "stop", "");     // tell animation script to stop
  854.         llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES);       // make gun invisible
  855.        
  856.         llListen(g_COMMCHAN, "", g_OWNER, "");
  857.         llListen(g_MENUCHAN, "", g_OWNER, "");
  858.        
  859.     }
  860.    
  861.     touch_start(integer num_detected)
  862.     {
  863.         if (llDetectedKey(0) == g_OWNER)
  864.         {
  865.             llDialog(g_OWNER, "Slung", ["Draw", "Reset"], g_MENUCHAN);
  866.         }
  867.        
  868.     }
  869.    
  870.    
  871.     listen(integer channel, string name, key id, string msg)
  872.     {
  873.         if (llStringLength(msg) > 5)
  874.         {
  875.             return;
  876.         }
  877.        
  878.         msg = llToLower(msg);
  879.        
  880.         if (msg == "draw")
  881.         {
  882.            llSay(19, "draw");
  883. state default;
  884.         }
  885.        
  886.         else if (msg == "reset")
  887.         {
  888.             llResetScript();
  889.         }
  890.        
  891.     }
  892.    
  893.    
  894. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement