quinta-feira, 31 de julho de 2008

Follower by Darkmystery

////////CONFIG:///////////
Leader = 'Eternal Oblivion'; // The person who can say the 'follow'/'stop' word.
FollowWord = 'follow'; // Word to follow, example: follow Darkmystery.
StopFollowWord = 'stop';// Word that stops the following.
SQMDistance = 4; // The distance that the char will be behind you. (1 = right behind you)
FollowMode = 2; // 1 = Walking Behind something, 2 = Walking in front of something.
//////////////////////////

var
X1: Integer;
Y1: Integer;
CreatureToFollow: string;
OK: Boolean;
Tile: TTile;
procedure Event_Message(Channel: integer; Name, Text: String);
var
Followname :string;
begin
if Name = Leader then begin
if Text = StopFollowWord then begin
OK := False
exit;
end;
updateworld;
FollowName := Text;
if Pos(FollowWord, FollowName)<>0 then
begin
OK := False;
Delete(FollowName, 1, length(FollowWord)+1);
CreatureToFollow := FollowName;
OK := True;
end;
end;
end;

function GetTileFromXYZ(X, Y, Z: integer): TTile;
begin
Result := nil;
if abs((Self.X - 7) - X) > 14 then Exit;
if abs((Self.Y - 5) - Y) > 11 then Exit;
if Self.Z <> Z then Exit;
Result := Screen.Tile[abs((Self.X - 7) - X), abs((Self.Y - 5) - Y)];
end;

function IsTileWalkable(Tile: TTile): boolean;
begin
Result := True;
for Z := 0 to Tile.Count - 1 do
begin
if Tile.Item[Z].Properties.Hole then
begin
Result := False;
end
else if Tile.Item[Z].Properties.Stairs then
begin
Result := False;
end
else if not Tile.Item[Z].Properties.Walkable then
begin
OutputDebugString('Not Walk: ' + IntToStr(Tile.Item[Z].ID));
Result := False;
end;
end;
end;

function GetCreature: byte;
var
x, Adjustment: integer;
begin
updateworld;
result := 0;
for x := 0 to Creatures.Count - 1 do
begin
if(Creatures.Creature[x].Name <> Self.Name) then begin
if(Creatures.Creature[x].Name = CreatureToFollow) then begin
X1 := Creatures.Creature[x].X
Y1 := Creatures.Creature[x].Y

if FollowMode = 1 then Adjustment := SQMDistance
if FollowMode = 2 then begin
Adjustment := SQMDistance * 2
Adjustment := SQMDistance - Adjustment
end;

case Creatures.Creature[x].Direction of
0 : Y1 := Y1 + Adjustment
1 : X1 := X1 - Adjustment
2 : Y1 := Y1 - Adjustment
3 : X1 := X1 + Adjustment
end;

result := 1;
exit;
end;
end;
end;
end;

begin
while not Terminated do
begin
processevents;

if OK then begin
if GetCreature = 1 then begin
Tile := GetTileFromXYZ(X1, Y1, Self.Z)
if IsTileWalkable(Tile) then
Self.MoveTo(X1, Y1, Self.Z);
end;
end;

sleep(500);
end;
end;

0 Comments: