Results 1 to 6 of 6

Thread: Profile Script Trading if else [Help Request]

  1. #1
    Join Date
    Jul 2007
    Posts
    14
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default Profile Script Trading if else [Help Request]

    hello

    i am creating a nature script with master and slave function.
    i am realy newb to simba coding.

    when i use:
    writeln(GetTradersName);
    I get the rs name with no problems.


    but when i do:
    if(GetTradersName = 'xxxxx')then
    writeln('Trading is allow!');
    it dont work

    i also tryed to make a function:
    function CheckName(player: string);
    var
    i, score: integer;
    begin
    case Lowercase(player) of
    'xxxxx':
    Result := true;
    else
    Result := false;
    end;
    end;

    if(CheckName(Trader))then
    begin
    writeln('trade ok');
    wait(5000);
    end else
    writeln('trade not');
    wait(5000);
    this dont work, but if i change "if(CheckName(Trader))then" to "if(CheckName('xxxx'))then" then it works.


    please help thanks.
    Last edited by lasse48; 01-16-2014 at 10:04 AM.

  2. #2
    Join Date
    Mar 2007
    Posts
    5,125
    Mentioned
    275 Post(s)
    Quoted
    901 Post(s)

    Default

    Simba Code:
    function CheckName(player: string);
    var
    i, score: integer;
    begin
    case Lowercase(player) of
    'xxxxx':
    Result := true;
    else
    Result := false;
    end;
    end;

    Where you have 'xxxxx', are you putting the the display name in lower-case?

    Forum account issues? Please send me a PM

  3. #3
    Join Date
    Jul 2007
    Posts
    14
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default

    Hello Justin.

    yes i am indeed.

    fx if i had 2 slaves named "bango1" and "bango2"

    checking if player is on runner list.
    Code:
    function CheckName(player: string);
    var
       i, score: integer;
    begin
       case Lowercase(player) of
          'bango1': Result := true;
          'bango2': Result := true;
       else
          Result := false;
       end;
    end;

    this function runs when waiting on runner to trade and it calls the "CheckName" to check if runner is allow to trade.
    Code:
    function TradePlayer: Boolean;
    var
      x: Integer;
      y: Integer;
      Trader: String;
      Userstatus: Integer;
    begin
      writeln('Waiting On Players To Trade..');
      repeat
        if (SomeoneTrades) then
        begin
           Trader := GetTradersName;
           writeln(Trader);
           wait(1000);
    
           if(CheckName(Trader))then
           begin
              writeln('trade ok');
              wait(5000);
           end else
              writeln('trade not');
              wait(5000);
          end;
      until (PlayerAccepted);
    end;
    thanks
    Last edited by lasse48; 01-16-2014 at 11:35 AM.

  4. #4
    Join Date
    Mar 2007
    Posts
    5,125
    Mentioned
    275 Post(s)
    Quoted
    901 Post(s)

    Default

    Try this

    Simba Code:
    function CheckName(player: string) : Boolean;
    var
       i, score: integer;
    begin
       case Lowercase(player) of
          'bango1': Result := true;
          'bango2': Result := true;
       else
          Result := false;
       end;
    end;

    Forum account issues? Please send me a PM

  5. #5
    Join Date
    Jul 2007
    Posts
    14
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default

    Just testet it out.

    It dont work getting "trade not" from "if then else"

    marby its a space in the player string, is there anyway to strip it for spaces, like in php ( $string = preg_replace('/\s+/','',$string); )




    i found out that its the "getradersname" that is worng:
    Simba Code:
    Trader := GetTradersName;
    this dont work.


    if i change it to:
    Simba Code:
    Trader := 'bango1';
    then it works
    so you can see the "CheckName" function works fine but its the "GetTradersName" i am doing something worng with


    the ess runner has a name like:
    Simba Code:
    Username II
    where the username is not is the real name, and it has one space and 2x "I"
    but when i "writeln" the players name it only print out username with out space and 2x "I"
    i have tryed to add all kind of username to the check up, but i dont work.
    Simba Code:
    //-----------------------------------------------//
    //------------- Check Player Start --------------//
    //-----------------------------------------------//
    function CheckName(player: string) : Boolean;
    var
      i, score: integer;
      tradeuser: string;
    begin
      tradeuser := Lowercase(player);
      writeln(tradeuser);
      case (tradeuser) of
        'username ': Result := true;
        ' username': Result := true;
        'Username ': Result := true;
        ' Username': Result := true;
        'username ii': Result := true;
        'Username II': Result := true;
       
      else
          Result := false;
      end;
    end;
    //-----------------------------------------------//
    //-------------- Check Player End ---------------//
    //-----------------------------------------------//
    It dont works






    here is the full script, i strip if for some function you dont need to see, to get it to be smaler
    Simba Code:
    program NatureRuneMaster;
    {$DEFINE SMART8}
    {$I SRL-OSR/SRL.Simba}
    {$I SPS/sps-osr.simba}
    {$I SRL-OSR/SRL/misc/trade.Simba}

    var
      x, y: integer;
      BList: TIntegerArray;

    Procedure DeclarePlayers;
    Begin
      HowManyPlayers := 1;
      NumberOfPlayers(HowManyPlayers);
      CurrentPlayer := 0;

       Players[0].Name := 'xxxxxxxxxxxx';
       Players[0].Pass :='xxxxxxxxx';
       Players[0].Nick :='xxxxxxxxx';
       Players[0].Active:=True;
    End;


    //-----------------------------------------------//
    //------------- Check Player Start --------------//
    //-----------------------------------------------//
    function CheckName(player: string) : Boolean;
    var
      i, score: integer;
      tradeuser: string;
    begin
      tradeuser := Lowercase(player);
      writeln(tradeuser);
      case (tradeuser) of
        'username ': Result := true;
        ' username': Result := true;
        'Username ': Result := true;
        ' Username': Result := true;
        'username ii': Result := true;
        'Username II': Result := true;
       
      else
          Result := false;
      end;
    end;
    //-----------------------------------------------//
    //-------------- Check Player End ---------------//
    //-----------------------------------------------//


    //-----------------------------------------------//
    //------------- Trade Player Start --------------//
    //-----------------------------------------------//
    function TradePlayer: Boolean;
    var
      x: Integer;
      y: Integer;
      Trader: String;
      Userstatus: Integer;
    begin
      writeln('Waiting On Players To Trade..');
      repeat
        if (SomeoneTrades) then
        begin
           Trader := GetTradersName;

           wait(1000);

           if(CheckName(Trader)) then
           begin
              writeln('trade ok');
              wait(5000);
           end else
              writeln('trade not');
              wait(5000);
          end;
      until (PlayerAccepted);
    end;
    //-----------------------------------------------//
    //-------------- Trade Player End ---------------//
    //-----------------------------------------------//


    Begin
       SetupSRL;
       DeclarePlayers;
       LoginPlayer;
       wait(2000);
       //MakeCompass('e');
       setAngle(SRL_ANGLE_HIGH);

       //EnterAltar;
       //Craftaltar;
       //LeaveAltar;
       TradePlayer;



    end.


    Thanks
    Last edited by lasse48; 01-17-2014 at 03:10 AM.

  6. #6
    Join Date
    Jul 2007
    Posts
    14
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default

    Found ,my problem:

    SRL-OSR\SRL\misc\trade.simba
    Simba Code:
    function GetTradersName: string;
    var
      ii, x, y, TPos: Integer;
      TP: TPoint;
      TS: string;
    begin
      for ii := 8 downto 4 do
      begin
        TP := TextCoords(ii);
        if (FindColor(x, y, 8388736, TP.x, TP.y, MCX2, TP.y + 13)) then Break;
      end;
      TS := GetChatBoxText(II, 8388736);
      TPos := Pos('wishes', TS) - 1;
      Result := Trim(Copy(TS, 1, TPos));
    end;

    i copyed this into my script
    Simba Code:
    for ii := 8 downto 4 do
      begin
        TP := TextCoords(ii);
        if (FindColor(x, y, 8388736, TP.x, TP.y, MCX2, TP.y + 13)) then Break;
      end;
      TS := GetChatBoxText(II, 8388736);
      TPos := Pos('wishes', TS) - 1;
      Result := Trim(Copy(TS, 1, TPos));

    And change:
    Simba Code:
    TPos := Pos('wishes', TS) - 1;

    To:
    Simba Code:
    TPos := Pos('wishes', TS) - 2;

    Now it work 100%

    I will like to thanks Justin, Tootoot222 and R0b0t1 for sparing there time on helping me. Thanks

Thread Information

Users Browsing this Thread

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

Posting Permissions

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