Script Name: Random Player
Script Description Returns the ID of a random player in the server. Returns 0 if server is empty.
Author: iDante (http://soldatcentral.com/index.php?page=profile&u=7)
Compile Test: (http://soldatcentral.com/images/pass.gif) Passed
Core Version: 2.6.3
Hosted by: Soldat Central - http://soldatcentral.com/ (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.
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.
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;
(http://soldatcentral.com/images/download.gif) (http://soldatcentral.com/dl.php?id=78&act=1)
(Size 1020 B)
- http://soldatcentral.com/index.php?page=script&f=78 -
** Script hosted by Soldat Central (http://soldatcentral.com/index.php?page=script&f=78)! Please visit the author's script page (http://soldatcentral.com/index.php?page=script&f=78) and Rate this script **