findobj.txt
snippets · 5.1 KB · 2010-03-30
Find object by wear location (findobj).
Download « Back to the snippets list
/************************** Description *************************************
* Snippit name: object find wear location *
* *
* Description: *
* Loop through all objects, returning a list of all with a given wear *
* location *
* *
* Exampel: *
* ofwl arms , This will retutn all objects with wear location arms *
****************************************************************************/
/****************************** Install *************************************
* Add this in the end of act_wiz. (From after * Copy from here *) *
* interp.h: *
* Add DECLARE_DO_FUN( do_objectfindwearlocation ); in the end of the file *
* interp.c: *
* Add: *
* { "ofwl", do_objectfindwearlocation, POS_RESTING, 0, LOG_NORMAL, 1 }, *
****************************************************************************/
// * Copy from here *
/************************** License *****************************************
* Fate of Kingdoms 4.0 is copyright 2000-???? Christian Tusborg (Kazmir) *
* By using this code, you have agreed to follow the terms of the *
* Fate of Kingdoms snippit license. *
* License: *
* Anyone is allowed to use this snippit, as long you keep this header. *
* Fate of kingdoms or Fate of Kingdoms staff can not be hold responsible. *
* for any damage this snippit may cause on your mud. *
* *
* Original Fate of Kingdom Mud (mud.kingdom.dk 4000) *
* Homepage: http://www.kingdom.dk *
* Fate of Kingdoms publish by snippit@kingdom.dk *
* Bug reporting: snpbug@kingdom.dk *
****************************************************************************/
void do_objectfindwearlocation( CHAR_DATA *ch, char *argument )
/*****************************************************************************
Called By: File: interp.c | Function: interpret( CHAR_DATA *ch, char *argument )
Pre: ch != NULL | ON PRE ERROR: return and and inform player |if ch == NULL
then report bug and abort
Post: Send object with a give argument as wear location;
Mobile: Nothing prevent mobiles in this function
*****************************************************************************/
/* Note:
* Yeah, so what it take over all vnum's (like 10,000 loops).
* Get_obj_index is fast, and I don't feel like threading another link.
*/
{
//extern var
extern int top_obj_index;
//internal var
char buf[MAX_STRING_LENGTH];
char arg[MAX_INPUT_LENGTH];
char arg1[MAX_INPUT_LENGTH];
OBJ_INDEX_DATA *pObjIndex = NULL;
int vnum = -1;
int nMatch = 0;
bool fAll = FALSE;
bool found = FALSE;
int intFind = 0;
int intFound = -1;
if (ch == NULL)
{
bug( "*BUG* File: objectfindwearlocation.c | Function: do_objectfindwearlocation | Error: ch = NULL",0 );
return;
}
//Splitting argument
argument = one_argument( argument, arg );
one_argument( argument, arg1 );
//Do player use an argument?
if ( arg[0] == '\0' )
{
//Give list with vnums
send_to_char( "Syntax: ofwl <wear location>.\n\r", ch );
//Give list without vnums
send_to_char( "Syntax: ofwl <wear location> <nonvnum>.\n\r", ch );
return;
}
//Did user write a real wear location?
for ( intFind = 0; wear_flags[intFind].name != NULL; intFind++)
{
//check if wear location found.
if (!str_cmp (wear_flags[intFind].name, argument))
intFound = intFind;
}
//The wear location was NOT right
if (intFound < 0)
return;
//For all objects on the mud.
for ( vnum = 0; nMatch < top_obj_index; vnum++ )
{
if ( ( pObjIndex = get_obj_index( vnum ) ) != NULL )
{
nMatch++;
//Check if right wear location
if ( fAll || CAN_WEAR(pObjIndex, wear_flags[intFound].bit) )
{
found = TRUE;
//how do we write it to the player.
if (str_cmp(arg1,"nonvnum"))
sprintf( buf, "[%5d] %s\n\r",pObjIndex->vnum, pObjIndex->short_descr );
else
sprintf( buf, "%s\n\r",pObjIndex->short_descr );
//Send it to the player.
send_to_char( buf, ch );
}
}
}
//We didn't find any objects with the wear location.
if ( !found )
send_to_char( "No objects with this wear location found.\n\r", ch );
return;
}