Results 1 to 9 of 9

Thread: Need help with script

  1. #1
    Join Date
    Sep 2015
    Posts
    4
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Angry Need help with script

    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.

  2. #2
    Join Date
    Jan 2012
    Location
    East Coast
    Posts
    733
    Mentioned
    81 Post(s)
    Quoted
    364 Post(s)

    Default

    Is '!roll' case sensitive? you have '!Roll' in the script.

    I'm not familiar with OSR.

  3. #3
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    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?
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Bad™ before everyone gets laser pistols

  4. #4
    Join Date
    Sep 2015
    Posts
    4
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    when u type it in the clan chat the R is uppercase anyways, so I don't believe that would matter.

  5. #5
    Join Date
    Sep 2015
    Posts
    4
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    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.

  6. #6
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Quote Originally Posted by qwertyuiop12345 View Post
    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
    Simba Code:
    writeLn(FindChatBoxText('!Roll', 8, clFriend));
    so you can see what Simba sees. Maybe it's failing to find the text.
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Bad™ before everyone gets laser pistols

  7. #7
    Join Date
    Sep 2015
    Posts
    4
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    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.

  8. #8
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Try using reflection to get the messages

    Simba Code:
    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

  9. #9
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Quote Originally Posted by qwertyuiop12345 View Post
    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.
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Bad™ before everyone gets laser pistols

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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