// Wolf Roleplay example - FARM PLOT. One prim of soil. Owned by the game's owner (or a no-modify // copy made by them), so it may move the game's items (wolfGameExchange). // // touch an empty plot -> plant: takes 1 seed // touch a growing plot -> water it (rain on the region waters it for you) // touch a ripe plot -> harvest: 3-5 wheat and 1-2 seeds back // // The crop survives a region restart: its state is kept in linkset data, and growth is worked // out from the time it was planted, not counted by a timer. Left dry for longer than DRY_SECONDS // it withers and the seed is lost. integer GROW_SECONDS = 1800; // each of the two growing stages integer DRY_SECONDS = 2700; // how long it can go without water vector SOIL = <0.36, 0.25, 0.16>; vector SPROUT = <0.45, 0.70, 0.25>; vector RIPE = <0.85, 0.72, 0.30>; vector DEAD = <0.40, 0.38, 0.30>; integer gMenu; integer MENU_CH; string lsd(string k) { return llLinksetDataRead(k); } put(string k, string v) { llLinksetDataWrite(k, v); } // 0 empty, 1 seedling, 2 growing, 3 ripe, 4 withered integer stage() { integer planted = (integer)lsd("planted"); if (planted == 0) return 0; if ((integer)lsd("withered")) return 4; integer now = llGetUnixTime(); if (now - (integer)lsd("watered") > DRY_SECONDS && now - planted < 2 * GROW_SECONDS) { put("withered", "1"); return 4; } if (now - planted >= 2 * GROW_SECONDS) return 3; if (now - planted >= GROW_SECONDS) return 2; return 1; } show() { integer s = stage(); vector c = SOIL; string t = "Empty plot\nTouch to plant (1 seed)"; if (s == 1) { c = SPROUT; t = "Seedling\nTouch to water"; } else if (s == 2) { c = SPROUT; t = "Growing\nTouch to water"; } else if (s == 3) { c = RIPE; t = "Ripe wheat\nTouch to harvest"; } else if (s == 4) { c = DEAD; t = "Withered - nobody watered it\nTouch to clear"; } llSetColor(c, ALL_SIDES); llSetText(t, <1, 1, 1>, 1.0); } // Rain on the region waters every plot on it. checkRain() { list w = wolfGetRegionWeather(); integer i = llListFindList(w, ["kind"]); if (i != -1 && llList2String(w, i + 1) == "rain" && (integer)lsd("planted") && !(integer)lsd("withered")) put("watered", (string)llGetUnixTime()); } default { state_entry() { MENU_CH = -2000000 - (integer)llFrand(1000000); show(); llSetTimerEvent(60.0); } on_rez(integer p) { llResetScript(); } timer() { checkRain(); show(); } touch_start(integer n) { key av = llDetectedKey(0); if (!wolfGameIsPlaying(av)) { llRegionSayTo(av, 0, "Join the game first (Roleplay floater > Join)."); return; } integer s = stage(); if (s == 0) { // Planting costs one seed - taken in the same step the plot is claimed. if (!wolfGameExchange(av, ["seed", 1], [], "planted wheat")) { llRegionSayTo(av, 0, "You need a wheat seed to plant here (" + wolfGetLastError() + ")."); return; } put("planted", (string)llGetUnixTime()); put("watered", (string)llGetUnixTime()); put("farmer", (string)av); put("withered", "0"); } else if (s == 1 || s == 2) { put("watered", (string)llGetUnixTime()); llRegionSayTo(av, 0, "Watered."); } else if (s == 3) { integer wheat = 3 + (integer)llFrand(3.0); integer seeds = 1 + (integer)llFrand(2.0); if (!wolfGameExchange(av, [], ["wheat", wheat, "seed", seeds], "harvest")) { llRegionSayTo(av, 0, "Could not harvest: " + wolfGetLastError()); return; } wolfGameNotify(av, "Harvest", "You harvested " + (string)wheat + " wheat and " + (string)seeds + " seeds.", "success"); llLinksetDataReset(); } else if (s == 4) { llLinksetDataReset(); llRegionSayTo(av, 0, "Cleared. Plant again with a seed."); } show(); } }