Exemplo n.º 1
0
int gmfSayFireTeam( gmThread *a_thread )
{
	CHECK_THIS_BOT();
	if ( a_thread->GetNumParams() > 0 )
	{
		const int bufferSize = 512;
		char buffer[ bufferSize ];

		int iMsgPos = 0;
		const int chatMsgSize = 2048;
		char chatMsg[ chatMsgSize ] = { 0 };

		// build the string
		for ( int i = 0; i < a_thread->GetNumParams(); ++i )
		{
			const char *pAsString = a_thread->Param( i ).AsString( a_thread->GetMachine(), buffer, bufferSize );
			if ( pAsString )
			{
				int len = (int)strlen( pAsString );
				if ( chatMsgSize - iMsgPos > len )
				{
					Utils::StringCopy( &chatMsg[ iMsgPos ], pAsString, len );
					iMsgPos += len;
				}
			}
		}

		gEngineFuncs->BotCommand( native->GetGameID(), va( "say_buddy \"%s\"", chatMsg ) );
		return GM_OK;
	}

	GM_EXCEPTION_MSG( "Expected 1+ parameters" );
	return GM_EXCEPTION;
}
Exemplo n.º 2
0
	static int GM_CDECL gmfDumpGlobals( gmThread *a_thread )
	{
		if ( GM_NUM_PARAMS > 2 )
		{
			GM_EXCEPTION_MSG( "expecting 1 - 2 parameters" );
			return GM_EXCEPTION;
		}

		GM_CHECK_STRING_PARAM( filename, 0 );
		int iFlags = a_thread->ParamInt( 1, gmUtility::DUMP_ALL );
		DumpGlobals( a_thread->GetMachine(), filename, iFlags );

		return GM_OK;
	}
Exemplo n.º 3
0
	// function: dumpTable
	//		This function will dump a specific table.
	//
	// Parameters:
	//
	//		std::string - The filename to dump to
	//		std::string - The table to dump
	//		int - The bitflags of things to dump. See the global DUMP table.
	//
	// Returns:
	//		None
	static int GM_CDECL gmfDumpTable( gmThread *a_thread )
	{
		if ( GM_NUM_PARAMS > 3 )
		{
			GM_EXCEPTION_MSG( "expecting 2 - 3 parameters" );
			return GM_EXCEPTION;
		}

		GM_CHECK_STRING_PARAM( filename, 0 );
		GM_CHECK_STRING_PARAM( tablename, 1 );
		int iFlags = a_thread->ParamInt( 2, gmUtility::DUMP_ALL );
		DumpTable( a_thread->GetMachine(), filename, tablename, iFlags );

		return GM_OK;
	}
Exemplo n.º 4
0
static int GM_CDECL gmfDoFile(gmThread * a_thread) // filename, now (1), return thread id, null on error, exception on compile error.
{
  GM_CHECK_NUM_PARAMS(1);
  GM_CHECK_STRING_PARAM(filename, 0);
  GM_INT_PARAM(now, 1, 1);
  gmVariable paramThis = a_thread->Param(2, gmVariable::s_null); // 3rd param is 'this'

  int id = GM_INVALID_THREAD;
  if(filename)
  {
    char * string = NULL;

    FILE * fp = fopen(filename, "rb");
    if(fp)
    {
      fseek(fp, 0, SEEK_END);
      int size = ftell(fp);
      rewind(fp);
      string = new char[size + 1];
      fread(string, 1, size, fp);
      string[size] = 0;
      fclose(fp);
    }
    else
    {
      GM_EXCEPTION_MSG("failed to open file '%s'", filename);
      return GM_EXCEPTION;
    }
    if(string == NULL) return GM_OK;

    int errors = a_thread->GetMachine()->ExecuteString(string, &id, (now) ? true : false, filename, &paramThis);
    delete[] string;
    if(errors)
    {
      return GM_EXCEPTION;
    }
    else
    {
      a_thread->PushInt(id);
    }
  }
  return GM_OK;
}