Log in

View Full Version : AllPlayersInactive - Useful Procedure



TOB
12-02-2006, 08:42 PM
Well I didn't see this in SRL and NextPlayer was against the 'no endless loops' policy.

{************************************************* ****************************
function HowManyPlayersInactive: Integer;
By: TOB
Description: Counts how many players in the Players array are set to inactive
************************************************** ***************************}
function HowManyPlayersInactive: Integer;
var
Player, NumberOfInactivePlayers: Integer;
begin
NumberOfInactivePlayers:= 0;
for Player:= 0 to HowManyPlayers - 1 do
begin
if(Players[Player].Active = False) then
NumberOfInactivePlayers:= NumberOfInactivePlayers + 1;
end;
Result:= NumberOfInactivePlayers;
end;

{************************************************* ****************************
procedure AllPlayersInactive;
By: TOB
Description: Checks to see if all players are set to inactive, if True terminates script
************************************************** ***************************}
procedure AllPlayersInactive;
var
InactivePlayers: Integer;
begin
InactivePlayers:= HowManyPlayersInactive;
if(InactivePlayers = HowManyPlayers) then
begin
WriteLn(TheTime + ' All players are inactive, terminating script');
TerminateScript;
end;
end;

Here is Login.scar implemented with AllPlayersInactive

Ignore the attachment
good version of Login.scar is at http://www.sofakingpro.com/SCAR/chickenkiller/Login.scar

Edit: That is an old version of Login.scar but you can see how the NextPlayer and such have been modified.

Boreas
12-02-2006, 09:02 PM
Nice.

What would be cool is support for RC.scar. So that when all players are inactive, every so often a player logs in (preferably ones that are lost rather than ones stuck in random, if it's possible to choose) and checks if the master is on, and if the master is on, it will say we all need fixing. Then there needs to be a system so that there is always a player on, waiting for the master to give the ok, but they take in order so that they don't go on when you are fixing them from work/school. I think this would work with 3 or more players. So you log on to the master, and player 2 is on, and tells you they all need fixing. So you log on to player 1, and player 2 sees that, and knows youll be using player 2 next, so it logs on to player 0. Then player 0 is on and sees player 1 go off and player 2 go on, so it switches to player 1. Then player player 1 sees you go off of player 2 and on to player 0. So it will switch to player 2. Then player 2 sees you go off player 0 and on to master, then the master tells player 2 to start up the script again, setting everyone to active. Hopefully, people will use enough players, good enough scripts, and fix it with the master often enough (or don't run the script for days) so that this will never be needed, because I'm almost confusing myself lol.

TOB
12-02-2006, 09:11 PM
Yeah you kind of confused me but I think you're saying instead of doing a NextPlayer routine you could have the players tell each other that its time to switch players. Not sure how that would be accomplished unless you worked in a system of switching tabs. Maybe use SCSS and select title windows to switch active clients and if(titleblah = Player X) then do this.

Starblaster showed me my 3 AM mistake.

It should be:

function HowManyPlayersInactive: Integer;
var
Player: Integer;
begin
for Player:= 0 to HowManyPlayers - 1 do
begin
if(Players[Player].Active = False) then
Result:= Result + 1;
end;
end;

It won't let me modify attachments so eh...

_______________________

Was just thinking, in the Login.scar I provided

In NextPlayerOrder and NextPlayer


while Players[CurrentPlayer].Active = False do
begin
CurrentPlayer := CurrentPlayer + 1;
if CurrentPlayer > HowManyPlayers - 1 then
AllPlayersInactive;

Really only needs to be "AllPlayersInactive;"

Boreas
12-02-2006, 09:32 PM
Sorry for the confusion. I just meant that RC.scar lets you fix inactive players by talking with the player that is on at the time, but if ALL the players are inactive, the master has no-one to talk to.

So when all players are inactive, they would take turns looking out for the master. Once they tell the master to fix all of them, they take turns waiting for the master to come back and say everyone is fixed, but in such a way that the player waiting for the master to come back isn't the one you are about to log on to and fix.

WT-Fakawi
12-03-2006, 06:24 PM
Granted Member access on acount of exceptional coding skill and a good attitude.

TOB
02-26-2007, 05:26 AM
I suppose this is a bit of an old thread but I feel it needs to be brought up again, and one change to the function.

{************************************************* ****************************
function AllPlayersInactive: Boolean;
By: TOB
Description: Checks to see if all players are set to inactive, if True terminates script
************************************************** ***************************}
function AllPlayersInactive: Boolean;
var
InactivePlayers: Integer;
begin
InactivePlayers:= HowManyPlayersInactive;
if(InactivePlayers = HowManyPlayers) then
begin
WriteLn(TheTime + ' All players are inactive.');
Result:= True;
end;
end;

It should just be a boolean, not a termination.

XcanadamanX
02-27-2007, 08:52 PM
you forgot to change it to function AllPlayersInactive:boolean; instead of procedure AllPlayersInactive;

TOB
02-28-2007, 06:11 AM
Oops, thanks. I had put it in the description so I must have forgotten the function itself.

XcanadamanX
02-28-2007, 01:00 PM
AllPlayersInactive:boolean; not
AllPlayersInactive;boolean. it wont work they way you have it.

Wizzup?
02-28-2007, 02:58 PM
Sorry for the confusion. I just meant that RC.scar lets you fix inactive players by talking with the player that is on at the time, but if ALL the players are inactive, the master has no-one to talk to.

So when all players are inactive, they would take turns looking out for the master. Once they tell the master to fix all of them, they take turns waiting for the master to come back and say everyone is fixed, but in such a way that the player waiting for the master to come back isn't the one you are about to log on to and fix.

I'm working on some stuff. :)
Maybe, in the future you might be able to reset players by on internet (not login into rs).