PDA

View Full Version : Multiplayer in forms.



jhildy
07-14-2007, 03:16 AM
Ok first things first. i know everyone has seen the forms with unlimited players and i am going to demonstrate how to do this. This technique was created by RSN and all of the procedures were probably made by him. I will just teach you to adapt them to your script.

1.First off go into Srl/SRL/misc/UsersManager.scar

2.Copy all of those procedures in there except "LoadForm" "TheForm" "ShowFormModal" and "TehForm" you don't have to copy the vars, only the procedure that i did not mention.

3.Setting up your form. First off you have to have created your form with every necissary object. For example
ignore everything that has an x over it they are all just to make it more user friendly. but everything else is necissary for the user manager to work for what i am doing.
http://img526.imageshack.us/img526/7097/tutorialpic1yz2.th.png (http://img526.imageshack.us/my.php?image=tutorialpic1yz2.png)
In this script i had
Players[0].Name
Players[0].Pass
Players[0].Nick
Players[0].Integer[0]
Players[0].Active
I believe you can tell which of these represents each object in my form if not i will go into greater detail.
So i made my form for those specific Player variables.
Next you need to add those four buttons that are not Xed out.
Make one a left arrow(<-,<=,ect.) one say Add Player one say Delete Player and one with a right arrow(=>,->). The last thing you can do is add a groupbox to make it look neater (it is the Box that says Player Control around my buttons. Although this is not necissary to make this function, it looks neater. Another thing you should do is name your Edit1,Edit2 objects something easy like Eduser,Edpass,Ednick,Edloads,ect. Naming Eduser,Edpass,and Ednick makes your life easier since in RSN's procedures thats what the variables are already set as. Also add a label in the corner and name it lblUser.

4. Adapting the procedures. Ok this part takes the longest. Paste RSN's procedures into your script. As you look at his procedures, you probably can guess what you have to do. I will go through step by step anyway.
Look at this Procedure.
procedure AddUser;
begin
SetArrayLength(Players, GetArrayLength(Players) + 1);
Players[GetArrayLength(Players) - 1].Name := 'New Name';
Players[GetArrayLength(Players) - 1].Pass := 'New Pass';
Players[GetArrayLength(Players) - 1].Nick := 'New Nick';
Players[GetArrayLength(Players) - 1].Active := True;
Players[GetArrayLength(Players) - 1].Loc := 'New Location';
end;

Here you should set all of your Players Vars to something similar to this. For example if you have Players[0].Integer[0] and it is loads, i would reset that to 0 so you can just add in
procedure AddUser;
begin
SetArrayLength(Players, GetArrayLength(Players) + 1);
Players[GetArrayLength(Players) - 1].Name := 'New Name';
Players[GetArrayLength(Players) - 1].Pass := 'New Pass';
Players[GetArrayLength(Players) - 1].Nick := 'New Nick';
Players[GetArrayLength(Players) - 1].Active := True;
Players[GetArrayLength(Players) - 1].Loc := 'New Location';
Players[GetArrayLength(Players) - 1].Integer[0] := 0;
end;

And just do that for all the Players variables you have in your script.
The next Procedure is
procedure Inititate(Sender: TObject);
begin
lblUser.Caption := IntToStr(cUser);
Players[cUser].Nick := edNick.Text;
Players[cUser].Name := edUser.Text;
Players[cUser].Pass := edPass.Text;
Players[cUser].Loc := edLocation.Text;
Players[cUser].Integer[0] := (strtoint(edloads.Text));
if (cbActive.Text = 'True') then
Players[cUser].Active := True
else
Players[cUser].Active := False;
cUser := GetArrayLength(Players) - 1;
end;
This is where you would have saved time by naming your edit boxes accordingly. If not then you have to find out which of your editboxes are named what and input them in the place of edNick.Text or edUser.Text
if you have more such as an integer you would just add that as a variable like thisprocedure Inititate(Sender: TObject);
begin
lblUser.Caption := IntToStr(cUser);
Players[cUser].Nick := edNick.Text;
Players[cUser].Name := edUser.Text;
Players[cUser].Pass := edPass.Text;
Players[cUser].Loc := edLocation.Text;
Players[cUser].Integer[0] := Strtoint(edLoads.Text);
if (cbActive.Text = 'True') then
Players[cUser].Active := True
else
Players[cUser].Active := False;
cUser := GetArrayLength(Players) - 1;
end;
I will be using Integer1 throughout this Tutorial and the edit box will be named edLoads. So if you have a string or a boolean then you can add it like that. The cbActive is a combobox. If you go back to the picture of my form you will see a combobox there. I find this the easiest way to use booleans but any other way would work.

Again all you have to do in this picture is put your players variables in and change the names of your form objects to what they are.
procedure CreateUser(Sender: TObject);
begin
Players[cUser].Nick := edNick.Text;
Players[cUser].Name := edUser.Text;
Players[cUser].Pass := edPass.Text;
Players[cUser].Loc := edLocation.Text;
Players[cUser].Integer[0] := Strtoint(edLoads.Text);
if (cbActive.Text = 'True') then
Players[cUser].Active := True
else
Players[cUser].Active := False;
AddUser;
cUser := GetArrayLength(Players) - 1;
lblUser.Caption := IntToStr(cUser);
edLocation.Text := Players[cUser].Loc;
edNick.Text := Players[cUser].Nick;
edUser.Text := Players[cUser].Name;
edPass.Text := Players[cUser].Pass;
Strtoint(edLoads.text) := Players[cUser].Integer[0];
if (Players[cUser].Active) then
cbActive.Text := 'True'
else
cbActive.Text := 'False';
end;
Same thing as you have been doing.
procedure ForwardUser(Sender: TObject);
begin
Players[cUser].Nick := edNick.Text;
Players[cUser].Name := edUser.Text;
Players[cUser].Pass := edPass.Text;
Players[cUser].Loc := edLocation.Text;
Players[cUser].Integer[0] := Strtoint(edLoads.Text);
if (cbActive.Text = 'True') then
Players[cUser].Active := True
else
Players[cUser].Active := False;
if (cUser + 1 > GetArrayLength(Players) - 1) then
cUser := 0
else
cUser := cUser + 1;
lblUser.Caption := IntToStr(cUser);
edLocation.Text := Players[cUser].Loc;
edNick.Text := Players[cUser].Nick;
edUser.Text := Players[cUser].Name;
edPass.Text := Players[cUser].Pass;
Strtoint(edLoads.text) := Players[cUser].Integer[0];
if (Players[cUser].Active) then
cbActive.Text := 'True'
else
cbActive.Text := 'False';
end;

Same thing once again.
procedure BackUser(Sender: TObject);
begin
Players[cUser].Nick := edNick.Text;
Players[cUser].Name := edUser.Text;
Players[cUser].Pass := edPass.Text;
Players[cUser].Loc := edLocation.Text;
Players[cUser].Integer[0] := Strtoint(edLoads.Text);
if (cbActive.Text = 'True') then
Players[cUser].Active := True
else
Players[cUser].Active := False;
if (cUser - 1 < 0) then
cUser := GetArrayLength(Players) - 1
else
cUser := cUser - 1;
lblUser.Caption := IntToStr(cUser);
edLocation.Text := Players[cUser].Loc;
edNick.Text := Players[cUser].Nick;
edUser.Text := Players[cUser].Name;
edPass.Text := Players[cUser].Pass;
Strtoint(edLoads.text) := Players[cUser].Integer[0];
if (Players[cUser].Active) then
cbActive.Text := 'True'
else
cbActive.Text := 'False';
end;

Almost there!
procedure DeleteUser(Sender: TObject);
var
lo, na, ni: string;
ac: Boolean;
in: integer;
begin
lo := Players[GetArrayLength(Players) - 1].Loc;
na := Players[GetArrayLength(Players) - 1].Name;
ni := Players[GetArrayLength(Players) - 1].Nick;
ac := Players[GetArrayLength(Players) - 1].Active;
in :=Players[GetArrayLength(Players) - 1].Integer[0];
Players[cUser].Loc := lo;
Players[cUser].Name := na;
Players[cUser].Nick := ni;
Players[cUser].Active := ac;
Players[cUser].Integer[0] := in;
SetArrayLength(Players, GetArrayLength(Players) - 1);
if (cUser + 1 > GetArrayLength(Players) - 1) then
cUser := 0
else
cUser := cUser + 1;
lblUser.Caption := IntToStr(cUser);
edLocation.Text := Players[cUser].Loc;
edNick.Text := Players[cUser].Nick;
edUser.Text := Players[cUser].Name;
edPass.Text := Players[cUser].Pass;
strtoint(edloads.text) := Players[cUser].Integer[0];
if (Players[cUser].Active) then
cbActive.Text := 'True'
else
cbActive.Text := 'False';
end;

Last one!!!
procedure Start(Sender: TObject);
begin
lblUser.Caption := IntToStr(cUser);
edLocation.Text := Players[cUser].Loc;
edNick.Text := Players[cUser].Nick;
edUser.Text := Players[cUser].Name;
edPass.Text := Players[cUser].Pass;
strtoint(edLoads.text) := Players[cUser].integer[0];
if (Players[cUser].Active) then
cbActive.Text := 'True'
else
cbActive.Text := 'False';
end;


Ok when you are finally done adapting all of those procedures to fit your script you can move on.

5. Your buttons. Remember the buttons (<=,Add User,Delete User,=>) well now is when you have to use these. Scroll down to your initform procedure and find your left arrow button (<-,<=).
When you get to it everything should be there except for btnBack := TButton.Create(gbControl);
btnBack.Parent := gbControl;
btnBack.Left := 12;
btnBack.Top := 22;
btnBack.Width := 45;
btnBack.Height := 25;
btnBack.Caption := '<-';
btnBack.TabOrder := 0;
btnBack.OnClick := @BackUser;//this

add that with the name of your button insted of btnback.
then with your (->) arrow
btnNext := TButton.Create(gbControl);
btnNext.Parent := gbControl;
btnNext.Left := 216;
btnNext.Top := 23;
btnNext.Width := 45;
btnNext.Height := 25;
btnNext.Caption := '->';
btnNext.TabOrder := 1;
btnNext.OnClick := @ForwardUser;// add this
again change the btnNext to whatever you named your button.
Now with Create User
btnCreate := TButton.Create(gbControl);
btnCreate.Parent := gbControl;
btnCreate.Left := 138;
btnCreate.Top := 22;
btnCreate.Width := 75;
btnCreate.Height := 25;
btnCreate.Caption := 'Create';
btnCreate.TabOrder := 2;
btnCreate.OnClick := @CreateUser;//add
and again with delete user
btnDelete := TButton.Create(gbControl);
btnDelete.Parent := gbControl;
btnDelete.Left := 59;
btnDelete.Top := 22;
btnDelete.Width := 75;
btnDelete.Height := 25;
btnDelete.Caption := 'Delete';
btnDelete.OnClick := @DeleteUser;//add
btnDelete.TabOrder := 3;
Now one last thing go to your frmdesign vars at the beginning of your initform procedure and add this.
frmDesign := CreateForm;
frmDesign.Left := 254;
frmDesign.Top := 107;
frmDesign.Width := 308;
frmDesign.Height := 316;
frmDesign.Caption := 'User 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;
frmDesign.OnShow := @Start;//add this

Now you are done with the button assignments.
6.Almost the last thing to do is add cUser as a Integer at the beginning and add this to your main loopLoadUs;
cUser := 0;
if (GetArrayLength(Players) = 0) then
AddUser;
Safeinitform;
SafeShowFormModal;
Saveus;

Now you should be done.

Ashur2Good
07-14-2007, 04:30 AM
W00T, Thank you!!! I'm nearly done with my form! Now all i gotta do is add the other vars :) Thank you!:spot: :spot: :spot:


-Ashur:stirthepot:

jhildy
07-14-2007, 04:31 AM
Your welcome glad i could help.

Santa_Clause
07-14-2007, 05:03 AM
Wow. Very nice tutorial Jhildy. I've been asked many times before about this and I'm glad someone explains it.

jhildy
07-14-2007, 05:16 AM
thanks for the feedback yea iv seen people ask this many times aswell

Santa_Clause
07-14-2007, 05:36 AM
...I do know how to do it. I meant that many people have asked me how to do it before :p

BobboHobbo
07-14-2007, 08:38 AM
Aww i always needed this TUT

Thanks for posting this, when i come back to SCAR ill use it :)

