PDA

View Full Version : function RandomRotate(p:integer):boolean;



Daniel
12-20-2007, 06:38 AM
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:
{************************************************* ******************************
Name: function RandomRotate:boolean;
Author: IP-Drowner
Description: Will rotate the compass to a random direction then it
return's true.
************************************************** *****************************}

Usage:
RandomRotate;

The 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!

LordGregGreg
12-20-2007, 06:56 AM
why didnt you just have

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

randomRotate();

Santa_Clause
12-20-2007, 12:21 PM
If they put it higher than 4, there's a chance that it doesn't rotate at all.

LordGregGreg
12-20-2007, 04:43 PM
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.

Daniel
12-20-2007, 11:09 PM
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! http://www.srl-forums.com/forum/images/smilies/duh.gif

Jackrawl
12-20-2007, 11:53 PM
I thought the higher the value the more random it was. Oh well, i was mistaken again! http://www.srl-forums.com/forum/images/smilies/duh.gif

....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.'

LordGregGreg
12-21-2007, 12:42 AM
....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.

Daniel
12-21-2007, 12:47 AM
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!

Daniel
12-21-2007, 01:16 AM
I just updated it. Now you don't have to input a number.

Fruity-Lo0py
12-21-2007, 03:41 PM
Could I please this in my new script :D Just thought I best ask permission incase you change your idea?

LordGregGreg
12-21-2007, 04:40 PM
Could I please this in my new script :D 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.

Daniel
12-22-2007, 06:19 AM
Could I please this in my new script :D 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.

osmm
12-23-2007, 11:37 PM
I just got this in my script

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.

Jackrawl
12-27-2007, 11:08 PM
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.

Killerdou
12-27-2007, 11:34 PM
i think the higher random then the amount of options is so it wont always do something, am i right?

Daniel
12-28-2007, 12:27 AM
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.

mickaliscious
01-03-2008, 05:36 PM
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:
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.

footballjds
01-03-2008, 10:26 PM
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/

Daniel
01-04-2008, 04:36 AM
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.

footballjds
01-04-2008, 05:10 AM
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.:rolleyes:

Daniel
01-04-2008, 08:07 AM
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.:rolleyes:

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.

footballjds
01-04-2008, 05:49 PM
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.:duh:

the flea
01-04-2008, 07:38 PM
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.:duh:

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

Jackrawl
01-05-2008, 12:44 AM
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

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.

Ultra
01-05-2008, 02:42 PM
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 :).

Daniel
01-07-2008, 01:22 AM
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 :).

BoredHuman is a procedure which is inside SRL. It clicks the door to log out but it doesn't log out.

R0b0t1
01-07-2008, 02:04 AM
Goto's are bad style... :(


repeat
case random(4) of
0: AString := 'N';
1: AString := 'S';
2: AString := 'W';
3: AString := 'E';
end;
MakeCompass(AString);
until(AString = 'N');

footballjds
01-07-2008, 02:14 AM
BoredHuman is a procedure which is inside SRL. It clicks the door to log out but it doesn't log out.

bored human rotates the camera veiw and randomly moves mouse, if it can itl right click and click examine. your thinking of AlmostLogout;