Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Weapons rocketlauncher  

rocketlauncher

rocketlauncher.lsl

Category: Weapons
By : John Linden
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for rocketlauncher
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. rocketlauncher_1.lsl
1
2 // Gun script
3 // John Linden
4
5 // Modified by Inuchance
6
7 // where the gun attaches itself if you click on it
8 // switch this to ATTACH_LHAND if you are left-handed
9 integer gAttachPart = ATTACH_RHAND;
10
11 integer gDesiredPerm;
12 integer gHavePermissions;
13
14 float gBulletSpeed = 3.0;
15
16
17 // when we last fired a shot
18 float gLastFireTime = 0;
19 // how long it takes to reload when tapping
20 float gTapReloadTime = 2.00;
21 // how long it takes to reload when holding
22 float gHoldReloadTime = 2.00;
23
24 // HACK: how far away the eye is from the avatar's center (approximately)
25 vector gEyeOffset = <0.0, 0.0, 0.84>;
26
27
28 say(string msg)
29 {
30 llSay(0, msg);
31 }
32 debug(string msg)
33 {
34 // llSay(0, msg);
35 }
36 func_debug(string msg)
37 {
38 // llSay(0, msg);
39 }
40
41
42 // the gun has only one state
43
44 default
45 {
46 on_rez(integer start_param)
47 {
48 func_debug("on_rez");
49 // HACK: try to compensate for height of avatar
50 // by changing firing position appropriately
52 gEyeOffset.z = gEyeOffset.z * (size.z / 2.0);
53
54 // NOTE: can't do this if we want to attach by dragging from
55 // inventory onto the av, because the llResetScript(); clears
56 // all the callbacks, including attach()
57 // llResetScript();
58
59 // NOTE 2: This can be uncommented in 1.1 because you won't have
60 // to ask for permissions, you can just take them. But for now
61 // it pops up two dialog boxes if you drag onto the av, so I'll
62 // leave it out.
63 // Try to attach to the rezzer
64 // if( !gHavePermissions )
65 // {
66 // llRequestPermissions(llGetOwner(), gDesiredPerm);
67 // }
68 }
69
71 {
72 func_debug("default state_entry");
73 gHavePermissions = FALSE;
74 // this should be initialized directly with the variable
75 // but I can't do that due to a bug
76 gDesiredPerm = (PERMISSION_TAKE_CONTROLS
79 }
80
81 // Player attaches us, either by dragging onto self or from pie menu
82 attach(key av_key)
83 {
84 func_debug("attach");
85
86 if(av_key != NULL_KEY)
87 {
88 // Can't attach if we don't own it
89 if( av_key != llGetOwner() )
90 {
91 llWhisper(0, ":O");
92 return;
93 }
94
95 //
96 // Always request permissions on attach, as we may be re-rezzing on login
97 llRequestPermissions(av_key, gDesiredPerm);
98
99 // run_time_permissions() is executed after this call
100 } else
101 {
102 func_debug(" detach");
103
104 if( gHavePermissions )
105 {
106 // we are being detached
107 llStopAnimation("hold_R_rifle");
109 llSetRot(<0.0, 0.0, 0.0, 1.0>);
110 gHavePermissions = FALSE;
111 }
112 }
113 }
114
115 // this is called whenever llRequestPermissions() returns
116 // i.e. the user has responded or dismissed the dialog
117 // perm is the permissions we now have
119 {
120 func_debug("run_time_permissions");
121
122 // see if we now have the permissions we need
123 if( (perm & gDesiredPerm) == gDesiredPerm )
124 {
125 func_debug(" got perms");
126
127 // we got the permissions we asked for
128 gHavePermissions = TRUE;
130 llStartAnimation("hold_R_rifle");
131 } else
132 {
133 func_debug(" didn't get perms");
134
135 // we didn't get them, kill ourselves
136 llDie();
137 }
138 }
139
140
141 // the player has used the controls, process them
142 control(key owner, integer level, integer edge)
143 {
144 func_debug("control");
145
146 // has our gun reloaded?
147 float time = llGetTime();
148
149 // see if av has fired
150 // (edge & level) == down edges, (edge & !level) == up edges
151 // repeat rate is faster for tapping than holding
152 if( ( ((edge & level) & CONTROL_ML_LBUTTON)
153 && (time > gTapReloadTime) )
154 || ( (time > gHoldReloadTime)
155 && (level & CONTROL_ML_LBUTTON) ) )
156 {
157 // if player is out of ammo, must wait for reload
158 // bang!
159 // llTriggerSound("railgf1a", 10);
160 // llTriggerSound("railgf1a", 10); // OMG LOUD
161
162 llResetTime(); // we fired, set timer back to 0
163
164 // HACK: gun shoots from gun pos, mouselook looks
165 // from player's eye, so we try to move the gun
166 // up to the eye. but we really don't
167 // know where it is, so we guess (see gEyeOffset)
168 vector my_pos = llGetPos() + gEyeOffset;
169 rotation my_rot = llGetRot();
170 vector my_fwd = llRot2Fwd(my_rot);
171
172 llTriggerSound("Launch", 10);
173 llRezObject("Missile",
174 my_pos + (my_fwd*2),
175 my_fwd * gBulletSpeed + llGetVel(),
176 llEuler2Rot(<0, PI_BY_TWO, 0>) * my_rot,
177 1);
178
179 }
180
181 } // control
182
183
184
185 } // default state
186
187 // END //

Back to the Best Free Tools in Second Life and OpenSim.