/** * Copyright (c)2000-2002 Sony Online Entertainment Inc. * All Rights Reserved * * Title: datatable.scriptlib * Description: library for generic datatable lookup functions * @author $Author:$ * @version $Revision:$ */ // TABULATION IN BELOW FILE IS FUCKED UP, BUT I DIDNT CHANGE IT. // NEW FUNCTIONS LIVE AT THE BOTTOM /***** INCLUDES ********************************************************/ include datatable_writer; /***** CONSTANTS *******************************************************/ /***** FUNCTIONS *******************************************************/ /***************************************************************** * @brief select a random object template from a datatable * * @param string datatable * * @return string the path & name of the selected template; * null if unable to find datatable or * datatable is not properly formatted *****************************************************************/ string getRandomTemplate(string datatable) { string[] templateFilenames = dataTableGetStringColumn(datatable, "templateFilename"); if ( templateFilenames == null ) { return null; } else { int numItems = templateFilenames.length; int row = rand(0, numItems-1); return templateFilenames[row]; } } /***************************************************************** * @brief instantiate a random object template from a datatable lookup * in the world * * @param string datatable * * @return obj_id the obj_id of the created object *****************************************************************/ obj_id createRandomTemplateInWorld(string datatable) { string templateFilename = getRandomTemplate(datatable); obj_id myObjects = createObject(templateFilename, getLocation( getSelf() )); if ( myObjects == null ) { return null; } else { return myObjects; } } /***************************************************************** * @brief instantiate a random object template from a datatable lookup * at the target * * @param string datatable * @param obj_id target * * @return obj_id the obj_id of the created object *****************************************************************/ obj_id createRandomTemplateAtTarget(string datatable, obj_id target) { string templateFilename = getRandomTemplate(datatable); if ( (target == null) || (templateFilename == null) ) { return null; } else { obj_id myObject = createObjectAt(templateFilename, target); if ( myObject == null ) { return null; } else { return myObject; } } } /***************************************************************** * @brief instantiate a random object template from a datatable lookup * at a specified location * * @param string datatable * @param location loc * * @return obj_id the obj_id of the created object *****************************************************************/ obj_id createRandomTemplateAtTarget(string datatable, location loc) { string templateFilename = getRandomTemplate(datatable); if ( (loc == null) || (templateFilename == null) ) { return null; } else { obj_id myObject = createObject(templateFilename, loc); if ( myObject == null ) { return null; } else { return myObject; } } } // I DID NOT CREATE THE ABOVE FUNCTIONS. THE TABULATION IS FUCKED UP AND ITS NOT MY FAULT. boolean createDataTable(string strFileName, string[] strHeaders, string[] strHeaderTypes) { if(strFileName==null) { LOG("ERROR", "Null string passed into createDataTable)"); return false; } int intIndex = strFileName.indexOf(".tab"); if(intIndex<0) { LOG("ERROR", "Datatbles need a .tab extension"); return false; } if(strHeaders.length!=strHeaderTypes.length) { LOG("ERROR", "You need to use the same length header/headertypes arrays"); return false; } string strHeaderString = ""; string strHeaderTypeString = ""; strFileName = "../../dsrc/sku.0/sys.server/compiled/game/"+strFileName; for(int intI = 0; intI