SRL Archive - Research & Development Lounge

procedure SetPlayer


Da 0wner

2009-02-08 22:46:17


procedure SetPlayer(name, pass, nick : string; active : boolean; bools : array of boolean; integers : array of integer; strings : array of string; Extendeds : array of extended);
var
i : integer;
begin
HowManyPlayers := GetArrayLength(Players) + 1;
NumberOfPlayers(HowManyPlayers);
Players[GetArrayLength(Players) - 1].Name := name;
Players[GetArrayLength(Players) - 1].Pass := pass;
Players[GetArrayLength(Players) - 1].Nick := nick;
Players[GetArrayLength(Players) - 1].Active := active;
for i := 0 to GetArrayLength(bools) - 1 do Players[GetArrayLength(Players) - 1].Booleans[i] := bools[i];
i := 0;
for i := 0 to GetArrayLength(integers) - 1 do Players[GetArrayLength(Players) - 1].Integers[i] := integers[i];
i := 0;
for i := 0 to GetArrayLength(strings) - 1 do Players[GetArrayLength(Players) - 1].Strings[i] := Strings[i];
i := 0;
for i := 0 to GetArrayLength(Extendeds) - 1 do Players[GetArrayLength(Players) - 1].Extendeds[i] := Extendeds[i];
i := 0;
end;

Sets a player with one procedure.

Used like so

SetPlayer('username', 'password', 'ser', true, [true, false], [1, 2, 3], ['a', 'b', 'c'], [0.1, 0.2, 0.3]);

You don't need to call NumberOfPlayers anymore either. It does that automatically.
However, you do need to call CurrentPlayer := whatever.

Enjoy :). :sasmokin:

Sir R. M8gic1an

2009-02-10 08:26:00

i don't actually see the use to this? it's nice coding and all, but calling it the way you did actually makes it harder cus you're not really sure where u're setting bools, strings, ints, extendeds… etc.

~RM

marpis

2009-02-10 13:49:53

I think the normal declare players procedure is quite a bit more user-friendly

Da 0wner

2009-02-10 20:06:26

DeclarePlayers is not a procedure that is already in SRL. It is just a common name most scripters give their procedure that sets up the players. And yea true it is more user friendly to people that are leechers or don't know how to script well.

It's like the SRL Player Form RM except without the form and armies and stuff like that :p.

