// ************************************* // ** Pretty Basic Kudzu Macro v2.0.2 ** // ** By Gorvin ** // ************************************* // **************************************************************************************** // /zu - Plants a seed. If a non-empty container is not currently equipped, one will // be equipped and planted from. // /zuget - Starts or stops a loop that automatically stores seeds into your containers as // they are picked up. // /zustore - Stores any loose seeds in your inventory into containers. // /zutrans from <#> to <#> - Transfers seeds // from one container to another. // Example: "/zutrans 5 from bag 3 to pack 1" to transfer 5 seeds from bag #3 to pack #1. // **************************************************************************************** setglobal gZu_running 0 setglobal gZu_storing 0 setglobal gZu_loose 0 setglobal gZu_ping 0 setglobal gZu_lastEquippedType 0 setglobal gZu_lastEquippedItemNum 0 setglobal gZu_types "sack pack bag" setglobal gZu_capacity "50 20 10" "/zu" { call "fZu_plant" } "/zuget" { call "fZu_auto_store" } "/zustore" { call "fZu_store" } "/zutrans" { set aZu_amount -1 set aZu_from_type 0 set aZu_from_item_num -1 set aZu_to_type 0 set aZu_to_item_num -1 set zu_word_idx 0 set zu_word @text.word[zu_word_idx] set aZu_string zu_word call "fZu_isBeginNumber" if rZu_isNum == 1 set aZu_amount zu_word set zu_word_idx + 1 set zu_word @text.word[zu_word_idx] end if if zu_word == "from" set zu_word_idx + 1 set zu_word @text.word[zu_word_idx] set zu_next "from" else if zu_word == "to" set zu_word_idx + 1 set zu_word @text.word[zu_word_idx] set zu_next "to" else set zu_next "" end if set zu_type 0 label ZUTYPE1 if zu_word == gZu_types.word[zu_type] if zu_next == "from" set aZu_from_type zu_type else if zu_next == "to" set aZu_to_type zu_type end if set zu_word_idx + 1 set zu_word @text.word[zu_word_idx] else set zu_type + 1 if zu_type < gZu_types.num_words goto "ZUTYPE1" end if end if set aZu_string zu_word call "fZu_isBeginNumber" if rZu_isNum == 1 if zu_next == "from" set aZu_from_item_num zu_word else if zu_next == "to" set aZu_to_item_num zu_word end if set zu_word_idx + 1 set zu_word @text.word[zu_word_idx] end if if zu_word == "from" set zu_word_idx + 1 set zu_word @text.word[zu_word_idx] set zu_next "from" else if zu_word == "to" set zu_word_idx + 1 set zu_word @text.word[zu_word_idx] set zu_next "to" else set zu_next "" end if set zu_type 0 label ZUTYPE2 if zu_word == gZu_types.word[zu_type] if zu_next == "from" set aZu_from_type zu_type else if zu_next == "to" set aZu_to_type zu_type end if set zu_word_idx + 1 set zu_word @text.word[zu_word_idx] else set zu_type + 1 if zu_type < gZu_types.num_words goto "ZUTYPE2" end if end if set aZu_string zu_word call "fZu_isBeginNumber" if rZu_isNum == 1 if zu_next == "from" set aZu_from_item_num zu_word else if zu_next == "to" set aZu_to_item_num zu_word end if set zu_word_idx + 1 set zu_word @text.word[zu_word_idx] end if if zu_word == "to" set zu_word_idx + 1 set zu_word @text.word[zu_word_idx] end if set zu_revertItem @my.left_item call "fZu_transfer" if rZu_failure == 1 message "/zutrans from <#> to <#> - Transfers seeds from one container to another." message "Example: \"/zutrans 5 from bag 3 to pack 1\" to transfer 5 seeds from bag #3 to pack #1." else if rZu_failure == 2 message gZu_types.word[aZu_from_type] aZu_from_item_num "not found in inventory." else if rZu_failure == 3 message gZu_types.word[aZu_to_type] aZu_to_item_num "not found in inventory." end if set aZu_item zu_revertItem call "fZu_revertEquip" } // ********** 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 set aZu_string @text.word[0] call "fZu_isBeginNumber" if rZu_isNum == 1 setglobal gZu_plant @text.word[0] else setglobal gZu_plant 1 end if set zu_revertItem @my.left_item setglobal gZu_running 1 call "fZu_plant_loop" setglobal gZu_running 0 set aZu_item zu_revertItem call "fZu_revertEquip" else // If the loop is running, tell it to plant another 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 } // Equips previously equipped left-hand item if it wasn't a kudzu container. // Args: // aZu_item - Item name. fZu_revertEquip { set zu_equip aZu_item set zu_type 0 label ZUEQUIPPED set zu_item gZu_types.word[zu_type] set zu_item + " of kudzu seedlings" if aZu_item >= zu_item set zu_equip "" else set zu_type + 1 if zu_type < gZu_types.num_words goto "ZUEQUIPPED" end if end if if zu_equip != "" if @my.left_item != zu_equip if zu_equip == "Nothing" "/unequip left\r" else "/equip \"" zu_equip "\"\r" 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 { set zu_timeout 0 // Run loop until number of seeds to be planted reaches 0 and timeout is reached. 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 container if one is not already equipped. set aZu_nonempty 1 set aZu_remember 1 call "fZu_equip" // If no container was equipped, there are no non-empty container. if rZu_type == -1 message "*** You have no seeds left. ***" setglobal gZu_plant 0 else // Plant a seed from the equipped container. "/useitem " gZu_types.word[rZu_type] "ofkudzuseedlings\r" set zu_timeout 15 end if setglobal gZu_ping 1 pause 1 goto "ZULOOP" else if zu_timeout > 0 set zu_timeout - 1 pause 1 goto "ZULOOP" end if end if } // Finds and equips a non-empty/full container if one is not already equipped. // Args: // aZu_nonempty - 1 if looking for a non-empty container. // 0 if looking for a non-full container. // aZu_remember - 1 if this function should remember the last equipped container. // Returns: // rZu_type - Type of container that was equipped. 0=Sack, 1=Pack, 2=Bag, -1=None. // rZu_item_num - Container number. Returns 0 if no non-empty/full container was found. // rZu_seeds - Number of seeds in the container. fZu_equip { // Get item number of equipped container. set aZu_name @my.left_item call "fZu_get_container_type_and_item_num" if rZu_type < 0 // No container equipped. if aZu_remember == 1 set zu_type gZu_lastEquippedType set zu_item_num gZu_lastEquippedItemNum if zu_item_num > 0 set zu_type_stop zu_type set zu_item_num_stop zu_item_num set zu_item_num_stop - 1 end if else set zu_item_num 0 end if if zu_item_num <= 0 set zu_type 0 set zu_item_num 1 set zu_type_stop gZu_types.num_words set zu_type_stop - 1 set zu_item_num_stop 999 end if else // Container equipped. set zu_type rZu_type set zu_item_num rZu_item_num call "fZu_get_seed_count" // Check if equipped container is what we're looking for. if aZu_nonempty == 1 if rZu_seeds > 0 goto "ZURETURN" end if else if rZu_seeds < gZu_capacity.word[zu_type] goto "ZURETURN" end if end if set zu_type_stop zu_type set zu_item_num_stop zu_item_num set zu_item_num_stop - 1 set zu_item_num + 1 end if if zu_item_num_stop == 0 set zu_type_stop - 1 if zu_type_stop < 0 set zu_type_stop gZu_types.num_words set zu_type_stop - 1 end if set zu_item_num_stop 999 end if // Sequentially check each container in inventory. label ZUFIND // Use /selectitem to scan for the next container in inventory. set zu_select gZu_types.word[zu_type] set zu_select + " of kudzu seedlings <#" set zu_select + zu_item_num "/selectitem \"" zu_select "\"\r" set aZu_name @my.selected_item if aZu_name >= zu_select // Container exists, check seed count. call "fZu_get_seed_count" set zu_done 0 if aZu_nonempty == 1 if rZu_seeds > 0 set zu_done 1 end if else if rZu_seeds < gZu_capacity.word[zu_type] set zu_done 1 end if end if if zu_done == 1 // Valid container found. set rZu_type zu_type set rZu_item_num zu_item_num "/equip " gZu_types.word[zu_type] "ofkudzuseedlings" zu_item_num "\r" if aZu_remember == 1 setglobal gZu_lastEquippedType zu_type setglobal gZu_lastEquippedItemNum zu_item_num end if goto "ZURETURN" end if // Check next container. if zu_item_num == zu_item_num_stop if zu_type == zu_type_stop goto "ZUFAIL" end if end if set zu_item_num + 1 else // This container doesn't exist, check next container type. if zu_type == zu_type_stop if zu_item_num <= zu_item_num_stop goto "ZUFAIL" end if end if set zu_type + 1 if zu_type >= gZu_types.num_words set zu_type 0 end if set zu_item_num 1 end if goto "ZUFIND" label ZUFAIL set rZu_type -1 set rZu_item_num 0 set rZu_seeds 0 label ZURETURN } // Returns container type and number. // Args: // aZu_name - Container's item name. // Returns: // rZu_type - Container type (0=Sack, 1=Pack, 2=Bag, -1=None) // rZu_item_num - Container number. fZu_get_container_type_and_item_num { // Get currently equipped container type. set zu_type 0 set zu_valid 0 label ZUTYPE set zu_name gZu_types.word[zu_type] set zu_name + " of kudzu seedlings" if aZu_name >= zu_name set zu_valid 1 else set zu_type + 1 if zu_type <= gZu_types.num_words goto "ZUTYPE" end if end if set rZu_type -1 set rZu_item_num 0 if zu_valid == 1 set zu_char_idx 21 set zu_char_idx + gZu_types.word[zu_type].num_letters set zu_char aZu_name.letter[zu_char_idx] if zu_char == "#" set rZu_type zu_type set zu_char_idx + 1 set zu_char aZu_name.letter[zu_char_idx] set aZu_string zu_char call "fZu_isBeginNumber" if rZu_isNum == 1 set rZu_item_num zu_char set zu_char_idx + 1 set zu_char aZu_name.letter[zu_char_idx] if zu_char != ":" if zu_char != ">" if zu_char != "" set aZu_string zu_char call "fZu_isBeginNumber" if rZu_isNum == 1 // Container number is double digit set rZu_item_num * 10 set rZu_item_num + zu_char end if end if end if end if end if end if end if } // Returns number of seeds in a container. // Args: // aZu_name - Container's item name. // Returns: // rZu_seeds - Number of seeds in specified container. fZu_get_seed_count { // Get the very last word in the item's label. set zu_word_idx aZu_name.num_words set zu_word_idx - 1 set zu_word aZu_name.word[zu_word_idx] set zu_char_idx 0 set zu_char zu_word.letter[zu_char_idx] // If the item has a custom label, the seed count will be in parenthesis. if zu_char == "(" set zu_char_idx + 1 set zu_char zu_word.letter[zu_char_idx] end if // Check to make sure there is actually a labeled seed count. set rZu_seeds 0 if zu_char != ")" if zu_char != "<" if zu_char != ">" if zu_char != "" set aZu_string zu_char call "fZu_isBeginNumber" if rZu_isNum == 1 set rZu_seeds zu_char end if end if end if end if end if if rZu_seeds > 0 set zu_char_idx + 1 set zu_char zu_word.letter[zu_char_idx] if zu_char != ")" if zu_char != ">" if zu_char != "" set aZu_string zu_char call "fZu_isBeginNumber" if rZu_isNum == 1 // Double digit seed count set rZu_seeds * 10 set rZu_seeds + zu_char end if end if end if end if end if } // Starts or stops a loop that automatically stores seeds into your containers 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 containers. 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_revertItem @my.left_item 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 container // 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 container to store in. if rZu_failure == 1 set zu_loose 0 message "*** All containers are full. ***" end if end if pause 1 goto "ZUSTORE" end if set aZu_item zu_revertItem call "fZu_revertEquip" end if } // Runs a loop that automatically stores seeds into your containers as they are picked up. fZu_store_loop { setglobal gZu_storing 1 setglobal gZu_loose 32 set zu_delay 0 set zu_revertItem "" 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." 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 if zu_revertItem != "" set aZu_item zu_revertItem call "fZu_revertEquip" set zu_revertItem "" end if else if gZu_loose > 0 if zu_revertItem == "" set zu_revertItem @my.left_item end if 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 container the function // thinks is currently equipped or how many seeds are in it. set zu_delay 4 // If all containers were found to be full, set loose seed count // to 0 to stop trying to store any remaining loose seeds. if rZu_failure == 1 setglobal gZu_loose 0 message "*** All containers are full. ***" end if end if pause 1 goto "ZUAUTOSTORE" end if message "* No longer automatically storing seedlings." if zu_revertItem != "" set aZu_item zu_revertItem call "fZu_revertEquip" set zu_revertItem "" end if } // Finds and equips a non-full container, and stores a seed in it. // Returns: // rZu_failure - 0 if the function was successful. 1 if all containers are currently full. fZu_store_single { // First, equip a non-full container if one is not already equipped. set aZu_nonempty 0 set aZu_remember 1 call "fZu_equip" // If no container was equipped, there are no non-empty containers. if rZu_type == -1 set rZu_failure 1 else // Store a seed in the equipped container. set rZu_failure 0 "/useitem " gZu_types.word[rZu_type] "ofkudzuseedlings /add\r" end if } // Transfers seeds from one container to another. // Args: // aZu_from_type - Container type to transfer from. // aZu_from_item_num - Container number to transfer from. // aZu_to_type - Container type to transfer to. // aZu_to_item_num - Container 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" container doesn't exist. // 3 if "to" container doesn't exist. fZu_transfer { // First, determine if there were any errors in the passed parameters. set rZu_failure 1 if aZu_from_item_num != "" if aZu_from_item_num > 0 if aZu_to_item_num != "" if aZu_to_item_num > 0 if aZu_from_item_num != aZu_to_item_num set rZu_failure 0 else if aZu_from_type != aZu_to_type set rZu_failure 0 end if end if end if end if end if end if // Get number of seeds to transfer. if rZu_failure == 0 set zu_seeds aZu_amount if zu_seeds < 0 set zu_seeds gZu_capacity.word[aZu_from_type] end if end if // Use /selectitem to ensure that the specified containers exist. // Also cap the transfer amount if we're trying to transfer more seeds than exist in the // first container, or more seeds than can be fit into the second container. if rZu_failure == 0 set zu_select gZu_types.word[aZu_from_type] set zu_select + " of kudzu seedlings <#" set zu_select + aZu_from_item_num "/selectitem \"" zu_select "\"\r" set aZu_name @my.selected_item if aZu_name >= zu_select // Get a seed count from this container. call "fZu_get_seed_count" // If the seed count is smaller than the transfer amount, only transfer // as many as are in the container. if zu_seeds > rZu_seeds set zu_seeds rZu_seeds end if set zu_select gZu_types.word[aZu_to_type] set zu_select + " of kudzu seedlings <#" set zu_select + aZu_to_item_num "/selectitem \"" zu_select "\"\r" set aZu_name @my.selected_item if aZu_name >= zu_select // Get a seed count from this container. call "fZu_get_seed_count" // If the remaining capacity in this container is smaller than the // transfer amount, only transfer as many as can be fit into the container. set zu_capacity gZu_capacity.word[aZu_to_type] set zu_capacity - rZu_seeds if zu_seeds > zu_capacity set zu_seeds zu_capacity end if else set rZu_failure 3 end if else set rZu_failure 2 end if end if // Transfer the seeds. if rZu_failure == 0 label ZUTRANS if zu_seeds > 0 set zu_item gZu_types.word[aZu_from_type] set zu_item + "ofkudzuseedlings" set zu_item + aZu_from_item_num "/equip " zu_item "\r" "/useitem " zu_item " /remove\r" set zu_item gZu_types.word[aZu_to_type] set zu_item + "ofkudzuseedlings" set zu_item + aZu_to_item_num "/equip " zu_item "\r" "/useitem " zu_item " /add\r" set zu_seeds - 1 goto "ZUTRANS" end if end if } // Test if string begins with a number. (Workaround for Clieunk) // Args: // aZu_string - String to test. // Returns: // rZu_isNum - 0 if does not begin with a number. // 1 if begins with a number. fZu_isBeginNumber { if aZu_string == "" set rZu_isNum 0 else set zu_letter aZu_string.letter[0] if zu_letter == "0" set rZu_isNum 1 else if zu_letter == "1" set rZu_isNum 1 else if zu_letter == "2" set rZu_isNum 1 else if zu_letter == "3" set rZu_isNum 1 else if zu_letter == "4" set rZu_isNum 1 else if zu_letter == "5" set rZu_isNum 1 else if zu_letter == "6" set rZu_isNum 1 else if zu_letter == "7" set rZu_isNum 1 else if zu_letter == "8" set rZu_isNum 1 else if zu_letter == "9" set rZu_isNum 1 else set rZu_isNum 0 end if end if }