Page 1 of 1

Need help with a script

Posted: Wed Dec 19, 2012 3:45 pm
by kenzu38
Hi guyz, I'm here again asking for help haha.

Well, I want to modify a script I found here in the forums. I'd like it to check for cooldown of a transport spell and then decide what to do based on the returned value. So if the remaining time is more than 10 minutes, I'd like it to load a waypoint, else I'd like it to just wait and use the spell when it is available.

I found one of lisa's posted code that I think can be the foundation of this script. I just don't know how to proceed from there. Here's the code btw:

Code: Select all

local cooldown, remaining = sendMacro("GetSkillCooldown(1,2);")
if remaining > 1 then
printf("skill on cooldown\n") -- skills on cooldown
else
RoMScript('CastSpellByName("Heffner Camp Transport Spell")') -- use teleport
end
So based on this code, I think the macro returns value in minutes? If so, I think the script should go something like this:

Code: Select all

local cooldown, remaining = sendMacro("GetSkillCooldown(1,2);")
if remaining > 10 then
printf("skill on cooldown\n") -- skills on cooldown
loadPaths("waypointfile")
else
local y = ((remaining+1)*60000)
yrest(y)
RoMScript('CastSpellByName("Heffner Camp Transport Spell")') -- use teleport
end
I'm not even sure if you can put a variable to yrest hehe. But I think I got the right idea here, just don't know the correct syntax.

So can someone help me with this? Thanks.

Re: Need help with a script

Posted: Wed Dec 19, 2012 5:19 pm
by BillDoorNZ
http://www.theromwiki.com/API:GetSkillCooldown

Based on that, I'd say that the value returned is the SECONDS not the minutes - given a lot of skills don't have massive cooldowns, minutes would be useless. It may even be milliseconds - not sure tho, you'd have to test it.

You could do something like:

Code: Select all

local cooldown, remaining = sendMacro("GetSkillCooldown(1,2);")
if remaining > 10 then
	printf("skill on cooldown\n") -- skills on cooldown
	loadPaths("waypointfile")
else
	repeat
		yrest(500);
		cooldown, remaining = sendMacro("GetSkillCooldown(1,2);")
	until (1 > remaining)
	RoMScript('CastSpellByName("Heffner Camp Transport Spell")') -- use teleport
end

Re: Need help with a script

Posted: Wed Dec 19, 2012 6:40 pm
by lisa
the remaining is in seconds.

Code: Select all

if remaining > 10*60 then -- 10 minutes or did you want it to be 10 seconds??

local y = ((remaining+1)*1000)
with that change it should work, Bill's code would work aswell but it would be doing a macro every half a second for the entire time until the skill is off cooldown.

Re: Need help with a script

Posted: Wed Dec 19, 2012 8:50 pm
by BillDoorNZ
I'm an habitual 'just-in-case'er :)

Re: Need help with a script

Posted: Wed Dec 19, 2012 9:19 pm
by kenzu38
Thanks for that link, Bill. It wasn't really stated there clearly if it is in seconds but from the example the site gave, it seems likely that the returned value is in seconds.

Anyway, Lisa didn't say anything about the yrest(y) syntax, so I assume it's valid?

So my code will now look like this:

Code: Select all

local cooldown, remaining = sendMacro("GetSkillCooldown(1,2);")
if remaining > 600 then
printf("skill on cooldown\n") -- skills on cooldown
loadPaths("waypointfile")
else
local y = remaining
yrest(y)
RoMScript('CastSpellByName("Heffner Camp Transport Spell")') -- use teleport
end
I will test this later and let you guyz know if I encounter some prblems.

Thanks btw for helping me out guyz. Cheers!

Re: Need help with a script

Posted: Thu Dec 20, 2012 5:18 am
by Jandrana
I made a function that will give you the cooldown for a named transport skill. I found this usefull, because the GetSkillCooldown requires an index into the skill book page and depending on the learned skills, this index changes for the transport skill. So if one char did learn mining and another char did not learn mining you can't use the same index.

Code: Select all

        -- returns the max cooldown and remaining cooldown for a transport skill (in seconds)
        -- if a named transport skill is not available for this char cooldown will stay nil
        function GetSkillCoolDownTransport(skillName)
           local cooldown, remaining;
           for i=1,20 do 
           local name, _, icon, _, rank, type, upgradeCost, isSkillable, isAvailable = RoMScript("GetSkillDetail(1,"..tostring(i)..")");
             if name and string.find(name,skillName) ~= nil then 
                cooldown, remaining = RoMScript("GetSkillCooldown(1,"..tostring(i)..")");
             end
           end
           return cooldown, remaining
        end        

        transport = "Transport: Valley of Preparation"; -- change to appropriate transport skill 
        local cooldown, remaining = GetSkillCoolDownTransport(transport);
        if remaining == 0 then
            RoMScript("CastSpellByName(..transport..)");
        end

Re: Need help with a script

Posted: Thu Dec 20, 2012 5:24 am
by lisa
thanks for sharing.
Jandrana wrote:I found this usefull, because the GetSkillCooldown requires an index into the skill book page and depending on the learned skills, this index changes for the transport skill. So if one char did learn mining and another char did not learn mining you can't use the same index.
the transport cooldown is shared with recall and recall is always at 1,2 so just doing the cooldown for recall is all that is required for any transport skill =)

Re: Need help with a script

Posted: Thu Dec 20, 2012 5:27 am
by kenzu38
Haha lisa beat me to it. I was gonna say the same thing. But thanks for posting that code, I think I can use that with other skills.

Re: Need help with a script

Posted: Thu Dec 20, 2012 6:14 am
by rock5
You can also do

Code: Select all

local skill = FindSkillBookSkill(nameorid)
local cooldown, remaining = RoMScript("GetSkillCooldown("..skill.skilltab..","..skill.skillnum..")")
But like Lisa said, it's not necessary with transport skills because they all share a cooldown with Recall and Recall is always 1,2.

Re: Need help with a script

Posted: Thu Dec 20, 2012 6:51 am
by Jandrana
Ok, then we can keep it for the unlikely situation, that one day the cooldown of the two skills will be different ;-)

Re: Need help with a script

Posted: Thu Dec 20, 2012 7:00 am
by rock5
Well I mentioned it because it could be used for any other skill and kenzu38 mentioned "other skills", although maybe he meant "other transport skills" in which case my post wont be of help. I doubt the transport cooldowns will ever change.

Re: Need help with a script

Posted: Thu Dec 20, 2012 9:43 am
by kenzu38
Wow, maintenance is sure taking long today. Just when I have a lot of codes I wanna try.

And yeah, by other skills, I meant some offensive ones with long cooldown, I can think of some use for these codes in PVP.

Thanks again guyz for posting those codes.