PDA

View Full Version : Auto nick grabber



Ashaman88
04-04-2013, 01:44 AM
Someone pointed out that we could probably auto grab the nickname from the username displayed when they login. I came up with this:

var
h: integer;
Nick: string;
begin
setupsrl;
Nick:=(Trim(GetTextAtExWrap(9,460,132,473,0,5,2,cl Message,0,SmallChars07)));
writeln(Nick);
h:=high(Nick);
if h=3 then
Nick:=Copy(Nick, 1, min(h,3)) else
Nick:=Copy(Nick, 2, min(h,3));
writeln(Nick);
end.

Basically just takes three letters from their name (if it's longer than three it takes away first letter and gets the next 3). I'm sure there is a better way to do it...figuring out which letters are lowercase and such. Just an idea though, what do yall think

Justin
04-04-2013, 01:51 AM
SRL Compiled in 0 msec
Co Justin..
o J
Successfully executed.


Might need to look at if there is a space within the first 3, move onto the next 3 due to spacing?

Ashaman88
04-04-2013, 01:55 AM
SRL Compiled in 0 msec
Co Justin..
o J
Successfully executed.


Might need to look at if there is a space within the first 3, move onto the next 3 due to spacing?

Yeah, I'm not too good with strings, I'm sure we can get it pretty advanced though

Justin
04-04-2013, 01:57 AM
But then some users might complain that we are 'logging' their usernames and storing them in a database or something. (Like how people complain about the IP Screenshot)

Ashaman88
04-04-2013, 02:03 AM
But then some users might complain that we are 'logging' their usernames and storing them in a database or something. (Like how people complain about the IP Screenshot)

Of course..this is the next phase of the plan...I've just had people fail hardcore to put the nickname in, and even then they don't understand how to do it properly

Le Jingle
04-06-2013, 06:13 AM
Not sure how well this would work, Brandon guided me with general use of RegEx's, so thanks to him too (although I probably butchered in places and there's probably room for optimizations - although this is only for grabbing a nick name chunk)

Tested a little bit, should produce (hopefully) - posted here for more testing! :]

Info:


Use GetTextAtEx if the player didn't fill in a part of their name (may even use this still to make sure user didn't typo?)
after a string is obtained of the RSN, feed it into the first argument, RSN: string;
the 2nd argument is the length of a partial match of the Original RSN you want to make. (Ex. = 3 would give a string length of 3 back)




const
MAX_NAME_LENGTH = 20;

function ParseNick(RSN: string; ConsecutiveChars: Integer): string;
var
i, j, p: Integer;
Pref, iPref, chunks: TStringArray;
cList: TStringList;
begin
Result := RSN;
if (Length(RSN) < ConsecutiveChars) then
Exit;

// Build what we need to work with
cList := TStringList.Create;
SplitRegExpr('[^a-z 0-9_A-Z]', RSN, cList);

// Iterate from More replaced expressions (tighter/better fit result string)
// to less fit until match found.
Pref := ['[^a-z ]', '[^a-zA-Z ]', '[^a-zA-Z 0-9_]'];
iPref := ['[a-z ]', '[a-zA-Z ]', '[a-zA-Z 0-9_]'];

for i := 0 to high(Pref) do
begin
Result := ReplaceRegExpr(Pref[i], cList.CommaText, ' ', True);

if (ExecRegExpr(' ', Result)) then
begin
ExplodeWrap(' ', Result, chunks);
if (Length(chunks) > MAX_NAME_LENGTH) then
Exit;
for j := 0 to high(chunks) do
begin
if (Length(chunks[j]) < ConsecutiveChars) then
Continue
else if (ExecRegExpr(iPref[i], chunks[j])) then
begin
Result := Copy(chunks[j], 1, ConsecutiveChars);
Exit;
end;
end;
end else
begin
if (ExecRegExpr(iPref[high(Pref) - i], Result)) then
begin
Result := Copy(Result, 1, ConsecutiveChars);
Exit;
end;
end;
end;
cList.Free;
end;

var
i: Integer;
TSA: TStringArray;

begin
TSA := ['Zezima N4m3', 'Zyt3x', 'Coh3n', 'Wizzup?', 'Le Jingle'];
for i := 0 to high(TSA) do
Writeln('Before: ' + TSA[i] + #13 + #10 + 'After: ' + ParseNick(TSA[i], 3) + #13 + #10);
end.



Cheers,
Lj :)
Justin; Ashaman88;