SRL Archive - SRL Archives

Character Manager


masquerader

2006-02-24 17:29:32

So, I decided the most annoying part of running a SRL script was setting up the characters, names, passwords, etc. I felt like learning to do forms, so there. I made arrays of the edit boxes, so they are dynamically created. I invision this loading like 30 characters from chars.srl and then you can just pick which ones you want to run the script instead of copying and pasting. Right now it doesnt have that yet but I dont think it would be that hard to load and save them at the beginning and end. Let me know of you would use it or not, if not, oh well, I still learned a lot about forms. I never saw a dynamic form before, so it was cool.

i think all the threads are safe, whatever that means :)

edit: i updated it so it loads/saves settings from chars.srl, more below
program CharacterManager;
//by masquerader
{.include /srl/srl.scar}

var
frmDesign : TForm;
Names: array of TEdit;
Passes: array of TEdit;
Nicks: array of TEdit;
Active: array of TCheckBox;
NewUser, Ok: TButton;

procedure AddUser;
var
i:integer;
begin
i:=getarraylength(Names);
setarraylength(Names,i+1);
setarraylength(Passes,i+1);
setarraylength(Nicks,i+1);
setarraylength(Active,i+1);

Names[i] := TEdit.Create(frmDesign);
Names[i].Parent := frmDesign;
Names[i].Left := 13;
if(i=0)then
Names[i].Top := 54
else
Names[i].Top:=Names[i-1].Top+84;
Names[i].Width := 121;
Names[i].Height := 21;
Names[i].Text := 'Username '+inttostr(i);

Passes[i] := TEdit.Create(frmDesign);
Passes[i].Parent := frmDesign;
Passes[i].Left := 13;
Passes[i].Top := Names[i].Top+24;
Passes[i].Width := 121;
Passes[i].Height := 21;
Passes[i].Text := 'Password '+inttostr(i);
//Passes[i].PasswordChar := '*';

Active[i] := TCheckBox.Create(frmDesign);
Active[i].Parent := frmDesign;
Active[i].Left := 155;
Active[i].Top := Passes[i].Top;
Active[i].Width := 79;
Active[i].Height := 17;
Active[i].Caption := 'Active?';

Nicks[i] := TEdit.Create(frmDesign);
Nicks[i].Parent := frmDesign;
Nicks[i].Left := 13;
Nicks[i].Top := Passes[i].Top+24;
Nicks[i].Width := 121;
Nicks[i].Height := 21;
Nicks[i].Text := 'Nickname '+inttostr(i);
end;

procedure SaveSettings; // taken from users.scar, by RSN
var // t = names written to file
afile,i,p,t:integer; // p = players added to array
begin
aFile := RewriteFile(AppPath + 'chars.srl', false);
t:=0;
p:=0;
for i:= 0 to getarraylength(Names)-1 do
begin
//doesnt write unchanged or blank boxes :)
if(not(Names[i].text='Username '+inttostr(i)) and (length(Names[i].text)>2))then
begin
WriteFileString(aFile, 'name' + IntToStr(t) + '=' + Names[i].text + Chr(13));
WriteFileString(aFile, 'pass' + IntToStr(t) + '=' + Passes[i].text + Chr(13));
WriteFileString(aFile, 'nick' + IntToStr(t) + '=' + Nicks[i].text + Chr(13));

if(Active[i].state)then
begin
WriteFileString(aFile, 'active' + IntToStr(t) + '=true' + Chr(13));
setarraylength(players,p+1);
Players[p].Name := Names[i].text;
Players[p].Pass := Passes[i].text;
Players[p].Nick := Nicks[i].text;
Players[p].Active := true;
p:=p+1;
end;
t:=t+1;
end;
end;
CloseFile(aFile);
writeln('wrote '+inttostr(t)+' users');
writeln(inttostr(p)+' active users')
end;

procedure LoadSettings; // taken from users.scar, by RSN
var
i,t,afile:integer;
begin
afile := OpenFile(AppPath + 'chars.srl', False);
if(aFile < 0)then
Exit;
ReadFileString(aFile, cFile, FileSize(aFile));
CloseFile(aFile);
t:=getnumber;
for i:=0 to t-1 do
AddUser;

