View Full Version : Need Help With First Script!
Explicit
11-19-2012, 04:25 PM
Hey guys I know I'm new here but I'm really interested in learning to script. I read through the newbie tutorials and watched YoHoJo's videos and I can say I have an ehhh "basic" understanding of what I'm doing. :P
What I need help with is how to script an Auto Responder type program that would basically act like a dice bag in account form. I thought this would be a cool idea as it is my first script and I don't think it would be to over the top to code.
Just an overview of what I'm trying to accomplish, I want to run a script which would open up SMART, log into the lobby, stay there in a friends chat and when a select person says something like "Roll" the script would see it and say a random number between lets say 1 and 10.
Any help would be much appreciated but please don't code this for me. I want to learn how to do this myself so I can make my own more complicated scripts in the future :)
Here's what I have so far (I have the r variable there just as a placeholder for a random number):
program DiceBot;
{$DEFINE SMART}
{$I SRL/SRL.Simba}
procedure DiceRoll;
var
r: Integer;
begin
if FindChatBoxText('!Roll', 8, clFriend) then
TypeSend('Rolling the dice!');
repeat
DiceRoll;
until(false);
end;
begin
DiceRoll;
end.
first of all to login to rs you should have a declare players procedure. then in the bottom of the script where you have
begin
DiceRoll;
end.
you will have
begin
DeclarePlayers;
LoginPlayer;
DiceRoll;
end.
the declare players procedure looks like this:
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
Players[0].Name := ''
Players[0].Pass := ''
Players[0].Nick := ''
Players[0].Pin := ''
Players[0].Active := True
end;
try it out and see if u can login to rs. u have to fill the '' with ur rs username and pass
Explicit
11-19-2012, 07:23 PM
OK thanks! So now I have program DiceBot;
{$DEFINE SMART}
{$I SRL/SRL.Simba}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
Players[0].Name := 'Test'
Players[0].Pass := 'Test'
Players[0].Nick := ''
Players[0].Pin := ''
Players[0].Active := True
end;
procedure DiceRoll;
var
r: Integer;
begin
if FindChatBoxText('!Roll', 8, clFriend) then
TypeSend('Rolling the dice!');
repeat
DiceRoll;
until(false);
end;
begin
DeclarePlayers;
LoginPlayer;
DiceRoll;
end.
what exactly you want to do here.
repeat
DiceRoll;
until (false)
DiceRoll is the name of the procedure. You cant call a procedure inside the procedure itself.
KingKong
11-19-2012, 07:44 PM
yes u can call a procedure inside itself, its called recursion, but in this situation its not needed, he should put the loop outside the procedure
yes u can call a procedure inside itself, its called recursion, but in this situation its not needed, he should put the loop outside the procedure
ooh didnt know that. well, u should replace
repeat
DiceRoll;
until (false);
for what u want the script to do when it receives orders to dice. I'll not post here because you said u wanted to learn but if you want I can try to make it.
Hint: you should use Random(10) + 1 because Random(10) generates a nr from 0 to 9 so if u add 1 it will give u numbers from 1 to 10.
Also you should check the procedures/functions in the include that can type in rs.
Explicit
11-19-2012, 08:33 PM
ooh didnt know that. well, u should replace
repeat
DiceRoll;
until (false);
for what u want the script to do when it receives orders to dice. I'll not post here because you said u wanted to learn but if you want I can try to make it.
Hint: you should use Random(10) + 1 because Random(10) generates a nr from 0 to 9 so if u add 1 it will give u numbers from 1 to 10.
Also you should check the procedures/functions in the include that can type in rs.
Alright thanks for the help guys. I'm still trying to get this but its kinda hard :confused: if you make the script then don't give it to me unless you explain each line of code so I know exactly what you did and why it works :)
This is what I have now:
program DiceBot;
{$DEFINE SMART}
{$I SRL/SRL.Simba}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
Players[0].Name := 'Test'
Players[0].Pass := 'Test'
Players[0].Nick := ''
Players[0].Pin := ''
Players[0].Active := True
end;
var
R: Integer;
procedure DiceRoll;
begin
R := Random(100) + 1
if FindChatBoxText('!Roll', 8, clFriend) then
TypeSend('Rolling the dice!');
Wait(500);
TypeSend('The number rolled was' + IntToStr(R) + '.');
end;
begin
DeclarePlayers;
LoginPlayer;
DiceRoll;
end.
the var should go after procedure and before begin like this:
program DiceBot;
{$DEFINE SMART}
{$I SRL/SRL.Simba}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
Players[0].Name := 'Test'
Players[0].Pass := 'Test'
Players[0].Nick := ''
Players[0].Pin := ''
Players[0].Active := True
end;
procedure DiceRoll;
var
R: Integer;
begin
R := Random(100) + 1
if FindChatBoxText('!Roll', 8, clFriend) then
begin
TypeSend('Rolling the dice!');
Wait(500);
TypeSend('The number rolled was' + IntToStr(R) + '.');
end;
begin
DeclarePlayers;
LoginPlayer;
DiceRoll;
end.
did you tried running it already?
I think it should work now.
Explicit
11-20-2012, 04:06 AM
did you tried running it already?
I think it should work now.
It opens up SMART and logs in fine, but it keeps repeating just the "number rolled was" part over and over again without even looking for an chat dialog of !Roll
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.