// *********************** // ** Kudzu Lord v1.2.1 ** // ** By Gorvin ** // *********************** // ************************************************************************************ // /zu - Plants a seed. If a non-empty bag is not currently equipped, one will be // equipped and planted from. // /zuget - Starts or stops a loop that automatically stores seeds into your bags as // they are picked up. // /zustore - Stores any loose seeds in your inventory into bags. // /zutrans - Transfers seeds from one bag to another. // If amount is unspecified, all seeds will be transfered from the specified bag. // Example: "/zutrans 3 1 5" to transfer 5 seeds from bag #3 to bag #1. // ************************************************************************************ setglobal gZu_running 0 setglobal gZu_storing 0 setglobal gZu_loose 0 setglobal gZu_ping 0 "/zu" { call "fZu_plant" } "/zuget" { call "fZu_auto_store" } "/zustore" { call "fZu_store" } "/zutrans" { set aZu_from @text.word[0] set aZu_to @text.word[1] set aZu_amount @text.word[2] call "fZu_transfer" if rZu_failure == 1 message "/zutrans - Transfers seeds from one bag to another." message "If amount is unspecified, all seeds will be transfered from the specified bag." message "Example: \"/zutrans 3 1 5\" to transfer 5 seeds from bag #3 to bag #1." else if rZu_failure == 2 message "Bag" aZu_from "doesn't exist." else if rZu_failure == 3 message "Bag" aZu_to "doesn't exist." end if } // ********** Internal functions: ********** // Calls the seed planter function, or if the function is already running, tells it to plant another seed. fZu_plant { // If the loop isn't running yet, start it up. if gZu_running == 0 call "fZu_plant_loop" else // If the loop is running, tell it to plant a seed. setglobal gZu_plant + 1 // Set a variable to ping the loop to be certain that nothing has broken it. setglobal gZu_ping 0 set zu_wait 6 // Scan for 6 frames. If the loop hasn't reset the ping variable in that time, // it must have been broken. Start it up if so. label ZUPINGWAIT if gZu_ping == 0 if zu_wait > 0 set zu_wait - 1 pause 1 goto "ZUPINGWAIT" else setglobal gZu_ping 1 message "Loop break detected." call "fZu_plant_loop" end if end if end if } // Plants a seed. If /zu is called again while this function is running (eg pressed twice in the same frame), // it will queue up another seed to be planted by this function. fZu_plant_loop { setglobal gZu_running 1 setglobal gZu_plant 1 // Run loop until number of seeds to be planted reaches 0. label ZULOOP // Return a ping that confirms to the /zu command that the loop // hasn't been broken. setglobal gZu_ping 1 // If we have been told to plant a seed via the /zu command, plant a seed. if gZu_plant > 0 setglobal gZu_plant - 1 // First, equip a non-empty bag if one is not already equipped. set aZu_nonempty 1 call "fZu_equip" // If no bag was equipped, there are no non-empty bags. if rZu_bag == 0 message "*** You have no seeds left. ***" setglobal gZu_plant 0 else // Plant a seed from the equipped bag. "/useitem bagofkudzuseedlings\r" end if setglobal gZu_ping 1 pause 1 goto "ZULOOP" end if setglobal gZu_running 0 } // Finds and equips a non-empty/full bag if one is not already equipped. // Args: // aZu_nonempty - 1 if looking for a non-empty bag. // 0 if looking for a non-full bag. // Returns: // rZu_bag - Bag number of the bag that was equipped by this function call. // Returns 0 if no non-empty/full bag was found. // rZu_seeds - Number of seeds in the bag. Returns -1 if a bag with no seed // count label was equipped. fZu_equip { set zu_bag 0 // Set what comparisons to make depending on if we're looking for a non-empty or // non-full bag. if aZu_nonempty == 1 set zu_look 0 else set zu_look 10 end if set zu_seeds zu_look // Get currently equipped bag number and seed count, if any. set aZu_name @my.left_item if aZu_name >= "bag of kudzu seedlings <#" call "fZu_get_bag_number" set zu_bag rZu_bag call "fZu_get_seed_count" set zu_seeds rZu_seeds // If we're equipped with bag with an unknown quantity, treat it as empty // or full so that we'll move on to the next bag. if zu_seeds == -1 set zu_seeds zu_look end if end if set rZu_bag zu_bag // If we have an empty/full bag equipped, or no bag equipped, find the next // non-empty/full one. if zu_seeds == zu_look // Sequentially check each bag in inventory. // Start with the first bag, or the one after the currently equipped bag. set zu_end zu_bag label ZUFIND set zu_bag + 1 // If we've done a full loop, there is no non-empty/full bag. if zu_bag == zu_end set rZu_bag 0 else // Use /selectitem to scan for the next bag in inventory. set zu_compare "bag of kudzu seedlings <#" set zu_compare + zu_bag "/selectitem \"bag of kudzu seedlings <#" zu_bag "\"\r" set aZu_name @my.selected_item if aZu_name >= zu_compare // If we found a bag, get its seed count. call "fZu_get_seed_count" set zu_seeds rZu_seeds // If this bag isn't empty/full, we've found what we // wanted, otherwise check next bag. if zu_seeds != zu_look set rZu_bag zu_bag else goto "ZUFIND" end if else // There is no bag with this bag number, loop back to 1, // unless we started at 1. if zu_end == 0 set rZu_bag 0 else set zu_bag 0 goto "ZUFIND" end if end if end if // If we found a non-empty bag, equip it. if rZu_bag != 0 "/equip bagofkudzuseedlings" rZu_bag "\r" end if end if set rZu_seeds zu_seeds } // Returns bag number of a bag, given its full item name. // Args: // aZu_name - Bag's item name. // Returns: // rZu_bag - Bag number of specified bag. fZu_get_bag_number { // Item number starts at the 25th letter in the item's name. // The 26th letter must be checked also, in case the number is 10 or greater. set rZu_bag aZu_name.letter[25] if aZu_name.letter[26] != ":" if aZu_name.letter[26] != ">" if aZu_name.letter[26] != "" set rZu_bag * 10 set rZu_bag + aZu_name.letter[26] end if end if end if } // Returns number of seeds in a bag, given its full item name. // Args: // aZu_name - Bag's item name. // Returns: // rZu_seeds - Number of seeds in specified bag. // -1 is returned if the bag doesn't have a labeled seed count. fZu_get_seed_count { // Get the very last word in the item's label. set zu_word aZu_name.num_words set zu_word - 1 set zu_word aZu_name.word[zu_word] set zu_letter 0 // If the item has a custom label, the seed count will be in parenthesis. if zu_word.letter[0] == "(" set zu_letter 1 end if // Check to make sure there is actually a labeled seed count. if zu_word.letter[zu_letter] >= 0 // Get the labeled seed count. set rZu_seeds zu_word.letter[zu_letter] else // Return -1 if there is no labeled seed count. set rZu_seeds -1 end if // If the first digit is 1, the seed count may be 10 and thus contain 2 digits. if rZu_seeds == 1 set zu_letter + 1 if zu_word.letter[zu_letter] == 0 set rZu_seeds 10 end if end if } // Starts or stops a loop that automatically stores seeds into your bags as they // are picked up. fZu_auto_store { // Start up the loop if it isn't already being run. Otherwise, terminate it. if gZu_storing == 0 call "fZu_store_loop" else setglobal gZu_storing 0 end if } // Stores any loose seeds into your bags. fZu_store { message "* Storing loose seedlings." // If the auto-store loop is running, just tell it to store some seeds. if gZu_storing == 1 setglobal gZu_loose 32 else set zu_delay 0 set zu_loose 32 // Store seeds until there are no loose ones remaining in inventory. label ZUSTORE set zu_msg @env.textLog // Scan for "you don't have any seeds" messages, and end the loop if detected. if zu_msg >= "* You don't have any kudzu seedlings." message "All loose seeds stored." set zu_loose 0 end if // If we're still storing seeds and we've passed the delay period, store a seed. if zu_loose > 0 if zu_delay > 0 set zu_delay - 1 else set zu_loose - 1 call "fZu_store_single" // Set a delay period for when another seed can be stored. This is // done so that reasonable amounts of lag won't throw off what bag // the function thinks is currently equipped or how many seeds are // in it. set zu_delay 4 // Terminate the loop if we couldn't find a non-full bag to store in. if rZu_failure == 1 set zu_loose 0 message "*** All bags are full. ***" end if end if pause 1 goto "ZUSTORE" end if end if } // Runs a loop that automatically stores seeds into your bags as they are picked up. fZu_store_loop { setglobal gZu_storing 1 setglobal gZu_loose 32 set zu_delay 0 message "* Automatically storing seedlings." label ZUAUTOSTORE // Loop continues until another /zuget call sets the global variable back to 0. if gZu_storing == 1 set zu_msg @env.textLog // Scan for seed pickup messages, and increment the loose seed count if // detected. Set loose seed count to 0 if a "you don't have any seeds" // message is detected. if zu_msg >= "You pick up a kudzu seedling." message "Loose seed obtained." setglobal gZu_loose + 1 else if zu_msg >= "* You don't have any kudzu seedlings." message "All loose seeds stored." setglobal gZu_loose 0 end if // If we have a loose seed to store and we've passed the delay period, // store a seed. if zu_delay > 0 set zu_delay - 1 else if gZu_loose > 0 setglobal gZu_loose - 1 call "fZu_store_single" // Set a delay period for when another seed can be stored. This is // done so that reasonable amounts of lag won't throw off what bag // the function thinks is currently equipped or how many seeds are // in it. set zu_delay 4 // If all bags were found to be full, set loose seed count to 0 to // stop trying to store any currently loose seeds. if rZu_failure == 1 setglobal gZu_loose 0 message "*** All bags are full. ***" end if end if pause 1 goto "ZUAUTOSTORE" end if message "* No longer automatically storing seedlings." } // Finds and equips a non-full bag, and stores a seed in it. // Returns: // rZu_failure - 0 if the function was successful. 1 if all bags are currently full. fZu_store_single { // First, equip a non-full bag if one is not already equipped. set aZu_nonempty 0 call "fZu_equip" // If no bag was equipped, there are no non-empty bags. if rZu_bag == 0 set rZu_failure 1 else // Store a seed in the equipped bag. set rZu_failure 0 "/useitem bagofkudzuseedlings /add\r" end if } // Transfers seeds from one bag to another. // Args: // aZu_from - Bag number to transfer from. // aZu_to - Bag number to transfer to. // aZu_amount - How many seeds to transfer. If is a null string, all seeds will // be transfered. // Returns: // rZu_failure - 0 if the function was successful. // 1 if there was an error in the passed parameters. // 2 if "from" bag doesn't exist. // 3 if "to" bag doesn't exist. fZu_transfer { // First, determine if there were any errors in the passed parameters. // Also determine how many seeds to transfer set rZu_failure 1 // Check for null strings and values below 1 for bag numbers if aZu_from != "" if aZu_from > 0 if aZu_to != "" if aZu_to > 0 // Cannot transfer from a bag to itself. if aZu_from != aZu_to // If a null string was specified for the transfer // amount, the amount is 10. if aZu_amount == "" set rZu_failure 0 set zu_seeds 10 else if aZu_amount >= 0 set rZu_failure 0 set zu_seeds 0 set zu_seeds + aZu_amount end if end if end if end if end if end if // If there was no error, use /selectitem to ensure that the specified bags exist. // Also cap the transfer amount if we're trying to transfer more seeds than exist // in the first bag, or more seeds than can be fit into the second bag. if rZu_failure == 0 set zu_compare "bag of kudzu seedlings <#" set zu_compare + aZu_from "/selectitem \"bag of kudzu seedlings <#" aZu_from "\"\r" set aZu_name @my.selected_item if aZu_name >= zu_compare // Get a seed count from this bag. call "fZu_get_seed_count" // If the seed count is smaller than the transfer amount, only transfer // as many as are in the bag. if rZu_seeds != -1 if zu_seeds > rZu_seeds set zu_seeds rZu_seeds end if end if set zu_compare "bag of kudzu seedlings <#" set zu_compare + aZu_to "/selectitem \"bag of kudzu seedlings <#" aZu_to "\"\r" set aZu_name @my.selected_item if aZu_name >= zu_compare // Get a seed count from this bag. call "fZu_get_seed_count" // If the remaining capacity in this bag is smaller than the // transfer amount, only transfer as many as can be fit into the bag. if rZu_seeds != -1 set zu_capacity 10 set zu_capacity - rZu_seeds if zu_seeds > zu_capacity set zu_seeds zu_capacity end if end if else set rZu_failure 3 end if else set rZu_failure 2 end if end if // If there was still no error, proceed with the transfer. if rZu_failure == 0 label ZUTRANS if zu_seeds > 0 "/equip bagofkudzuseedlings" aZu_from "\r" "/useitem left /remove\r" "/equip bagofkudzuseedlings" aZu_to "\r" "/useitem left /add\r" set zu_seeds - 1 goto "ZUTRANS" end if end if }