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 sword_script  

sword_script

sword script.lsl

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

the Zip file

Download all files for sword_script
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. sword_script_1.lsl
1
2 // Gun script
3 // John Linden
4
5 // where the gun attaches itself if you click on it
6 // switch this to ATTACH_LHAND if you are left-handed
7 integer gAttachPart = ATTACH_RHAND;
8 vector rez_pos = <1.5, 0.0, 0.02>;
9 float height_offset;
10
11
12 integer gDesiredPerm;
13 // Indicates whether wearer has yet given permission
14 integer gHavePermissions;
15
16 // Bullet travel speed
17 float gBulletSpeed = 15.0;
18
19 // when we last fired a shot
20 float gLastFireTime = 0.01;
21 // how long it takes to reload when tapping
22 float gTapReloadTime = 0.01;
23 // how long it takes to reload when holding
24 float gHoldReloadTime = 0.01;
25 //the sword animation being used
26 integer swings;
27 string anim = "sword";
28 vector gEyeOffset = <0.0, 0.0, 0.75>;
29 key owner;
30
31
32
33
34 // the gun has only one state
35
36 default
37 {
38 on_rez(integer start_param)
39 {
40 swings = 0;
41 anim = "sword";
43 gEyeOffset.z = gEyeOffset.z * (size.z / 2.0);
44 // llStopAnimation("sword pose");
45
46
47
48
49 }
50
52 {
53
54 gHavePermissions = FALSE;
55 // this should be initialized directly with the variable
56 // but I can't do that due to a bug
57 gDesiredPerm = (PERMISSION_TAKE_CONTROLS
59 llStartAnimation("sword pose");
60 // Start with a full clip
61
63 }
64
65 // the player has touched us (left-clicked)
66 // give directions
68 {
69
70
71 // Guns only work for their owner
72 if( llDetectedKey(0) == llGetOwner() )
73 {
74 if( gHavePermissions )
75 {
76
77 } else
78 {
79
80 }
81 } else
82 {
83 // Not the owner
84
85 }
86 }
87
88 // Player attaches us, either by dragging onto self or from pie menu
89 attach(key av_key)
90 {
91
92
93 if(av_key != NULL_KEY)
94 {
95 // Can't attach if we don't own it
96 if( av_key != llGetOwner() )
97 {
98
99 return;
100 }
101
102 //
103 // Always request permissions on attach, as we may be re-rezzing on login
104 llRequestPermissions(av_key, gDesiredPerm);
105 llStartAnimation("sword pose");
106
107 // run_time_permissions() is executed after this call
108 } else
109 {
110
111
112 if( gHavePermissions )
113 {
114 // we are being detached
115 llStopAnimation("swordb");
116 llStopAnimation("swordcr");
117 llStopAnimation("sword pose");
119 llSetRot(<0.0, 0.0, 0.0, 1.0>);
120 gHavePermissions = FALSE;
121 }
122 }
123 }
124
125 // this is called whenever llRequestPermissions() returns
126 // i.e. the user has responded or dismissed the dialog
127 // perm is the permissions we now have
129 {
130
131
132 // see if we now have the permissions we need
133 if( (perm & gDesiredPerm) == gDesiredPerm )
134 {
135
136
137 // we got the permissions we asked for
138 gHavePermissions = TRUE;
140
141 } else
142 {
143
144
145 // we didn't get them, kill ourselves
146 //llDie();
147 }
148 }
149
150
151 // the player has used the controls, process them
152 control(key owner, integer level, integer edge)
153 {
154
155
156 // has our gun reloaded?
157 float time = llGetTime();
158
159 // see if av has fired
160 // (edge & level) == down edges, (edge & !level) == up edges
161 // repeat rate is faster for tapping than holding
162 if( ( ((edge & level) & CONTROL_ML_LBUTTON)
163 && (time > gTapReloadTime) )
164 || ( (time > gHoldReloadTime)
165 && (level & CONTROL_ML_LBUTTON) ) )
166 {
167 // if player is out of ammo, must wait for reload
168
169 if(swings = 0)
170 {
171 anim = "swordb";
172 }
173 if(swings = 1)
174 {
175 anim = "swordb";
176 }
177 if(swings = 2)
178 {
179 anim = "swordb";
180 }
181 if(swings = 3)
182 {
183 anim = "swordb";
184 swings = 0;
185 }
186
187 llTriggerSound("e19b1802-9dab-f9b0-5cbd-b3530e578908", 1.2);
188 llStartAnimation(anim);
189 llResetTime(); // we fired, set timer back to 0
190
191
192 vector my_pos = llGetPos() + gEyeOffset;
193
194
195 rotation my_rot = llGetRot();
196 vector my_fwd = llRot2Fwd(my_rot);
197
198 llRezObject("meele",
199 my_pos,
200 my_fwd * gBulletSpeed,
201 my_rot,
202 1);
203 llRezObject("meele",
204 my_pos + <0,0,0.15>,
205 my_fwd * gBulletSpeed,
206 my_rot,
207 1);
208 llRezObject("meele",
209 my_pos + <0,0,-0.15>,
210 my_fwd * gBulletSpeed,
211 my_rot,
212 1);
213
214
215
216
217 swings = swings + 1;
218 llStopAnimation(anim);
219 // llSleep(3.0);
220 // llStartAnimation("sword pose");
221 } // control
222 }
223 } // default state
224 // END //

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