// Wolf Roleplay example - THE PET OBJECT ("Wolf pup"). Made by the game's owner, given no-modify, // so this script may change its own owner's pet (it counts as the game's own item). // // The pet itself lives on the grid; this object only shows it. The first time it is rezzed it // takes the owner's newest pet of this type that no object has claimed yet, and keeps that pet // key in linkset data, so the same pet comes back every time it is rezzed. // // touch: Feed (1 pet food), Play, Rename, Status string TYPE = "wolf_pup"; integer MENU_CH; integer gMenu; integer gRename; string pet() { return llLinksetDataRead("pet"); } // The owner's pets of this type that are alive: the newest one this object can take. claim() { list pets = wolfGamePets(llGetOwner()); // [key, type, name, alive, ...] integer i; string chosen = ""; for (i = 0; i < llGetListLength(pets); i += 4) if (llList2String(pets, i + 1) == TYPE && llList2Integer(pets, i + 3)) chosen = llList2String(pets, i); // the list is oldest first; keep the newest if (chosen != "") llLinksetDataWrite("pet", chosen); } show() { if (pet() == "") { llSetText("No pet - buy one at the pet shop", <1, 0.6, 0.6>, 1.0); return; } list p = wolfGamePetGet(pet()); // [type, name, owner, alive, age, stat, v, m, ...] if (p == []) { llSetText("(" + wolfGetLastError() + ")", <1, 0.6, 0.6>, 1.0); return; } if (llList2String(p, 2) != (string)llGetOwner()) { // Given or sold to someone else since: this copy no longer shows that pet. llLinksetDataDelete("pet"); llSetText("This pet belongs to someone else now", <1, 0.6, 0.6>, 1.0); return; } string t = llList2String(p, 1); if (!llList2Integer(p, 3)) t += " (died)"; else { integer days = llList2Integer(p, 4) / 86400; t += " - " + (string)days + " day" + llList2String(["s", ""], days == 1); integer i; for (i = 5; i < llGetListLength(p); i += 3) t += "\n" + llList2String(p, i) + " " + (string)llList2Integer(p, i + 1) + "/" + (string)llList2Integer(p, i + 2); } llSetText(t, <1, 1, 1>, 1.0); } default { state_entry() { MENU_CH = -5000000 - (integer)llFrand(1000000); if (pet() == "") claim(); show(); llSetTimerEvent(120.0); } on_rez(integer p) { llResetScript(); } changed(integer c) { if (c & CHANGED_OWNER) { llLinksetDataReset(); llResetScript(); } } timer() { show(); } touch_start(integer n) { key av = llDetectedKey(0); if (av != llGetOwner()) return; llListenRemove(gMenu); gMenu = llListen(MENU_CH, "", av, ""); llDialog(av, "Your wolf pup", ["Feed", "Play", "Rename", "Status"], MENU_CH); } listen(integer ch, string name, key av, string msg) { if (ch == MENU_CH + 1) { llListenRemove(gRename); if (!wolfGamePetRename(pet(), llStringTrim(msg, STRING_TRIM))) llOwnerSay(wolfGetLastError()); } else if (msg == "Feed") { // One pet food, taken from the owner's game items, then +30 food for the pup. if (!wolfGameExchange(av, ["pet_food", 1], [], "fed the pup")) llOwnerSay("No pet food: " + wolfGetLastError()); else if (!wolfGamePetAddStat(pet(), "hunger", 30)) llOwnerSay(wolfGetLastError()); } else if (msg == "Play") { if (!wolfGamePetAddStat(pet(), "happiness", 20)) llOwnerSay(wolfGetLastError()); else llSetTimerEvent(120.0); } else if (msg == "Rename") { gRename = llListen(MENU_CH + 1, "", av, ""); llTextBox(av, "New name:", MENU_CH + 1); } show(); } }