New Feature: Userfunctions.lua

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

New Feature: Userfunctions.lua

#1 Post by rock5 » Sun Mar 07, 2010 11:12 pm

Ever since I asked the dev to support this feature I've been meaning to start a thread where users can share their function creations and here it is.

Description of the new feature:
Since version 413 users can create a userfunctions.lua file in the rombot root directory to hold their own functions to use in their waypoint files.

Below are some of my more useful functions. If you want to use 1 of my functions simply copy and paste it into your userfunctions.lua file.

If you are going to share your creations please include a description comment with the expected input variables and return values as I did with my functions.

I've created a wiki entry here http://www.solarstrike.net/wiki/index.p ... _Functions

Code: Select all

------------------------------------------------
-- CheckForBuff Script
-- buffname = name of buff as appears in player buffs
-- returns 'true' if buff was found or 'false' if it was not.
------------------------------------------------
function CheckForBuff(buffname)
    if buffname == nil then
        cprintf(cli.yellow,"No buff specified. Please use 'CheckForBuff(buffname)'.\n")
        return false
    end
    local buffnum=1
    local buff=RoMScript("UnitBuff('player',"..buffnum..")");
    while buff ~= nil do
        if buff == buffname then
            return true
        end
        buffnum=buffnum+1
        buff=RoMScript("UnitBuff('player',"..buffnum..")");
    end
    return false
end

Code: Select all

------------------------------------------------
-- CancelBuff Script
-- buffname = name of buff as appears in player buffs
-- returns 'true' if buff was removed or 'false' if did not have buff.
------------------------------------------------
function CancelBuff(buffname)
    if buffname == nil then
        cprintf(cli.yellow,"No buff specified. Please use 'CancelBuff(buffname)'.\n")
        return false
    end
    local buffnum=1
    local buff=RoMScript("UnitBuff('player',"..buffnum..")");
    while buff ~= nil do
        if buff == buffname then
            sendMacro("CancelPlayerBuff("..buffnum..");")
            return true
        end
        buffnum=buffnum+1
        buff=RoMScript("UnitBuff('player',"..buffnum..")");
    end
    return false
end

Code: Select all

------------------------------------------------
-- Select Option By Name
-- optiontext = option text or part of
-- NPC option dialog should already be open
------------------------------------------------
function SelectOptionByName(optiontext)
    counter = 1
    while RoMScript("GetSpeakOption("..counter..")") do
        if string.find(RoMScript("GetSpeakOption("..counter..")"),optiontext,0,"plain") then
            sendMacro("ChoiceOption("..counter..");"); yrest(1500);
            return true
        end
        counter = counter + 1
    end
    return false
end

Code: Select all

------------------------------------------------
-- Buy number of items by item name
-- itemname = name of item to buy
-- num = number of items to buy
-- Store should already be open
------------------------------------------------
function BuyItemByName(itemname, num)
    if num == nil then num = 1 end -- Assume you want to buy 1

    counter = 1
    icon, name = RoMScript("GetStoreSellItemInfo("..counter..")")
    while name do
        if string.find(name,itemname,0,"plain") then
            for i = 1, num do
                sendMacro("StoreBuyItem("..counter..")"); yrest(1000);
            end
            return true
        end
        counter = counter + 1
        icon, name = RoMScript("GetStoreSellItemInfo("..counter..")")
    end
    return false
end

Code: Select all

------------------------------------------------
-- Delete items from bag by name or id
-- itemNameOrId = Item name or ID of item to delete
-- onceOnly = True to delete only once otherwise check whole bag
-- returns number of slots freed
------------------------------------------------
function DeleteItemByNameOrId(itemNameOrId,onceOnly)
    freedSlots = 0
	for slot,item in pairs(inventory.BagSlot) do
		if item.Id == itemNameOrId or string.find(item.Name,itemNameOrId) then
            RoMScript("PickupBagItem("..item.BagId..");");
            RoMScript("DeleteCursorItem();");
			if onceOnly then
                return 1
            else
                freedSlots= freedSlots + 1
            end
		end
	end
    return freedSlots
end

Code: Select all

------------------------------------------------
-- Target NPC and make sure they are targeted
-- NPCName = Name of NPC to target
------------------------------------------------
function targetNPC(NPCName)
    while not player:target_NPC(NPCName) do
        print("Failed to target "..NPCName..". Target manually then press DELETE to continue.")
        player:sleep()
    end
end
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests