Results 1 to 9 of 9

Thread: rWait (Upgraded DivWait)

  1. #1
    Join Date
    Feb 2006
    Location
    Australia, NSW.
    Posts
    1,461
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default rWait (Upgraded DivWait)

    procedure rWait(ms: integer); - By XxKanexX

    If you are going to use this please read My DivWait thread so you can get an understanding of what this is based about.

    Code:
    Procedure rWait(ms: Integer);
    var
      i, diva, a: Integer;
    begin
    
     a:= Getsystemtime;
     if(ms <= 0)then
      ms:= 5;
    
     Diva:= ms div(ms div(Random(ms div(ms div(ms-(ms-Random(ms+1 div 2))+1)+1)+1)+1)+1);
    
     if(Diva <= 0)then
       Diva:= ms/((ms/4)+1);
    
      for I:= 1 to Diva do
     begin
       Wait(ms/diva + random(diva));
      if(Random(100)+1 = Random(100)+1)then
        Wait(Diva + Random(Diva div 2));
      if(trunc(Getsystemtime-a) > ms * ((Random(7)+2 + Random(3)+1)/(Random(2)+1)))then
        Break;
     end;
    
     if(Trunc(Getsystemtime-a) = ms)or (Trunc(Getsystemtime-a) < ms + (ms/4+(Random(3)+1)))then
        wait(Random(ms));
    
    end;
    In Divwait you had to choose it's divisision and random wait time. Well, in this all you need to specify is the time. The rest is COMPLETELY random.

    It divides the total wait time by a random number calculated by how big or small the wait time is (Just so it dosn't wait to long or not long enough).

    If it waits more than a certain random time times by the total time then it will break.
    If it waits the same amount as the time, it will wait a random time just so it's not the same.

    At first i got division errors, but now everything is working. I ran it around 2000 times and not 1 division error. Dosn't mean it's not possible though.

    I wouldn't suggest using this if you want to wait only the time you want to. This can increase it by a high amount.

    It has a 1 out of 100 chance of waiting longer every time it waits a section.

    Heres an example script:
    Code:
    var
      st, i: integer;
    begin
      for i:= 1 to 7 do
     begin
      st:= getsystemtime;
       rwait(1000);
      writeln(floattostr(getsystemtime-st));
     end;
    end.

    And the results (In Milliseconds):
    Code:
    3915
    2093
    1743
    1682
    2594
    3976
    1543
    I won't add this to SRL until i get everyones opinion. Should it be added?


    Sorry if that's alot of explaining. I normally want to explain it enough for everyone to understand.

    I highlight keywords in bold to annoy Fakawi ^^;; kekeke

  2. #2
    Join Date
    Feb 2006
    Posts
    920
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Hello Kane sorry for being so slow on this, but I think the one I just made is better.

    Code:
    program new;
    
    var i2: Integer;
    
    procedure rWait(ms, min: Integer);
    var
      i, tRan, tVal: Integer;
    begin
      if Length(IntToStr(ms)) > 1 then
        tVal:= Round(Length(IntToStr(ms)) div 2.0)
      else
        tVal:= 1;
      repeat
        for i := 1 to tVal do
          tRan := tRan + Random(ms div tVal) div 2;
        tVal := Random(4);
        if(tVal = 3)or(tVal = 2)then
          tRan := tRan * -1;
      until(ms + tRan >= min);
      WriteLn(IntToStr(ms) + 'ms = ' + IntToStr(ms + tRan));
      Wait(ms + tRan);
    end;
    
    begin
      ClearDebug;
      for i2 := 1 to 2 do
        rWait(2 * i2, 2);
      for i2 := 1 to 2 do
        rWait(20 * i2, 15);
      for i2 := 1 to 2 do
        rWait(50 * i2, 40);
      for i2 := 1 to 2 do
        rWait(100 * i2, 80);
      for i2 := 1 to 2 do
        rWait(1000 * i2, 800);
      for i2 := 1 to 2 do
        rWait(10000 * i2, 7000);
    end.
    here you can test it and the procedure in it self:

    Code:
    procedure rWait(ms, min: Integer);
    var
      i, tRan, tVal: Integer;
    begin
      if Length(IntToStr(ms)) > 1 then
        tVal:= Round(Length(IntToStr(ms)) div 2.0)
      else
        tVal:= 1;
      repeat
        for i := 1 to tVal do
          tRan := tRan + Random(ms div tVal) div 2;
        tVal := Random(4);
        if(tVal = 3)or(tVal = 2)then
          tRan := tRan * -1;
      until(ms + tRan >= min);
      Wait(ms + tRan);
    end;
    try it out. it gives some nice results, min and max can be added / removed if you wish to.

  3. #3
    Join Date
    Feb 2006
    Location
    Australia
    Posts
    628
    Mentioned
    15 Post(s)
    Quoted
    105 Post(s)

    Default

    Wow good work guys. I like kanes one a little more because it just spreads out a little more and not much input was required.
    I see that you have both know that it's important not to wait less than the specified wait time. I used code which was a little simpler, but still did the same job.
    Code:
    procedure ChanceWait(NormalWait: integer);
    begin
      if (random(100) < 5) then
        wait((NormalWait * 2) + random(round(NormalWait div 2)));
      else
        wait(NormalWait);
    end;
    I wasn't sure if NormalWait should have some random time added to it, the extended wait does :/

  4. #4
    Join Date
    Feb 2006
    Posts
    920
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Krazy_Meerkat
    Wow good work guys. I like kanes one a little more because it just spreads out a little more and not much input was required.
    I see that you have both know that it's important not to wait less than the specified wait time. I used code which was a little simpler, but still did the same job.
    Code:
    procedure ChanceWait(NormalWait: integer);
    begin
      if (random(100) < 5) then
        wait((NormalWait * 2) + random(round(NormalWait div 2)));
      else
        wait(NormalWait);
    end;
    I wasn't sure if NormalWait should have some random time added to it, the extended wait does :/
    That's a pretty bad wait procedure, mine and Kane's are more random, and off course mine is within the acceptable limits of randomness

  5. #5
    Join Date
    Feb 2006
    Location
    MS Paint
    Posts
    252
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    3915
    2093
    1743
    1682
    2594
    3976
    1543
    Nice on the randomness. Im going to hafta use this in future scripts.

    Awesome job .
    No room for thoughts.

  6. #6
    Join Date
    Feb 2006
    Location
    Australia
    Posts
    628
    Mentioned
    15 Post(s)
    Quoted
    105 Post(s)

    Default

    You're right lorax, it was just an example
    I've changed my mind, I think that lorax's one is a lot better (but you just need to get rid of that extra parameter).
    I've taken the liberty to do it myself. You don't mind if I use this do you lorax?
    Code:
    program new;
    
    var i2: Integer;
    
    procedure rWait(ms: Integer);
    var
      i, tRan, tVal, min: Integer;
    begin
      min:= ms
      if Length(IntToStr(ms)) > 1 then
        tVal:= Round(Length(IntToStr(ms)) div 2.0)
      else
        tVal:= 1;
      repeat
        for i := 1 to tVal do
          tRan := tRan + Random(ms div tVal) div 2;
        tVal := Random(4);
        if(tVal = 3)or(tVal = 2)then
          tRan := tRan * -1;
      until(ms + tRan >= min);
      WriteLn(IntToStr(ms) + 'ms = ' + IntToStr(ms + tRan));
      Wait(ms + tRan);
    end;
    
    begin
      ClearDebug;
        rWait(500);
    end.

  7. #7
    Join Date
    Feb 2006
    Location
    Australia, NSW.
    Posts
    1,461
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Krazy_Meerkat
    You're right lorax, it was just an example
    I've changed my mind, I think that lorax's one is a lot better (but you just need to get rid of that extra parameter).
    I've taken the liberty to do it myself. You don't mind if I use this do you lorax?
    Code:
    program new;
    
    var i2: Integer;
    
    procedure rWait(ms: Integer);
    var
      i, tRan, tVal, min: Integer;
    begin
      min:= ms
      if Length(IntToStr(ms)) > 1 then
        tVal:= Round(Length(IntToStr(ms)) div 2.0)
      else
        tVal:= 1;
      repeat
        for i := 1 to tVal do
          tRan := tRan + Random(ms div tVal) div 2;
        tVal := Random(4);
        if(tVal = 3)or(tVal = 2)then
          tRan := tRan * -1;
      until(ms + tRan >= min);
      WriteLn(IntToStr(ms) + 'ms = ' + IntToStr(ms + tRan));
      Wait(ms + tRan);
    end;
    
    begin
      ClearDebug;
        rWait(500);
    end.
    Harsh ;(

  8. #8
    Join Date
    Feb 2006
    Location
    Australia
    Posts
    628
    Mentioned
    15 Post(s)
    Quoted
    105 Post(s)

    Default

    No kaney you got it all wrong, I think it is a lot better than what I did before. I still <3 rWait

  9. #9
    Join Date
    Feb 2006
    Posts
    920
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Krazy_Meerkat
    No kaney you got it all wrong, I think it is a lot better than what I did before. I still <3 rWait
    I like the way you modified it, hehe. I added a possibility to wait the random less on the first script that can be removed though :
    First procedure:
    Code:
    procedure rWait(ms, min: Integer);
    var
      i, tRan, tVal: Integer;
    begin
      if Length(IntToStr(ms)) > 1 then
        tVal:= Round(Length(IntToStr(ms)) div 2.0)
      else
        tVal:= 1;
      repeat
        for i := 1 to tVal do
          tRan := tRan + Random(ms div tVal) div 2;
        tVal := Random(4);
        if(tVal = 3)or(tVal = 2)then
          tRan := tRan * -1;
      until(ms + tRan >= min);
      Wait(ms + tRan);
    end;

    procedure with removed ability to wait less than ms:
    Code:
    procedure rWait(ms: Integer);
    var
      i, tRan: Integer;
    begin
      if Length(IntToStr(ms)) > 1 then
        tVal:= Round(Length(IntToStr(ms)) div 2.0)
      else
        tVal:= 1;
      for i := 1 to tVal do
        tRan := tRan + Random(ms div tVal) div 2;
      Wait(ms + tRan);
    end;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Game Engine Upgraded!
    By phantombmx in forum RS has been updated.
    Replies: 10
    Last Post: 05-16-2006, 10:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •