Markus
2008-02-18 14:26:25
Decided to release this, it's not finished yet, but it provides a few lower-level functions you might wish to use :)
Current functions:
I will add more later.
You will need the type TNPC:
This addition to your fields:
Small testing script:
Current functions:
- function GetNPCCount : integer;
- function GetNameFromObject(npcob : integer) : string;
- function GetNPCAction(npc : TNPC; ActionNo : integer) : string;
- function GetAllNPCs : array of TNPC;
- function FindAllNPCSByName(name : string) : array of TNPC;
I will add more later.
You will need the type TNPC:
type TNPC = record
x, y, height, NPCId : integer;
name : string;
end;
This addition to your fields:
CharHeight = 'V';
//NPC Fields
NPCCount = 'ic.U';
NPCIndexarray = 'hc.e';
NPCArray = 'vh.c';
NPCName = 'zb';
NPCDef = 'Kc';
NPCActions = 'Y';
And the functions:
function GetNPCCount : integer;
begin
result := SmartGetFieldInt(0, NPCCount);
end;
function GetNameFromObject(npcob : integer) : string;
var
bytes: Integer;
begin
bytes:= SmartGetFieldObject(npcob, NPCDef+'.'+NPCName+'.'+StringBytes);
result:= StringFromBytes(bytes);
SmartFreeObject(bytes);
end;
function GetNPCAction(npc : TNPC; ActionNo : integer) : string;
var
c, b, CurNPC : integer;
S : string;
begin
CurNPC := SmartGetFieldArrayObject(0, NPCArray, npc.NPCId);
if (ActionNo > SmartGetFieldArraySize(CurNPC, NPCDef+'.'+NPCActions)) then
exit;
C := SmartGetFieldArrayObject(CurNPC, NPCDef+'.'+NPCActions, ActionNo);
B := SmartGetFieldObject(C, StringBytes);
S := StringFromBytes(B);
result := Trim(s);
SmartFreeObject(CurNPC);
SmartFreeObject(c);
SmartFreeObject(b);
end;
function GetAllNPCs : array of TNPC;
var
i, CurNPC, npcc : integer;
begin
SetArrayLength(result, GetNPCCount);
writeln('amount of NPCs: '+inttostr(length(result)));
npcc := GetNPCCount-1;
For i := 0 to npcc do
begin
Result[i].NPCId := SmartGetFieldArrayInt(0, NPCIndexarray, i);
CurNPC := SmartGetFieldArrayObject(0, NPCArray, result[i].NPCId);
Result[i].name := trim(GetNameFromObject(CurNPC));
Result[i].x := SmartGetFieldInt(0, BaseX)+SmartGetFieldInt(CurNPC, CurrentX) shr 7;
Result[i].y := SmartGetFieldInt(0, BaseY)+SmartGetFieldInt(CurNPC, CurrentY) shr 7;
Result[i].Height := SmartGetFieldInt(CurNPC, NPCDef+'.'+CharHeight); //I doubt this one is right.. Gives weird results =/
SmartFreeObject(CurNPC);
end;
end;
function FindAllNPCSByName(name : string) : array of TNPC;
var
i, j : integer;
TempNPC : array of TNPC;
begin
TempNPC := GetAllNPCs;
name := lowercase(name);
for i := 0 to high(TempNPC) do
begin
if lowercase(TempNPC[i].name) = name then
begin
inc(j);
SetLength(result, j);
result[j-1] := TempNPC[i];
end;
end;
end;
Small testing script:
program NPCCrap;
//RS Build = #487
const
//Global Static Hooks
SettingsArray = 'lh.a'; //int[]
CurrentLevels = 'qg.Z'; //int[]
MaxLevels = 'nd.i'; //int[]
Experiances = 'sb.f'; //int[]
BaseX = 'sb.j'; //int
BaseY = 'gg.R'; //int
MyPlayer = 'ha.p'; //Player
CompassAngle = 'ja.'; //int (MinimapInt1)
MapOffsetAngle = 'aa.ob'; //int (MinimapInt2)
BaseLayer = 'se.b'; //int (plane/terrainInt)
GroundSettings = 'di.tb'; //byte[][][] (groundByteArray)
GroundHeights = 'wa.b'; //int[][][] (groundIntArray)
CamX = 'ce.tb'; //int
CamY = 'ag.h'; //int
CamZ = 'f.L'; //int
CamYaw = 'fd.j'; //int (CamCurveY)
CamPitch = 'm.e'; //int (CamCurveX)
//Character Hooks
CurrentX = 'hc'; //int
CurrentY = 'tc'; //int
CharAnim = 'fb'; //int
CharMotion = 'Rb'; //int
CharName = 'yc'; //StringWrap
CharHeight = 'V';
//StringWrap Hooks
StringBytes = 'y'; //byte[]
//NPC Hooks
NPCCount = 'ic.U';
NPCIndexarray = 'hc.e';
NPCArray = 'vh.c';
NPCName = 'zb';
NPCDef = 'Kc';
NPCActions = 'Y';
//Converts a byte[] from StringWrap to a DelphiString (max length 256)
function StringFromBytes(jbytearray: integer): string;
begin
SetLength(result, 256);
SetLength(result, SmartStringFromBytes(jbytearray,result));
end;
type TNPC = record
x, y, height, NPCId : integer;
name : string;
end;
function GetNPCCount : integer;
begin
result := SmartGetFieldInt(0, NPCCount);
end;
function GetNameFromObject(npcob : integer) : string;
var
bytes: Integer;
begin
bytes:= SmartGetFieldObject(npcob, NPCDef+'.'+NPCName+'.'+StringBytes);
result:= StringFromBytes(bytes);
SmartFreeObject(bytes);
end;
function GetNPCAction(npc : TNPC; ActionNo : integer) : string;
var
c, b, CurNPC : integer;
S : string;
begin
CurNPC := SmartGetFieldArrayObject(0, NPCArray, npc.NPCId);
if (ActionNo > SmartGetFieldArraySize(CurNPC, NPCDef+'.'+NPCActions)) then
exit;
C := SmartGetFieldArrayObject(CurNPC, NPCDef+'.'+NPCActions, ActionNo);
B := SmartGetFieldObject(C, StringBytes);
S := StringFromBytes(B);
result := Trim(s);
SmartFreeObject(CurNPC);
SmartFreeObject(c);
SmartFreeObject(b);
end;
function GetAllNPCs : array of TNPC;
var
i, CurNPC, npcc : integer;
begin
SetArrayLength(result, GetNPCCount);
writeln('amount of NPCs: '+inttostr(length(result)));
npcc := GetNPCCount-1;
For i := 0 to npcc do
begin
Result[i].NPCId := SmartGetFieldArrayInt(0, NPCIndexarray, i);
CurNPC := SmartGetFieldArrayObject(0, NPCArray, result[i].NPCId);
Result[i].name := trim(GetNameFromObject(CurNPC));
Result[i].x := SmartGetFieldInt(0, BaseX)+SmartGetFieldInt(CurNPC, CurrentX) shr 7;
Result[i].y := SmartGetFieldInt(0, BaseY)+SmartGetFieldInt(CurNPC, CurrentY) shr 7;
Result[i].Height := SmartGetFieldInt(CurNPC, NPCDef+'.'+CharHeight); //I doubt this one is right.. Gives weird results =/
SmartFreeObject(CurNPC);
end;
end;
function TrimTilSpace(s : string; l : integer) : string;
var i : integer;
begin
result := s;
for i := Length(s) to l do
result := result + ' ';
end;
var i : integer;
npcs : array of TNPC;
begin
SmartSetup('nl3', false, true);
npcs := GetAllNPCs;
for i := 0 to high(npcs) do
begin
writeln(trimtilspace(npcs[i].name, 18)+':'+' X: '+inttostr(npcs[i].x)+' Y: '+inttostr(npcs[i].x) + ' ID: '+inttostr(npcs[i].npcid)+' ACTION: '+ GetNPCAction(npcs[i], 0));
end;
end.