Controlar um Char por outro Char (Magebomb)


//////////////////COMANDOS
///move up, down, left, right
///say text
///turn up, down, left, right
///follow name
///attack name
///sd name
//////////////////FIM DOS COMANDOS

const
MasterList = ['Kilecore', 'Hoobastank'] //Nome dos chars q vao dar os comandos, ponha entre as '.'

function GetCreatureByName(Name: string): TCreature;
begin
Result := nil;
for x := 0 to Creatures.Count - 1 do
begin
if x >= Creatures.Count then
Break;
if AnsiLowerCase(Creatures.Creature[x].Name) = AnsiLowerCase(Name) then
begin
Result := Creatures.Creature[x];
Exit;
end;
end;
end;

function CommandSay(Text: String);
begin
Self.Say(Text);
end;

function CommandAttack(Name: String);
var
Creature: TCreature;
begin
Creature := GetCreatureByName(Name);
if Creature <> nil then
Creature.Attacking := True;
end;

function CommandFollow(Name: String);
var
Creature: TCreature;
begin
Creature := GetCreatureByName(Name);
if Creature <> nil then
Creature.Following := True;
end;

function CommandSD(Name: String);
var
Creature: TCreature;
begin
Creature := GetCreatureByName(Name);
if Creature <> nil then
Self.Containers.UseItemWithCreature(3155, Creature);
end;

function CommandTurn(Dir: String);
begin
Dir := AnsiLowerCase(Dir);
case Dir of
'up': Self.FaceUp;
'right': Self.FaceRight;
'down': Self.FaceDown;
'left': Self.FaceLeft;
end;
end;

function CommandMove(Dir: String);
begin
Dir := AnsiLowerCase(Dir);
case Dir of
'up': Self.MoveUp;
'right': Self.MoveRight;
'down': Self.MoveDown;
'left': Self.MoveLeft;
end;
end;

function ExecuteCommand(Command, Parameter: String);
begin
case Command of
'say': CommandSay(Parameter);
'attack': CommandAttack(Parameter);
'follow': CommandFollow(Parameter);
'sd': CommandSD(Parameter);
'turn': CommandTurn(Parameter);
'move': CommandMove(Parameter);
end;
end;

function GetCommand(Text: String);
var
Command: String;
Parameter: String;
StrPos: Integer;
begin
StrPos := Pos(' ', Text);
Command := AnsiLowerCase(Copy(Text, 1, StrPos - 1));
Parameter := Copy(Text, Length(Command) + 2, Length(Text) - (Length(Command) + 1));
ExecuteCommand(Command, Parameter);
end;

procedure Event_Message(Channel: integer; Name, Text: String);
begin
for x := Low(MasterList) to High(MasterList) do
begin
if AnsiLowerCase(MasterList[x]) = AnsiLowerCase(Name) then
GetCommand(Text);
end;
end;

while not Terminated do
begin
UpdateWorld;
ProcessEvents;
Sleep(100);
end;