Author Topic: Slot Test (Active?)  (Read 6411 times)

0 Members and 2 Guests are viewing this topic.

Offline Bellamy

  • Major(1)
  • Posts: 42
Slot Test (Active?)
« on: July 02, 2008, 01:38:41 am »
Script Name: Slot Test
Script Description: When an admin types '/slots', messages list the slots and tell you if they are occupied.
Original Author(s): Bellamy
Core Version: 2.6.3




Code: [Select]
var
Counter: integer;

function OnCommand(ID: byte; Text: string): boolean;
begin
if Text = '/slots' then begin
for Counter := 1 to 16 do begin
if GetPlayerStat(Counter, 'active') then begin
WriteConsole(ID,'Slot ' + inttostr(Counter) + ' is occupied by ' + IDToName(Counter) + '.',$FF0000);
end;
if GetPlayerStat(Counter, 'active') = false then begin
WriteConsole(ID,'Slot ' + inttostr(Counter) + ' is inactive.',$FF0000);
end;
end;
end;
Result := false;
end;


I don't know if this would really help anyone do anything, so if it doesn't help anyone, call it practice for me.  ;)

P.S. - And if you haven't noticed, I like using tabs and not spaces. So please don't whine your ass off about it. TY.
« Last Edit: July 04, 2008, 01:39:31 am by Bellamy »

Offline Super Vegeta

  • Major
  • *
  • Posts: 57
    • SV Games - The home of all my creations.
Re: Slot Test (Active?)
« Reply #1 on: July 02, 2008, 03:35:26 am »
Well, using tabs is good for having the code all nice and tidy, and I use them too when writing something in TP or FP. Whitespace in Soldat scripts uses too much disk space imo. :p

The script itself isn't bad, but still, it ain't really useful since in Soldat Admin among the stats of players it displays you the slot they use, so if one would want to check if a slot is free or not, (s)he could simply scroll the list and that's it.

Continue with your work, practice makes perfect. :)

PS.Change counter to be a function variable instead of a global one, and change it to byte. Will use less memory.

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Slot Test (Active?)
« Reply #2 on: July 02, 2008, 04:31:52 am »
2 quick things:
1. if you see yourself write "= true" then STOP AND DELETE IT!
Code: [Select]
if GetPlayerStat(Counter, 'active') then begin does the same thing!

2. else is your friend. lets say, hypothetically, that GetPlayerStat takes a lot of system resources and time to call. instead of calling it twice to check whether the same thing is true or false, just call it once (checking true) and then use else for false (if its not true then... durrr...). Also use else if when you can, it saves the computer time.

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Slot Test (Active?)
« Reply #3 on: July 02, 2008, 09:43:42 am »
Whitespace in Soldat scripts uses too much disk space imo. :p


How big is your disk? 16 mb?

Also, afiak a tab is only one character.
Come join: EliteCTF
Listen to: My Music

Offline shantec

  • Soldier
  • **
  • Posts: 140
  • Get ANGREH!!
Re: Slot Test (Active?)
« Reply #4 on: July 02, 2008, 11:07:35 am »
"As Far I As Know"? Typo? :D
Well, there sould be some sort of "doubletab"... or user specified tab.............

Well, i think this script is kinda, - unneeded!
Lets say it was just practice for you ;D
Also Known As REIMA


Lol Happles (happy apples)

Offline Bellamy

  • Major(1)
  • Posts: 42
Re: Slot Test (Active?)
« Reply #5 on: July 02, 2008, 02:02:17 pm »
Guys, thats exactly why I put "If this doesn't help anyone do anything, call it practice for me."
lol

And iDante, I haven't learned else, for or the other more complicated ones yet.
I will go back and change it later and post the new form.


EDIT: I HAVE MADE THE SCRIPT TELL WHO IS TAKING UP THE ACTIVE SLOT**

And, Super Vegeta, I didn't really make this for ARSSE. It is meant for in-game use.
« Last Edit: July 02, 2008, 04:07:49 pm by Bellamy »

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Slot Test (Active?)
« Reply #6 on: July 02, 2008, 05:02:14 pm »
Code: [Select]
if GetPlayerStat(Counter, 'active') then begin should be
Code: [Select]
if GetPlayerStat(Counter, 'active') = true then begin sense GetPlayerStat returns variant, not boolean, and may not always work (i had a problem with this before, anything that returns a boolean, you can leave as just "if _ then")

Offline Super Vegeta

  • Major
  • *
  • Posts: 57
    • SV Games - The home of all my creations.
Re: Slot Test (Active?)
« Reply #7 on: July 02, 2008, 05:19:03 pm »
Quote from: Bellamy
Super Vegeta, I didn't really make this for ARSSE. It is meant for in-game use.
I don't use ARSSE, so I wasn't looking whether it will be more compatible or whatever you could have in mind. Simply after years of programming I think it's important to reduce memory usage - one byte one way or the other maybe does not make much difference, but if it all accumulates - the result can be very surprising.

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Slot Test (Active?)
« Reply #8 on: July 02, 2008, 05:46:31 pm »
Code: [Select]
if GetPlayerStat(Counter, 'active') then begin should be
Code: [Select]
if GetPlayerStat(Counter, 'active') = true then begin sense GetPlayerStat returns variant, not boolean, and may not always work (i had a problem with this before, anything that returns a boolean, you can leave as just "if _ then")
yeah but 'active' returns boolean. I tested it out, it does work.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Slot Test (Active?)
« Reply #9 on: July 02, 2008, 05:55:18 pm »
Code: [Select]
if GetPlayerStat(Counter, 'active') then begin should be
Code: [Select]
if GetPlayerStat(Counter, 'active') = true then begin sense GetPlayerStat returns variant, not boolean, and may not always work (i had a problem with this before, anything that returns a boolean, you can leave as just "if _ then")
yeah but 'active' returns boolean. I tested it out, it does work.
im just saying, i had a problem with it once; you all have been warned ^^

