//Title: isDirectChild
//Credit to: Darkcampainger
//Contributed by: DarkCampainger
// Returns if childType is a direct child of parentType
proc/isDirectChild(childType, parentType)
// Check if the child is derived form the parent at all
if(!ispath(childType,parentType))
return 0
// Check that the types are not equivalent
if(childType == parentType)
return 0
// If it's the direct descendant, there should only be one more / in its type
return !findtext("[childType]","/",length("[parentType]")+2)
// Example output:
// isDirectChild(/obj/item/knife, /obj/item) = 1
// isDirectChild(/obj/item/knife/steel, /obj/item) = 0
// isDirectChild(/obj/button, /obj/item) = 0
ID:195023
May 9 2011, 6:56 pm
|
|
May 19 2011, 11:57 pm (Edited on May 20 2011, 12:23 am)
|
|
Here's my version:
|
In response to Jemai1
|
|
Jemai1 wrote:
// isDirectChild(/obj,/atom/movable) = 1
Ah, good point. I hadn't considered types with altered parent_types. |