SRL Archive - SRL Snippets

command(s:string);


rj

2014-04-19 23:27:04

I was bored so I wrote a small snippet of a procedure that does basic commands based on a string. At first, I thought it was entirely useless, but then I figured it could have some small uses.


Command list



!execute procedure procedurename();
!execute function functionname();
!print "messagehere";
!openWebPage "www.google.com";
!wait 2000;
!prompt "This script is outdated, would you like to update it?","Attention",3";
!message "This script is outdated";



Now here is how this can be used. For my SS fighter, I have a file at pastebin http://pastebin.com/WFS9KJtK that has a list of monster profiles, and news and info. When the script starts, this file is updated and the user is updated on news

<news>
<1>Soulsplit Fighter Version 2.00</>
<2>==Recent updates==</>
<3>- Displays your combat level, weapon name, and attack mode</>
<4>==Upcoming updates==</>
<5>- More accurate looting</>
<6>- More monster profiles</>
</news>



With this command function, it could take a string from the file and alert the user, or do other things without them having to restart the script (or redownload/find updated) << the whole point of this, such as


!message "Soulsplit staff is on bot watch, be careful!";

because most users don't read the writeln..


Or



!execute procedure clearDebug();
!message "Please view the rules on SRL!';
!openwebpage "http://villavu.com/forum/showthread.php?t=6964";
!print "what a pointless command";



Code, nothing special

var
cmd:string;

function string.startsWith(s:string):boolean;
var
i, l, c:integer;
begin
l := length(s);
for i := 1 to length(self) do
if (self[i] = s[i]) then
c := c + 1;
result := (c = l);
end;

function string.contains(s:string):boolean;
var
i:integer;
begin
for i := 1 to length(self) do
if (Pos(s[i], self) > 0) then
exit(true);
end;

function string.scanInvalidTokens():string;
var
i, l, c:integer;
tokens:string;
begin
tokens := '!@#$%^&*()-=`~[]{}./?<>\|';
for i := 1 to length(self) do
for l := 1 to length(tokens) do
if (tokens[l] = self[i]) then
exit(tokens[l]);
end;

function HelloWorld:boolean;
begin
writeln('Hello world');
result := true;
end;

procedure command(s:string);
var
excStr, procName, invl:string;
reply:integer;
begin
if s.startsWith('!execute') then
begin
excStr := between('execute ', ' ', s);
if (excStr = 'function') or (excStr = 'procedure') then
begin
procName := between('execute ' + excStr + ' ','()', s);
invl := procName.scanInvalidTokens();
if (invl = '') then
begin
try
if (excStr = 'function') then
begin
writeln('function ', procName , ' result = [');
writeln(variantInvoke(procName));
writeln(']')
end else
variantInvoke(procName);
except
writeln('Something went wrong with ' , excStr , ' ', procName);
end;
end else
writeln('Invalid charactor "', invl , '"');
end else
writeln('Invalid token "' , excStr,'"');

end else if s.startsWith('!print') then
begin
if s.contains('"') then
writeln(between('print "', '"', s))
else
writeln('Invalid print command!');

end else if s.startsWith('!openwebpage') then
begin
if s.contains('"') then
begin
reply := messageBox('Do you want to open webpage ' + between('"', '"', s) + '?', 'Attention', 3);
if (reply = 6) then
openWebPage(between('"', '"', s));
end else
writeln('Invalid openwebpage command!');

end else if (s.startsWith('!wait')) then
begin
try
wait(StrToInt(between(' ', ';', s)));
except
writeln('Invalid wait characters!');
end;

end else if (s.startsWith('!prompt')) then
begin
if (s.contains('"')) then
begin
try
invl := between('"', '"', s);
excStr := between(invl + '","' , '"', s);
messageBox(invl, excStr, StrToInt(between('"' + excStr + '",', ';', s)));
except
writeln('Invalid prompt integer!');
end;
end else
writeln('Invalid prompt command!');

end else if (s.startsWith('!message' )) then
begin
if (s.contains('"')) then
showMessage(between('"', '"', s))
else
writeln('Invalid message command!');

end else
writeln('"', s , '" is a invalid command!');
end;

begin
repeat
inputQuery('Enter a command: ' , 'Command', cmd);
command(cmd);
wait(500);
until (isKeyDown(113));
exit;
end.





No, this is not for updating your script. It's for alerting the user of news/information.