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
Explosion Opensim exploding wall and grenade  

Opensim exploding wall and grenade

This script generates the explosion for a spawned grenade once this grenade is detonataed. This script handles the detonation events, communication with surrounding objects, and deletion of the grenade object.
Use: Apply this script to a grenade object

Category: Explosion
By : Steven Thompson
Created: 2015-04-23 Edited: 2015-04-23
Worlds: Second Life

the Zip file

Download all files for Opensim exploding wall and grenade
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Apache License.txt
Get file # 2. [40534 bytes] DestructibleWall.jpg
Get file # 3. Instructions.txt
Get file # 4. GetExploded.lsl
Get file # 5. PrimDeleter.lsl
Get file # 6. GenerateSmokeEffects.lsl
Get file # 7. GrenadeThrower.lsl
Get file # 8. GrenadeExploder.lsl
Get file # 9. DeletePrims_ButtonScript.lsl
Get file # 10. RezBricks.lsl
Get file # 11. SetWallAlpha.lsl
Get file # 12. SetWallAlpha_ButtonScript.lsl
1
2 // Copyright 2015 ARL
3 //Licensed under the Apache License, Version 2.0 (the "License");
4 //you may not use this file except in compliance with the License.
5 //You may obtain a copy of the License at
6 //
7 //http://www.apache.org/licenses/LICENSE-2.0
8 //
9 //Unless required by applicable law or agreed to in writing, software
10 //distributed under the License is distributed on an "AS IS" BASIS,
11 //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 //See the License for the specific language governing permissions and
13 // limitations under the License.
14
15
16 integer grenadeChannel = -9000; // This channel variable MUST have the same value as that in the greandeThrower script.
17 integer explosionChannel = -1337; // CHannel used to make nearby objects react physically to the grenade explosion
18 //integer listenHandle;/ unused fkb
19 float detonationTime = 4.0;
20 float counter = 0.0;
21 integer primGeneratorStartValue = 10;
22 float explosionForce = 0.5;
23 // BELOW: Particle Effect Variables
24 integer particleCount = 450;
25 vector particleColorStart = <1.000, 0.863, 0.000>/1.5; // Orange
26 vector particleColorEnd = <0.5, 0.5, 0.5>;//<0.667, 0.667, 0.667>; // Grey
27 vector particleScaleStart = <0.8, 0.8, 0.8>;
28 vector particleScaleEnd = <5.0, 5.0, 5.0>;
29 float particleSpeed = 8;
30 float particleLifetime = 0.2;
31 float particleBurstRate = 10.0;
32 string sourceTextureID = "";
33 vector localOffset = <0.0, 0.0, 0.0>; // local_offset is ignored
34
35 // Taken from http://community.secondlife.com/t5/Scripting/Starting-an-explosion-script/td-p/453247
36 fakeMakeExplosion(integer particle_count, vector particle_color_start, vector particle_color_end,
37 vector particle_scale_start, vector particle_scale_end, float particle_speed,
38 float particle_lifetime, float particle_burst_rate, string source_texture_id, vector local_offset)
39 {
40 // Make explosion burst
45 PSYS_PART_START_COLOR, particle_color_start,
46 PSYS_PART_END_COLOR, particle_color_end,
47 PSYS_PART_START_SCALE, particle_scale_start,
48 PSYS_PART_END_SCALE, particle_scale_end,
49 PSYS_PART_MAX_AGE, particle_lifetime,
51 PSYS_SRC_BURST_RATE, particle_burst_rate,
52 PSYS_SRC_BURST_PART_COUNT, particle_count,
54 PSYS_SRC_BURST_SPEED_MAX, particle_speed
55 ]);
56 }
57
58 default
59 {
61 {
62 counter = 0.0;
63 }
64 on_rez(integer start_param)
65 {
66 if(start_param == primGeneratorStartValue) // If ball was spawned from the 'grenade launcher', then start the timer.
67 {
68 llSetTimerEvent(1.0); // Start the timer
69 }
70 }
71 touch_start(integer num_detected) // Set grenade timer by clicking it
72 {
73 llSetTimerEvent(1.0); // Start the timer
74 }
75 timer()
76 {
77 string landLocation;
78 ++counter;
79 if(counter == detonationTime-1){ // Explosion is generated one second before grenade is removed
80 fakeMakeExplosion(particleCount, particleColorStart, // Make an explosion
81 particleColorEnd, particleScaleStart,
82 particleScaleEnd, particleSpeed,
83 particleLifetime, particleBurstRate,
84 sourceTextureID, localOffset);
85 llSetAlpha(0, ALL_SIDES); // Make the grenade no longer visible... but don't delete it just yet because particle effects
86 llRegionSay(explosionChannel, "Smokey Time"); // Generate lingering smoke effects
87 llTriggerSound("Grenade_Explosion", 30.0); // Make explosion sound
88 landLocation = (string)llGetPos();
89 string grenadeMessage = landLocation + "|" + (string)explosionForce;
90 llRegionSay(explosionChannel, grenadeMessage); // Tell Nearby objects to react to explosion
91 }
92 if(counter == detonationTime)
93 {
94 llDie(); // Destroy Grenade
95 counter = 0.0; // Reset Counter... just in case
96 }
97 }
98 }

