plugins/include/sdktools_stringtables.inc
author David Anderson <dvander@alliedmods.net>
Wed Jul 25 20:23:34 2007 +0000 (2007-07-25)
changeset 1169 47a8892d2c81
parent 1115 13d96df8ead8
child 1330 ab94316bb52b
permissions -rw-r--r--
added amb416 - SlapPlayer()
ds@1114
     1
/**
ds@1114
     2
 * vim: set ts=4 :
ds@1114
     3
 * ===============================================================
ds@1114
     4
 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
ds@1114
     5
 * ===============================================================
ds@1114
     6
 *
ds@1114
     7
 *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be used 
ds@1114
     8
 * or modified under the Terms and Conditions of its License Agreement, which is found 
ds@1114
     9
 * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
ds@1114
    10
 * may change at any time.  To view the latest information, see:
ds@1114
    11
 *   http://www.sourcemod.net/license.php
ds@1114
    12
 *
ds@1114
    13
 * Version: $Id$
ds@1114
    14
 */
ds@1114
    15
ds@1114
    16
#if defined _sdktools_stringtables_included
ds@1114
    17
  #endinput
ds@1114
    18
#endif
ds@1114
    19
#define _sdktools_stringtables_included
ds@1114
    20
ds@1114
    21
#define INVALID_STRING_TABLE -1		/**< An invalid string table index */
ds@1114
    22
#define INVALID_STRING_INDEX -1		/**< An invalid string index in a table */
ds@1114
    23
ds@1114
    24
/**
ds@1114
    25
 * Searches for a string table.
ds@1114
    26
 *
ds@1114
    27
 * @param name			Name of string table to find.
ds@1114
    28
 * @return				A string table index number if found, INVALID_STRING_TABLE otherwise.
ds@1114
    29
 */
ds@1114
    30
native FindStringTable(const String:name[]);
ds@1114
    31
ds@1114
    32
/**
ds@1114
    33
 * Returns the number of string tables that currently exist.
ds@1114
    34
 *
ds@1114
    35
 * @return				Number of string tables that currently exist.
ds@1114
    36
 */
ds@1114
    37
native GetNumStringTables();
ds@1114
    38
ds@1114
    39
/**
ds@1114
    40
 * Returns the number of strings that currently exist in a given string table.
ds@1114
    41
 *
ds@1114
    42
 * @param tableidx		A string table index.
ds@1114
    43
 * @return				Number of strings that currently exist.
ds@1114
    44
 * @error				Invalid string table index.
ds@1114
    45
 */
ds@1114
    46
native GetStringTableNumStrings(tableidx);
ds@1114
    47
ds@1114
    48
/**
ds@1114
    49
 * Returns the maximum number of strings that are allowed in a given string table.
ds@1114
    50
 *
ds@1114
    51
 * @param tableidx		A string table index.
ds@1114
    52
 * @return				Maximum number of strings allowed.
ds@1114
    53
 * @error				Invalid string table index.
ds@1114
    54
 */
ds@1114
    55
native GetStringTableMaxStrings(tableidx);
ds@1114
    56
ds@1114
    57
/**
ds@1114
    58
 * Retrieves the name of a string table.
ds@1114
    59
 *
ds@1114
    60
 * @param tableidx		A string table index.
ds@1114
    61
 * @param name			Buffer to store the name of the string table.
ds@1114
    62
 * @param maxlength		Maximum length of string buffer.
ds@1114
    63
 * @return				Number of bytes written to the buffer (UTF-8 safe).
ds@1114
    64
 * @error				Invalid string table index.
ds@1114
    65
 */
ds@1114
    66
native GetStringTableName(tableidx, String:name[], maxlength);
ds@1114
    67
ds@1114
    68
/**
ds@1114
    69
 * Searches for the index of a given string in a string table.
ds@1114
    70
 *
ds@1114
    71
 * @param tableidx		A string table index.
ds@1114
    72
 * @param string		String to find.
ds@1114
    73
 * @return				String index if found, INVALID_STRING_INDEX otherwise.
ds@1114
    74
 * @error				Invalid string table index.
ds@1114
    75
 */
ds@1114
    76
native FindStringIndex(tableidx, const String:str[]);
ds@1114
    77
ds@1114
    78
/**
ds@1114
    79
 * Retrieves the string at a given index of a string table.
ds@1114
    80
 *
ds@1114
    81
 * @param tableidx		A string table index.
ds@1114
    82
 * @param stringidx		A string index.
ds@1114
    83
 * @param name			Buffer to store the string value.
ds@1114
    84
 * @param maxlength		Maximum length of string buffer.
ds@1114
    85
 * @return				Number of bytes written to the buffer (UTF-8 safe).
ds@1114
    86
 * @error				Invalid string table index or string index.
ds@1114
    87
 */
ds@1114
    88
native ReadStringTable(tableidx, stringIdx, String:str[], maxlength);
ds@1114
    89
ds@1114
    90
/**
ds@1114
    91
 * Returns the length of the user data associated with a given string index.
ds@1114
    92
 *
ds@1114
    93
 * @param tableidx		A string table index.
ds@1114
    94
 * @param stringidx		A string index.
ds@1114
    95
 * @return				Length of user data. This will be 0 if there is no user data.
ds@1114
    96
 * @error				Invalid string table index or string index.
ds@1114
    97
 */
ds@1114
    98
native GetStringTableDataLength(tableidx, stringidx);
ds@1114
    99
ds@1114
   100
/**
ds@1114
   101
 * Retrieves the user data associated with a given string index.
ds@1114
   102
 *
ds@1114
   103
 * @param tableidx		A string table index.
ds@1114
   104
 * @param stringidx		A string index.
ds@1114
   105
 * @param userdata		Buffer to store the user data. This will be set to "" if there is no user data.
ds@1114
   106
 * @param maxlength		Maximum length of string buffer.
ds@1114
   107
 * @return				Number of bytes written to the buffer (UTF-8 safe).
ds@1114
   108
 * @error				Invalid string table index or string index.
ds@1114
   109
 */
ds@1114
   110
native GetStringTableData(tableidx, stringIdx, String:userdata[], maxlength);
ds@1114
   111
ds@1114
   112
/**
ds@1114
   113
 * Sets the user data associated with a given string index.
ds@1114
   114
 *
ds@1114
   115
 * @param tableidx		A string table index.
ds@1114
   116
 * @param stringidx		A string index.
ds@1114
   117
 * @param userdata		User data string that will be set.
ds@1114
   118
 * @param length		Length of user data string. This should include the null terminator.
ds@1114
   119
 * @return				Number of bytes written to the buffer (UTF-8 safe).
ds@1114
   120
 * @error				Invalid string table index or string index.
ds@1114
   121
 */
ds@1114
   122
native SetStringTableData(tableidx, stringIdx, const String:userdata[], length);
ds@1114
   123
ds@1114
   124
/**
ds@1114
   125
 * Adds a string to a given string table.
ds@1114
   126
 *
ds@1114
   127
 * @param tableidx		A string table index.
ds@1114
   128
 * @param string		String to add.
ds@1114
   129
 * @param userdata		An optional user data string.
ds@1114
   130
 * @param length		Length of user data string. This should include the null terminator.
ds@1114
   131
 *						If set to -1, then user data will be not be altered if the specified string
ds@1114
   132
 *						already exists in the string table.
ds@1114
   133
 */
ds@1114
   134
native AddToStringTable(tableidx, const String:str[], const String:userdata[]="", length=-1);
ds@1114
   135
ds@1114
   136
/**
ds@1114
   137
 * Locks or unlocks the network string tables.
ds@1114
   138
 *
ds@1114
   139
 * @param lock			Determines whether network string tables should be locked.
ds@1114
   140
 *						True means the tables should be locked for writing; false means unlocked.
ds@1114
   141
 * @return				Previous lock state.
ds@1114
   142
 */
ds@1114
   143
native bool:LockStringTables(bool:lock);
ds@1114
   144
ds@1114
   145
/**
ds@1114
   146
 * Adds a file to the downloadables network string table.
ds@1114
   147
 * This forces a client to download the file if they do not already have it.
ds@1114
   148
 *
ds@1114
   149
 * @param filename		File that will be added to downloadables table.
ds@1114
   150
 */
ds@1115
   151
stock AddFileToDownloadsTable(const String:filename[])
ds@1114
   152
{
ds@1114
   153
	static table = INVALID_STRING_TABLE;
ds@1114
   154
	
ds@1114
   155
	if (table == INVALID_STRING_TABLE)
ds@1114
   156
	{
ds@1114
   157
		table = FindStringTable("downloadables");
ds@1114
   158
	}
ds@1114
   159
	
ds@1114
   160
	new bool:save = LockStringTables(false);
ds@1114
   161
	AddToStringTable(table, filename);
ds@1114
   162
	LockStringTables(save);
ds@1114
   163
}