jhildy
07-14-2007, 02:55 PM
...I do know how to do it. I meant that many people have asked me how to do it before :p

yes i edited my post i misunderstood.

Santa_Clause
07-14-2007, 03:00 PM
:p

How'd you learns forms?

jhildy
07-14-2007, 03:07 PM
idk just playing around with them. There my favorite thing to do lol.

n3ss3s
07-14-2007, 03:24 PM
Very good tut.

jhildy
07-14-2007, 03:43 PM
Thanks a lot everyone.

Lalaji
07-14-2007, 03:57 PM
great tut!

itSchRis917
07-15-2007, 05:07 AM
I need some help, i got an error, here's my thread:
http://www.villavu.com/forum/showthread.php?t=13573

Lalaji
07-17-2007, 10:07 PM
How do you creat the white boxes for username and pass?

Is that Lable or edit?

Nice tut by the way (again)

Widget
07-17-2007, 10:26 PM
Great Tut!


How do you creat the white boxes for username and pass?

Is that Lable or edit?

Nice tut by the way (again)

TEdits :)

Lalaji
07-18-2007, 04:25 PM
I still cant do this, getting some errors...:(

Ill try once again.

EDIT :: 1 more question, the last part, the main loop thing, "loadUs' and "SaveUs" are your procedures right? we dont have to add them, Right?

jhildy
07-18-2007, 09:40 PM
you dont have to add them but they save your player array and load it every time the script is started and finished. they are not required however.

Lalaji
07-18-2007, 11:58 PM
yeah i know.. i have a better chance for srl member if i put the thought...;)

