CHAPTER 1
CHAPTER 2
CHAPTER 3
CHAPTER 4
CHAPTER 5
CHAPTER 7
CHAPTER 9
CHAPTER 10
CHAPTER 11
CHAPTER 12
CHAPTER 13
CHAPTER 14
CHAPTER 15
APPENDIC
E
S
145
CHAPTER 6
SHAPING THE LAND BY TERRAFORMING
You can certainly be your own landscape contractor in Second Life, as this next series of scripts reveals.
Most people terraform their land manually, using the SL GUI. You can raise and lower the land to create
mountains or pools. You can also use a scripted approach to terraforming, which might allow you to, for
example, quickly create a mountain range or a sequence of tidal pools. The script shown in Listing 6.4
lowers the land and rezzes a pool of water into the depression. (The ground at SYW HQ is at such a high
altitude that only a very deep well would reach the real SL water.) You can extend this idea to have each
mountain rez its own forest, snow-capped peaks, and ski lodges.
Create a cylinder, name it Pool, apply a watery texture to it, and place the code from Listings 6.2 and
6.5 in its Content folder. Create another object and call it Digger; place Listing 6.4s code and the Pool
in its Content folder.
BUILD NOTE
Listing 6.4: Terraforming Pool Digger
integer OB_CHANNEL = -654321; // or use a random value
integer gRadius = 4; // how far to scan around starting point
integer gBrush = 0; // brush size 0=2m, 1=4m, 2=8m: see wiki
integer gDig = TRUE; // should we dig on the next touch?
scan(vector center, integer operation) {
float step = llPow(2.0, (float) gBrush);
float x;
for (x = -gRadius; x <= gRadius; x += step) {
float y;
for (y = -gRadius; y <= gRadius; y += step) {
vector p = <center.x + x, center.y + y, center.z>;
float dist = llVecDist(p, center);
if (dist <= gRadius) {
llSetPos(p);
integer z;
integer c = (integer) (((float) gRadius - dist) / 2);
for (z = 0; z <= c; z++) {
llModifyLand(operation, gBrush);
}
}
}
}
}
CHAPTER 6
146
A WATERFALL
SHAPING THE
LAND BY
TERRAFORMING
LAND
SECURITY
ARE YOU ON
THE LIST?
LAND
INFORMATION
FUNCTIONS
SUMMARY
default
{
touch_start(integer total_number) {
vector home = llGetPos();
if (gDig) {
scan(home, LAND_LOWER);
} else {
llSay(OB_CHANNEL, “die”);
scan(home, LAND_RAISE);
}
llSetPos(home);
if (gDig) {
llRezObject(“Pool”, <home.x, home.y, home.z - 1.0>,
<0,0,0>, ZERO_ROTATION, OB_CHANNEL);
llSay(OB_CHANNEL, “size=” + (string)(2 * (gRadius + 1)));
}
gDig = !gDig;
}
}
When the Digger is touched, if the state of gDig is TRUE, it lowers the land; that is, it digs a pool
gRadius meters wide and rezzes the Pool (a cylinder with a water texture) to fill it. The digger object
must also have the Pool in inventory, as llRezObject() will be used to generate it. Figure 6.3 shows
the digger at work and the finished pool.
Figure 6.3: Terraforming Digger at
work before the Pool is rezzed, and the
completed Pool
The basic function call, used in a loop, is llModifyLand(). The loop control moves around the
starting point from east to west in the y direction and north to south in the x direction. The brush
argument pushes the land beneath the object in which it exists in the direction specified by the action
argument. On alternate touches, the Digger lowers the land and raises it back.

Get Scripting Your World: The Official Guide to Second Life® Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.