SRL Archive - SRL Snippets

Use Ability, CoordsToAbilitySlot, SendAction


Ixilisi

2012-11-28 12:13:24

First two are just modified slightly, adding "Chat" to the TypeSendExModified Procedure, as the existing one would try to type it into the actual chat.
Slightly Modified Laimonas171's useActionKey to work with the above thing and to use integer.

and my own completely new function, probably needs the most scrutiny. Takes the x coordinate and returns the slot number (index starting at 1 from the left) that the coordinate corresponds to in the ability's bar.

makes it nice and easy to go:
var x, y:Integer;
FindDTM(HumidifyDTM, x, y, 45, 345 - SRL_NAVBAR_INGAME_Y, 474, 378 - SRL_NAVBAR_INGAME_Y);
useActionKey(CoordstoAB(x));

procedure TypeSendExModified(Text: string; PressEnter, Chat: Boolean); //This is modified as it defaulted to chatting
var
I: Integer;
begin
if (not PlayerChatActive and chat) then
TypeByte(VK_ENTER);

for i := 1 to Length(Text) do
begin
{$IFDEF SIMBAMAJOR980}
SendKeys(Text[i], 40 + Random(40));
{$ELSE}
SendKeys(Text[i], 30 + Random(30), 30 + Random(30));
{$ENDIF}
Wait(40 + Random(40));
end;

if (PressEnter) then
TypeByte(VK_ENTER);
end;



Function useActionKey(KeyPosition: Integer): boolean; //Laimonas171's useActionKey, modified
begin

Case KeyPosition of
1: begin
TypeSendExModified('1',False, False);
result := true;
end;
2: begin
TypeSendExModified('2',False, False);
result := true;
end;
3: begin
TypeSendExModified('3',False, False);
result := true;
end;
4: begin
TypeSendExModified('4',False, False);
result := true;
end;
5: begin
TypeSendExModified('5',False, False);
result := true;
end;
6: begin
TypeSendExModified('6',False, False);
result := true;
end;
7: begin
TypeSendExModified('7',False, False);
result := true;
end;
8: begin
TypeSendExModified('8',False, False);
result := true;
end;
9: begin
TypeSendExModified('9',False, False);
result := true;
end;
10: begin
TypeSendExModified('0',False, False);
result := true;
end;
11: begin
TypeSendExModified('-',False, False);
result := true;
end;
12: begin
TypeSendExModified('=',False, False);
result := true;
end;
else
result := false;
end;
end;

Function CoordToSlotAB(x: Integer): Integer;
var
SlotNo: Integer; //Returns the slot Number (Index starts at 1) given a coordinates, returns 0 if invalid!
begin
if ((x > 474) OR (x < 45)) then
begin
WriteLn('x is outside the bounds of the ActionBar! (45 - 474)');
Result := 0;
end;

If ((x - (Floor((x - 45)/35)*35))/33 > 1) then
begin
WriteLn('x is inbetween slots');
Result := 0;
end;

SlotNo := Floor((x-10)/35);
Writeln(intToStr(x) + ' ' + IntToStr(SlotNo));
Result := SlotNo;
end;

Le Jingle

2012-11-28 12:18:10

from the includes:

(*
TypeSendEx
~~~~~~~~~~

.. code-block:: pascal

procedure TypeSendEx(Text : string; PressEnter : Boolean);

Types text in a human-like way.

.. note::

by SKy Scripter

Example:

.. code-block:: pascal

*)
procedure TypeSendEx(Text: string; PressEnter: Boolean);
var
I: Integer;
begin
if not PlayerChatActive then
TypeByte(VK_ENTER);

for i := 1 to Length(Text) do
begin
{$IFDEF SIMBAMAJOR980}
SendKeys(Text[i], 40 + Random(40));
{$ELSE}
SendKeys(Text[i], 30 + Random(30), 30 + Random(30));
{$ENDIF}
Wait(40 + Random(40));
end;

if (PressEnter) then
TypeByte(VK_ENTER);
end;

Wouldn't you also want to exit the function in your if then statements instead of potentially assigning the result to zero with still rewriting it later?? (CoordToSlotAB)

Ixilisi

2012-11-28 20:58:49

From: Le Jingle
from the includes:

(*
TypeSendEx
~~~~~~~~~~
*)
begin
if not PlayerChatActive then
TypeByte(VK_ENTER);




It's that part there which I have modified, with
 if not PlayerChatActive and chat
so it's just a minor modification, but vital when calling abilities using the keyboard.


From: Le Jingle

Wouldn't you also want to exit the function in your if then statements instead of potentially assigning the result to zero with still rewriting it later?? (CoordToSlotAB)


I was unsure about this, I assumed you had to always assign a value to result for a function, so instead should I just use break; ?

so like this:
Function CoordToSlotAB(x: Integer): Integer;
var
SlotNo: Integer; //Returns the slot Number (Index starts at 1) given a coordinates, returns 0 if invalid!
begin
if ((x > 474) OR (x < 45)) then
begin
WriteLn('x is outside the bounds of the ActionBar! (45 - 474)');
break;
end;

If ((x - (Floor((x - 45)/35)*35))/33 > 1) then
begin
WriteLn('x is inbetween slots');
break;
end;

SlotNo := Floor((x-10)/35);
Writeln(intToStr(x) + ' ' + IntToStr(SlotNo));
Result := SlotNo;
end;

Le Jingle

2012-11-28 21:14:10


function CoordToSlotAB(x: Integer): Integer;
begin
result := 0;
if (x > 474) or (x < 45) or ((x - (Floor((x - 45) / 35) * 35)) / 33 > 1) then
exit;
Result := Floor((x - 10) / 35);
end;
Basically we 'exit;' if our argument, x, meets a criteria in an if/then statement that we do not like.
Otherwise we will process the result with the given function.

riwu

2012-11-28 21:22:23

From: Ixilisi
It's that part there which I have modified, with
 if not PlayerChatActive and chat
so it's just a minor modification, but vital when calling abilities using the keyboard.




I was unsure about this, I assumed you had to always assign a value to result for a function, so instead should I just use break; ?

so like this:
Function CoordToSlotAB(x: Integer): Integer;
var
SlotNo: Integer; //Returns the slot Number (Index starts at 1) given a coordinates, returns 0 if invalid!
begin
if ((x > 474) OR (x < 45)) then
begin
WriteLn('x is outside the bounds of the ActionBar! (45 - 474)');
break;
end;

If ((x - (Floor((x - 45)/35)*35))/33 > 1) then
begin
WriteLn('x is inbetween slots');
break;
end;

SlotNo := Floor((x-10)/35);
Writeln(intToStr(x) + ' ' + IntToStr(SlotNo));
Result := SlotNo;
end;

Break is for breaking out of loops. There's no loop here so it will return a compiling error.

Also i've said this at least 5 times…why use TypeSend which loops through the string when the string has a length of one?!

It's as funny as doing this:

SetLength(TPA, 1);
for i:=0 to High(TPA) do
TPA[i]:= Point(x,y);

Also, just add PressEnter as extra boolean check if you really prefer TypeSend to type a single character:
https://github.com/SRL/SRL-5/pull/122/files