It's basically easier for me because it's one line. When I use it in my script there will be an explanation on how to set it up using this procedure. When scripters are writing up their script(s') declare player procedure(s) then they can just put this procedure there and tell people to set the players up using that. It's so you don't have to type all the lines like Players[0].Name… and stuff like that.

Kyle Undefined

2009-02-10 21:22:42

From: Da 0wner
DeclarePlayers is not a procedure that is already in SRL. It is just a common name most scripters give their procedure that sets up the players. And yea true it is more user friendly to people that are leechers or don't know how to script well.

It's like the SRL Player Form RM except without the form and armies and stuff like that :p.

It's basically easier for me because it's one line. When I use it in my script there will be an explanation on how to set it up using this procedure. When scripters are writing up their script(s') declare player procedure(s) then they can just put this procedure there and tell people to set the players up using that. It's so you don't have to type all the lines like Players[0].Name… and stuff like that.


I'm pretty sure that all scripters use DeclarePlayers(If they don't use a form) but that doesn't mean they don't know how to script well. What if you have multiple integers for a script, how will you set which one to look for? It's just an array, it will look for all of those in the array. Also, there is no good way to do CurrentPlayer. DeclarePlayers is better than your function. It's nice, but not needed.

~Camo

Da 0wner

2009-02-10 21:40:44

Yes, of course it's not needed. And I didn't say they don't know how to script well? If you have multiple integers in a script you do if Players[0].Integers[?] = 5 (or w/e) then …

It dosen't act any different.

Kyle Undefined

2009-02-10 23:41:50

But how do you do it with yours? Because if you have a 5 for a certain integer and a 6 for another, that will confuse it and your script will not work.

~Camo

Da 0wner

2009-02-11 01:52:31


program New;
{.include SRL/SRL.scar}

procedure SetPlayer(name, pass, nick : string; active : boolean; bools : array of boolean; integers : array of integer; strings : array of string; Extendeds : array of extended);
var
i : integer;
begin
HowManyPlayers := GetArrayLength(Players) + 1;
NumberOfPlayers(HowManyPlayers);
Players[GetArrayLength(Players) - 1].Name := name;
Players[GetArrayLength(Players) - 1].Pass := pass;
Players[GetArrayLength(Players) - 1].Nick := nick;
Players[GetArrayLength(Players) - 1].Active := active;
for i := 0 to GetArrayLength(bools) - 1 do Players[GetArrayLength(Players) - 1].Booleans[i] := bools[i];
i := 0;
for i := 0 to GetArrayLength(integers) - 1 do Players[GetArrayLength(Players) - 1].Integers[i] := integers[i];
i := 0;
for i := 0 to GetArrayLength(strings) - 1 do Players[GetArrayLength(Players) - 1].Strings[i] := Strings[i];
i := 0;
for i := 0 to GetArrayLength(Extendeds) - 1 do Players[GetArrayLength(Players) - 1].Extendeds[i] := Extendeds[i];
i := 0;

Writeln('Player "' + name + '" added.');
end;

procedure DeclarePlayers;
begin
SetPlayer('player1', 'password1', 'lay', true, [true], [5, 6], [], []);
SetPlayer('player2', 'password2', 'lay', true, [false], [1, 2], [], []);
CurrentPlayer := 0;
end;

procedure WritePlayers;
var
i, ii : integer;
begin
ClearDebug;
for i := 0 to High(Players) do
begin
Writeln('Player ' + IntToStr(i) + ' name: ' + Players[i].Name);
Writeln('Player ' + IntToStr(i) + ' pass: ' + Players[i].Pass);
Writeln('Player ' + IntToStr(i) + ' nick: ' + Players[i].Nick);
Writeln('Player ' + IntToStr(i) + ' active: ' + BoolToStr(Players[i].Active));
Writeln('Player ' + IntToStr(i) + ' integers[0]: ' + IntToStr(Players[i].Integers[0]));
Writeln('Player ' + IntToStr(i) + ' integers[1]: ' + IntToStr(Players[i].Integers[1]));
end;


end;

begin
DeclarePlayers;
WritePlayers;
end.

marpis

2009-02-11 07:46:18

From: Da 0wner
DeclarePlayers is not a procedure that is already in SRL. It is just a common name most scripters give their procedure that sets up the players. And yea true it is more user friendly to people that are leechers or don't know how to script well.

It's like the SRL Player Form RM except without the form and armies and stuff like that :p.

It's basically easier for me because it's one line. When I use it in my script there will be an explanation on how to set it up using this procedure. When scripters are writing up their script(s') declare player procedure(s) then they can just put this procedure there and tell people to set the players up using that. It's so you don't have to type all the lines like Players[0].Name… and stuff like that.

Dude, i know what declareplayers is -.-
Everyone use it because the normal method is understandable.
That's like i'd say "people use Inc(x) cause they dont know how to use
x:=x+exp(logn(e, 1))"

Da 0wner

2009-02-11 07:51:08

I know this is just shorter for the scripter. It may not be more understandable but it is easier for the scripter.

Kyle Undefined

2009-02-11 08:17:19

procedure DeclarePlayers;
begin
SetPlayer('player1', 'password1', 'lay', true, [true], [5, 6], [], []);
SetPlayer('player2', 'password2', 'lay', true, [false], [1, 2], [], []);
CurrentPlayer := 0;
end;
Which one is 0? Wouldn't it have to be 0 := SetPlayer(blah)? You haven't declared which player is which.

~Camo

Da 0wner

2009-02-11 09:25:52

It does that automatically.
Player 1 would be Players[0] and Player 2 would be Players[1].