SRL Archive - OSR Help

Choosing a random sps path


Parade

2012-06-13 13:19:54

As an anti-ban procedure for my script, I made different paths for the character to walk to a location. But I realized, I'm unsure how random works. How would I call for a random path to be used?

Paths: ToGold, ToGoldTwo, ToGoldThree

procedure GoToGold;
begin
SetRun(True);
MakeCompass('n');
SPS_WalkPath(ToGold);
end;

CephaXz

2012-06-13 13:33:51


procedure GoToGold;
begin
SetRun(True);
MakeCompass('n');
case Random(3) of //Randoming 3 cases: 0, 1, 2
0: if SPS_WalkPath(ToGold) then
writeln('Walking path 1');
1: if SPS_WalkPath(ToGold2) then
writeln('Walking path 2');
2: if SPS_WalkPath(ToGold3) then
writeln('Walking path 3');
end; //case needs an end
end;

putonajonny

2012-06-13 13:47:09

procedure GoToGold;
begin
SetRun(True);
MakeCompass('n');
Case Random(3) of//Random() generates a random number between 0 and 1 less than the number you put in brackets, so Random(3) generates a number between 0 and 2.
0 : ToGold := [];//Path 1 The case function checks these against these numbers and sets the path appropriately...
1 : ToGold := [];//Path 2
2 : ToGold := [];//Path 3
end;
SPS_WalkPath(ToGold);
end;

Parade

2012-06-13 14:24:29

From: putonajonny
procedure GoToGold;
begin
SetRun(True);
MakeCompass('n');
Case Random(3) of//Random() generates a random number between 0 and 1 less than the number you put in brackets, so Random(3) generates a number between 0 and 2.
0 : ToGold := [];//Path 1 The case function checks these against these numbers and sets the path appropriately...
1 : ToGold := [];//Path 2
2 : ToGold := [];//Path 3
end;
SPS_WalkPath(ToGold);
end;


Wouldn't this only work if ToGold was a variable declared as an integer? It wouldn't be difficult at all to change it, of course, but in my script ToGold is a path and declared as a TPointArray.
Thank you for explaining how this works. I can definitely apply this in a lot of places now. :]



From: CephaXz

procedure GoToGold;
begin
SetRun(True);
MakeCompass('n');
case Random(3) of //Randoming 3 cases: 0, 1, 2
0: if SPS_WalkPath(ToGold) then
writeln('Walking path 1');
1: if SPS_WalkPath(ToGold2) then
writeln('Walking path 2');
2: if SPS_WalkPath(ToGold3) then
writeln('Walking path 3');
end; //case needs an end
end;


Thank you so much! I like the idea of posting the path in the debug, too.

putonajonny

2012-06-13 14:28:20

From: Parade
Wouldn't this only work if ToGold was a variable declared as an integer? It wouldn't be difficult at all to change it, of course, but in my script ToGold is a path and declared as a TPointArray.
Thank you for explaining how this works. I can definitely apply this in a lot of places now. :]

No ToGold could be a global or local TPointArray, not an integer.

Parade

2012-06-13 15:06:06

From: putonajonny
No ToGold could be a global or local TPointArray, not an integer.


Ohhhhhh..I see. That's clever! It would reset ToGold to the path the random chooses. At first, I was reading that ToGold was being set to a path number eg. 1, 2, etc.

That's a clean piece of code, there!

P1ng

2012-06-13 15:30:47

I like to use one path more than the other because I feel it's more humanlike than running 3 different paths evenly all the time.

Case Random(6) of
0..3: ToGold :=
4: ToGold :=
5: ToGold :=

NB: All cases will begin from 0 not 1

Parade

2012-06-15 18:02:30

Now I'm having a bit of trouble debugging all of the different paths. Since it only writes in the debug after the path is completed, I'm having an awful hard time of figuring out which paths need modification and which one's don't. Any ideas?

procedure GoToGold;
begin
SetRun(True);
MakeCompass('n');
case Random(4) of
0: if SPS_WalkPath(ToGold) then
writeln('Walking path 1');
1: if SPS_WalkPath(ToGoldTwo) then
writeln('Walking path 2');
2: if SPS_WalkPath(ToGoldThree) then
writeln('Walking path 3');
3: if SPS_WalkPath(ToGoldFour) then
Writeln('Walking path 4');
end;
wait(1000);
end;

CephaXz

2012-06-15 18:04:12

writeln first, then just walk path.

putonajonny

2012-06-15 18:18:10

procedure GoToGold;
begin
SetRun(True);
MakeCompass('n');
case Random(4) of
0: begin
writeln('Walking path 1');
if SPS_WalkPath(ToGold) then
WriteLn('Path 1 Successful');
end;
1: begin
writeln('Walking path 2');
if SPS_WalkPath(ToGoldTwo) then
WriteLn('Path 2 Successful');
end;
2: begin
writeln('Walking path 3');
if SPS_WalkPath(ToGoldThree) then
WriteLn('Path 3 Successful');
end;
3: begin
writeln('Walking path 4');
if SPS_WalkPath(ToGoldFour) then
WriteLn('Path 4 Successful');
end;
end;
wait(1000+Random(1000));//Remember your randomness!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
end;

Parade

2012-06-15 21:11:56

From: putonajonny
procedure GoToGold;
begin
SetRun(True);
MakeCompass('n');
case Random(4) of
0: begin
writeln('Walking path 1');
if SPS_WalkPath(ToGold) then
WriteLn('Path 1 Successful');
end;
1: begin
writeln('Walking path 2');
if SPS_WalkPath(ToGoldTwo) then
WriteLn('Path 2 Successful');
end;
2: begin
writeln('Walking path 3');
if SPS_WalkPath(ToGoldThree) then
WriteLn('Path 3 Successful');
end;
3: begin
writeln('Walking path 4');
if SPS_WalkPath(ToGoldFour) then
WriteLn('Path 4 Successful');
end;
end;
wait(1000+Random(1000));//Remember your randomness!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
end;




Thank you. and thank you for the random wait. hahah
Now, I had a question about that.. Do you know why I would need to add "begin" and "end" when I add the writeln line before the walkpath?

riwu

2012-06-15 21:19:32

Because u would be performing 2 actions (writeln+walkpath), but if u put
if condition1 then action1;
it would be considered 1 single action (since the latter action will not be executed without the former condition).
If u dont put a begin, it means that for the case of Random=0, it is only going to perform the writeln (because thats where the command ends, as denoted by ";" at the end of the writeln.

EDIT: just remember the simple rule: if u are going to perform >1 actions after a conditional/case statement, always add begin and end. If its 1 action, u can STILL put begin and end, but most experienced scripters just leave it out for cleanness.

putonajonny

2012-06-16 05:39:24

An example where you wouldn't need it:
Case Random(3) of
0 : DoThis;
1 : DoThat;
2 : DoThisOtherThing;
end;

An Example where you would:
Case Random(3) of
0 : begin
DoThis;
AndThat;
end;
1 : begin
Something;
SomethingElse;
end;
2 : begin
GoOutside;
HaveFun;
end;
end;

Sometimes you might do both:
Case Random(3) of
0 : DoThisSuperAwesomeThing;
1 : begin
Something;
SomethingElse;
end;
2 : DoASlightlyLessAwesomeThing;
end;

Hopefully from that you can see :)

Parade

2012-06-17 18:16:01

@riwu & putonajonny



Thanks for all of the info and thanks putonajonny for the examples. It really makes a lot more sense now. :] Now back to the devious world of scripting for me.