Opensim exploding wall and grenade

This script is goes into a brick

Category: Explosion
By : Steven Thompson
Created: 2015-04-23 Edited: 2015-04-23
Worlds: Second Life

1 // Copyright 2015 ARL
2 //Licensed under the Apache License, Version 2.0 (the "License");
3 //you may not use this file except in compliance with the License.
4 //You may obtain a copy of the License at
5 //
6 //http://www.apache.org/licenses/LICENSE-2.0
7 //
8 //Unless required by applicable law or agreed to in writing, software
9 //distributed under the License is distributed on an "AS IS" BASIS,
10 //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 //See the License for the specific language governing permissions and
12 // limitations under the License.
13
14
15
16 integer ExplosionChannel = -1337;
17 integer listenHandle;
18 // float explosionDistance; // unused fkb
19 // vector impulseDirection; / unused fkb
20 float blastRadius = 2.0;
21 integer counter = 0;
22 integer superCounter = 0;
23 default
24 {
26 {
27 listenHandle = llListen(ExplosionChannel, "", "", "");
28 }
29 listen (integer channel, string name, key id, string message)
30 {
31 list messageList = llParseString2List(message, ["|"], []);// Parse Message to get greande position and explosion force
32 //llSay(0, messageList(0));
33 vector grenadeLocation = llList2Vector(messageList, 0); // Grenade position is in the first cell of the list
34 float explosionForce = (float)llList2String(messageList, 1); // Explosion force value is in the second cell of the list
35 vector objectLocation = llGetPos();
36 /*explosionDistance = llVecDist(grenadeLocation, objectLocation); // Calculate the distance from grenade to object
37 // Impulse on object is based on how close the object is to the explosion
38 impulseDirection = <grenadeLocation.x-objectLocation.x, grenadeLocation.y-objectLocation.y, grenadeLocation.z-objectLocation.z>;//explosionDistance;
39 if(explosionDistance <= 15) llApplyImpulse(impulseDirection*10, TRUE); // If the object is within 15 meters of the explosion, make object react
40 llSay(0, message);*/
41
42 //llSay(0, (string)objectLocation);
43 //llSay(0, (string)grenadeLocation);
44 //BELOW: From Mike
45 vector diff = objectLocation-grenadeLocation;//objectLocation-grenadeLocation;//mypos-bpos;
46 //llSay(0, (string)diff);
47 float mag = llVecMag(diff);
48 //llSay(0, (string)mag);
49 //llSay(0, "diff.z: " + (string)diff.z);
50 float cylinderMag = llVecMag(<diff.x, diff.y, 0>); // Come up with better name
51 if(cylinderMag < blastRadius && diff.z < blastRadius*2){ // Make bricks within blast radius and those near destroyed bricks ready to react to detonation
52 llSetStatus(STATUS_PHYSICS, TRUE); // make the object Physical
53 llSetStatus(STATUS_PHANTOM, FALSE); // no phantom objects
54 }
55 if(mag < blastRadius){ // Make all bricks within blast radius to get exploded
56 //llSetStatus(STATUS_PHYSICS, TRUE); // make the object Physical
57 //llSetStatus(STATUS_PHANTOM, FALSE); // no phantom objects
58 float brickMass = llGetMass();
59 vector velocityVector = explosionForce*diff;
60 vector momentumVector = brickMass * velocityVector;
61 //llSetVelocity(diff*(blastRadius-mag), TRUE);
62 //llSetPos(llGetPos()+diff*(blastRadius-mag));
63 llApplyImpulse(momentumVector, FALSE);//diff*(blastRadius-mag), FALSE);
64 //llSetForce(diff*(blastRadius-mag), TRUE);
65 llSetTimerEvent(1.0); // Start timer to see how long it make bricks come to rest after so many seconds
66 }
67 }
68 timer()
69 {
70 counter++;
71 if(counter == 20) {
72 //llSay(0, (string)llGetVel());
73 if(llVecMag(llGetVel()) == 0) {
74 llSetStatus(STATUS_PHYSICS, FALSE); // If the object has stopped moving, make it Non-physical
75 } else if(superCounter == 5){
76 llSetVelocity(<0.0,0.0,0.0>, FALSE);
78 } else {
79 counter = 0;
80 superCounter++;
81 //llSay(0, (string)superCounter);
82 }
83 }
84 }
85 }