Ok, my script cant identify "players" in any of RSN's procedures. What do i do?

jhildy
07-19-2007, 07:09 PM
lol thats the player array are you sure your not including srl or something.

Lalaji
07-19-2007, 07:13 PM
:O I did actually forget...See i was making a seprate script to test it on first.
Thanks once again

EDIT:: YES!! finally got it!!! and it only took me 3 days :)

Garrett
07-19-2007, 07:55 PM
Thanks for this tutorial. Got myself some multiplayer forms now.

jhildy
07-20-2007, 12:48 AM
lalaji good job finally lol.

Santa_Clause
07-20-2007, 09:58 AM
Ahh...now you see how popular this tutorial is...;)

Nitro
07-26-2007, 05:27 PM
Thank you Jhildy! This tutorial basically saved my life. I was trying to find out how to add variables to my PlayerArrays

For example I thought this piece of code was right but I wasn't quite sure so I decided to check it up.

Players[0].Name :='Username';
Players[0].Pass :='Password';
Players[0].Nick :='sern';
Players[0].Active := True;
Pkayers[0].Boolean1 := (ExampleVariable1)
Players[0].String1 := (ExampleVariable2)

However I think after reading this it should now be this.

Players[0].Name := 'Username';
Players[0].Pass := 'Password';
Players[0].Nick := 'sern';
Players[0].Active := True;
Pkayers[0].Boolean1 := ExampleVariable1;
Players[0].String1 := ExampleVariable2;

