SRL Archive - OSR Help

Profile Script Trading if else [Help Request]


lasse48

2014-01-16 04:20:17

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.

Justin

2014-01-16 06:23:33

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?

lasse48

2014-01-16 06:31:17

Hello Justin.

yes i am indeed.

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

checking if player is on runner list.

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.

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 :)

Justin

2014-01-16 06:44:05

Try this

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;

lasse48

2014-01-16 07:24:03

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:

Trader := GetTradersName;
this dont work.


if i change it to:

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:

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.

//-----------------------------------------------//
//------------- 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 :)

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

lasse48

2014-01-17 00:36:05

Found ,my problem:

SRL-OSR\SRL\misc\trade.simba

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

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:

TPos := Pos('wishes', TS) - 1;

To:

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