putonajonny
2012-03-09 12:27:19
[P]utonajonnys ncredible [C]ustomisable cript
Some teaser code for you, try it out, It will bring up the form for you to input your script, if anybody here has ever tried out RIDiverse (or something like that) you may notice some similarities, graphically it looks awful at the moment but I am rubbish at that king of thing, if anybody has any ideas let me know:
This is an example setup for Superheating Steel.
New Images:
I have now added a "printing to string" feature to save actions for later use, together with a reading from string feature, both work well. Importantly you can add strings to the end of each other to increase the length of your actions, e.g if Clicking Item 1 was '0:1:2:3:' and Clicking Item 2 was '4:5:6:7:' then clicking Item 1 then Item 2 is '0:1:2:3:4:5:6:7:'.


This code needs cleaning up majorly, I learnt most of the stuff I know about forms whilst making this so I may re-write it at some point.
program new;
{.include SRL/SRL.simba}
var
Setup, Fake : TForm;
Confirm, Cancel, Plus, Minus : TButton;
Edits : array of array of TEdit;
InitialLists : array of TListBox;
Shown : integer;
SpellLists, WaitLists : array of TComboBox;
type
Action = record
Spell, Select : String;
ToDo, ItemNumber, Time, Amount, Timeout, OnItem : integer;
Rep : Boolean;
end;
Var
A : array of Action;
Procedure ButtonClick(Sender: TObject);
Var
i, j : integer;
begin
Case Sender of
Confirm : begin
Setup.ModalResult := mrOk;
for i := 0 to high(InitialLists) do
if(InitialLists[i].Parent = Setup)then
inc(j);
for i := 0 to j - 1 do
begin
SetArrayLength(A, GetArrayLength(A) + 1);
A[i].ToDo := InitialLists[i].ItemIndex;
if(Edits[0][i].Text = '<Item Number>')then
A[i].ItemNumber := -1
else
A[i].ItemNumber := StrToInt(Edits[0][i].Text);
A[i].Select := Edits[1][i].Text;
if(Edits[2][i].Text = '<Wait Time (msec)>')then
A[i].Time := -1
else
A[i].Time := StrToInt(Edits[2][i].Text);
A[i].Spell := SpellLists[i].Text;
if(Edits[3][i].Text = '<Amount (0 = all)>')then
A[i].Amount := -1
else
A[i].Amount := StrToInt(Edits[3][i].Text);
if(Edits[4][i].Text = '<Timeout (msec)>')then
A[i].Timeout := -1
else
A[i].Timeout := StrToInt(Edits[5][i].Text);
if(Edits[5][i].Text = '<On Item (0 = none)>')then
A[i].OnItem := -1
else
A[i].OnItem := StrToInt(Edits[5][i].Text);
if(Edits[6][i].Text = '<Repeat Until No More>')then
A[i].Rep := False
else
A[i].Rep := StrToBool(Edits[6][i].Text);
WriteLn(IntToStr(i)+':');
WriteLn(A[i]);
end;
end;
Cancel : begin
Setup.ModalResult:= mrOk;
end;
Plus : begin
inc(Shown);
for i := 0 to high(InitialLists) do
if(Shown >= i) then
InitialLists[i].Parent := Setup
else
InitialLists[i].Parent := Fake;
end;
Minus : begin
if(Shown > 0)then
dec(Shown);
for i := 0 to high(InitialLists) do
if(Shown >= i) then
InitialLists[i].Parent := Setup
else
begin
InitialLists[i].Parent := Fake;
Edits[0][i].Parent := Fake;
Edits[1][i].Parent := Fake;
Edits[2][i].Parent := Fake;
SpellLists[i].Parent := Fake;
end;
end;
end;
end;
Const
ClickItem_ = 0;
RClickItem_ = 1;
CastSpell_ = 2;
Use_ = 3;
WaitUntil_ = 4;
WaitFor_ = 5;
Withd_ = 6;
Dep_ = 7;
Procedure ListClick(Sender: TObject);
Var
i, n : integer;
begin
for i := 0 to high(InitialLists) do
if(InitialLists[i] = Sender)then
n := i;
Case Sender of
InitialLists[n] : begin
i := InitialLists[n].ITEMINDEX;
Case i of
ClickItem_ : begin
Edits[0][n].Parent := Setup;
Edits[1][n].Parent := Fake;
Edits[2][n].Parent := Fake;
Edits[3][n].Parent := Fake;
Edits[4][n].Parent := Fake;
Edits[5][n].Parent := Fake;
Edits[6][n].Parent := Fake;
SpellLists[n].Parent := Fake;
WaitLists[n].Parent := Fake;
end;
RClickItem_ : begin
Edits[0][n].Parent := Setup;
Edits[1][n].Parent := Setup;
Edits[2][n].Parent := Fake;
Edits[3][n].Parent := Fake;
Edits[4][n].Parent := Fake;
Edits[5][n].Parent := Fake;
Edits[6][n].Parent := Fake;
SpellLists[n].Parent := Fake;
WaitLists[n].Parent := Fake;
end;
CastSpell_ : begin
Edits[0][n].Parent := Fake;
Edits[1][n].Parent := Fake;
Edits[2][n].Parent := Fake;
Edits[3][n].Parent := Fake;
Edits[4][n].Parent := Fake;
Edits[5][n].Parent := Setup;
Edits[6][n].Parent := Setup;
SpellLists[n].Parent := Setup;
WaitLists[n].Parent := Fake;
end;
Use_ : begin
Edits[0][n].Parent := Setup;
Edits[1][n].Parent := Fake;
Edits[2][n].Parent := Fake;
Edits[3][n].Parent := Fake;
Edits[4][n].Parent := Fake;
Edits[5][n].Parent := Fake;
Edits[6][n].Parent := Fake;
SpellLists[n].Parent := Fake;
WaitLists[n].Parent := Fake;
end;
WaitUntil_ : begin
Edits[0][n].Parent := Fake;
Edits[1][n].Parent := Fake;
Edits[2][n].Parent := Fake;
Edits[3][n].Parent := Fake;
Edits[4][n].Parent := Setup;
Edits[5][n].Parent := Fake;
Edits[6][n].Parent := Fake;
SpellLists[n].Parent := Fake;
WaitLists[n].Parent := Setup;
end;
WaitFor_ : begin
Edits[0][n].Parent := Fake;
Edits[1][n].Parent := Fake;
Edits[2][n].Parent := Setup;
Edits[3][n].Parent := Fake;
Edits[4][n].Parent := Fake;
Edits[5][n].Parent := Fake;
Edits[6][n].Parent := Fake;
SpellLists[n].Parent := Fake;
WaitLists[n].Parent := Fake;
end;
Withd_ : begin
Edits[0][n].Parent := Setup;
Edits[1][n].Parent := Fake;
Edits[2][n].Parent := Fake;
Edits[3][n].Parent := Setup;
Edits[4][n].Parent := Fake;
Edits[5][n].Parent := Fake;
Edits[6][n].Parent := Fake;
SpellLists[n].Parent := Fake;
WaitLists[n].Parent := Fake;
end;
Dep_ : begin
Edits[0][n].Parent := Setup;
Edits[1][n].Parent := Fake;
Edits[2][n].Parent := Fake;
Edits[3][n].Parent := Setup;
Edits[4][n].Parent := Fake;
Edits[5][n].Parent := Fake;
Edits[6][n].Parent := Fake;
SpellLists[n].Parent := Fake;
WaitLists[n].Parent := Fake;
end;
end;
end;
end;
end;
Const
ClickItem = 'Left click item';
RClickItem = 'Right click item';
CastSpell = 'Cast spell';
Use = 'Use item';
WaitUntil = 'Wait until';
WaitFor = 'Wait for';
Withd = 'Withdraw';
Dep = 'Deposit';
procedure InitForm;
Var
InitialListsString : array of string;
Title : TLabel;
i, n, m : integer;
Prompts, Spells, Waits : array of String;
begin
Setup := CreateForm;
With Setup do
begin
Left := 100;
Top := 100;
Width := 500;
Height := 500;
Caption := 'Script Setup';
Color := ClWhite;
end;
Confirm := TButton.Create(Setup);
With Confirm do
begin
Parent := Setup;
Left := 285;
Top := 45;
Height := 20;
Width := 100;
Caption := 'Confirm';
OnClick := @ButtonClick;
end;
Cancel := TButton.Create(Setup);
With Cancel do
begin
Parent := Setup;
Left := 395;
Top := 45;
Height := 20;
Width := 100;
Caption := 'Cancel';
OnClick := @ButtonClick;
end;
Plus := TButton.Create(Setup);
With Plus do
begin
Parent := Setup;
Left := 5;
Top := 45;
Height := 20;
Width := 20;
Caption := '+';
OnClick := @ButtonClick;
end;
Minus := TButton.Create(Setup);
With Minus do
begin
Parent := Setup;
Left := 30;
Top := 45;
Height := 20;
Width := 20;
Caption := '-';
OnClick := @ButtonClick;
end;
Title := TLabel.Create(Setup);
With Title do
begin
Parent := Setup;
Top := 10;
Left := 10;
Caption := '[P]utonajonnys [I]ncredible [C]ustomisable [S]cript';
Font.Size := 15;
Font.Color := ClBlue;
Font.Name := 'Comic Sans MS';
end;
SetArrayLength(InitialLists, 100);
SetArrayLength(Edits, 7);
for n := 0 to high(Edits) do
SetArrayLength(Edits[n], 100);
SetArrayLength(SpellLists, 100);
SetArrayLength(WaitLists, 100);
Shown := 0;
InitialListsString := [ClickItem, RClickItem, CastSpell, Use, WaitUntil, WaitFor, Withd, Dep];
for n := 0 to high(InitialLists) do
begin
InitialLists[n] := TListBox.Create(Setup);
With InitialLists[n] do
begin
if(Shown >= n) then
Parent := Setup
else
Parent := Fake;
Top := 90 + 120 * (n mod 5);
Left := 60 + 300 * (n div 5);
Width := 110;
Height := 110;
OnClick := @ListClick;
for i := 0 to high(InitialListsString) do
Items.Add(InitialListsString[i]);
end;
end;
Prompts := ['<Item Number>', '<Click Option>', '<Wait Time (msec)>', '<Amount (0 = all)>', '<Timeout (msec)>', '<On Item (0 = none)>', '<Repeat Until No More>']
for m := 0 to high(Edits) do
begin
for n := 0 to high(Edits[m]) do
begin
Edits[m][n] := TEdit.Create(Setup);
With Edits[m][n] do
begin
Top := 90 + 120 * (n mod 5) + 25 * Byte((m = 1) or (m > 2)) + Byte(m = 6) * 25;
Left := 180 + 300 * (n div 5);
Width := 110;
Height := 20;
Text := Prompts[m];
end;
end;
end;
Spells := ['ardougne teleport', 'bind', 'bones to bananas', 'bones to peaches',
'camelot teleport', 'charge', 'charge air orb', 'charge earth orb',
'charge fire orb', 'charge water orb', 'claws of guthix', 'confuse',
'crumble undead', 'curse', 'earth blast', 'earth bolt',
'earth strike', 'earth surge', 'earth wave', 'enchant crossbow bolt',
'enfeeble', 'entangle', 'falador teleport', 'fire blast',
'fire bolt', 'fire strike', 'fire surge', 'fire wave',
'flames of zamorak', 'high level alchemy', 'iban blast',
'low level alchemy', 'lumbridge home teleport', 'lumbridge teleport',
'lvl-1 enchant', 'lvl-2 enchant', 'lvl-3 enchant', 'lvl-4 enchant',
'lvl-5 enchant', 'lvl-6 enchant', 'magic dart',
'mobilising armies teleport', 'saradomin strike', 'snare',
'storm of armadyl', 'stun', 'superheat item', 'telekinetic grab',
'teleother camelot', 'teleother falador', 'teleother lumbridge',
'teleport block', 'teleport to ape atoll', 'teleport to house',
'trollheim teleport', 'varrock teleport', 'vulnerability',
'watchtower teleport', 'water blast', 'water bolt', 'water strike',
'water surge', 'water wave', 'weaken', 'wind blast', 'wind bolt',
'wind rush', 'wind strike', 'wind surge', 'wind wave'];
for n := 0 to high(SpellLists) do
begin
SpellLists[n] := TComboBox.Create(Setup);
With SpellLists[n] do
begin
Top := 90 + 120 * (n mod 5);
Left := 180 + 300 * (n div 5);
Width := 110;
Height := 110;
Text := '<Select Spell>';
for i := 0 to high(Spells) do
Items.Add(Spells[i]);
end;
end;
Waits := ['Inventory Full', 'Inventory Empty'];
for n := 0 to high(WaitLists) do
begin
WaitLists[n] := TComboBox.Create(Setup);
With WaitLists[n] do
begin
Top := 90 + 120 * (n mod 5);
Left := 180 + 300 * (n div 5);
Width := 110;
Height := 110;
Text := '<Please Select>';
for i := 0 to high(Waits) do
Items.Add(Waits[i]);
end;
end;
end;
procedure SafeInitForm;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('InitForm', v);
end;
procedure ShowFormModal;
begin
Setup.ShowModal;
end;
procedure SafeShowFormModal;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('ShowFormModal', v);
end;
begin
SafeInitForm;
SafeShowFormModal;
end.This is the output of "A" which is our array of actions, this is for the example shown above with the superheating, the 3rd parameter shows what it is doing, the others show the options chosen.
0:
('<Select Spell>', '<Click Option>', 6, 1, -1, 0, 0)
1:
('<Select Spell>', '<Click Option>', 6, 2, -1, 0, 0)
2:
('superheat item', '<Click Option>', 2, -1, -1, 0, 0)
3:
('<Select Spell>', '<Click Option>', 0, 1, -1, 0, 0)
4:
('<Select Spell>', '<Click Option>', 4, 1, 30000, 0, 0)
5:
('<Select Spell>', '<Click Option>', 7, 3, -1, 0, 0)
6:
('<Select Spell>', '<Click Option>', 7, 2, -1, 0, 0)
7:
('<Select Spell>', '<Click Option>', 7, 1, -1, 0, 0)