However, if I have made another mistake please correct me ;)

-Nitro

dvdcrayola
08-15-2007, 05:22 AM
this is a great tut.. but should my declareplayers just be this?

Procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name :='';
Players[0].Pass :='';
Players[0].Nick :='';
Players[0].Integer1 := 3;
Players[0].Loc :='Loc1';
Players[0].Active := False;
end;

jhildy
08-15-2007, 05:58 AM
no need for declare players at all just delete it.

dvdcrayola
08-15-2007, 06:11 AM
oh ok.

thanks again for all your help.

rotflmfwao
08-20-2007, 01:25 AM
Sorry for grave digging if I did, but could you update this for 4.0 please Jhildy? Just when you get the chance.

jhildy
08-20-2007, 02:14 PM
sure lol i didn't even think of that.

rotflmfwao
08-20-2007, 03:54 PM
Thanks, I read the tut, did the stuff, and realised that there was no LoadUs or SaveUs procedure in UsersManager XD Then I updated my players arrays for 4.0 but the real problem was the LoadUs SaveUs stuff.
EDIT: After a long time of searching SRL (5min) I found SaveSettings and LoadSettings in the PlayerForm.scar file in Misc... :duh:

There's stuff like HowManyBooleans and LoadPlayerArray, and I have no clue where to put that.

Also, you have it as Players[cUser].Integer[0] When it should bePlayers[cUser].Integers[0]

jhildy
08-21-2007, 12:53 AM
oh you don't even need those procedures because they just save the players they are not completely necisary.

ShowerThoughts
08-21-2007, 08:27 AM
is it working for srl 4.0 beta /offtopic get on msn/

rotflmfwao
08-21-2007, 06:45 PM
@Jhildy:
Oh, ok, that helps a lot. I thought they were necessary because they freed up a lot of memory :p

Negaal
09-29-2007, 12:09 PM
thank you for this, i didnt knew how to do those:D

Naum
12-29-2007, 08:31 PM
Good tut jhildy!

Pure1993
03-03-2008, 12:40 PM
great tut, I didn't even know that UsersManager.Scar existed. O.o
But I have a question (sorry if this sound noobish, but I just started with forms, want to add them to my guild miner...): I get the error message unkown Identifier LoadUs (it also doesn't find SaveUs). I would like to know if anything changed which I need to add or get rid of...
Thanks a lot,
Stur Pure

EDIT: well, dunno exactly why and how, but it doesn't seem to need it anymore. works like a charm the way it does. AWSOME TUT! :)

jhildy
03-04-2008, 03:14 AM
you dont need those and they dont exist any more.

Pure1993
03-04-2008, 05:21 PM
When I use the Integer[0] example, I always get the error: Unknown identifier 'INTEGER' in script", do I need to define it anywhere, and if so, how and where (I tried defining it as "array of Integer", just for fun, and to see if it worked for ssome weird reason, but it didn't...

ShowerThoughts
03-04-2008, 05:27 PM
12-29-2007, 09:31 PM

-_-
with old threads like those it's not forbidden to ask somthing just pm the thread starter or the person where you need the info from.

Pure1993
03-04-2008, 06:11 PM
Well, yeah, I guess, but posting it here is one way I guess (won't kill anyone lol). and heck, I got an answer to the first question, so why not to the second one too? :D

Zezi
04-01-2008, 10:59 PM
I'm VERY sorry if i'm gravedigging, but does this still work? As loadus doesn't actually exist anymore, i haven't started far into the tutorial, but i would just like to know before i continue doing this :P

Tyvm, hoping for a somewhat fast reply :)