Difference between revisions of "ScriptCore3.Random"

From Soldat Community Wiki
Jump to: navigation, search
(new page)
 
m (Example)
Line 11: Line 11:
 
<syntaxhighlight lang="pascal">
 
<syntaxhighlight lang="pascal">
 
var
 
var
i: integer;
+
  i: integer;
id: byte;
+
  id: byte;
  
 
function OnCommand(P: TActivePlayer; Command: string): Boolean;
 
function OnCommand(P: TActivePlayer; Command: string): Boolean;
 
begin
 
begin
Result := FALSE;
+
  Result := FALSE;
if Command = '/killrandom' then
+
  if Command = '/killrandom' then
begin
+
  begin
repeat
+
    repeat
id := Random(1,32);
+
      id := Random(1,32);
until Players[id].Active;
+
    until Players[id].Active;
Players[id].Damage(P.ID,1000);
+
    Players[id].Damage(P.ID,1000);
Players[id].WriteConsole('Random kill by '+P.Name,$FF0000);
+
    Players[id].WriteConsole('Random kill by '+P.Name,$FF0000);
end;
+
  end;
 
end;
 
end;
  
 
begin
 
begin
for i:=1 to 32 do
+
  for i:=1 to 32 do
Players[i].OnCommand := @OnCommand;
+
    Players[i].OnCommand := @OnCommand;
 
end.
 
end.
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Functions]]
 
[[Category:Functions]]

Revision as of 16:36, 22 August 2013

function Random(Min, Max: Integer): Integer
 Min: minimum value that can be generated
 Max: maximum value that can be generated
 Result: generated number

Description

This function will generate a pseudo-random number between Min and Max

Example

Below script kills random player in game and grants user a kill (if killed an enemy).

var
  i: integer;
  id: byte;

function OnCommand(P: TActivePlayer; Command: string): Boolean;
begin
  Result := FALSE;
  if Command = '/killrandom' then
  begin
    repeat
      id := Random(1,32);
    until Players[id].Active;
    Players[id].Damage(P.ID,1000);
    Players[id].WriteConsole('Random kill by '+P.Name,$FF0000);
  end;
end;

begin
  for i:=1 to 32 do
    Players[i].OnCommand := @OnCommand;
end.