Author Topic: Randomize  (Read 1164 times)

0 Members and 1 Guest are viewing this topic.

Offline okt

  • Major(1)
  • Posts: 4
Randomize
« on: February 24, 2007, 10:41:30 am »
Im trying to create a script that randomly selects a player from a game and performs some action. Any ideas how to do it ? Is there any random() function that can randomly select player name or ID?

Date Posted: February 24, 2007, 08:43:08 AM
Code: [Select]
function powerOf(a:integer;b:integer):integer;
var
        t,i: integer;
begin
        t:=1;
        for i:=1 to b do begin
                t:=t*a;
        end;
        result:= t;
end;


function rand(limit: integer):integer;
begin
        result:= powerOf(strtoint(formatdate('zz')),3) mod limit;
end;

procedure AppOnIdle(Ticks: integer);
var
        playernumber: integer;
        ifdelta: integer;

begin
if Ticks mod (3600 * 10) = 0 then
begin
        playernumber:=(rand(20) +1);
        ifdelta:=(rand(2) +1);
        if (ifdelta<2) then
        begin
                Command('/say delta pick:  '+IDToName(playernumber)+'! Good luck');
                Command('/setteam4 '+playernumber); // <====== THIS IS 31 LINE
        end
        else
                Command('/say charlie pick: '+IDToName(playernumber)+'! Good luck');
                Command('/setteam3 '+playernumber);
        end;
        end;
end;

 
Code: [Select]
[*] (randomize.pas) [Error] (31:49): Type mismatch
 [*] Exception raised on SetVariables(Access violation at address 0808A241, accessing address 00000000)
 [*] Run-time error (ActivateServer "function powerOf(a:integer;b:integer):integer;"): No Error

I tried like above, but it doesnt want to compile, why?
« Last Edit: February 24, 2007, 10:43:15 am by okt »

Offline nub

  • Major
  • *
  • Posts: 56
Re: Randomize
« Reply #1 on: February 24, 2007, 07:21:39 pm »
You are trying to add an integer to a string. Unlike in other languages like Java, where the interpreter will convert the integer to a string automatically, this won't work with Pascal. You have to convert the integer to a string explicitly.

so your line should look like this:
Code: [Select]
Command('/setteam4 '+inttostr(playernumber));

same for the other line which will have the same error (line 35).
« Last Edit: February 24, 2007, 07:24:32 pm by nub »
Можно зарезать, украсть и всё-таки быть счастливым...