SRL Archive - Reflection

Player Organization Include


Smartzkid

2011-04-18 22:30:24

Here's a small include to help organize your players into groups.

Features:
  • Quickly organize players into different groups
  • Specify values for players[ ].integers[ ], .booleans[ ], .strings[ ]
  • Values for the above fields can be set for an entire group or individually (individual settings override script settings)
  • Never have to write another DeclarePlayers!

To add it to a script, include groups.simba, then go to the built in DeclarePlayers and remove HowManyPlayers, NumberOfPlayers(), and Players[ ].____ and add thisScript := 'GroupName'; and SmartzDeclarePlayers;

It reads configuration information from const accountFile; here's a sample config:

; Players section
[Villavu]
name = Villavu
pass = SimbaIsCool
nick = lla

[Player2IsCool]
name = Player2 Is Cool
pass = OhYeahhh
nick = lay
pin = 2345
Integers5 = 40
Integers6 = 99
Integers7 = 1


; Groups section
[Ratinator1]
0 = Villavu
1 = Player2IsCool

Integers2 = 20
Integers5 = 40
Integers6 = 99
Integers14 = 15
Integers15 = 6
Booleans0 = True
Booleans1 = True


groups.simba
const accountFile = 'Drive:\Path\To\Config.ini';
var
thisScript: string;

function INI(section: string; key: string): string;
begin
result := ReadINI(section, key, accountFile);
end;

procedure SmartzDeclarePlayers;
var
i_AssignedPlayerCount: integer;
s_setting: string;
i, j: integer;
playerName: string;
begin
while(not(INI(thisScript, IntToStr(i_AssignedPlayerCount)) = '')) do
i_AssignedPlayerCount := i_AssignedPlayerCount + 1;

HowManyPlayers := i_AssignedPlayerCount;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

for i := 0 to i_AssignedPlayerCount - 1 do
begin
playerName := INI(thisScript, IntToStr(i));
with Players[i] do
begin
//Set login details
Name := INI(playerName, 'name');
Pass := INI(playerName, 'pass');
Nick := INI(playerName, 'nick');
pin := INI(playerName, 'pin');
Active := true;

//Set Integers
for j := 0 to 15 do
begin
s_setting := INI(playerName, 'Integers' + IntToStr(j));
if(not(s_setting = '')) then
begin
Integers[j] := StrToInt(s_setting);
end else
begin
s_setting := INI(thisScript, 'Integers' + IntToStr(j));
if(not(s_setting = '')) then
Integers[j] := StrToInt(s_setting);
end;
end;

//Set booleans
for j := 0 to 15 do
begin
s_setting := INI(playerName, 'Booleans' + IntToStr(j));
if(not(s_setting = '')) then
begin
Booleans[j] := StrToBool(s_setting);
end else
begin
s_setting := INI(thisScript, 'Booleans' + IntToStr(j));
if(not(s_setting = '')) then
Booleans[j] := StrToBool(s_setting);
end;
end;

//Set strings
for j := 0 to 15 do
begin
s_setting := INI(playerName, 'Strings' + IntToStr(j));
if(not(s_setting = '')) then
begin
Strings[j] := s_setting;
end else
begin
s_setting := INI(thisScript, 'Strings' + IntToStr(j));
if(not(s_setting = '')) then
Strings[j] := s_setting;
end;
end;
end;
end;

writeln('Declared ' + IntToStr(HowManyPlayers) + ' players.');
if(HowManyPlayers = 0) then
begin
writeln('No players defined, terminating script');
TerminateScript;
end;
end;

Overtime

2011-04-27 22:56:35

OMZOIMGOIHSIUYUG!!

GEEZUS!

You saved my trouble ty!!!

Smartzkid

2011-04-27 23:05:03

No problem, I'm glad someone else can get some use out of it!

Gu3st...

2011-04-28 04:05:25

Why do you save "Specify values for players[ ].integers[ ], .booleans[ ], .strings[ ]"? That differs for each script

Smartzkid

2011-04-28 18:24:06

You can set values for the integers, strings, and booleans array on a player level or on a script level. Player settings override script settings.

For example: I'm running Ratinator and I usually want my players to level to 40-60-20, so I set script wide values for this in the integers array. However, if I decide I want one player to have extra high defense, I can set that player's integers without disrupting the rest of my players.