Offline Bellamy

  • Major(1)
  • Posts: 42
Re: Slot Test (Active?)
« Reply #10 on: July 03, 2008, 12:38:39 am »
Yahh.. w/e. It works and that's that.

This script is useful if you think about it.
You can check the ID of each player.
 ;)  ;D  [retard]

Offline Neosano

  • Camper
  • ***
  • Posts: 253
  • IIAWAK!
Re: Slot Test (Active?)
« Reply #11 on: July 03, 2008, 04:07:41 am »
Yahh.. w/e. It works and that's that.

This script is useful if you think about it.
You can check the ID of each player.
 ;)  ;D  [retard]
Not really.

and again - USE 'ELSE'!
But if you want to get false from boolean you can use
Code: [Select]
if not GetPlayerStat(Counter, 'active') then begin
KAWAAAAAAAIIIIIIIIII

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: Slot Test (Active?)
« Reply #12 on: July 03, 2008, 11:47:17 am »
Yahh.. w/e. It works and that's that.
you'll change your mind when you move to bigger stuff

Offline Bellamy

  • Major(1)
  • Posts: 42
Re: Slot Test (Active?)
« Reply #13 on: July 03, 2008, 12:07:25 pm »
Yahh.. w/e. It works and that's that.

This script is useful if you think about it.
You can check the ID of each player.
 ;) ;D [retard]
Not really.

and again - USE 'ELSE'!
But if you want to get false from boolean you can use
Code: [Select]
if not GetPlayerStat(Counter, 'active') then begin
1) else doesnt work good in this script.
2) if i want to get false, i use '= false' its that easy. [retard] :P

Offline a fool

  • Major
  • *
  • Posts: 98
  • Wait, what?
Re: Slot Test (Active?)
« Reply #14 on: July 03, 2008, 02:23:35 pm »
2) if i want to get false, i use '= false' its that easy. [retard] :P

yeah... but it's good to optimize your code at most. It makes it run faster (Considerable when you have a lot of script). it's more human readable and clear.
You're probably like me and saying to your self "Bah, I'm too lazy for that". but just do it in further times. Also, it saves a lot of work when scripting :3

over all, here is a cleaner example:
Code: [Select]
var
Counter: integer;

function OnCommand(ID: byte; Text: string): boolean;
begin
if Text = '/slots' then
begin
for Counter := 1 to 16 do
begin
case GetPlayerStat(Counter, 'active') of
True: WriteConsole(ID,'Slot '+inttostr(Counter)+' is occupied by '+IDToName(Counter)+'.',$FF0000);
False: WriteConsole(ID,'Slot '+inttostr(Counter)+' is inactive.',$FF0000);
end;
end;
Result := false;
end;
end;

I believe this should work. if not... well  [retard]
« Last Edit: July 03, 2008, 02:31:59 pm by a fool »
Verily!

Offline Neosano

  • Camper
  • ***
  • Posts: 253
  • IIAWAK!
Re: Slot Test (Active?)
« Reply #15 on: July 03, 2008, 04:52:18 pm »
Wtf, why you can't use else here? O_O
And its much easier to write 3 letters instead of 6

Date Posted: July 03, 2008, 05:45:24 pm
A fool, i don't see any reason to use case for boolean.
Bellamy, else wont work only if you are retard ^_^
Try this:
Code: [Select]
if GetPlayerStat(Counter, 'active') then
WriteConsole(ID,'Slot ' + inttostr(Counter) + ' is occupied by ' + IDToName(Counter) + '.',$FF0000)
else
WriteConsole(ID,'Slot ' + inttostr(Counter) + ' is inactive.',$FF0000);
KAWAAAAAAAIIIIIIIIII

Offline Boblekonvolutt

  • Soldier
  • **
  • Posts: 222
  • "YOU are a CAR."
Re: Slot Test (Active?)
« Reply #16 on: July 03, 2008, 06:50:19 pm »
Why even bother saying a slot is empty? If it's not mentioned, it's not used.
Code: [Select]
function OnCommand(ID: Byte; Text: String): Boolean;
var i: Integer;
begin

  if LowerCase(Text) = '/slots' then
    for i := 1 to 32 do
      if GetPlayerStat(i, 'Active') then
        WriteConsole(ID, 'Slot ' + IntToStr(i) + ' (' + GetPlayerStat(i, 'Name') + ') is occupied.', $FF0000);

end;
I think its fairly easy to read and understand. Just a quick look will tell you what it does.

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Slot Test (Active?)
« Reply #17 on: July 03, 2008, 07:14:37 pm »
wouldn't you want to use MaxPlayers instead of 32?

Offline Bellamy

  • Major(1)
  • Posts: 42
Re: Slot Test (Active?)
« Reply #18 on: July 04, 2008, 12:19:59 am »
Boblekonvolutt, I made it say the empty slots solely for better understanding. That's all.

And guys, really. It works fine. No need to harrass me with suggestions.
But I will use else, Neosano. I think I was just using it in the wrong spot.

And keep in mind that I haven't yet had much experience with using else, so don't think I'm horrible at scripting.
« Last Edit: July 04, 2008, 12:24:46 am by Bellamy »

Offline EnEsCe

  • Retired Soldat Developer
  • Flamebow Warrior
  • ******
  • Posts: 3101
  • http://enesce.com/
    • [eC] Official Website
Re: Slot Test (Active?)
« Reply #19 on: July 04, 2008, 12:30:05 am »
wouldn't you want to use MaxPlayers instead of 32?
Flawed logic, what if the max players is 6 and there's 2 admins in there, making it 8 players being used. kthx