Code
Edit: // Assign Unique IDs to everything.
// Misc Indices. Mess with these to avoid collisions with other scripts.
const int FFC_ID_INDEX = 0;
const int NPC_ID_INDEX = 0;
const int LWEAPON_ID_INDEX = 0;
const int EWEAPON_ID_INDEX = 0;
const int ITEM_ID_INDEX = 0;
// Values indicating unassigned ids. Assign this to whatever the
// default value for your selected index is.
const int FFC_ID_NULL = 0;
const int NPC_ID_NULL = 0;
const int LWEAPON_ID_NULL = 0;
const int EWEAPON_ID_NULL = 0;
const int ITEM_ID_NULL = 0;
// Value indicating next id.
int NextFFCId = FFC_ID_NULL + 1;
int NextNPCId = NPC_ID_NULL + 1;
int NextLWeaponId = LWEAPON_ID_NULL + 1;
int NextEWeaponId = EWEAPON_ID_NULL + 1;
int NextItemId = ITEM_ID_NULL + 1;
// Get the id of an ffc, first assigning one if needed.
int GetId(ffc _ffc) {
if (_ffc->Misc[FFC_ID_INDEX] == FFC_ID_NULL) {
_ffc->Misc[FFC_ID_INDEX] = NextFFCId;
NextFFCId++;
if (NextFFCId == FFC_ID_NULL) {
NextFFCId++;}}
return _ffc->Misc[FFC_ID_INDEX];}
// Get the id of an npc, first assigning one if needed.
int GetId(npc _npc) {
if (_npc->Misc[NPC_ID_INDEX] == NPC_ID_NULL) {
_npc->Misc[NPC_ID_INDEX] = NextNPCId;
NextNPCId++;
if (NextNPCId == NPC_ID_NULL) {
NextNPCId++;}}
return _npc->Misc[NPC_ID_INDEX];}
// Get the id of an lweapon, first assigning one if needed.
int GetId(lweapon _lweapon) {
if (_lweapon->Misc[LWEAPON_ID_INDEX] == LWEAPON_ID_NULL) {
_lweapon->Misc[LWEAPON_ID_INDEX] = NextLWeaponId;
NextLWeaponId++;
if (NextLWeaponId == LWEAPON_ID_NULL) {
NextLWeaponId++;}}
return _lweapon->Misc[LWEAPON_ID_INDEX];}
// Get the id of an eweapon, first assigning one if needed.
int GetId(eweapon _eweapon) {
if (_eweapon->Misc[EWEAPON_ID_INDEX] == EWEAPON_ID_NULL) {
_eweapon->Misc[EWEAPON_ID_INDEX] = NextEWeaponId;
NextEWeaponId++;
if (NextEWeaponId == EWEAPON_ID_NULL) {
NextEWeaponId++;}}
return _eweapon->Misc[EWEAPON_ID_INDEX];}
// Get the id of an item, first assigning one if needed.
int GetId(item _item) {
if (_item->Misc[ITEM_ID_INDEX] == ITEM_ID_NULL) {
_item->Misc[ITEM_ID_INDEX] = NextItemId;
NextItemId++;
if (NextItemId == ITEM_ID_NULL) {
NextItemId++;}}
return _item->Misc[ITEM_ID_INDEX];}
// Return the ffc with the given id.
ffc FindFFC(int id) {
for (int i = 1; i <= 32; i++) {
ffc _ffc = Screen->LoadFFC(i);
if (GetId(_ffc) == id) {
return _ffc;}}}
// Return the npc with the given id.
npc FindNPC(int id) {
for (int i = 1; i <= Screen->NumNPCs(); i++) {
npc _npc = Screen->LoadNPC(i);
if (GetId(_npc) == id) {
return _npc;}}}
// Return the lweapon with the given id.
lweapon FindLWeapon(int id) {
for (int i = 1; i <= Screen->NumLWeapons(); i++) {
lweapon _lweapon = Screen->LoadLWeapon(i);
if (GetId(_lweapon) == id) {
return _lweapon;}}}
// Return the eweapon with the given id.
eweapon FindEWeapon(int id) {
for (int i = 1; i <= Screen->NumEWeapons(); i++) {
eweapon _eweapon = Screen->LoadEWeapon(i);
if (GetId(_eweapon) == id) {
return _eweapon;}}}
// Return the item with the given id.
item FindItem(int id) {
for (int i = 1; i <= Screen->NumItems(); i++) {
item _item = Screen->LoadItem(i);
if (GetId(_item) == id) {
return _item;}}}
A minor bug that nobody will ever run into, seriously don't bother reading this
I thought I'd mention real quick, just for completeness, the bug I'm sure that no one will ever run across. The IDs will eventually loop around and hit the start point again. This is only a problem if you, say, make an npc, and keep it alive while you make and then destroy another 200,000 or so. Since FFCs are the only thing that can travel across screens, they're the only thing that have a remote chance of running into this problem. If you do, you just need to periodically reset the travelling FFC's ids. But again, I don't see anybody running into this problem. 
Edit 2: I got around to using this, just fixing some typos.
Edited by grayswandir, 01 June 2013 - 11:52 AM.