for i:= 0 to t - 1 do
begin
Names[i].Text := getData(i, 'name');
Passes[i].Text := getData(i, 'pass');
Nicks[i].Text := getData(i, 'nick');
Active[i].state := (getData(i, 'active') = 'true');
end;
writeln('loaded '+inttostr(t)+' users');
end;

procedure buttonclick(sender: tobject);
var
v: TVariantArray;
begin
setarraylength(V, 0);
if(Sender is TButton)then
case(TButton(Sender).tag) of
-1:ThreadSafeCall('AddUser', v);
-2:begin
frmDesign.ModalResult:= mrOk;
ThreadSafeCall('SaveSettings',v);
end;
end;
end;

procedure InitForm;
begin
frmDesign := CreateForm;
frmDesign.Left := 259;
frmDesign.Top := 132;
frmDesign.Width := 440;
frmDesign.Height := 540;
frmDesign.Caption := 'Character Manager';
frmDesign.Color := clBtnFace;
frmDesign.Font.Color := clWindowText;
frmDesign.Font.Height := -11;
frmDesign.Font.Name := 'MS Sans Serif';
frmDesign.Font.Style := [];
frmDesign.Visible := False;
frmDesign.PixelsPerInch := 96;

NewUser := TButton.Create(frmDesign);
NewUser.Parent := frmDesign;
NewUser.Left := 116;
NewUser.Top := 21;
NewUser.Width := 75;
NewUser.Height := 25;
NewUser.Caption := 'New User';
NewUser.OnClick:= @buttonclick;
NewUser.Tag := -1;

Ok := TButton.Create(frmDesign);
Ok.Parent := frmDesign;
Ok.Left := 258;
Ok.Top := 21;
Ok.Width := 75;
Ok.Height := 25;
Ok.Caption := 'Ok';
Ok.OnClick:= @buttonclick;
Ok.Tag := -2;
end;

procedure SafeInitForm;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('InitForm', v);
setarraylength(V, 0);
ThreadSafeCall('LoadSettings', v);
end;

procedure ShowFormModal;
begin
frmDesign.ShowModal;
end;

procedure SafeShowFormModal;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('ShowFormModal', v);
end;

begin
SafeInitForm;
SafeShowFormModal;
FreeForm(FrmDesign)
end.

Lorax

2006-02-25 07:09:27

Very lovely ..

XxKanexX

2006-02-25 08:19:10

Looks good. Update the layout a little bit so it's more perty. <3

masquerader

2006-02-25 15:42:21

From: XxKanexX
Looks good. Update the layout a little bit so it's more perty. <3

erm.. thats not really what I was going for right now..
i'll add the flowers and ribbons later, right now I just want to see if people will use it

update: I added LoadSettings and SaveSettings. It's basically just users.scar hacked into using forms. It will load users from chars.srl, allow you to add new ones, write them back into chars.srl, and only add the active users to the players array. Blank boxes, or unchanged boxes aren't added, so don't worry. It was easier than I thought, because RsN already wrote nice functions in users.scar for reading/writing to file. The goal was for you to use this to set up the players array using a form, and not have to type/copy and paste all your users in every script, just select the active ones from a list of all characters you have.

I don't know how to clear the arrays, because they probably use a lot of memory. Can you just go setarraylength(array, 0), or is it more complicated?

BenLand100

2006-02-25 16:13:10

all vars die with the script they are in when it is stopped, terminated, killed, etc… bitmaps are an exception for some reason

masquerader

2006-02-26 22:56:11

hehe, fawki said forms are "not practical for my purpose".
it was "too dynamic" and "just plain offensive", so i guess the character manager is a no :p
oh well

WT-Fakawi

2006-04-30 06:16:11

Did I say that?

How crude :)

I like the Player Manager though. And I certainly like having it all optional :)

Dankness

2006-04-30 08:51:11

I like the player manager even thou i hate forms myself, Iv also edited it to be able to change the filename it loads the chars from inside the scripts now, just set variable

[php]
FileName := 'FileNameHere';
[/php]

and it will load different files, i added this do to the fact that each script normally uses different skills, like Mining and Fighting scripts so now you can have a char file for each script you run. :)