Author Topic: RandomPlayer  (Read 1603 times)

0 Members and 1 Guest are viewing this topic.

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
RandomPlayer
« on: December 25, 2008, 06:59:06 am »
Script Name: Random Player
Script Description Returns the ID of a random player in the server. Returns 0 if server is empty.
Author: iDante
Compile Test: Passed
Core Version: 2.6.3
Hosted by: Soldat Central - http://soldatcentral.com/

Full Description:
Returns the ID of a random player in the server. Returns 0 if server is empty.
Takes no parameters.
Uses a fancy little function that I wrote, stringoccurs.
I wasn't even gonna release this due to simplicity, but upnPAD insisted...

function StringOccurs(needle, haystack: string): integer; - Returns how many times needle appears in haystack.
Code: [Select]
function StringOccurs(needle, haystack: string): integer;
begin
Result := 0;
while strpos(needle,haystack) <> 0 do begin
Result := Result + 1;
haystack := copy(haystack,strpos(needle,haystack)+1,length(haystack));
end;
end;

function RandomPlayer; - Returns a random player from the game.
Code: [Select]
function RandomPlayer: byte;
var
all: string;
i: integer;
begin
for i := 1 to 32 do all := all + iif(GetPlayerStat(i,'active')=true,inttostr(i)+' ','');
Result := strtoint(iif(Length(all) > 0,GetPiece(all,' ',Random(0,StringOccurs(' ',all))),'0'))
end;


(Size 1020 B)
- http://soldatcentral.com/index.php?page=script&f=78 -


** Script hosted by Soldat Central! Please visit the author's script page and Rate this script **
« Last Edit: December 26, 2008, 05:43:37 pm by iDante »

Offline Mr

  • Inactive Soldat Developer
  • Soldier
  • ******
  • Posts: 166
Re: RandomPlayer
« Reply #1 on: December 26, 2008, 11:31:50 am »
Because it's only a simple function, what about quoting it here? That would save us a lot of time ;P
Anyways - good job!

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: RandomPlayer
« Reply #2 on: December 27, 2008, 02:54:54 am »
May be useful.
Good that upnPAD insisted. ;)

[edit]@DarkCrusade: I suggest you to delete that post before more ppl read it
[edit2]@DarkCrusade: Too late  :P
« Last Edit: December 27, 2008, 06:20:19 am by Gizd »

DarkCrusade

  • Guest
Re: RandomPlayer
« Reply #3 on: December 27, 2008, 05:53:39 am »
Sorry for I dont see why a admin could need the script, because he can kick players like he wants, he just kicks the players he dont like/who had broken the law :)

I´m sorry if I´m missunderstanding ;D

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: RandomPlayer
« Reply #4 on: December 27, 2008, 06:18:28 am »
omg..
It's function for scripters who often need to get ID of random plyer in their scripts, not for server admins kicking players.