SRL Archive - SRL Snippets

chooseAbility


Spartan 117

2014-01-20 14:06:17

I noticed there is a lack of combat scripts and I thought the EoC is probably why. Well here is a snippet of code I put together that will choose which ability you should be using at a certain time. This code isn't great for bosses/PvP but it is perfect for training!


function abilityReady(slot: integer): boolean;
begin
result := (actionBar.getAbilityCooldown(slot) = 1);
end;

//Returns the actionbar slot that is best to use
function chooseAbility : integer;
var
i: Integer;
begin
result := -1;
case(actionBar.getAdrenalinePercent()) of
0..50:
begin
for i := 0 to high(basic) do
begin
if abilityready(basic[i]) then
begin
result := basic[i];
wait(randomrange(50, 75));
break;
end;
end;
Exit;
end;
51..99:
begin
for i := 0 to high(threshold) do
begin
if abilityready(threshold[i]) then
begin
result := threshold[i];
wait(randomrange(50, 75));
Exit;
end;
end;
for i := 0 to high(basic) do
begin
if abilityready(basic[i]) then
begin
result := basic[i];
wait(randomrange(50, 75));
break;
end;
end;
Exit;
end;
100:
begin
if useUltimate then
begin
for i := 0 to high(ultimate) do
begin
if abilityready(ultimate[i]) then
begin
result := ultimate[i];
wait(randomrange(50, 75));
break;
end;
end;
Exit;
end else
begin
for i := 0 to high(threshold) do
begin
if abilityready(threshold[i]) then
begin
result := threshold[i];
wait(randomrange(50, 75));
break;
end;
end;
Exit;
end;
end;
end;
end;

//Uses the ability given by chooseAbility
procedure useAbility;
var
ability: Integer;
begin
if not notUsingAbility then
waitfunc(@notUsingAbility, 100, 4000);

ability := chooseAbility;
if (not (ability = (-1))) then
begin
case(randomrange(1,5)) of
1..2: actionbar.clickSlot(ability);
3..5: typesend(format('%d',[ability]), false);
end;
end;
wait(randomrange(25, 60));
end;


That is the function. It uses arrays that should be declared as globals or constants earlier in the script. Also you need to setup a boolean that is true if you want to use ultimate abilities(I prefer not to) For example:


basic := [1,2,3,4,5]; //Which actionbar slots do you have a basic ability in?
threshold := [6,7]; //Which actionbar slots do you have a threshold ability in?
ultimate := [8]; //Which actionbar slots do you have an ultimate ability in?
useUltimate := false; //Set true if you want to use ultimate abilities

The way I implement the code is something along the lines of:


procedure mainloop;
begin
repeat
if not isLoggedIn then Exit;

if inCombat then
useAbility;
until(false);
end;

Edit: I have eliminated some if statements with a case, which is just a little faster. I have also added the function useAbility. Use ability will randomly either click on the slot or will type them number of the slot.

Edit2: Fixed bug where it sits still between threshold and basic abilities