npc.template

Archive of the older Feature Request Forum Posts

Moderator: POL Developer

Locked
innominabile
Adept Poster
Posts: 85
Joined: Wed Aug 30, 2006 5:24 pm

npc.template

Post by innominabile »

A member "template" in npc like:

me.template := FindConfigElem(ReadConfigFile(":*:npcdesc"), Filter(me.npctemplate));

where Filter(me.npctemplate) is a function that remove package name in npctempalte is template is defined in to package and non in config/npcdesc.cfg....
Shinigami
Former Developer
Posts: 308
Joined: Mon Jan 30, 2006 9:28 am

Post by Shinigami »

why not a core function like FullShard(shardname) ?

sorry...

Shinigami
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post by Austin »

CoreChanges.txt
September 14, 2006
Added - CoreShard.em.
Contains over a hundred billion functions.
See file for more information.
DeiviD
Expert Poster
Posts: 79
Joined: Mon Jun 19, 2006 4:48 pm

Post by DeiviD »

cant you just use splitwords with the ":" spliter and get the last return?

owned by austin and shini i gotta add
MuadDib
Former Developer
Posts: 1091
Joined: Sun Feb 12, 2006 9:50 pm

Post by MuadDib »

....................

interesting feature

....................

Find() and Splitwords() are a better idea to me. Since the addition of a delimeter in the SplitWords() function, that gives you all the power you need to do what you want with this,without an all new, cutie pie function in the core to do it.
DeiviD
Expert Poster
Posts: 79
Joined: Mon Jun 19, 2006 4:48 pm

Post by DeiviD »

SplitWords(template, ":")[SplitWords(template, ":").size()];

;)
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post by Austin »

From npcutil.inc in the brain AI...
Helps with the pol/config/npcdesc.cfg and packaged npcs..

Code: Select all

/* $Id: npcUtil.inc 373 2006-06-17 18:27:33Z austinheilman $
 *
 */
/*===============================================================
* Current Version
* NPCUTIL.INC - v1.0
* Updated 8/31/2005 4:23AM
*
* -- Revision v1.0 --
* Austin:
*  Created include file
===============================================================*/

use uo;
use os;
use polsys;
use cfgfile;

/*
 * NPC_ParseTemplateName(template_name)
 *
 * Purpose
 * Finds the appropriate npcdesc.cfg to load.
 * This enables npcs to be placed in packages and not just the ::npcdesc file.
 * ReadConfigFile(":*:npcdesc") does not work in this case because packaged npcs
 * have the package name at the begining of their .npctemplate member. Reading the
 * specific config file - helps to avoid possible elem name collisions.
 *
 * Parameters
 * template_name:	Name of the npc template to parse
 *
 * Return value
 * Returns struct .package .template
 *
 */
function NPC_ParseTemplateName(template_name)
	if ( template_name.IsA(POLCLASS_NPC) )
		template_name := template_name.npctemplate;
	endif

	//Find positions of ":" characters
	var colon_a := Find(template_name, ":", 1);
	var colon_b := Find(template_name, ":", 2);

	var parsed := struct{"package", "template"};

	if ( !colon_a || !colon_b )
		//Not a complete package name - use default npcdesc.cfg
		parsed.package := "";
		parsed.template := template_name;
	else
		parsed.package := template_name[colon_a+1, colon_b-2];
		parsed.template := template_name[colon_b+1, Len(template_name)];
	endif

	return parsed;
endfunction

/*
 * NPC_GetNPCConfig(template)
 *
 * Purpose
 * Retrieves a config elem for an npc template.
 *
 * Parameters
 * info:	Template info from NPC_ParseTemplateName()
 *
 * Return value
 * Config elem reference
 *
 */
function NPC_GetNPCConfig(template)
	if ( !template.package )
		template := NPC_ParseTemplateName(template);
	endif

	var npc_cfg := ReadConfigFile(":"+template.package+":npcdesc");
	if ( npc_cfg.errortext )
		return error{"errortext":="Error::NPC_GetNPCConfig() - Could not open :"+template.package+":npcdesc ->"+npc_cfg.errortext};
	endif

	var cfg_elem := npc_cfg[template.template];
	if ( cfg_elem.errortext )
		return error{"errortext":="Error::NPC_GetNPCConfig() - Could not find elem ["+template.template+"] ->"+cfg_elem.errortext};
	endif

	return cfg_elem;
endfunction

/*
 * NPC_GetAllTemplateNames()
 *
 * Purpose
 * Retrieves a list of all npc templates in the shard's npcdesc.cfg files
 *
 * Parameters
 *
 * Return value
 * Returns an array
 *
 */
function NPC_GetAllTemplateNames()
	var elem_names := array{};
	elem_names := elem_names + GetConfigStringKeys(ReadConfigFile("::npcdesc"));
	foreach package in (Packages())
		if ( package.npcdesc )
			var pkg_name := ":"+package.name+":";
			foreach template_name in (GetConfigStringKeys(ReadConfigFile(pkg_name+"npcdesc")))
				elem_names.Append(pkg_name+template_name);
				SleepMS(2);
			endforeach
		endif
		SleepMS(2);
	endforeach

	return elem_names;
endfunction
Locked