PDA

View Full Version : [Utility] Need help with script



qwertyuiop12345
09-02-2015, 05:56 PM
Hello, I'm trying to make a dice script were someone says !roll in your clan chat and the script rolls a random number. I'm having trouble trying to get the script to recognize the command !roll. Can someone please help me? This is what I have so far:

program DiceBot;
{$DEFINE SMART}
{$I SRL-OSR/SRL.Simba}

var
outcome: Integer;

procedure DeclarePlayers;
begin

HowManyPlayers:= 1;
CurrentPlayer:= 0;
NumberOfPlayers(HowManyPlayers);


Players[0].Name := 'Test';
Players[0].Pass := 'Test';
Players[0].Nick := '';
Players[0].Active := True;
end;

procedure DiceRoll;
begin
outcome := Random(100) + 1
if FindChatBoxText('!Roll', 8, clFriend) then
TypeSend('The number rolled was ' + IntToStr(outcome) + '.');
end;

begin
SetupSRL;
DeclarePlayers;
LoginPlayer;
DiceRoll;
end.

Ross
09-02-2015, 06:20 PM
Is '!roll' case sensitive? you have '!Roll' in the script.

I'm not familiar with OSR.

KeepBotting
09-02-2015, 06:21 PM
What are you having trouble with? You've outlined the general issue but nothing specific enough for us to help.

Is the script not seeing the "!roll" text, and thus, not running any of the conditional code?

qwertyuiop12345
09-02-2015, 06:28 PM
when u type it in the clan chat the R is uppercase anyways, so I don't believe that would matter.

qwertyuiop12345
09-02-2015, 06:31 PM
when I run the script its basically like an auto typer, I'm trying to make it recognize the !Roll command so I added:

if FindChatBoxText('!Roll', 8, clFriend) then
TypeSend('The number rolled was ' + IntToStr(outcome) + '.');

but it is still not working.

KeepBotting
09-02-2015, 06:33 PM
when I run the script its basically like an auto typer, I'm trying to make it recognize the !Roll command so I added:

if FindChatBoxText('!Roll', 8, clFriend) then
TypeSend('The number rolled was ' + IntToStr(outcome) + '.');

but it is still not working.

Try doing writeLn(FindChatBoxText('!Roll', 8, clFriend)); so you can see what Simba sees. Maybe it's failing to find the text.

qwertyuiop12345
09-02-2015, 06:38 PM
So now I have this:

procedure DiceRoll;
begin
outcome := Random(100) + 1
writeLn(FindChatBoxText('!Roll', 8, clFriend));
TypeSend('/The number rolled was ' + IntToStr(outcome) + '.');
end;

and it started typing continuously.

rj
09-02-2015, 06:52 PM
Try using reflection to get the messages

function TReflectionChat.Messages(): TStringArray;
var
ChatWidget, ChatChild: TReflectWidget;
i:integer;
begin
setLength(result, 16);
ChatWidget.GetWidget(WIDGET_Chat_Container, 2);
for i := 0 to 16 do
begin
ChatChild.GetChild(ChatWidget, i);
Result[i] := Reflect.Text.RemoveFormatting(ChatChild.GetText);
ChatChild.Free;
end;
ChatWidget.Free;
end;

I made a script similar to this, except it just mimicked a player with a certain name. It might get a little bit tricky getting new !Roll commands

KeepBotting
09-02-2015, 07:51 PM
So now I have this:

procedure DiceRoll;
begin
outcome := Random(100) + 1
writeLn(FindChatBoxText('!Roll', 8, clFriend));
TypeSend('/The number rolled was ' + IntToStr(outcome) + '.');
end;

and it started typing continuously.

Well that's the idea. the writeLn() in there is meant to print the result of findChatBoxText() to the debug box so you can see what Simba is returning when it searches for text.