item.isA(POLCLASS_*)

Archive of the older Feature Request Forum Posts

Moderator: POL Developer

Locked
GEEK
New User
Posts: 29
Joined: Sat Jul 22, 2006 8:25 am

item.isA(POLCLASS_*)

Post by GEEK »

A command like
GetItemPolclass(item) ?
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post by Austin »

This is in the 097 distro's uo_extend.inc and will do what you're asking for.

Code: Select all

// For: GetIsAType()
CONST ISA_GET_MAIN	:= 0x0; // Default
CONST ISA_GET_ALL	:= 0x1;

Code: Select all

/*
 * GetIsAType(object, flags)
 *
 * Purpose
 * Retrieves the 'IsA' type for an object or all of the
 * classes it belongs to.
 *
 * Parameters:
 * object:	Anything belonging to the UObject class heirarchy.
 * flags:	Flags...
 *
 * Return value:
 * Returns an error on failure.
 * Returns an integer if ISA_GET_MAIN is passed for flags.
 * Returns an array of integers if ISA_GET_ALL is used.
 *
 */
function GetIsAType(object, flags:=ISA_GET_MAIN)
	var type_list := array;
	var i := 16; // Max number of IsA Id #s
	for ( i; i > 0; i-=1 )
		if ( !object.IsA(i) )
			continue;
		elseif ( flags & ISA_GET_ALL )
			type_list.Append(i);
		else
			return i;
		endif
		SleepMS(2);
	endfor

	if ( type_list.Size() > 0 )
		return type_list;
	else
		return error{"errortext":="Unable to determine IsA type of '"+TypeOf(object)+"'"};
	endif
endfunction
GEEK
New User
Posts: 29
Joined: Sat Jul 22, 2006 8:25 am

Post by GEEK »

It is not a very fast code to do a loop to scan all possibile POLCLASS_*

const POLCLASS_UOBJECT := 1;
const POLCLASS_ITEM := 2;
const POLCLASS_MOBILE := 3;
const POLCLASS_NPC := 4;
const POLCLASS_LOCKABLE := 5;
const POLCLASS_CONTAINER := 6;
const POLCLASS_CORPSE := 7;
const POLCLASS_DOOR := 8;
const POLCLASS_SPELLBOOK := 9;
const POLCLASS_MAP := 10;
const POLCLASS_MULTI := 11;
const POLCLASS_BOAT := 12;
const POLCLASS_HOUSE := 13;
const POLCLASS_EQUIPMENT := 14;
const POLCLASS_ARMOR := 15;
const POLCLASS_WEAPON := 16;

I was able to write a function like the one upper :-)
Anymore thnks for reply.
Locked