Home |
Add a script
|
||
|---|---|---|---|
| Category: | Contributor: | Description | |
| Weapons | Anonymous | Popgun.lsl | |
Popgun type weapon
Popgun.lsl
Download this script - Please use this link to get this script. If you see all the code on one long line, please use Wordpad or another editor, such as LSLEdit.exe. The .LSL file you will download is an ordinary text file.
1 // CATEGORY:Weapons 2 // DESCRIPTION:Popgun 3 // ARCHIVED BY:Ferd Frederix 4 5 // 6 // Popgun 7 // 8 9 float RECHARGE_TIME = 1.5; 10 float BASE_POWER = 25.0; 11 12 float last_time = 0.0; 13 vector fwd; 14 vector pos; 15 quaternion rot; 16 float power = 1.0; 17 key holder; // Key of avatar holding gun 18 integer hListen = 0; 19 22 23 fire_ball() 24 { 25 // 26 // Actually fires the ball 27 // 28 rot = llGetRot(); 29 fwd = llRot2Fwd(rot); 30 pos = llGetPos(); 31 pos = pos + fwd; 32 pos.z += 0.75; // Correct to eye point 33 fwd = fwd * BASE_POWER*power; 34 // llTriggerSound("tube", 1.0); 35 // llSay(0, "Boom!"); 36 llRezObject("webshot", pos, fwd, <0,0,0,1>, 2); 37 last_time = llGetTime(); 38 llSetTimerEvent(0.1); 39 } 40 hover() 41 { 42 // 43 // Spin at current position 44 // 45 //llTargetOmega(<0,0,1>, 1.0, 0.5); 46 } 47 48 no_hover() 49 { 50 //llTargetOmega(<0,0,1>, 0.0, 0.5); 51 } 52 53 default 54 { 55 state_entry() 56 { 57 //llSay(0, "Popgun, v1.0"); 58 hover(); 59 } 60 run_time_permissions(integer permissions) 61 { 62 if (permissions > 0) 63 { 64 // llSay(0, "Enter Mouselook to shoot me!"); 65 66 llSetLinkColor(3, <1,1,0>, -1); 68 permissions = TRUE; 69 } 70 } 71 touch_start(integer total_number) 72 { 73 if (!attached) 74 { 75 // 76 // If clicked and not attached, ask to attach to avatar 77 // 78 key avatar = llDetectedKey(0); 79 key owner = llGetOwner(); 80 if (owner == avatar) 81 { 82 // llSetText("Attach me to your right hand to use", <0,1,0>, 0.5); 83 llSleep(1.0); 84 llSetText("", <1,1,1>, 1.0); 85 } 86 else 87 { 88 // llSetText("$ Buy Me! $", <0,1,0>, 0.5); 89 llSleep(1.0); 90 llSetText("", <1,1,1>, 1.0); 91 } 92 return; 93 } 94 95 llReleaseControls(); 96 llDetachFromAvatar(); 97 } 98 100 {101 //102 // If attached/detached from agent, change behavior 103 // 104 if (attachedAgent != NULL_KEY)105 {106 // llTriggerSound("switch", 1.0);107 if (!permissions)108 {109 llRequestPermissions(attachedAgent, PERMISSION_TAKE_CONTROLS); 110 }111 attached = TRUE;112 no_hover();113 }114 else115 {116 // llTriggerSound("switch", 1.0);117 attached = FALSE;118 llReleaseControls();119 hover();120 121 }122 }123 125 {126 if ( ((edges & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON)127 &&((levels & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON) )128 {129 fire_ball();130 }131 }132 timer()133 {135 if ((current_time - last_time) < RECHARGE_TIME)136 {137 power = (current_time - last_time)/RECHARGE_TIME;138 // llSetLinkColor(3, <power,power,0>, -1);139 }140 else141 {142 power = 1.0; 143 // llSetLinkColor(3, <1,1,1>, -1);144 llSetTimerEvent(0.0);145 // llTriggerSound("splat3",1.0); // Play sound to indicate 'fully charged'146 }147 } 148 }149 // END //