• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Reading All Attributes of [Something]

Pieter Boelen

Navigation Officer
Administrator
Storm Modder
Hearts of Oak Donator
Sulan once asked me if it is possible to read all attributes that something has. Turns out that you CAN!

For example, this will return all attributes that the player has:
Code:
	aref arAttributes; makearef(arAttributes, PChar);
int nMasts = GetAttributesNum(arAttributes);
for (int m = 0; m < nMasts; m++)
{
aref arAttribute = GetAttributeN(arAttributes, m);
string sAttribute = GetAttributeName(arAttribute);
LogIt("Attribute Name = " + sAttribute);
}
You can investigate further with, for example, all attributes that the player ship has:
Code:
	aref arAttributes; makearef(arAttributes, PChar.ship); // Change what you are interrogating here
int nMasts = GetAttributesNum(arAttributes);
for (int m = 0; m < nMasts; m++)
{
aref arAttribute = GetAttributeN(arAttributes, m);
string sAttribute = GetAttributeName(arAttribute);
LogIt("Attribute Name = " + sAttribute);
}
You can also check the player ship type:
Code:
	int iShipType = GetCharacterShipType(PChar);
if (iShipType < 0 || iShipType == SHIP_NOTUSED) return 0;
ref rShip; makeref(rShip, ShipsTypes[iShipType]);
aref arAttributes; makearef(arAttributes, rShip);
int nMasts = GetAttributesNum(arAttributes);
for (int m = 0; m < nMasts; m++)
{
aref arAttribute = GetAttributeN(arAttributes, m);
string sAttribute = GetAttributeName(arAttribute);
LogIt("Attribute Name = " + sAttribute);
}
Or the player location:
Code:
	ref lcn = &Locations[FindLocation(pchar.location)];
aref arAttributes; makearef(arAttributes, lcn);
int nMasts = GetAttributesNum(arAttributes);
for (int m = 0; m < nMasts; m++)
{
aref arAttribute = GetAttributeN(arAttributes, m);
string sAttribute = GetAttributeName(arAttribute);
LogIt("Attribute Name = " + sAttribute);
}
Or the blade that the player uses:
Code:
	string weaponID = PChar.equip.blade; // defines weaponname
aref weapon;
Items_FindItem(weaponID, &weapon);	// defines object for weaponattributes

aref arAttributes; makearef(arAttributes, weapon);
int nMasts = GetAttributesNum(arAttributes);
for (int m = 0; m < nMasts; m++)
{
aref arAttribute = GetAttributeN(arAttributes, m);
string sAttribute = GetAttributeName(arAttribute);
LogIt("Attribute Name = " + sAttribute);
}
Use trace() instead of LogIt() to have the full list posted in compile.log so you can read it without it disappearing from your screen.

I hope you find this useful for modding! :woot
 
Note for CoAS-users: replace "LogIt" with "Log_SetStringToLog" .
 
You can interrogate basically any "object" type in the code. I have unfortunately not yet found any object type that I'm interested in.
I'm searching for locators at sea!!!
 
This is cool stuff Pieter, nice find mate! :onya

I don't know near enough about coding to make use of it though, but I am sure others will.
 
Why do you try to reinvent a wheel? There's a nice command (DumpAttributes(ref ref_variable);) which will print all attributes which object has, taking a ref or aref variable:
Code:
object obj_var;
ref refobj; makeref(refobj, obj_var);
aref aref_var; makearef(aref_var, refobj.some_attribute_with_subnodes);
trace("obj_var attributes:");
DumpAttributes(refobj);
trace("aref_var attributes:");
DumpAttributes(aref_var);
With variables defined as following (for example):
Code:
obj_var.id=id;
obj_var.index=1;
obj_var.some_attribute_with_subnodes.s1=sub1;
obj_var.some_attribute_with_subnodes.s2=sub2;
obj_var.some_attribute_with_subnodes.s2.a=ssub1;
obj_var.some_attribute_with_subnodes.s2.b=ssub2;
the output in compile.log would be:
Code:
obj_var attributes:
id=id
index=1
some_attribute_with_subnodes=
s1=sub1
s2=sub2
a=ssub1
b=ssub2
aref_var attributes:
s1=sub1
s2=sub2
a=ssub1
b=ssub2

pirate_kk
 
Hey, that IS much better! Thanks a lot! :woot

Why do you try to reinvent a wheel?
Because I don't have a CLUE what I'm doing, mate! Really, I don't. :rofl
I extracted that code I posted above from some of your flag/mast-reading code.
 
Wow - that is EXACTLY what I needed to know! Thanks a lot - it's a pity I don't have much time for coding currently.

Cheers,
Sulan
 
Back
Top