Opensim exploding wall and grenade

When attached to an object, this script will allow that object to be deleted once the deleter button is pushed.
Use: attach this script to any item that needs to be deleted regularly. This is good for cleaning up after spawning a large number of that you may or may not be keeping track of.

Category: Explosion
By : Steven Thompson
Created: 2015-04-23 Edited: 2015-04-23
Worlds: Second Life

1
2
3 // Copyright 2015 ARL
4 //Licensed under the Apache License, Version 2.0 (the "License");
5 //you may not use this file except in compliance with the License.
6 //You may obtain a copy of the License at
7 //
8 //http://www.apache.org/licenses/LICENSE-2.0
9 //
10 //Unless required by applicable law or agreed to in writing, software
11 //distributed under the License is distributed on an "AS IS" BASIS,
12 //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 //See the License for the specific language governing permissions and
14 // limitations under the License.
15
16
17 integer objectChannel = -9;
18
19 default
20 {
22 {
23 llListen(objectChannel, "", "", "Die Prims"); // Listen for "Die Prims" to be entered broadcasted over objectChannel
24 }
25 listen(integer channel, string name, key id, string message)
26 {
27 if(message == "Die Prims") llDie(); //Delete Prims
28 }
29 }

Opensim exploding wall and grenade

This script is used to generate lingering smoke effects after detonation of Grenade etc.
Use: This should be applied to a grenade object. It's best if this script is placed in one of the other prims comprising the grenade other than the one using the GrenadeExploder script.

Category: Explosion
By : Steven Thompson
Created: 2015-04-23 Edited: 2015-04-23
Worlds: Second Life

1 // Copyright 2015 ARL
2 //Licensed under the Apache License, Version 2.0 (the "License");
3 //you may not use this file except in compliance with the License.
4 //You may obtain a copy of the License at
5 //
6 //http://www.apache.org/licenses/LICENSE-2.0
7 //
8 //Unless required by applicable law or agreed to in writing, software
9 //distributed under the License is distributed on an "AS IS" BASIS,
10 //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 //See the License for the specific language governing permissions and
12 // limitations under the License.
13
14
15
16
17 integer explosionChannel = -1337; // CHannel used to make objects involved in explosions communicate with one another
18 // integer listenHandle; // unused - Ferd Frederix
19 float detonationTime = 4.0;
20 float counter = 0.0;
21 integer primGeneratorStartValue = 10;
22
23 // Modified from http://community.secondlife.com/t5/Scripting/Starting-an-explosion-script/td-p/453247
24 makeLingeringSmoke()
25 {
26 //local_offset is ignored
27 llParticleSystem([ // Taken From: http://forums-archive.secondlife.com/54/73/273441/1.html
30 PSYS_PART_START_COLOR, <0.667, 0.667, 0.667>,
31 PSYS_PART_END_COLOR, <0.667, 0.667, 0.667>,
32 PSYS_PART_START_SCALE, <20.0, 20.0, 20.0>,
33 PSYS_PART_END_SCALE, <5.0, 5.0, 5.0>,
44 PSYS_SRC_PATTERN_EXPLODE,
46 0
49 ]);
50 }
51
52 default // Detonate grenade after so many seconds
53 {
55 {
56 }
57 on_rez(integer start_param)
58 {
59 if(start_param == primGeneratorStartValue) // If Grenade was spawned from the 'grenade launcher', then start the timer.
60 {
61 llSetTimerEvent(1.0); // Start timer
62 }
63 }
64 timer()
65 {
66 ++counter;
67 if(counter == detonationTime-1){ // Explosion is generated one second before grenade is removed
68 makeLingeringSmoke(); // Generate the lingering smoke effects
69 }
70 }
71 }

Opensim exploding wall and grenade

