Difference between revisions of "ScriptCore3.Random"
m (→Example) |
|||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
'''function Random(Min, Max: Integer): Integer''' | '''function Random(Min, Max: Integer): Integer''' | ||
− | Min: minimum value that can be generated | + | Min: minimum value inclusive that can be generated |
− | Max: maximum value that can be generated | + | Max: maximum value exclusive that can be generated |
Result: generated number | Result: generated number | ||
==Description== | ==Description== | ||
− | This function will generate a pseudo-random number between ''Min'' and ''Max'' | + | This function will generate a pseudo-random number between ''Min'' and ''Max - 1'' |
==Example== | ==Example== | ||
Line 18: | Line 18: | ||
Result := FALSE; | Result := FALSE; | ||
if Command = '/killrandom' then | if Command = '/killrandom' then | ||
− | + | if not P.Alive then | |
− | + | P.WriteConsole('You can use this only when alive',$FF0000) | |
− | + | else | |
− | + | begin | |
− | + | repeat | |
− | + | id := Random(1,32+1); | |
− | + | until Players[id].Active; | |
+ | Players[id].Damage(P.ID,1000); | ||
+ | Players[id].WriteConsole('Random kill by '+P.Name,$FF0000); | ||
+ | end; | ||
end; | end; | ||
Latest revision as of 18:32, 14 April 2020
function Random(Min, Max: Integer): Integer Min: minimum value inclusive that can be generated Max: maximum value exclusive that can be generated Result: generated number
Description
This function will generate a pseudo-random number between Min and Max - 1
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
if not P.Alive then
P.WriteConsole('You can use this only when alive',$FF0000)
else
begin
repeat
id := Random(1,32+1);
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.