Page 1 of 2 12 LastLast
Results 1 to 25 of 28

Thread: function RandomRotate(p:integer):boolean;

  1. #1
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default function RandomRotate(p:integer):boolean;

    UPDATED

    I know this is a basic function but it can be very useful to some. Please remember to post feedback. Also, you may edit this code freely but you cannot distribute this code without my permission.

    It has worked well in my private scripts.

    Information:
    SCAR Code:
    {*******************************************************************************
       Name: function RandomRotate:boolean;
       Author: IP-Drowner
       Description: Will rotate the compass to a random direction then it
                         return's true.
    *******************************************************************************}

    Usage:
    SCAR Code:
    RandomRotate;

    The Code:
    SCAR Code:
    function RandomRotate:Boolean;
    begin
      case random(5) of
          0: begin
               MakeCompass('N');
               Writeln('Changed the compass to North');
               Result:=True;
             end;
          1: begin
               MakeCompass('S');
               Writeln('Changed the compass to South');
               Result:=True;
             end;
          2: begin
               MakeCompass('E');
               Writeln('Changed the compass to East');
               Result:=True;
             end;
          3: begin
               MakeCompass('W');
               Writeln('Changed the compass to West');
               Result:=True;
             end;
          4: begin
               Writeln('Did not change the compass angle.');
               Result:=True;
              end;
      end;
    end;

    Enjoy!
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  2. #2
    Join Date
    Apr 2007
    Location
    Texas
    Posts
    1,668
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    why didnt you just have
    SCAR Code:
    function RandomRotate():Boolean;
    begin
      case random(4) of
          0: begin
               MakeCompass('N');
               Writeln('Changed the compass to North');
               Result:=True;
             end;
          1: begin
               MakeCompass('S');
               Writeln('Changed the compass to South');
               Result:=True;
             end;
          2: begin
               MakeCompass('E');
               Writeln('Changed the compass to East');
               Result:=True;
             end;
          3: begin
               MakeCompass('W');
               Writeln('Changed the compass to West');
               Result:=True;
             end;
      end;
    end;

    this would make your function easier to use, not to mention prevent people from passing it wrong parameters. I can see no real reason to pass it anything other than 4.

    the usage would be
    SCAR Code:
    randomRotate();
    [IMG]http://farm3.static.flickr.com/2120/2052732965_348f3629d0_o.jpg[/IMG]

  3. #3
    Join Date
    Nov 2006
    Location
    NSW, Australia
    Posts
    3,487
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    If they put it higher than 4, there's a chance that it doesn't rotate at all.
    [CENTER][img]http://signatures.mylivesignature.com/54486/113/4539C8FAAF3EAB109A3CC1811EF0941B.png[/img][/CENTER]
    [CENTER][BANANA]TSN ~ Vacation! ~ says :I Love Santy[/BANANA][/CENTER]

    [CENTER][BANANA]Raymond - Oh rilie? says :Your smart[/BANANA][/CENTER]

  4. #4
    Join Date
    Apr 2007
    Location
    Texas
    Posts
    1,668
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Santa_Clause View Post
    If they put it higher than 4, there's a chance that it doesn't rotate at all.
    well, yeah, but that is tacky.

    if you want something like that then you should do something like if random(10)>5 then
    ...

    or at least have it be an option in the parameters fo the script.
    [IMG]http://farm3.static.flickr.com/2120/2052732965_348f3629d0_o.jpg[/IMG]

  5. #5
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by Santa_Clause View Post
    If they put it higher than 4, there's a chance that it doesn't rotate at all.
    I thought the higher the value the more random it was. Oh well, i was mistaken again!
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  6. #6
    Join Date
    Jun 2007
    Posts
    1,312
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by IP-Drowner View Post
    I thought the higher the value the more random it was. Oh well, i was mistaken again!
    ....The higher the value is the more random it is..You aren't mistaken.
    Random(4) means any number between 0 and 4 can be the 'result.'
    Active only during the Summer...

  7. #7
    Join Date
    Apr 2007
    Location
    Texas
    Posts
    1,668
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by JackLKrawl View Post
    ....The higher the value is the more random it is..You aren't mistaken.
    Random(4) means any number between 0 and 4 can be the 'result.'
    well, depends on what youmean "more random"

    random(10) will generate a random number between 0 and 9,

    but seince your script only handles four diferent numbers, and number greater than 4 would basical break your script,and result init doing nothing.
    [IMG]http://farm3.static.flickr.com/2120/2052732965_348f3629d0_o.jpg[/IMG]

  8. #8
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by LordGregGreg View Post
    well, depends on what youmean "more random"

    random(10) will generate a random number between 0 and 9,

    but seince your script only handles four diferent numbers, and number greater than 4 would basical break your script,and result init doing nothing.
    Oh, now i understand. Thanks LordGregGreg!
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  9. #9
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    I just updated it. Now you don't have to input a number.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  10. #10
    Join Date
    Sep 2007
    Posts
    50
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Could I please this in my new script Just thought I best ask permission incase you change your idea?

  11. #11
    Join Date
    Apr 2007
    Location
    Texas
    Posts
    1,668
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Fruity-Lo0py View Post
    Could I please this in my new script Just thought I best ask permission incase you change your idea?
    by default, all scar code is open sourced. you may use it and modify it as much as you want, as long as you add in a comment in your script with credit.

    but i supose asking him personally is polite as well.
    [IMG]http://farm3.static.flickr.com/2120/2052732965_348f3629d0_o.jpg[/IMG]

  12. #12
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by Fruity-Lo0py View Post
    Could I please this in my new script Just thought I best ask permission incase you change your idea?
    Yes you can use it but you must add a //Thanks to IP-Drowner line are the semi-colon of the function name.

    Also, if you modify this code, do not post it anywhere without permission. PM me first before distrubuting.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  13. #13
    Join Date
    Jul 2007
    Posts
    1,055
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I just got this in my script

    SCAR Code:
    procedure RandomlyMoveCompass; // By Osmm
    begin
      Case Random(6) of
        0: MakeCompass('N');
        1: begin
             MakeCompass('W');
             MakeCompass('E');
           end;
        2: begin
             MakeCompass('E');
             MakeCompass('S');
             MakeCompass('W');
           end;
        3: MakeCompass('S');
        4: begin
             LowestAngle;
             MakeCompass('W');
             MakeCompass('S');
           end;
        5: begin
             MakeCompass('S');
             LowestAngle;
             MakeCompass('W');
           end;
      end;
      HighestAngle;
      MakeCompass('N');
    end;

    I just picked random directions and pluged them in with a mix of LowestAngle. Then after it does that it goes back to HighestAngle and Compass North.

  14. #14
    Join Date
    Jun 2007
    Posts
    1,312
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by LordGregGreg View Post
    well, depends on what youmean "more random"

    random(10) will generate a random number between 0 and 9,

    but seince your script only handles four diferent numbers, and number greater than 4 would basical break your script,and result init doing nothing.
    Really? Hmm. I thought Random(10) generated 11 numbers...

    How can a higher random value not be more random? If there are ten socks in a drawer, you are less likely to pull out the same one as you are if there is only one sock in the drawer that is the same sock.
    Active only during the Summer...

  15. #15
    Join Date
    Nov 2006
    Posts
    1,103
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    i think the higher random then the amount of options is so it wont always do something, am i right?
    Infractions, reputation, reflection, the dark side of scripting, they are.

  16. #16
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by Killerdou View Post
    i think the higher random then the amount of options is so it wont always do something, am i right?
    Yes, you're right.

    New version released. It will either Randomly rotate the compass or it won't rotate at all.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  17. #17
    Join Date
    Jul 2007
    Location
    St. Louis, Missouri, USA.
    Posts
    575
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    As your function is right now, it should really be a procedure because it always results as true, making the boolean aspect of it useless. I took a little time and suped up your function, giving it an actually result based on whether or not the compass angle changed. It also does more than the 4 poles of the compass, it can now do angles in between.

    Here's the function:
    SCAR Code:
    function RandomRotate:Boolean;
    var
      StartAngle: Extended;
    begin
      StartAngle := rs_GetCompassAngleDegrees;
      case random(7) of
          0: MakeCompass('N');
          1: MakeCompass('S');
          2: MakeCompass('E');
          3: MakeCompass('W');
          4: begin
               KeyDown(VK_Left);
               Wait(RandomRange(100,600));
               KeyUp(VK_Left);
             end;
          5: begin
               KeyDown(VK_Right);
               Wait(RandomRange(100,600));
               KeyUp(VK_Right);
             end;
      end;
      Result := (StartAngle <> rs_GetCompassAngleDegrees);
    end;

    Nifty right? Lol. I think I even Santa-proofed it for you.
    -You can call me Mick-



  18. #18
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)
    Quote Originally Posted by IP-Drowner View Post
    Yes you can use it but you must add a //Thanks to IP-Drowner line are the semi-colon of the function name.

    Also, if you modify this code, do not post it anywhere without permission. PM me first before distrubuting.
    this is nothing new... in fact i use it in some of my scripts, you didn't create something others didn't already. you just posted it, so its not "yours" many others use this, its a simple random map, nothing super about it. lol... just noobs that don't know how to do anything would come here and say.. oh.. hey i want to use this 1337 thing.. =p/

  19. #19
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by footballjds View Post
    this is nothing new... in fact i use it in some of my scripts, you didn't create something others didn't already. you just posted it, so its not "yours" many others use this, its a simple random map, nothing super about it. lol... just noobs that don't know how to do anything would come here and say.. oh.. hey i want to use this 1337 thing.. =p/
    What is your problem. I did make the script and others obviously gave me ideas and some fixes.

    So i don't know if your a know-it-all that thinks i am trying to take credit for someone else's work or your just a bloody ass-hole who wants to get more posts. Either post to contribute to the topic or don't post at all.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  20. #20
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    Quote Originally Posted by IP-Drowner View Post
    What is your problem. I did make the script and others obviously gave me ideas and some fixes.

    So i don't know if your a know-it-all that thinks i am trying to take credit for someone else's work or your just a bloody ass-hole who wants to get more posts. Either post to contribute to the topic or don't post at all.
    im just saying its not really anything everyone dosn't already use, so you can't tell everyone To "GIVE ME PHr33 CREDIT P10X" and BTW no offense.

  21. #21
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by footballjds View Post
    im just saying its not really anything everyone dosn't already use, so you can't tell everyone To "GIVE ME PHr33 CREDIT P10X" and BTW no offense.
    If it is used a lot, then why doesn't WT-Fawaki implement it into SRL 4 Revision 10? Look, i at least want a thanks in appreciation. Is that hard to ask as it may get leeched all over the SCAR world and the author is unknown.

    If it is implemented into SRL then i wouldn't need a thanks.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  22. #22
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    Quote Originally Posted by IP-Drowner View Post
    If it is used a lot, then why doesn't WT-Fawaki implement it into SRL 4 Revision 10? Look, i at least want a thanks in appreciation. Is that hard to ask as it may get leeched all over the SCAR world and the author is unknown.

    If it is implemented into SRL then i wouldn't need a thanks.
    as i was trying to say b4 your not the "author" many other ppl have used this or somthing similer(myself included) b4 you even posted this.

  23. #23
    Join Date
    Jun 2006
    Location
    N Wales
    Posts
    558
    Mentioned
    2 Post(s)
    Quoted
    56 Post(s)

    Default

    Quote Originally Posted by footballjds View Post
    as i was trying to say b4 your not the "author" many other ppl have used this or somthing similer(myself included) b4 you even posted this.
    technically he is the author of this script since he created it. just because the idea has been done before doesent mean he isnt the author. there are loads of different versions of allmost all scripts but they all have their own author

  24. #24
    Join Date
    Jun 2007
    Posts
    1,312
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by footballjds View Post
    this is nothing new... in fact i use it in some of my scripts, you didn't create something others didn't already. you just posted it, so its not "yours" many others use this, its a simple random map, nothing super about it. lol... just noobs that don't know how to do anything would come here and say.. oh.. hey i want to use this 1337 thing.. =p/
    Now what does thumper say? "FOOOOZBALLL!"

    I do something similar to this, except I prefer gotos
    SCAR Code:
    A:  
    case random(4) of
      0:AString:='N';
      1:AString:='S';
      2:AString:='W';
      3:AString:='E';
    end;
    MakeCompass(AString) //lol, get it?
    if not AString = 'N' then
      goto A;
    There are many ways to do it, they're all the same really. But if I were you, I would have chosen 'P' to be a string instead, so you could choose the ending direction.
    Active only during the Summer...

  25. #25
    Join Date
    Oct 2007
    Posts
    742
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I think that this was made somewhere already, its called procedure boredhuman.
    It rotates the angle randomly also. I am not sure, i will check it out later.

    Still nice way to start some scripting .
    Woot woot.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Posting Permissions

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