//This script generates the grenade prim at a certain velocity in the direction of where the avatar's camera is facing //Use: Create a Grenade Launcher Button, and apply this script to it. Each time you click the button a grenade should fly out of it, so it's best if the button is on your HUD somewhere; this will cause the grenade to fly out of your avatar at about head level.

Category: Explosion
By : Steven Thompson
Created: 2015-04-23 Edited: 2015-04-23
Worlds: Second Life

1
2
3 // Copyright 2015 ARL
4 //Licensed under the Apache License, Version 2.0 (the "License");
5 //you may not use this file except in compliance with the License.
6 //You may obtain a copy of the License at
7 //
8 //http://www.apache.org/licenses/LICENSE-2.0
9 //
10 //Unless required by applicable law or agreed to in writing, software
11 //distributed under the License is distributed on an "AS IS" BASIS,
12 //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 //See the License for the specific language governing permissions and
14 // limitations under the License.
15
16
17
18 integer Boxes = 1;
19 integer permission_track_camera = 0x400; // Permission varaible for tracking the camera position
20
21 vector relativePosOffset = <0.4, 0.0, 0.0>;
22 vector relativeVel = <7.0, 0.0, 5.0>;
23 rotation relativeRot = <0.0, 0.0, 0.0, 0.0>;
24 integer startParam = 10; // Variable needed by llRezObject that provides permissions to allow the object to be spawned
25 integer grenadeChannel = -9000;
26
27 makePrims(){
28 integer i = 0;
29 relativePosOffset = relativePosOffset + llGetCameraPos(); // Adjust the spawn direction to be that of the camera
30 vector myPos = llGetPos();
31 rotation myRot = llGetRot();
32 vector rezPos = myPos+relativePosOffset*myRot; // Set the spawn location to be offset by the avatar position and the camera position
33 vector rezVel = relativeVel*myRot; // modify the grenade velocity by the avatar's rotation... think of Shot Put
34 rotation rezRot = relativeRot*myRot; // modify the grenade rotation with that of the avatar's... again... Shot Put
35
36 // Spawn the grenade with the appropriate position, velocity, and rotation
37 llRezObject(llGetInventoryName(INVENTORY_OBJECT, 0), rezPos, rezVel, rezRot, startParam);
38 }
39
40 default
41 {
43 {
45 }
47 {
48 }
50 {
51 llRegionSay(grenadeChannel, "Destroy Grenade"); // Destroy any lingering grenades... This may deprecated
52 makePrims();
53 }
54 }

Opensim exploding wall and grenade

This script will broadcast the message "Die Prims" across the region on the objectChannel = -9. This will cause any objects with the PrimDeleter script to get deleted.
Use: This should be applied to a button. I called mine DeleterButton.

Category: Explosion
By : Steven Thompson
Created: 2015-04-23 Edited: 2015-04-23
Worlds: Second Life

1
2 // Copyright 2015 ARL
3 //Licensed under the Apache License, Version 2.0 (the "License");
4 //you may not use this file except in compliance with the License.
5 //You may obtain a copy of the License at
6 //
7 //http://www.apache.org/licenses/LICENSE-2.0
8 //
9 //Unless required by applicable law or agreed to in writing, software
10 //distributed under the License is distributed on an "AS IS" BASIS,
11 //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 //See the License for the specific language governing permissions and
13 // limitations under the License.
14
15
16
17 integer objectChannel = -9;
18
19 default
20 {
22 {
23 llRegionSay(objectChannel, "Die Prims");
24 }
25 }

Opensim exploding wall and grenade


This script spawns brick objects based off of the wall's location.
Use: Apply this script to a hollow, non-physical, phantom wall. When the wall is clicked and if the brick object is in the wall, then bricks will be spawned in a staggered pattern
NOTE: The dimensions of the wall aren't important. They act more as a place-holder within an environment.

Category: Explosion
By : Steven Thompson
Created: 2015-04-23 Edited: 2015-04-23
Worlds: Second Life

1
2
3 // Copyright 2015 ARL
4 //Licensed under the Apache License, Version 2.0 (the "License");
5 //you may not use this file except in compliance with the License.
6 //You may obtain a copy of the License at
7 //
8 //http://www.apache.org/licenses/LICENSE-2.0
9 //
10 //Unless required by applicable law or agreed to in writing, software
11 //distributed under the License is distributed on an "AS IS" BASIS,
12 //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 //See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 integer startParam = 0;
17 vector rezPos;
18 integer brickRowAmount = 5; // brickRowAmount / brickSize.z = number of bricks rows (round up)
19 integer brickColumnAmount = 7; // brickColumnAmount / brickSize.x = number of brick columns (round up)
20
21 default
22 {
24 {
25 }
26 touch_start(integer num_detected)
27 {
28 float i;
29 float j;
30 float k = 0.0;
31 vector brickSize = <0.5,0.24,0.25>; // Dimensions of brick placed in wall: a mechanism to grab this data is currently being made
32 vector wallSize = llGetScale(); // Get the wall location
33 rotation wallRot = llGetRot(); // Get the wall rotation
34 vector wallRotVector = llRot2Euler(wallRot); // Convert the wall rotation to vector so it can be applied the placement formula
35 // NOTE: Getting the wall to spawn bricks once it's been rotated is currently not working. This mechanism is currently being worked on.
36 // Below: loop for spawning bricks
37 for(j=0;j<brickRowAmount;j+=brickSize.z){
38 if(k == 0.0){ // Stagger the placement of the bricks every other row
39 k = brickSize.x/2; // Stagger them by half length of the bricks
40 } else {
41 k =0.0;
42 }
43 for(i=0;i<=brickColumnAmount;i+=brickSize.x){
44 rezPos = llGetPos() - <(wallSize.x/2 - brickSize.x/2 - (float)i + k), 0.0, (wallRotVector.z + wallSize.z/2 - brickSize.z/2 - (float)j)>; // Position Equation
45 llRezObject("Brick", rezPos, <0.0,0.0,0.0>, wallRot, startParam); // Rez them bricks
46 }
47 }
48 }
49 }

Opensim exploding wall and grenade

Allows the destructible wall's alpha to be changed via button click
Use: Apply this script to a button to change the wall's aplha; I called mine SetWallAlphaButton.

Category: Explosion
By : Steven Thompson
Created: 2015-04-23 Edited: 2015-04-23
Worlds: Second Life

1
2
3 // Copyright 2015 ARL
4 //Licensed under the Apache License, Version 2.0 (the "License");
5 //you may not use this file except in compliance with the License.
6 //You may obtain a copy of the License at
7 //
8 //http://www.apache.org/licenses/LICENSE-2.0
9 //
10 //Unless required by applicable law or agreed to in writing, software
11 //distributed under the License is distributed on an "AS IS" BASIS,
12 //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 //See the License for the specific language governing permissions and
14 // limitations under the License.
15
16
17 integer setWallAlphaButtonChannel = -88;
18
19 default
20 {
22 {
23 }
24 touch_start(integer num_detected)
25 {
26 llRegionSay(setWallAlphaButtonChannel, ""); // Send an empty message to DestructibleWall_Brick that makes it change its alpha
27 }
28 }

Opensim exploding wall and grenade

This script is nice to have but not necessarily essential. It allows the destructible wall to switch from being visible to invisible at the press of a button, which is nice if you need to know where it is when it's not populated by bricks or when it is populated by bricks and you don't want users to see the wall.
Use: Apply the script to the destructible that spawns the bricks. It will be listening for the corresponding button press.

Category: Explosion
By : Steven Thompson
Created: 2015-04-23 Edited: 2015-04-23
Worlds: Second Life

1
2
3 // Copyright 2015 ARL
4 //Licensed under the Apache License, Version 2.0 (the "License");
5 //you may not use this file except in compliance with the License.
6 //You may obtain a copy of the License at
7 //
8 //http://www.apache.org/licenses/LICENSE-2.0
9 //
10 //Unless required by applicable law or agreed to in writing, software
11 //distributed under the License is distributed on an "AS IS" BASIS,
12 //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 //See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 integer setWallAlphaButtonChannel = -88; // Channel for making the wall visible or transparent
17
18 default
19 {
21 {
22 integer listenHandle = llListen(setWallAlphaButtonChannel, "", "", ""); // Listen to SetWallAlpha Button
23 }
24 listen(integer channel, string name, key id, string message)
25 {
26 if(channel == setWallAlphaButtonChannel) { // Make sure the channel is correct
27 if(llGetAlpha(ALL_SIDES) == 0.0){
28 llSetAlpha(0.5, ALL_SIDES); // Make the wall half-way visible
29 } else {
30 llSetAlpha(0.0, ALL_SIDES); // Make the wall completely invisible
31 }
32 }
33 }
34 }

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