Normalize all the line endings
This commit is contained in:
@ -10,118 +10,118 @@
|
||||
//
|
||||
// Message Stocks
|
||||
//
|
||||
|
||||
#if defined _message_stocks_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _message_stocks_included
|
||||
|
||||
/* Creates a death message. */
|
||||
stock dod_make_deathmsg(killer, victim, weaponNUM)
|
||||
{
|
||||
message_begin(MSG_ALL, get_user_msgid("DeathMsg"), {0,0,0}, 0);
|
||||
write_byte(killer);
|
||||
write_byte(victim);
|
||||
write_byte(weaponNUM);
|
||||
message_end();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Kills a user without a message. */
|
||||
stock user_silentkill(index)
|
||||
{
|
||||
static msgid = 0;
|
||||
new msgblock;
|
||||
if (!msgid)
|
||||
{
|
||||
msgid = get_user_msgid("DeathMsg");
|
||||
}
|
||||
msgblock = get_msg_block(msgid);
|
||||
set_msg_block(msgid, BLOCK_ONCE);
|
||||
user_kill(index, 1);
|
||||
set_msg_block(msgid, msgblock);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Creates a death message. */
|
||||
stock make_deathmsg(killer, victim, headshot, const weapon[])
|
||||
{
|
||||
message_begin(MSG_ALL, get_user_msgid("DeathMsg"), {0,0,0}, 0);
|
||||
write_byte(killer);
|
||||
write_byte(victim);
|
||||
|
||||
new mod_name[32];
|
||||
get_modname(mod_name, 31);
|
||||
if (equal(mod_name, "cstrike") || equal(mod_name, "czero") || equal(mod_name, "csv15") || equal(mod_name, "cs13"))
|
||||
write_byte(headshot);
|
||||
write_string(weapon);
|
||||
message_end();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a predefined text message to player.
|
||||
* Predefined texts are default game messages which will be translated
|
||||
* to player's game language, e.g. #Game_join_ct.
|
||||
*
|
||||
* @note Set index to 0 to send text globally.
|
||||
*
|
||||
* @note There does not necessarily have to be a total of 6 arguments.
|
||||
* It will depend if message takes arguments, e.g.:
|
||||
* client_printex(id, print_chat, "#Game_join_ct", "Pimp Daddy")
|
||||
* client_printex(id, print_chat, "1", "#Game_radio", "Pimp Daddy", "Hello world!")
|
||||
*
|
||||
* @param index Index of the player, use 0 to send to all players.
|
||||
* @param type The message destination. See print_* constants.
|
||||
* @param msg_name The custom or predefined message to send.
|
||||
* @param msg_param1 Optional message argument.
|
||||
* @param msg_param2 Optional message argument.
|
||||
* @param msg_param3 Optional message argument.
|
||||
* @param msg_param4 Optional message argument.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
stock client_printex(index, type, const msg_name[], const msg_param1[] = "", const msg_param2[] = "", const msg_param3[] = "", const msg_param4[] = "")
|
||||
{
|
||||
new ch = msg_name[0];
|
||||
|
||||
// If not a predefined message, we don't care about it and forward directly to client_print.
|
||||
// Special case for radio message. msg_name is an index, msg_param1 #Game_radio*, etc. Checking index should be enough.
|
||||
if (ch != '#' && (type != print_radio || !strtol(msg_name)))
|
||||
{
|
||||
return client_print(index, type, msg_name, msg_param1, msg_param2, msg_param3, msg_param4);
|
||||
}
|
||||
|
||||
// Even if message starts with '#', we should check its length for safety.
|
||||
new length = strlen(msg_name);
|
||||
|
||||
// If string is larger than expected, we forward to client_print which will cut message properly.
|
||||
// This means also this can't be a predefined game message.
|
||||
// Max console length: 128 = \n (126) + \0 (127)
|
||||
// Max SayText length: 192 = \n (190) + \0 (191)
|
||||
if ((length > 126 && (print_notify <= type <= print_console))
|
||||
|| ( length > 190 && (print_chat <= type <= print_radio)))
|
||||
{
|
||||
return client_print(index, type, msg_name, msg_param1, msg_param2, msg_param3, msg_param4);
|
||||
}
|
||||
|
||||
static msgTextMsg;
|
||||
if (!msgTextMsg)
|
||||
{
|
||||
msgTextMsg = get_user_msgid("TextMsg");
|
||||
}
|
||||
|
||||
message_begin(index > 0 ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, msgTextMsg, .player = index);
|
||||
write_byte(type);
|
||||
write_string(msg_name);
|
||||
if (msg_param1[0]) { write_string(msg_param1); }
|
||||
if (msg_param2[0]) { write_string(msg_param2); }
|
||||
if (msg_param3[0]) { write_string(msg_param3); }
|
||||
if (msg_param4[0]) { write_string(msg_param4); }
|
||||
message_end();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if defined _message_stocks_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _message_stocks_included
|
||||
|
||||
/* Creates a death message. */
|
||||
stock dod_make_deathmsg(killer, victim, weaponNUM)
|
||||
{
|
||||
message_begin(MSG_ALL, get_user_msgid("DeathMsg"), {0,0,0}, 0);
|
||||
write_byte(killer);
|
||||
write_byte(victim);
|
||||
write_byte(weaponNUM);
|
||||
message_end();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Kills a user without a message. */
|
||||
stock user_silentkill(index)
|
||||
{
|
||||
static msgid = 0;
|
||||
new msgblock;
|
||||
if (!msgid)
|
||||
{
|
||||
msgid = get_user_msgid("DeathMsg");
|
||||
}
|
||||
msgblock = get_msg_block(msgid);
|
||||
set_msg_block(msgid, BLOCK_ONCE);
|
||||
user_kill(index, 1);
|
||||
set_msg_block(msgid, msgblock);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Creates a death message. */
|
||||
stock make_deathmsg(killer, victim, headshot, const weapon[])
|
||||
{
|
||||
message_begin(MSG_ALL, get_user_msgid("DeathMsg"), {0,0,0}, 0);
|
||||
write_byte(killer);
|
||||
write_byte(victim);
|
||||
|
||||
new mod_name[32];
|
||||
get_modname(mod_name, 31);
|
||||
if (equal(mod_name, "cstrike") || equal(mod_name, "czero") || equal(mod_name, "csv15") || equal(mod_name, "cs13"))
|
||||
write_byte(headshot);
|
||||
write_string(weapon);
|
||||
message_end();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a predefined text message to player.
|
||||
* Predefined texts are default game messages which will be translated
|
||||
* to player's game language, e.g. #Game_join_ct.
|
||||
*
|
||||
* @note Set index to 0 to send text globally.
|
||||
*
|
||||
* @note There does not necessarily have to be a total of 6 arguments.
|
||||
* It will depend if message takes arguments, e.g.:
|
||||
* client_printex(id, print_chat, "#Game_join_ct", "Pimp Daddy")
|
||||
* client_printex(id, print_chat, "1", "#Game_radio", "Pimp Daddy", "Hello world!")
|
||||
*
|
||||
* @param index Index of the player, use 0 to send to all players.
|
||||
* @param type The message destination. See print_* constants.
|
||||
* @param msg_name The custom or predefined message to send.
|
||||
* @param msg_param1 Optional message argument.
|
||||
* @param msg_param2 Optional message argument.
|
||||
* @param msg_param3 Optional message argument.
|
||||
* @param msg_param4 Optional message argument.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
stock client_printex(index, type, const msg_name[], const msg_param1[] = "", const msg_param2[] = "", const msg_param3[] = "", const msg_param4[] = "")
|
||||
{
|
||||
new ch = msg_name[0];
|
||||
|
||||
// If not a predefined message, we don't care about it and forward directly to client_print.
|
||||
// Special case for radio message. msg_name is an index, msg_param1 #Game_radio*, etc. Checking index should be enough.
|
||||
if (ch != '#' && (type != print_radio || !strtol(msg_name)))
|
||||
{
|
||||
return client_print(index, type, msg_name, msg_param1, msg_param2, msg_param3, msg_param4);
|
||||
}
|
||||
|
||||
// Even if message starts with '#', we should check its length for safety.
|
||||
new length = strlen(msg_name);
|
||||
|
||||
// If string is larger than expected, we forward to client_print which will cut message properly.
|
||||
// This means also this can't be a predefined game message.
|
||||
// Max console length: 128 = \n (126) + \0 (127)
|
||||
// Max SayText length: 192 = \n (190) + \0 (191)
|
||||
if ((length > 126 && (print_notify <= type <= print_console))
|
||||
|| ( length > 190 && (print_chat <= type <= print_radio)))
|
||||
{
|
||||
return client_print(index, type, msg_name, msg_param1, msg_param2, msg_param3, msg_param4);
|
||||
}
|
||||
|
||||
static msgTextMsg;
|
||||
if (!msgTextMsg)
|
||||
{
|
||||
msgTextMsg = get_user_msgid("TextMsg");
|
||||
}
|
||||
|
||||
message_begin(index > 0 ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, msgTextMsg, .player = index);
|
||||
write_byte(type);
|
||||
write_string(msg_name);
|
||||
if (msg_param1[0]) { write_string(msg_param1); }
|
||||
if (msg_param2[0]) { write_string(msg_param2); }
|
||||
if (msg_param3[0]) { write_string(msg_param3); }
|
||||
if (msg_param4[0]) { write_string(msg_param4); }
|
||||
message_end();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -6,311 +6,311 @@
|
||||
// This software is licensed under the GNU General Public License, version 3 or higher.
|
||||
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
||||
// https://alliedmods.net/amxmodx-license
|
||||
|
||||
#if defined _newmenus_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _newmenus_included
|
||||
|
||||
#define MEXIT_ALL 1 /* Menu will have an exit option (default)*/
|
||||
#define MEXIT_FORCE 2 /* Menu will have an exit option, even when pagination is disabled.
|
||||
* There have to be less than 10 items in the menu or it won't appear. The exit
|
||||
* option will be appended to the last item with no extra slot padding. If you
|
||||
* want it in the 10th slot you have to pad it manually with menu_addblank2 */
|
||||
#define MEXIT_NEVER -1 /* Menu will not have an exit option */
|
||||
|
||||
#define MPROP_PERPAGE 1 /* Number of items per page (param1 = number, 0=no paginating, 7=default) */
|
||||
#define MPROP_BACKNAME 2 /* Name of the back button (param1 = string) */
|
||||
#define MPROP_NEXTNAME 3 /* Name of the next button (param1 = string) */
|
||||
#define MPROP_EXITNAME 4 /* Name of the exit button (param1 = string) */
|
||||
#define MPROP_TITLE 5 /* Menu title text (param1 = string) */
|
||||
#define MPROP_EXIT 6 /* Exit functionality (param1 = number, see MEXIT constants) */
|
||||
#define MPROP_NOCOLORS 8 /* Sets whether colors are not auto (param1 = number, 0=default) */
|
||||
#define MPROP_NUMBER_COLOR 10 /* Color indicator to use for numbers (param1 = string, "\r"=default) */
|
||||
|
||||
#define MEXIT_NORMAL 0 /* DEPRECATED, do not use (has no effect) */
|
||||
#define MENUPAD_NONE 0 /* DEPRECATED, do not use (has no effect) */
|
||||
#define MENUPAD_PAGE 1 /* DEPRECATED, do not use (has no effect) */
|
||||
#define MPROP_ORDER 7 /* DEPRECATED, do not use (has no effect) */
|
||||
#define MPROP_PADMENU 9 /* DEPRECATED, do not use (has no effect) */
|
||||
|
||||
/**
|
||||
* @brief Creates a new menu object.
|
||||
*
|
||||
* The handler function should be prototyped as:
|
||||
*
|
||||
* public <function>(id, menu, item)
|
||||
* id - Client the menu is being acted upon.
|
||||
* menu - Menu resource identifier.
|
||||
* item - Item the client selected. If less than 0, the menu was
|
||||
* cancelled and the item is a status code. menu_display
|
||||
* should never be called immediately if the item is a status
|
||||
* code, for re-entrancy reasons.
|
||||
*
|
||||
* The handler function should always return PLUGIN_HANDLED to block
|
||||
* any old menu handlers from potentially feeding on the menu, unless
|
||||
* that is the desired functionality.
|
||||
*
|
||||
* @param title Title the menu should use.
|
||||
* @param handler Name of the handler function. The function will be invoked
|
||||
* once and only once to every menu_display() call.
|
||||
* @param ml Unused (should be 0).
|
||||
* @return Menu resource identifier which must be destroyed via
|
||||
* menu_destroy(). All menus are destroyed when the plugin
|
||||
* unloads.
|
||||
* @error Function name not found.
|
||||
*/
|
||||
native menu_create(const title[], const handler[], ml=0);
|
||||
|
||||
/**
|
||||
* Creates a menu item callback handler.
|
||||
*
|
||||
* The handler function should be prototyped as:
|
||||
*
|
||||
* public <function>(id, menu, item)
|
||||
* id - Client index being displayed to.
|
||||
* menu - Menu resource identifier.
|
||||
* item - Item being drawn.
|
||||
* <return> - ITEM_IGNORE to use the default functionality. ITEM_ENABLED to
|
||||
* explicitly enable or ITEM_DISABLED to explicitly disable.
|
||||
*
|
||||
* @param function Function name.
|
||||
* @return Menu callback ID.
|
||||
*/
|
||||
native menu_makecallback(const function[]);
|
||||
|
||||
/**
|
||||
* Adds an menu to a menu.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param name Item text to display.
|
||||
* @param info Item info string for internal information.
|
||||
* @param paccess Access required by the player viewing the menu.
|
||||
* @param callback If set to a valid ID from menu_makecallback(), the
|
||||
* callback will be invoked before drawing the item.
|
||||
* @noreturn
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_additem(menu, const name[], const info[]="", paccess=0, callback=-1);
|
||||
|
||||
/**
|
||||
* Returns the number of pages in a menu.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @return Number of pages in the menu.
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_pages(menu);
|
||||
|
||||
/**
|
||||
* Returns the number of items in a menu.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @return Number of items in the menu.
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_items(menu);
|
||||
|
||||
/**
|
||||
* Displays a menu to one client. This should never be called from a handler
|
||||
* when the item is less than 0 (i.e. calling this from a cancelled menu will
|
||||
* result in an error).
|
||||
*
|
||||
* Starting with 1.8.3 this allows to specify a menu timeout similar to the
|
||||
* show_menu native. If the menu exists on the client past the timeout *any*
|
||||
* further action will send the MENU_TIMEOUT status code to the menu handler.
|
||||
* That includes actions which would otherwise send MENU_EXIT, such as the
|
||||
* client selecting an item or disconnecting and calling menu_cancel or
|
||||
* menu_destroy on a live menu.
|
||||
*
|
||||
* @param id Client index.
|
||||
* @param menu Menu resource identifier.
|
||||
* @param page Page to start from (starting from 0).
|
||||
* @param time If >=0 menu will timeout after this many seconds
|
||||
* @noreturn
|
||||
* @error Invalid menu resource or client index.
|
||||
*/
|
||||
native menu_display(id, menu, page=0, time=-1);
|
||||
|
||||
/**
|
||||
* Given a page on a menu and a keypress on that page, returns the item id selected.
|
||||
* If the item is less than 0, a special option was chosen (such as MENU_EXIT).
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param page Page on the menu.
|
||||
* @param key Key pressed (from 1 to 10).
|
||||
* @return Item identifier, or <0 for a special selection code.
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_find_id(menu, page, key);
|
||||
|
||||
/**
|
||||
* Retrieves info about a menu item.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param item Item identifier.
|
||||
* @param access Variable to store access value.
|
||||
* @param info Buffer to store item info.
|
||||
* @param infolen Item info buffer length.
|
||||
* @param name Buffer to store item display text.
|
||||
* @param namelen Item name buffer length.
|
||||
* @param callback Callback ID.
|
||||
* @return 1 on success, 0 on failure.
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_item_getinfo(menu, item, &access, info[], infolen, name[]="", namelen=0, &callback);
|
||||
|
||||
/**
|
||||
* Sets an item's display text.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param item Item identifier.
|
||||
* @param name New item display text.
|
||||
* @return 1 on success, 0 on failure.
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_item_setname(menu, item, const name[]);
|
||||
|
||||
/**
|
||||
* Sets an item's info string.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param item Item identifier.
|
||||
* @param info New item info string.
|
||||
* @return 1 on success, 0 on failure.
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_item_setcmd(menu, item, const info[]);
|
||||
|
||||
/**
|
||||
* Sets an item's callback.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param item Item identifier.
|
||||
* @param callback New callback from menu_makecallback(), or -1 to clear.
|
||||
* @return 1 on success, 0 on failure.
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_item_setcall(menu, item, callback=-1);
|
||||
|
||||
/**
|
||||
* Destroys a menu. Player menus will be cancelled (although may still linger
|
||||
* on the HUD), and future attempts to access the menu resource will result in
|
||||
* an error.
|
||||
*
|
||||
* This must be called if you create menus dynamically, otherwise you will
|
||||
* leak memory. For normal dynamic menus, you will destroy the menu in the
|
||||
* handler function (remembering to handle the case of a menu being cancelled,
|
||||
* it must still be destroyed).
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @noreturn
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_destroy(menu);
|
||||
|
||||
/**
|
||||
* Returns information about a menu (if any) the client is currently viewing.
|
||||
*
|
||||
* If newmenu is valid, then the menu will refer to the menuid associated with
|
||||
* the title. If newmenu is not valid, and the menu is valid, then the player
|
||||
* is viewing a menu displayed with show_menu().
|
||||
*
|
||||
* Both may be invalid if the player is not viewing a menu.
|
||||
*
|
||||
* @param id Client index.
|
||||
* @param menu Variable to store old menu id. If none, then <1 will be
|
||||
* stored.
|
||||
* @param newmenu Variable to store new menu id. If none, then -1 will be
|
||||
* stored.
|
||||
* @param menupage Variable to store current page of the new menu, if any.
|
||||
* @return 1 if the player is viewing a menu, 0 otherwise.
|
||||
* @error Invalid client.
|
||||
*/
|
||||
native player_menu_info(id, &menu, &newmenu, &menupage=0);
|
||||
|
||||
/**
|
||||
* Adds a blank line to a menu.
|
||||
*
|
||||
* When using slot=1 this might break your menu. To achieve this functionality
|
||||
* menu_addblank2 should be used.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param slot 1 (default) if the line should shift the numbering down.
|
||||
* 0 if the line should be a visual shift only.
|
||||
* @noreturn
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_addblank(menu, slot=1);
|
||||
|
||||
/**
|
||||
* Adds a text line to a menu. Only available in amxmodx 1.8.1 and above.
|
||||
*
|
||||
* When using slot=1 this might break your menu. To achieve this functionality
|
||||
* menu_addtext2 should be used.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param text Text to add.
|
||||
* @param slot 1 (default) if the line should shift the numbering down.
|
||||
* 0 if the line should be a visual shift only.
|
||||
* @noreturn
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_addtext(menu, const text[], slot=1);
|
||||
|
||||
/**
|
||||
* Adds a blank line to a menu, always shifting the numbering down.
|
||||
*
|
||||
* This will add a special item to create a blank line. It will affect the menu
|
||||
* item count and pagination. These items can be modified later but will ignore
|
||||
* access and item callback results.
|
||||
*
|
||||
* Only available in 1.8.3 and above.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
*
|
||||
* @return 1 on success, 0 on failure.
|
||||
* @error Invalid menu resource.
|
||||
* Too many items on non-paginated menu (max is 10)
|
||||
*/
|
||||
native menu_addblank2( menu );
|
||||
|
||||
/**
|
||||
* Adds a text line to a menu, always shifting the numbering down.
|
||||
*
|
||||
* This will add a special item to create a blank line. It will affect the menu
|
||||
* item count and pagination. These items can be modified later but will ignore
|
||||
* access and item callback results.
|
||||
*
|
||||
* Only available in 1.8.3 and above.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param text Text to add.
|
||||
*
|
||||
* @return 1 on success, 0 on failure.
|
||||
* @error Invalid menu resource.
|
||||
* Too many items on non-paginated menu (max is 10)
|
||||
*/
|
||||
native menu_addtext2( menu, const text[] );
|
||||
|
||||
/**
|
||||
* Sets a menu property.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param prop MPROP_ constant.
|
||||
* @param ... Property parameters.
|
||||
* @return 1 on success, 0 on failure.
|
||||
* @error Invalid menu resource or property.
|
||||
*/
|
||||
native menu_setprop(menu, prop, ...);
|
||||
|
||||
/**
|
||||
* Cancels a player's menu, effectively forcing the player to select MENU_EXIT.
|
||||
* The menu will still exist on their screen but any results are invalidated,
|
||||
* and the callback is invoked.
|
||||
*
|
||||
* @param player Client index.
|
||||
* @noreturn
|
||||
* @error Invalid client index.
|
||||
*/
|
||||
native menu_cancel(player);
|
||||
|
||||
#if defined _newmenus_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _newmenus_included
|
||||
|
||||
#define MEXIT_ALL 1 /* Menu will have an exit option (default)*/
|
||||
#define MEXIT_FORCE 2 /* Menu will have an exit option, even when pagination is disabled.
|
||||
* There have to be less than 10 items in the menu or it won't appear. The exit
|
||||
* option will be appended to the last item with no extra slot padding. If you
|
||||
* want it in the 10th slot you have to pad it manually with menu_addblank2 */
|
||||
#define MEXIT_NEVER -1 /* Menu will not have an exit option */
|
||||
|
||||
#define MPROP_PERPAGE 1 /* Number of items per page (param1 = number, 0=no paginating, 7=default) */
|
||||
#define MPROP_BACKNAME 2 /* Name of the back button (param1 = string) */
|
||||
#define MPROP_NEXTNAME 3 /* Name of the next button (param1 = string) */
|
||||
#define MPROP_EXITNAME 4 /* Name of the exit button (param1 = string) */
|
||||
#define MPROP_TITLE 5 /* Menu title text (param1 = string) */
|
||||
#define MPROP_EXIT 6 /* Exit functionality (param1 = number, see MEXIT constants) */
|
||||
#define MPROP_NOCOLORS 8 /* Sets whether colors are not auto (param1 = number, 0=default) */
|
||||
#define MPROP_NUMBER_COLOR 10 /* Color indicator to use for numbers (param1 = string, "\r"=default) */
|
||||
|
||||
#define MEXIT_NORMAL 0 /* DEPRECATED, do not use (has no effect) */
|
||||
#define MENUPAD_NONE 0 /* DEPRECATED, do not use (has no effect) */
|
||||
#define MENUPAD_PAGE 1 /* DEPRECATED, do not use (has no effect) */
|
||||
#define MPROP_ORDER 7 /* DEPRECATED, do not use (has no effect) */
|
||||
#define MPROP_PADMENU 9 /* DEPRECATED, do not use (has no effect) */
|
||||
|
||||
/**
|
||||
* @brief Creates a new menu object.
|
||||
*
|
||||
* The handler function should be prototyped as:
|
||||
*
|
||||
* public <function>(id, menu, item)
|
||||
* id - Client the menu is being acted upon.
|
||||
* menu - Menu resource identifier.
|
||||
* item - Item the client selected. If less than 0, the menu was
|
||||
* cancelled and the item is a status code. menu_display
|
||||
* should never be called immediately if the item is a status
|
||||
* code, for re-entrancy reasons.
|
||||
*
|
||||
* The handler function should always return PLUGIN_HANDLED to block
|
||||
* any old menu handlers from potentially feeding on the menu, unless
|
||||
* that is the desired functionality.
|
||||
*
|
||||
* @param title Title the menu should use.
|
||||
* @param handler Name of the handler function. The function will be invoked
|
||||
* once and only once to every menu_display() call.
|
||||
* @param ml Unused (should be 0).
|
||||
* @return Menu resource identifier which must be destroyed via
|
||||
* menu_destroy(). All menus are destroyed when the plugin
|
||||
* unloads.
|
||||
* @error Function name not found.
|
||||
*/
|
||||
native menu_create(const title[], const handler[], ml=0);
|
||||
|
||||
/**
|
||||
* Creates a menu item callback handler.
|
||||
*
|
||||
* The handler function should be prototyped as:
|
||||
*
|
||||
* public <function>(id, menu, item)
|
||||
* id - Client index being displayed to.
|
||||
* menu - Menu resource identifier.
|
||||
* item - Item being drawn.
|
||||
* <return> - ITEM_IGNORE to use the default functionality. ITEM_ENABLED to
|
||||
* explicitly enable or ITEM_DISABLED to explicitly disable.
|
||||
*
|
||||
* @param function Function name.
|
||||
* @return Menu callback ID.
|
||||
*/
|
||||
native menu_makecallback(const function[]);
|
||||
|
||||
/**
|
||||
* Adds an menu to a menu.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param name Item text to display.
|
||||
* @param info Item info string for internal information.
|
||||
* @param paccess Access required by the player viewing the menu.
|
||||
* @param callback If set to a valid ID from menu_makecallback(), the
|
||||
* callback will be invoked before drawing the item.
|
||||
* @noreturn
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_additem(menu, const name[], const info[]="", paccess=0, callback=-1);
|
||||
|
||||
/**
|
||||
* Returns the number of pages in a menu.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @return Number of pages in the menu.
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_pages(menu);
|
||||
|
||||
/**
|
||||
* Returns the number of items in a menu.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @return Number of items in the menu.
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_items(menu);
|
||||
|
||||
/**
|
||||
* Displays a menu to one client. This should never be called from a handler
|
||||
* when the item is less than 0 (i.e. calling this from a cancelled menu will
|
||||
* result in an error).
|
||||
*
|
||||
* Starting with 1.8.3 this allows to specify a menu timeout similar to the
|
||||
* show_menu native. If the menu exists on the client past the timeout *any*
|
||||
* further action will send the MENU_TIMEOUT status code to the menu handler.
|
||||
* That includes actions which would otherwise send MENU_EXIT, such as the
|
||||
* client selecting an item or disconnecting and calling menu_cancel or
|
||||
* menu_destroy on a live menu.
|
||||
*
|
||||
* @param id Client index.
|
||||
* @param menu Menu resource identifier.
|
||||
* @param page Page to start from (starting from 0).
|
||||
* @param time If >=0 menu will timeout after this many seconds
|
||||
* @noreturn
|
||||
* @error Invalid menu resource or client index.
|
||||
*/
|
||||
native menu_display(id, menu, page=0, time=-1);
|
||||
|
||||
/**
|
||||
* Given a page on a menu and a keypress on that page, returns the item id selected.
|
||||
* If the item is less than 0, a special option was chosen (such as MENU_EXIT).
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param page Page on the menu.
|
||||
* @param key Key pressed (from 1 to 10).
|
||||
* @return Item identifier, or <0 for a special selection code.
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_find_id(menu, page, key);
|
||||
|
||||
/**
|
||||
* Retrieves info about a menu item.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param item Item identifier.
|
||||
* @param access Variable to store access value.
|
||||
* @param info Buffer to store item info.
|
||||
* @param infolen Item info buffer length.
|
||||
* @param name Buffer to store item display text.
|
||||
* @param namelen Item name buffer length.
|
||||
* @param callback Callback ID.
|
||||
* @return 1 on success, 0 on failure.
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_item_getinfo(menu, item, &access, info[], infolen, name[]="", namelen=0, &callback);
|
||||
|
||||
/**
|
||||
* Sets an item's display text.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param item Item identifier.
|
||||
* @param name New item display text.
|
||||
* @return 1 on success, 0 on failure.
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_item_setname(menu, item, const name[]);
|
||||
|
||||
/**
|
||||
* Sets an item's info string.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param item Item identifier.
|
||||
* @param info New item info string.
|
||||
* @return 1 on success, 0 on failure.
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_item_setcmd(menu, item, const info[]);
|
||||
|
||||
/**
|
||||
* Sets an item's callback.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param item Item identifier.
|
||||
* @param callback New callback from menu_makecallback(), or -1 to clear.
|
||||
* @return 1 on success, 0 on failure.
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_item_setcall(menu, item, callback=-1);
|
||||
|
||||
/**
|
||||
* Destroys a menu. Player menus will be cancelled (although may still linger
|
||||
* on the HUD), and future attempts to access the menu resource will result in
|
||||
* an error.
|
||||
*
|
||||
* This must be called if you create menus dynamically, otherwise you will
|
||||
* leak memory. For normal dynamic menus, you will destroy the menu in the
|
||||
* handler function (remembering to handle the case of a menu being cancelled,
|
||||
* it must still be destroyed).
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @noreturn
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_destroy(menu);
|
||||
|
||||
/**
|
||||
* Returns information about a menu (if any) the client is currently viewing.
|
||||
*
|
||||
* If newmenu is valid, then the menu will refer to the menuid associated with
|
||||
* the title. If newmenu is not valid, and the menu is valid, then the player
|
||||
* is viewing a menu displayed with show_menu().
|
||||
*
|
||||
* Both may be invalid if the player is not viewing a menu.
|
||||
*
|
||||
* @param id Client index.
|
||||
* @param menu Variable to store old menu id. If none, then <1 will be
|
||||
* stored.
|
||||
* @param newmenu Variable to store new menu id. If none, then -1 will be
|
||||
* stored.
|
||||
* @param menupage Variable to store current page of the new menu, if any.
|
||||
* @return 1 if the player is viewing a menu, 0 otherwise.
|
||||
* @error Invalid client.
|
||||
*/
|
||||
native player_menu_info(id, &menu, &newmenu, &menupage=0);
|
||||
|
||||
/**
|
||||
* Adds a blank line to a menu.
|
||||
*
|
||||
* When using slot=1 this might break your menu. To achieve this functionality
|
||||
* menu_addblank2 should be used.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param slot 1 (default) if the line should shift the numbering down.
|
||||
* 0 if the line should be a visual shift only.
|
||||
* @noreturn
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_addblank(menu, slot=1);
|
||||
|
||||
/**
|
||||
* Adds a text line to a menu. Only available in amxmodx 1.8.1 and above.
|
||||
*
|
||||
* When using slot=1 this might break your menu. To achieve this functionality
|
||||
* menu_addtext2 should be used.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param text Text to add.
|
||||
* @param slot 1 (default) if the line should shift the numbering down.
|
||||
* 0 if the line should be a visual shift only.
|
||||
* @noreturn
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_addtext(menu, const text[], slot=1);
|
||||
|
||||
/**
|
||||
* Adds a blank line to a menu, always shifting the numbering down.
|
||||
*
|
||||
* This will add a special item to create a blank line. It will affect the menu
|
||||
* item count and pagination. These items can be modified later but will ignore
|
||||
* access and item callback results.
|
||||
*
|
||||
* Only available in 1.8.3 and above.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
*
|
||||
* @return 1 on success, 0 on failure.
|
||||
* @error Invalid menu resource.
|
||||
* Too many items on non-paginated menu (max is 10)
|
||||
*/
|
||||
native menu_addblank2( menu );
|
||||
|
||||
/**
|
||||
* Adds a text line to a menu, always shifting the numbering down.
|
||||
*
|
||||
* This will add a special item to create a blank line. It will affect the menu
|
||||
* item count and pagination. These items can be modified later but will ignore
|
||||
* access and item callback results.
|
||||
*
|
||||
* Only available in 1.8.3 and above.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param text Text to add.
|
||||
*
|
||||
* @return 1 on success, 0 on failure.
|
||||
* @error Invalid menu resource.
|
||||
* Too many items on non-paginated menu (max is 10)
|
||||
*/
|
||||
native menu_addtext2( menu, const text[] );
|
||||
|
||||
/**
|
||||
* Sets a menu property.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param prop MPROP_ constant.
|
||||
* @param ... Property parameters.
|
||||
* @return 1 on success, 0 on failure.
|
||||
* @error Invalid menu resource or property.
|
||||
*/
|
||||
native menu_setprop(menu, prop, ...);
|
||||
|
||||
/**
|
||||
* Cancels a player's menu, effectively forcing the player to select MENU_EXIT.
|
||||
* The menu will still exist on their screen but any results are invalidated,
|
||||
* and the callback is invoked.
|
||||
*
|
||||
* @param player Client index.
|
||||
* @noreturn
|
||||
* @error Invalid client index.
|
||||
*/
|
||||
native menu_cancel(player);
|
||||
|
@ -16,92 +16,92 @@
|
||||
// C standard library, which uses the Quick Sort algorithm.
|
||||
// For more info, see: http://linux.wku.edu/~lamonml/algor/sort/sort.html
|
||||
//
|
||||
|
||||
#if defined _sorting_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _sorting_included
|
||||
|
||||
/**
|
||||
* Contains sorting orders.
|
||||
*/
|
||||
enum SortMethod
|
||||
{
|
||||
Sort_Ascending = 0,
|
||||
Sort_Descending,
|
||||
Sort_Random,
|
||||
};
|
||||
|
||||
/**
|
||||
* Data types for ADT Array Sorts
|
||||
*/
|
||||
enum SortType
|
||||
{
|
||||
Sort_Integer = 0,
|
||||
Sort_Float,
|
||||
Sort_String,
|
||||
};
|
||||
/**
|
||||
* Basic sorting functions below.
|
||||
*/
|
||||
|
||||
native SortIntegers(array[], array_size, SortMethod:order = Sort_Ascending);
|
||||
|
||||
native SortFloats(Float:array[], array_size, SortMethod:order = Sort_Ascending);
|
||||
|
||||
native SortStrings(array[][], num_strings, SortMethod:order = Sort_Ascending);
|
||||
|
||||
/**
|
||||
* Custom sorting functions below.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sorts a custom 1D array. You must pass in a comparison function.
|
||||
* The sorting algorithm then uses your comparison function to sort the data.
|
||||
* The function is called in the following manner:
|
||||
*
|
||||
* public MySortFunc(elem1, elem2, const array[], const data[], data_size)
|
||||
*
|
||||
* elem1, elem2 - Current element pair being compared
|
||||
* array[] - Array in its current mid-sorted state.
|
||||
* data[] - Extra data array you passed to the sort func.
|
||||
* data_size - Size of extra data you passed to the sort func.
|
||||
*
|
||||
* Your function should return:
|
||||
* -1 if elem1 should go before elem2
|
||||
* 0 if elem1 and elem2 are equal
|
||||
* 1 if elem1 should go after elem2
|
||||
* Note that the parameters after elem2 are all optional and you do not need to specify them.
|
||||
*/
|
||||
native SortCustom1D(array[], array_size, const comparefunc[], data[]="", data_size=0);
|
||||
|
||||
|
||||
/**
|
||||
* Sorts a custom 2D array.
|
||||
* The sorting algorithm then uses your comparison function to sort the data.
|
||||
* The function is called in the following manner:
|
||||
*
|
||||
* public MySortFunc(const elem1[], const elem2[], const array[], data[], data_size)
|
||||
*
|
||||
* elem1[], elem2[] - Current element array pairs being compared
|
||||
* array[][] - Array in its currently being sorted state.
|
||||
* data[] - Extra data array you passed to the sort func.
|
||||
* data_size - Size of extra data you passed to the sort func.
|
||||
*
|
||||
* Your function should return:
|
||||
* -1 if elem1[] should go before elem2[]
|
||||
* 0 if elem1[] and elem2 are equal[]
|
||||
* 1 if elem1[] should go after elem2[]
|
||||
* Note that the parameters after elem2[] are all optional and you do not need to specify them.
|
||||
*/
|
||||
native SortCustom2D(array[][], array_size, const comparefunc[], data[]="", data_size=0);
|
||||
|
||||
/**
|
||||
* Sort an ADT Array. Specify the type as Integer, Float, or String.
|
||||
*
|
||||
* @param array Array Handle to sort
|
||||
* @param order Sort order to use, same as other sorts.
|
||||
* @param type Data type stored in the ADT Array
|
||||
* @noreturn
|
||||
*/
|
||||
native SortADTArray(Array:array, SortMethod:order, SortType:type);
|
||||
|
||||
#if defined _sorting_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _sorting_included
|
||||
|
||||
/**
|
||||
* Contains sorting orders.
|
||||
*/
|
||||
enum SortMethod
|
||||
{
|
||||
Sort_Ascending = 0,
|
||||
Sort_Descending,
|
||||
Sort_Random,
|
||||
};
|
||||
|
||||
/**
|
||||
* Data types for ADT Array Sorts
|
||||
*/
|
||||
enum SortType
|
||||
{
|
||||
Sort_Integer = 0,
|
||||
Sort_Float,
|
||||
Sort_String,
|
||||
};
|
||||
/**
|
||||
* Basic sorting functions below.
|
||||
*/
|
||||
|
||||
native SortIntegers(array[], array_size, SortMethod:order = Sort_Ascending);
|
||||
|
||||
native SortFloats(Float:array[], array_size, SortMethod:order = Sort_Ascending);
|
||||
|
||||
native SortStrings(array[][], num_strings, SortMethod:order = Sort_Ascending);
|
||||
|
||||
/**
|
||||
* Custom sorting functions below.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sorts a custom 1D array. You must pass in a comparison function.
|
||||
* The sorting algorithm then uses your comparison function to sort the data.
|
||||
* The function is called in the following manner:
|
||||
*
|
||||
* public MySortFunc(elem1, elem2, const array[], const data[], data_size)
|
||||
*
|
||||
* elem1, elem2 - Current element pair being compared
|
||||
* array[] - Array in its current mid-sorted state.
|
||||
* data[] - Extra data array you passed to the sort func.
|
||||
* data_size - Size of extra data you passed to the sort func.
|
||||
*
|
||||
* Your function should return:
|
||||
* -1 if elem1 should go before elem2
|
||||
* 0 if elem1 and elem2 are equal
|
||||
* 1 if elem1 should go after elem2
|
||||
* Note that the parameters after elem2 are all optional and you do not need to specify them.
|
||||
*/
|
||||
native SortCustom1D(array[], array_size, const comparefunc[], data[]="", data_size=0);
|
||||
|
||||
|
||||
/**
|
||||
* Sorts a custom 2D array.
|
||||
* The sorting algorithm then uses your comparison function to sort the data.
|
||||
* The function is called in the following manner:
|
||||
*
|
||||
* public MySortFunc(const elem1[], const elem2[], const array[], data[], data_size)
|
||||
*
|
||||
* elem1[], elem2[] - Current element array pairs being compared
|
||||
* array[][] - Array in its currently being sorted state.
|
||||
* data[] - Extra data array you passed to the sort func.
|
||||
* data_size - Size of extra data you passed to the sort func.
|
||||
*
|
||||
* Your function should return:
|
||||
* -1 if elem1[] should go before elem2[]
|
||||
* 0 if elem1[] and elem2 are equal[]
|
||||
* 1 if elem1[] should go after elem2[]
|
||||
* Note that the parameters after elem2[] are all optional and you do not need to specify them.
|
||||
*/
|
||||
native SortCustom2D(array[][], array_size, const comparefunc[], data[]="", data_size=0);
|
||||
|
||||
/**
|
||||
* Sort an ADT Array. Specify the type as Integer, Float, or String.
|
||||
*
|
||||
* @param array Array Handle to sort
|
||||
* @param order Sort order to use, same as other sorts.
|
||||
* @param type Data type stored in the ADT Array
|
||||
* @noreturn
|
||||
*/
|
||||
native SortADTArray(Array:array, SortMethod:order, SortType:type);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7,126 +7,126 @@
|
||||
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
||||
// https://alliedmods.net/amxmodx-license
|
||||
|
||||
#include <amxmodx>
|
||||
|
||||
new __testnumber;
|
||||
new errcount;
|
||||
|
||||
enum TestType
|
||||
{
|
||||
TT_Equal = 0,
|
||||
TT_LessThan,
|
||||
TT_GreaterThan,
|
||||
TT_LessThanEqual,
|
||||
TT_GreaterThanEqual,
|
||||
TT_NotEqual
|
||||
};
|
||||
|
||||
new TestWords[6][] = {
|
||||
"==",
|
||||
"<",
|
||||
">",
|
||||
"<=",
|
||||
">=",
|
||||
"!="
|
||||
};
|
||||
|
||||
|
||||
|
||||
stock test(A,B=0,TestType:Type=TT_Equal)
|
||||
{
|
||||
++__testnumber;
|
||||
|
||||
new passed=0;
|
||||
|
||||
switch (Type)
|
||||
{
|
||||
case TT_Equal: if (A==B) passed=1;
|
||||
case TT_LessThan: if (A<B) passed=1;
|
||||
case TT_GreaterThan: if (A>B) passed=1;
|
||||
case TT_LessThanEqual: if (A<=B) passed=1;
|
||||
case TT_GreaterThanEqual: if (A>=B) passed=1;
|
||||
case TT_NotEqual: if (A!=B) passed=1;
|
||||
}
|
||||
|
||||
if (!passed)
|
||||
{
|
||||
log_amx("Failed test #%d (%d %s %d)",__testnumber,A,TestWords[_:Type],B);
|
||||
errcount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_srvcmd("testadmins","testadmins");
|
||||
}
|
||||
public testadmins()
|
||||
{
|
||||
|
||||
new AuthData[44];
|
||||
new Password[32];
|
||||
new Access;
|
||||
new Flags;
|
||||
new id;
|
||||
|
||||
__testnumber=0;
|
||||
errcount=0;
|
||||
|
||||
|
||||
test(admins_num(),0);
|
||||
|
||||
admins_push("STEAM_0:1:23456","",read_flags("abcdefghijklmnopqrstu"),read_flags("ce"));
|
||||
|
||||
test(admins_num(),1);
|
||||
|
||||
admins_push("ABCDEFGHIJKLMNOP","abcdefghijklmnop",read_flags("z"),read_flags("a"));
|
||||
|
||||
test(admins_num(),2);
|
||||
|
||||
admins_push("ZYXWVUTSRQPONMLKJIHGFEDCBA","plop",read_flags("a"),read_flags("b"));
|
||||
|
||||
test(admins_num(),3);
|
||||
|
||||
id=0;
|
||||
|
||||
admins_lookup(id,AdminProp_Auth,AuthData,sizeof(AuthData)-1);
|
||||
admins_lookup(id,AdminProp_Password,Password,sizeof(Password)-1);
|
||||
Access=admins_lookup(id,AdminProp_Access);
|
||||
Flags=admins_lookup(id,AdminProp_Flags);
|
||||
|
||||
test(strcmp(AuthData,"STEAM_0:1:23456"),0);
|
||||
test(strcmp(Password,""),0);
|
||||
test(Access,read_flags("abcdefghijklmnopqrstu"));
|
||||
test(Flags,read_flags("ce"));
|
||||
|
||||
id++;
|
||||
|
||||
admins_lookup(id,AdminProp_Auth,AuthData,sizeof(AuthData)-1);
|
||||
admins_lookup(id,AdminProp_Password,Password,sizeof(Password)-1);
|
||||
Access=admins_lookup(id,AdminProp_Access);
|
||||
Flags=admins_lookup(id,AdminProp_Flags);
|
||||
|
||||
test(strcmp(AuthData,"ABCDEFGHIJKLMNOP"),0);
|
||||
test(strcmp(Password,"abcdefghijklmnop"),0);
|
||||
test(Access,read_flags("z"));
|
||||
test(Flags,read_flags("a"));
|
||||
|
||||
id++;
|
||||
|
||||
admins_lookup(id,AdminProp_Auth,AuthData,sizeof(AuthData)-1);
|
||||
admins_lookup(id,AdminProp_Password,Password,sizeof(Password)-1);
|
||||
Access=admins_lookup(id,AdminProp_Access);
|
||||
Flags=admins_lookup(id,AdminProp_Flags);
|
||||
|
||||
test(strcmp(AuthData,"ZYXWVUTSRQPONMLKJIHGFEDCBA"),0);
|
||||
test(strcmp(Password,"plop"),0);
|
||||
test(Access,read_flags("a"));
|
||||
test(Flags,read_flags("b"));
|
||||
|
||||
admins_flush();
|
||||
|
||||
test(admins_num(),0);
|
||||
|
||||
server_print("test complete, %d errors",errcount);
|
||||
#include <amxmodx>
|
||||
|
||||
new __testnumber;
|
||||
new errcount;
|
||||
|
||||
enum TestType
|
||||
{
|
||||
TT_Equal = 0,
|
||||
TT_LessThan,
|
||||
TT_GreaterThan,
|
||||
TT_LessThanEqual,
|
||||
TT_GreaterThanEqual,
|
||||
TT_NotEqual
|
||||
};
|
||||
|
||||
new TestWords[6][] = {
|
||||
"==",
|
||||
"<",
|
||||
">",
|
||||
"<=",
|
||||
">=",
|
||||
"!="
|
||||
};
|
||||
|
||||
|
||||
|
||||
stock test(A,B=0,TestType:Type=TT_Equal)
|
||||
{
|
||||
++__testnumber;
|
||||
|
||||
new passed=0;
|
||||
|
||||
switch (Type)
|
||||
{
|
||||
case TT_Equal: if (A==B) passed=1;
|
||||
case TT_LessThan: if (A<B) passed=1;
|
||||
case TT_GreaterThan: if (A>B) passed=1;
|
||||
case TT_LessThanEqual: if (A<=B) passed=1;
|
||||
case TT_GreaterThanEqual: if (A>=B) passed=1;
|
||||
case TT_NotEqual: if (A!=B) passed=1;
|
||||
}
|
||||
|
||||
if (!passed)
|
||||
{
|
||||
log_amx("Failed test #%d (%d %s %d)",__testnumber,A,TestWords[_:Type],B);
|
||||
errcount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_srvcmd("testadmins","testadmins");
|
||||
}
|
||||
public testadmins()
|
||||
{
|
||||
|
||||
new AuthData[44];
|
||||
new Password[32];
|
||||
new Access;
|
||||
new Flags;
|
||||
new id;
|
||||
|
||||
__testnumber=0;
|
||||
errcount=0;
|
||||
|
||||
|
||||
test(admins_num(),0);
|
||||
|
||||
admins_push("STEAM_0:1:23456","",read_flags("abcdefghijklmnopqrstu"),read_flags("ce"));
|
||||
|
||||
test(admins_num(),1);
|
||||
|
||||
admins_push("ABCDEFGHIJKLMNOP","abcdefghijklmnop",read_flags("z"),read_flags("a"));
|
||||
|
||||
test(admins_num(),2);
|
||||
|
||||
admins_push("ZYXWVUTSRQPONMLKJIHGFEDCBA","plop",read_flags("a"),read_flags("b"));
|
||||
|
||||
test(admins_num(),3);
|
||||
|
||||
id=0;
|
||||
|
||||
admins_lookup(id,AdminProp_Auth,AuthData,sizeof(AuthData)-1);
|
||||
admins_lookup(id,AdminProp_Password,Password,sizeof(Password)-1);
|
||||
Access=admins_lookup(id,AdminProp_Access);
|
||||
Flags=admins_lookup(id,AdminProp_Flags);
|
||||
|
||||
test(strcmp(AuthData,"STEAM_0:1:23456"),0);
|
||||
test(strcmp(Password,""),0);
|
||||
test(Access,read_flags("abcdefghijklmnopqrstu"));
|
||||
test(Flags,read_flags("ce"));
|
||||
|
||||
id++;
|
||||
|
||||
admins_lookup(id,AdminProp_Auth,AuthData,sizeof(AuthData)-1);
|
||||
admins_lookup(id,AdminProp_Password,Password,sizeof(Password)-1);
|
||||
Access=admins_lookup(id,AdminProp_Access);
|
||||
Flags=admins_lookup(id,AdminProp_Flags);
|
||||
|
||||
test(strcmp(AuthData,"ABCDEFGHIJKLMNOP"),0);
|
||||
test(strcmp(Password,"abcdefghijklmnop"),0);
|
||||
test(Access,read_flags("z"));
|
||||
test(Flags,read_flags("a"));
|
||||
|
||||
id++;
|
||||
|
||||
admins_lookup(id,AdminProp_Auth,AuthData,sizeof(AuthData)-1);
|
||||
admins_lookup(id,AdminProp_Password,Password,sizeof(Password)-1);
|
||||
Access=admins_lookup(id,AdminProp_Access);
|
||||
Flags=admins_lookup(id,AdminProp_Flags);
|
||||
|
||||
test(strcmp(AuthData,"ZYXWVUTSRQPONMLKJIHGFEDCBA"),0);
|
||||
test(strcmp(Password,"plop"),0);
|
||||
test(Access,read_flags("a"));
|
||||
test(Flags,read_flags("b"));
|
||||
|
||||
admins_flush();
|
||||
|
||||
test(admins_num(),0);
|
||||
|
||||
server_print("test complete, %d errors",errcount);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7,63 +7,63 @@
|
||||
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
||||
// https://alliedmods.net/amxmodx-license
|
||||
|
||||
#include <amxmodx>
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("callfunc test", "1.0", "BAILOPAN")
|
||||
|
||||
register_srvcmd("test_callfunc", "Command_Callfunc")
|
||||
}
|
||||
|
||||
public OnCallfuncReceived(num, str[], &val, array[], array2[], size, hello2[1])
|
||||
{
|
||||
server_print("num = %d (expected: %d)", num, 5)
|
||||
server_print("str[] = ^"%s^" (expected: %s)", str, "Gaben")
|
||||
|
||||
server_print("val = %d (expected %d, setting to %d)", val, 62, 15)
|
||||
val = 15
|
||||
server_print("printing %d elements of array[] (expected: %d)", size, 6)
|
||||
for (new i=0; i<size; i++)
|
||||
{
|
||||
server_print("array[%d] = %d (expected: %d)", i, array[i], i)
|
||||
}
|
||||
for (new i=0; i<size; i++)
|
||||
{
|
||||
server_print("array2[%d] = %d (expected: %d)", i, array[i], i)
|
||||
}
|
||||
array[0] = 5
|
||||
array2[1] = 6
|
||||
hello2[0] = 25
|
||||
}
|
||||
|
||||
public Command_Callfunc()
|
||||
{
|
||||
new a = 62
|
||||
new hello[] = {0,1,2,3,4,5}
|
||||
new hello2[] = {9}
|
||||
new pm = 6
|
||||
new err
|
||||
|
||||
if ((err=callfunc_begin("OnCallfuncReceived")) < 1)
|
||||
{
|
||||
server_print("Failed to call callfunc_begin()! Error: %d", err)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
callfunc_push_int(5)
|
||||
callfunc_push_str("Gaben")
|
||||
callfunc_push_intrf(a)
|
||||
callfunc_push_array(hello, pm)
|
||||
callfunc_push_array(hello, pm)
|
||||
callfunc_push_int(pm)
|
||||
callfunc_push_array(hello2, 1, false)
|
||||
callfunc_end()
|
||||
|
||||
server_print("a = %d (expected: %d)", a, 15)
|
||||
server_print("hello[0] = %d (expected: %d)", hello[0], 5)
|
||||
server_print("hello[1] = %d (expected: %d)", hello[1], 6)
|
||||
server_print("hello2[0] = %d (expected: %d)", hello2[0], 9)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
#include <amxmodx>
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("callfunc test", "1.0", "BAILOPAN")
|
||||
|
||||
register_srvcmd("test_callfunc", "Command_Callfunc")
|
||||
}
|
||||
|
||||
public OnCallfuncReceived(num, str[], &val, array[], array2[], size, hello2[1])
|
||||
{
|
||||
server_print("num = %d (expected: %d)", num, 5)
|
||||
server_print("str[] = ^"%s^" (expected: %s)", str, "Gaben")
|
||||
|
||||
server_print("val = %d (expected %d, setting to %d)", val, 62, 15)
|
||||
val = 15
|
||||
server_print("printing %d elements of array[] (expected: %d)", size, 6)
|
||||
for (new i=0; i<size; i++)
|
||||
{
|
||||
server_print("array[%d] = %d (expected: %d)", i, array[i], i)
|
||||
}
|
||||
for (new i=0; i<size; i++)
|
||||
{
|
||||
server_print("array2[%d] = %d (expected: %d)", i, array[i], i)
|
||||
}
|
||||
array[0] = 5
|
||||
array2[1] = 6
|
||||
hello2[0] = 25
|
||||
}
|
||||
|
||||
public Command_Callfunc()
|
||||
{
|
||||
new a = 62
|
||||
new hello[] = {0,1,2,3,4,5}
|
||||
new hello2[] = {9}
|
||||
new pm = 6
|
||||
new err
|
||||
|
||||
if ((err=callfunc_begin("OnCallfuncReceived")) < 1)
|
||||
{
|
||||
server_print("Failed to call callfunc_begin()! Error: %d", err)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
callfunc_push_int(5)
|
||||
callfunc_push_str("Gaben")
|
||||
callfunc_push_intrf(a)
|
||||
callfunc_push_array(hello, pm)
|
||||
callfunc_push_array(hello, pm)
|
||||
callfunc_push_int(pm)
|
||||
callfunc_push_array(hello2, 1, false)
|
||||
callfunc_end()
|
||||
|
||||
server_print("a = %d (expected: %d)", a, 15)
|
||||
server_print("hello[0] = %d (expected: %d)", hello[0], 5)
|
||||
server_print("hello[1] = %d (expected: %d)", hello[1], 6)
|
||||
server_print("hello2[0] = %d (expected: %d)", hello2[0], 9)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
@ -7,21 +7,21 @@
|
||||
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
||||
// https://alliedmods.net/amxmodx-license
|
||||
|
||||
#include <amxmodx>
|
||||
#include <fakemeta>
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("Fakemeta Tests", "1.0", "BAILOPAN")
|
||||
register_forward(FM_ServerDeactivate, "Hook_ServerDeactivate")
|
||||
}
|
||||
|
||||
public Hook_ServerDeactivate()
|
||||
{
|
||||
server_print("[FAKEMETA TEST] ServerDeactivate() at %f", get_gametime())
|
||||
}
|
||||
|
||||
public plugin_end()
|
||||
{
|
||||
server_print("[FAKEMETA TEST] plugin_end() at %f", get_gametime())
|
||||
}
|
||||
#include <amxmodx>
|
||||
#include <fakemeta>
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("Fakemeta Tests", "1.0", "BAILOPAN")
|
||||
register_forward(FM_ServerDeactivate, "Hook_ServerDeactivate")
|
||||
}
|
||||
|
||||
public Hook_ServerDeactivate()
|
||||
{
|
||||
server_print("[FAKEMETA TEST] ServerDeactivate() at %f", get_gametime())
|
||||
}
|
||||
|
||||
public plugin_end()
|
||||
{
|
||||
server_print("[FAKEMETA TEST] plugin_end() at %f", get_gametime())
|
||||
}
|
||||
|
@ -7,61 +7,61 @@
|
||||
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
||||
// https://alliedmods.net/amxmodx-license
|
||||
|
||||
#include <amxmodx>
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("Format Test", "1.0", "BAILOPAN")
|
||||
|
||||
register_srvcmd("test_format", "Command_TestFormat")
|
||||
register_srvcmd("test_replace", "Command_TestReplace")
|
||||
}
|
||||
|
||||
public gabprint(const fmt[], ...)
|
||||
{
|
||||
static buffer[2048]
|
||||
vformat(buffer, 2047, fmt, 2)
|
||||
|
||||
server_print("%s", buffer)
|
||||
}
|
||||
|
||||
public Command_TestFormat()
|
||||
{
|
||||
server_print("Printing -1 with d: %d", -1)
|
||||
server_print("Printing -1 with u: %u", -1)
|
||||
server_print("Printing (1<<31) with d: %d", (1<<31))
|
||||
server_print("Printing (1<<31) with u: %u", (1<<31))
|
||||
server_print("Printing 1 with d: %d", 1)
|
||||
server_print("Printing 1 with u: %u", 1)
|
||||
}
|
||||
|
||||
public Command_TestReplace()
|
||||
{
|
||||
new message[192] = "^"@test^""
|
||||
|
||||
replace_all(message, 191, "^"", "")
|
||||
server_print("Got: %s (expected: %s)", message, "@test")
|
||||
|
||||
copy(message, 191, "test")
|
||||
replace_all(message, 191, "t", "tt")
|
||||
server_print("Got: %s (expected: %s)", message, "ttestt")
|
||||
|
||||
replace_all(message, 191, "tt", "")
|
||||
server_print("Got: %s (expected: %s)", message, "es")
|
||||
|
||||
copy(message, 191, "good boys do fine always")
|
||||
replace_all(message, 191, " ", "-----")
|
||||
server_print("Got %s (expected: %s)", message, "good-----boys-----do-----fine-----always")
|
||||
|
||||
copy(message, 191, "-----")
|
||||
replace_all(message, 191, "-", "")
|
||||
server_print("Got ^"%s%^" (expected: ^"%s%^")", message, "")
|
||||
|
||||
copy(message, 191, "-----")
|
||||
replace_all(message, 191, "--", "")
|
||||
server_print("Got ^"%s%^" (expected: ^"%s%^")", message, "-")
|
||||
|
||||
copy(message, 191, "aaaa")
|
||||
replace_all(message, 191, "a", "Aaa")
|
||||
server_print("Got %s (expected: %s)", message, "AaaAaaAaaAaa")
|
||||
}
|
||||
#include <amxmodx>
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("Format Test", "1.0", "BAILOPAN")
|
||||
|
||||
register_srvcmd("test_format", "Command_TestFormat")
|
||||
register_srvcmd("test_replace", "Command_TestReplace")
|
||||
}
|
||||
|
||||
public gabprint(const fmt[], ...)
|
||||
{
|
||||
static buffer[2048]
|
||||
vformat(buffer, 2047, fmt, 2)
|
||||
|
||||
server_print("%s", buffer)
|
||||
}
|
||||
|
||||
public Command_TestFormat()
|
||||
{
|
||||
server_print("Printing -1 with d: %d", -1)
|
||||
server_print("Printing -1 with u: %u", -1)
|
||||
server_print("Printing (1<<31) with d: %d", (1<<31))
|
||||
server_print("Printing (1<<31) with u: %u", (1<<31))
|
||||
server_print("Printing 1 with d: %d", 1)
|
||||
server_print("Printing 1 with u: %u", 1)
|
||||
}
|
||||
|
||||
public Command_TestReplace()
|
||||
{
|
||||
new message[192] = "^"@test^""
|
||||
|
||||
replace_all(message, 191, "^"", "")
|
||||
server_print("Got: %s (expected: %s)", message, "@test")
|
||||
|
||||
copy(message, 191, "test")
|
||||
replace_all(message, 191, "t", "tt")
|
||||
server_print("Got: %s (expected: %s)", message, "ttestt")
|
||||
|
||||
replace_all(message, 191, "tt", "")
|
||||
server_print("Got: %s (expected: %s)", message, "es")
|
||||
|
||||
copy(message, 191, "good boys do fine always")
|
||||
replace_all(message, 191, " ", "-----")
|
||||
server_print("Got %s (expected: %s)", message, "good-----boys-----do-----fine-----always")
|
||||
|
||||
copy(message, 191, "-----")
|
||||
replace_all(message, 191, "-", "")
|
||||
server_print("Got ^"%s%^" (expected: ^"%s%^")", message, "")
|
||||
|
||||
copy(message, 191, "-----")
|
||||
replace_all(message, 191, "--", "")
|
||||
server_print("Got ^"%s%^" (expected: ^"%s%^")", message, "-")
|
||||
|
||||
copy(message, 191, "aaaa")
|
||||
replace_all(message, 191, "a", "Aaa")
|
||||
server_print("Got %s (expected: %s)", message, "AaaAaaAaaAaa")
|
||||
}
|
||||
|
@ -7,48 +7,48 @@
|
||||
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
||||
// https://alliedmods.net/amxmodx-license
|
||||
|
||||
#include <amxmodx>
|
||||
|
||||
new g_BlockLog
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("Log Tester", "1.0", "BAILOPAN")
|
||||
register_srvcmd("log_addlogevent", "Command_AddLogEvent")
|
||||
register_srvcmd("log_setblock", "Command_LogSetBlock")
|
||||
}
|
||||
|
||||
public event_round_start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Command_LogSetBlock()
|
||||
{
|
||||
if (read_argc() < 2)
|
||||
{
|
||||
server_print("Specify 1 or 0.")
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
new temp[12]
|
||||
read_argv(1, temp, 11)
|
||||
|
||||
g_BlockLog = str_to_num(temp) ? true : false
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
public plugin_log()
|
||||
{
|
||||
server_print("Got log event! Blocking: %d", g_BlockLog)
|
||||
|
||||
return g_BlockLog ? PLUGIN_HANDLED : PLUGIN_CONTINUE
|
||||
}
|
||||
|
||||
public Command_AddLogEvent(id)
|
||||
{
|
||||
register_logevent("event_round_start", 2, "0=World triggered", "1=Round_Start")
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
#include <amxmodx>
|
||||
|
||||
new g_BlockLog
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("Log Tester", "1.0", "BAILOPAN")
|
||||
register_srvcmd("log_addlogevent", "Command_AddLogEvent")
|
||||
register_srvcmd("log_setblock", "Command_LogSetBlock")
|
||||
}
|
||||
|
||||
public event_round_start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Command_LogSetBlock()
|
||||
{
|
||||
if (read_argc() < 2)
|
||||
{
|
||||
server_print("Specify 1 or 0.")
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
new temp[12]
|
||||
read_argv(1, temp, 11)
|
||||
|
||||
g_BlockLog = str_to_num(temp) ? true : false
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
public plugin_log()
|
||||
{
|
||||
server_print("Got log event! Blocking: %d", g_BlockLog)
|
||||
|
||||
return g_BlockLog ? PLUGIN_HANDLED : PLUGIN_CONTINUE
|
||||
}
|
||||
|
||||
public Command_AddLogEvent(id)
|
||||
{
|
||||
register_logevent("event_round_start", 2, "0=World triggered", "1=Round_Start")
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
@ -7,34 +7,34 @@
|
||||
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
||||
// https://alliedmods.net/amxmodx-license
|
||||
|
||||
#include <amxmodx>
|
||||
|
||||
native Factorial(num)
|
||||
|
||||
public __Factorial(id, num)
|
||||
{
|
||||
new num = get_param(1)
|
||||
if (num == 0)
|
||||
{
|
||||
return 1
|
||||
}
|
||||
|
||||
return num * Factorial(num - 1)
|
||||
}
|
||||
|
||||
public plugin_natives()
|
||||
{
|
||||
register_native("Factorial", "__Factorial")
|
||||
}
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("Native Test", "1.0", "BAILOPAN")
|
||||
register_srvcmd("test_native1", "Command_TestNative1")
|
||||
}
|
||||
|
||||
public Command_TestNative1()
|
||||
{
|
||||
new num = Factorial(6)
|
||||
server_print("Factorial of 6 is: %d", num)
|
||||
}
|
||||
#include <amxmodx>
|
||||
|
||||
native Factorial(num)
|
||||
|
||||
public __Factorial(id, num)
|
||||
{
|
||||
new num = get_param(1)
|
||||
if (num == 0)
|
||||
{
|
||||
return 1
|
||||
}
|
||||
|
||||
return num * Factorial(num - 1)
|
||||
}
|
||||
|
||||
public plugin_natives()
|
||||
{
|
||||
register_native("Factorial", "__Factorial")
|
||||
}
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("Native Test", "1.0", "BAILOPAN")
|
||||
register_srvcmd("test_native1", "Command_TestNative1")
|
||||
}
|
||||
|
||||
public Command_TestNative1()
|
||||
{
|
||||
new num = Factorial(6)
|
||||
server_print("Factorial of 6 is: %d", num)
|
||||
}
|
||||
|
@ -7,23 +7,23 @@
|
||||
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
||||
// https://alliedmods.net/amxmodx-license
|
||||
|
||||
#include <amxmodx>
|
||||
#include <nvault>
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("nVault Test", "1.0", "BAILOPAN")
|
||||
|
||||
register_srvcmd("test_nvault", "Command_TestNvault")
|
||||
}
|
||||
|
||||
public Command_TestNvault()
|
||||
{
|
||||
new v = nvault_open("://:/1/R!?#@41345$%:$")
|
||||
server_print("Vault value: %d (expected: %d)", v, -1)
|
||||
|
||||
if (v != -1)
|
||||
{
|
||||
nvault_close(v)
|
||||
}
|
||||
}
|
||||
#include <amxmodx>
|
||||
#include <nvault>
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("nVault Test", "1.0", "BAILOPAN")
|
||||
|
||||
register_srvcmd("test_nvault", "Command_TestNvault")
|
||||
}
|
||||
|
||||
public Command_TestNvault()
|
||||
{
|
||||
new v = nvault_open("://:/1/R!?#@41345$%:$")
|
||||
server_print("Vault value: %d (expected: %d)", v, -1)
|
||||
|
||||
if (v != -1)
|
||||
{
|
||||
nvault_close(v)
|
||||
}
|
||||
}
|
||||
|
@ -7,294 +7,294 @@
|
||||
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
||||
// https://alliedmods.net/amxmodx-license
|
||||
|
||||
#include <amxmodx>
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("Sort Test", "1.0", "BAILOPAN")
|
||||
|
||||
register_srvcmd("test_sort_ints", "Command_TestSortInts")
|
||||
register_srvcmd("test_sort_floats", "Command_TestSortFloats")
|
||||
register_srvcmd("test_sort_strings", "Command_TestSortStrings")
|
||||
register_srvcmd("test_sort_1d", "Command_TestSort1D")
|
||||
register_srvcmd("test_sort_2d", "Command_TestSort2D")
|
||||
register_srvcmd("test_adtsort_ints", "Command_TestSortADTInts")
|
||||
register_srvcmd("test_adtsort_floats", "Command_TestSortADTFloats")
|
||||
register_srvcmd("test_adtsort_strings", "Command_TestSortADTStrings")
|
||||
}
|
||||
|
||||
/*****************
|
||||
* INTEGER TESTS *
|
||||
*****************/
|
||||
// Note that integer comparison is just int1-int2 (or a variation therein)
|
||||
|
||||
PrintIntegers(const array[], size)
|
||||
{
|
||||
for (new i=0; i<size; i++)
|
||||
{
|
||||
server_print("array[%d] = %d", i, array[i])
|
||||
}
|
||||
}
|
||||
|
||||
public Command_TestSortInts()
|
||||
{
|
||||
new array[10] = {6, 7, 3, 2, 8, 5, 0, 1, 4, 9}
|
||||
|
||||
server_print("Testing ascending sort:")
|
||||
SortIntegers(array, 10, Sort_Ascending)
|
||||
PrintIntegers(array, 10)
|
||||
|
||||
server_print("Testing descending sort:")
|
||||
SortIntegers(array, 10, Sort_Descending)
|
||||
PrintIntegers(array, 10)
|
||||
|
||||
server_print("Testing random sort:")
|
||||
SortIntegers(array, 10, Sort_Random)
|
||||
PrintIntegers(array, 10)
|
||||
}
|
||||
|
||||
/**************************
|
||||
* Float comparison tests *
|
||||
**************************/
|
||||
|
||||
PrintFloats(const Float:array[], size)
|
||||
{
|
||||
for (new i=0; i<size; i++)
|
||||
{
|
||||
server_print("array[%d] = %f", i, array[i])
|
||||
}
|
||||
}
|
||||
|
||||
public Command_TestSortFloats()
|
||||
{
|
||||
new Float:array[10] = {6.3, 7.6, 3.2, 2.1, 8.5, 5.2, 0.4, 1.7, 4.8, 8.2}
|
||||
|
||||
server_print("Testing ascending sort:")
|
||||
SortFloats(array, 10, Sort_Ascending)
|
||||
PrintFloats(array, 10)
|
||||
|
||||
server_print("Testing descending sort:")
|
||||
SortFloats(array, 10, Sort_Descending)
|
||||
PrintFloats(array, 10)
|
||||
|
||||
server_print("Testing random sort:")
|
||||
SortFloats(array, 10, Sort_Random)
|
||||
PrintFloats(array, 10)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
public Custom1DSort(Float:elem1, Float:elem2)
|
||||
{
|
||||
if (elem1 > elem2)
|
||||
{
|
||||
return -1;
|
||||
} else if (elem1 < elem2) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Command_TestSort1D()
|
||||
{
|
||||
new Float:array[10] = {6.3, 7.6, 3.2, 2.1, 8.5, 5.2, 0.4, 1.7, 4.8, 8.2}
|
||||
|
||||
SortCustom1D(_:array, 10, "Custom1DSort")
|
||||
PrintFloats(array, 10)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
/***************************
|
||||
* String comparison tests *
|
||||
***************************/
|
||||
|
||||
PrintStrings(const array[][], size)
|
||||
{
|
||||
for (new i=0; i<size; i++)
|
||||
{
|
||||
server_print("array[%d] = %s", i, array[i])
|
||||
}
|
||||
}
|
||||
|
||||
public Command_TestSortStrings()
|
||||
{
|
||||
new array[][] =
|
||||
{
|
||||
"faluco",
|
||||
"bailopan",
|
||||
"pm onoto",
|
||||
"damaged soul",
|
||||
"sniperbeamer",
|
||||
"sidluke",
|
||||
"johnny got his gun",
|
||||
"gabe newell",
|
||||
"hello",
|
||||
"WHAT?!"
|
||||
}
|
||||
|
||||
server_print("Testing ascending sort:")
|
||||
SortStrings(array, 10, Sort_Ascending)
|
||||
PrintStrings(array, 10)
|
||||
|
||||
server_print("Testing descending sort:")
|
||||
SortStrings(array, 10, Sort_Descending)
|
||||
PrintStrings(array, 10)
|
||||
|
||||
server_print("Testing random sort:")
|
||||
SortStrings(array, 10, Sort_Random)
|
||||
PrintStrings(array, 10)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
public Custom2DSort(const elem1[], const elem2[])
|
||||
{
|
||||
return strcmp(elem1, elem2)
|
||||
}
|
||||
|
||||
public Command_TestSort2D()
|
||||
{
|
||||
new array[][] =
|
||||
{
|
||||
"faluco",
|
||||
"bailopan",
|
||||
"pm onoto",
|
||||
"damaged soul",
|
||||
"sniperbeamer",
|
||||
"sidluke",
|
||||
"johnny got his gun",
|
||||
"gabe newell",
|
||||
"hello",
|
||||
"WHAT?!"
|
||||
}
|
||||
|
||||
SortCustom2D(array, 10, "Custom2DSort")
|
||||
PrintStrings(array, 10)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
|
||||
/*******************
|
||||
* ADT ARRAY TESTS *
|
||||
*******************/
|
||||
// Int and floats work the same as normal comparisions. Strings are direct
|
||||
// comparisions with no hacky memory stuff like Pawn arrays.
|
||||
|
||||
PrintADTArrayIntegers(Array:array)
|
||||
{
|
||||
new size = ArraySize(array);
|
||||
for (new i=0; i<size;i++)
|
||||
{
|
||||
server_print("array[%d] = %d", i, ArrayGetCell(array, i));
|
||||
}
|
||||
}
|
||||
|
||||
public Command_TestSortADTInts()
|
||||
{
|
||||
new Array:array = ArrayCreate();
|
||||
ArrayPushCell(array, 6);
|
||||
ArrayPushCell(array, 7);
|
||||
ArrayPushCell(array, 3);
|
||||
ArrayPushCell(array, 2);
|
||||
ArrayPushCell(array, 8);
|
||||
ArrayPushCell(array, 5);
|
||||
ArrayPushCell(array, 0);
|
||||
ArrayPushCell(array, 1);
|
||||
ArrayPushCell(array, 4);
|
||||
ArrayPushCell(array, 9);
|
||||
|
||||
server_print("Testing ascending sort:")
|
||||
SortADTArray(array, Sort_Ascending, Sort_Integer)
|
||||
PrintADTArrayIntegers(array)
|
||||
|
||||
server_print("Testing descending sort:")
|
||||
SortADTArray(array, Sort_Descending, Sort_Integer)
|
||||
PrintADTArrayIntegers(array)
|
||||
|
||||
server_print("Testing random sort:")
|
||||
SortADTArray(array, Sort_Random, Sort_Integer)
|
||||
PrintADTArrayIntegers(array)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
PrintADTArrayFloats(Array:array)
|
||||
{
|
||||
new size = ArraySize(array);
|
||||
for (new i=0; i<size;i++)
|
||||
{
|
||||
server_print("array[%d] = %f", i, Float:ArrayGetCell(array, i));
|
||||
}
|
||||
}
|
||||
|
||||
public Command_TestSortADTFloats()
|
||||
{
|
||||
new Array:array = ArrayCreate();
|
||||
ArrayPushCell(array, 6.0);
|
||||
ArrayPushCell(array, 7.0);
|
||||
ArrayPushCell(array, 3.0);
|
||||
ArrayPushCell(array, 2.0);
|
||||
ArrayPushCell(array, 8.0);
|
||||
ArrayPushCell(array, 5.0);
|
||||
ArrayPushCell(array, 0.0);
|
||||
ArrayPushCell(array, 1.0);
|
||||
ArrayPushCell(array, 4.0);
|
||||
ArrayPushCell(array, 9.0);
|
||||
|
||||
server_print("Testing ascending sort:")
|
||||
SortADTArray(array, Sort_Ascending, Sort_Float)
|
||||
PrintADTArrayFloats(array)
|
||||
|
||||
server_print("Testing descending sort:")
|
||||
SortADTArray(array, Sort_Descending, Sort_Float)
|
||||
PrintADTArrayFloats(array)
|
||||
|
||||
server_print("Testing random sort:")
|
||||
SortADTArray(array, Sort_Random, Sort_Float)
|
||||
PrintADTArrayFloats(array)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
PrintADTArrayStrings(Array:array)
|
||||
{
|
||||
new size = ArraySize(array);
|
||||
new buffer[64];
|
||||
for (new i=0; i<size;i++)
|
||||
{
|
||||
ArrayGetString(array, i, buffer, sizeof(buffer));
|
||||
server_print("array[%d] = %s", i, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public Command_TestSortADTStrings()
|
||||
{
|
||||
new Array:array = ArrayCreate(64);
|
||||
ArrayPushString(array, "faluco");
|
||||
ArrayPushString(array, "bailopan");
|
||||
ArrayPushString(array, "pm onoto");
|
||||
ArrayPushString(array, "damaged soul");
|
||||
ArrayPushString(array, "sniperbeamer");
|
||||
ArrayPushString(array, "sidluke");
|
||||
ArrayPushString(array, "johnny got his gun");
|
||||
ArrayPushString(array, "gabe newell");
|
||||
ArrayPushString(array, "Hello pRED*");
|
||||
ArrayPushString(array, "WHAT?!");
|
||||
|
||||
server_print("Testing ascending sort:")
|
||||
SortADTArray(array, Sort_Ascending, Sort_String)
|
||||
PrintADTArrayStrings(array)
|
||||
|
||||
server_print("Testing descending sort:")
|
||||
SortADTArray(array, Sort_Descending, Sort_String)
|
||||
PrintADTArrayStrings(array)
|
||||
|
||||
server_print("Testing random sort:")
|
||||
SortADTArray(array, Sort_Random, Sort_String)
|
||||
PrintADTArrayStrings(array)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
#include <amxmodx>
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("Sort Test", "1.0", "BAILOPAN")
|
||||
|
||||
register_srvcmd("test_sort_ints", "Command_TestSortInts")
|
||||
register_srvcmd("test_sort_floats", "Command_TestSortFloats")
|
||||
register_srvcmd("test_sort_strings", "Command_TestSortStrings")
|
||||
register_srvcmd("test_sort_1d", "Command_TestSort1D")
|
||||
register_srvcmd("test_sort_2d", "Command_TestSort2D")
|
||||
register_srvcmd("test_adtsort_ints", "Command_TestSortADTInts")
|
||||
register_srvcmd("test_adtsort_floats", "Command_TestSortADTFloats")
|
||||
register_srvcmd("test_adtsort_strings", "Command_TestSortADTStrings")
|
||||
}
|
||||
|
||||
/*****************
|
||||
* INTEGER TESTS *
|
||||
*****************/
|
||||
// Note that integer comparison is just int1-int2 (or a variation therein)
|
||||
|
||||
PrintIntegers(const array[], size)
|
||||
{
|
||||
for (new i=0; i<size; i++)
|
||||
{
|
||||
server_print("array[%d] = %d", i, array[i])
|
||||
}
|
||||
}
|
||||
|
||||
public Command_TestSortInts()
|
||||
{
|
||||
new array[10] = {6, 7, 3, 2, 8, 5, 0, 1, 4, 9}
|
||||
|
||||
server_print("Testing ascending sort:")
|
||||
SortIntegers(array, 10, Sort_Ascending)
|
||||
PrintIntegers(array, 10)
|
||||
|
||||
server_print("Testing descending sort:")
|
||||
SortIntegers(array, 10, Sort_Descending)
|
||||
PrintIntegers(array, 10)
|
||||
|
||||
server_print("Testing random sort:")
|
||||
SortIntegers(array, 10, Sort_Random)
|
||||
PrintIntegers(array, 10)
|
||||
}
|
||||
|
||||
/**************************
|
||||
* Float comparison tests *
|
||||
**************************/
|
||||
|
||||
PrintFloats(const Float:array[], size)
|
||||
{
|
||||
for (new i=0; i<size; i++)
|
||||
{
|
||||
server_print("array[%d] = %f", i, array[i])
|
||||
}
|
||||
}
|
||||
|
||||
public Command_TestSortFloats()
|
||||
{
|
||||
new Float:array[10] = {6.3, 7.6, 3.2, 2.1, 8.5, 5.2, 0.4, 1.7, 4.8, 8.2}
|
||||
|
||||
server_print("Testing ascending sort:")
|
||||
SortFloats(array, 10, Sort_Ascending)
|
||||
PrintFloats(array, 10)
|
||||
|
||||
server_print("Testing descending sort:")
|
||||
SortFloats(array, 10, Sort_Descending)
|
||||
PrintFloats(array, 10)
|
||||
|
||||
server_print("Testing random sort:")
|
||||
SortFloats(array, 10, Sort_Random)
|
||||
PrintFloats(array, 10)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
public Custom1DSort(Float:elem1, Float:elem2)
|
||||
{
|
||||
if (elem1 > elem2)
|
||||
{
|
||||
return -1;
|
||||
} else if (elem1 < elem2) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Command_TestSort1D()
|
||||
{
|
||||
new Float:array[10] = {6.3, 7.6, 3.2, 2.1, 8.5, 5.2, 0.4, 1.7, 4.8, 8.2}
|
||||
|
||||
SortCustom1D(_:array, 10, "Custom1DSort")
|
||||
PrintFloats(array, 10)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
/***************************
|
||||
* String comparison tests *
|
||||
***************************/
|
||||
|
||||
PrintStrings(const array[][], size)
|
||||
{
|
||||
for (new i=0; i<size; i++)
|
||||
{
|
||||
server_print("array[%d] = %s", i, array[i])
|
||||
}
|
||||
}
|
||||
|
||||
public Command_TestSortStrings()
|
||||
{
|
||||
new array[][] =
|
||||
{
|
||||
"faluco",
|
||||
"bailopan",
|
||||
"pm onoto",
|
||||
"damaged soul",
|
||||
"sniperbeamer",
|
||||
"sidluke",
|
||||
"johnny got his gun",
|
||||
"gabe newell",
|
||||
"hello",
|
||||
"WHAT?!"
|
||||
}
|
||||
|
||||
server_print("Testing ascending sort:")
|
||||
SortStrings(array, 10, Sort_Ascending)
|
||||
PrintStrings(array, 10)
|
||||
|
||||
server_print("Testing descending sort:")
|
||||
SortStrings(array, 10, Sort_Descending)
|
||||
PrintStrings(array, 10)
|
||||
|
||||
server_print("Testing random sort:")
|
||||
SortStrings(array, 10, Sort_Random)
|
||||
PrintStrings(array, 10)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
public Custom2DSort(const elem1[], const elem2[])
|
||||
{
|
||||
return strcmp(elem1, elem2)
|
||||
}
|
||||
|
||||
public Command_TestSort2D()
|
||||
{
|
||||
new array[][] =
|
||||
{
|
||||
"faluco",
|
||||
"bailopan",
|
||||
"pm onoto",
|
||||
"damaged soul",
|
||||
"sniperbeamer",
|
||||
"sidluke",
|
||||
"johnny got his gun",
|
||||
"gabe newell",
|
||||
"hello",
|
||||
"WHAT?!"
|
||||
}
|
||||
|
||||
SortCustom2D(array, 10, "Custom2DSort")
|
||||
PrintStrings(array, 10)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
|
||||
/*******************
|
||||
* ADT ARRAY TESTS *
|
||||
*******************/
|
||||
// Int and floats work the same as normal comparisions. Strings are direct
|
||||
// comparisions with no hacky memory stuff like Pawn arrays.
|
||||
|
||||
PrintADTArrayIntegers(Array:array)
|
||||
{
|
||||
new size = ArraySize(array);
|
||||
for (new i=0; i<size;i++)
|
||||
{
|
||||
server_print("array[%d] = %d", i, ArrayGetCell(array, i));
|
||||
}
|
||||
}
|
||||
|
||||
public Command_TestSortADTInts()
|
||||
{
|
||||
new Array:array = ArrayCreate();
|
||||
ArrayPushCell(array, 6);
|
||||
ArrayPushCell(array, 7);
|
||||
ArrayPushCell(array, 3);
|
||||
ArrayPushCell(array, 2);
|
||||
ArrayPushCell(array, 8);
|
||||
ArrayPushCell(array, 5);
|
||||
ArrayPushCell(array, 0);
|
||||
ArrayPushCell(array, 1);
|
||||
ArrayPushCell(array, 4);
|
||||
ArrayPushCell(array, 9);
|
||||
|
||||
server_print("Testing ascending sort:")
|
||||
SortADTArray(array, Sort_Ascending, Sort_Integer)
|
||||
PrintADTArrayIntegers(array)
|
||||
|
||||
server_print("Testing descending sort:")
|
||||
SortADTArray(array, Sort_Descending, Sort_Integer)
|
||||
PrintADTArrayIntegers(array)
|
||||
|
||||
server_print("Testing random sort:")
|
||||
SortADTArray(array, Sort_Random, Sort_Integer)
|
||||
PrintADTArrayIntegers(array)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
PrintADTArrayFloats(Array:array)
|
||||
{
|
||||
new size = ArraySize(array);
|
||||
for (new i=0; i<size;i++)
|
||||
{
|
||||
server_print("array[%d] = %f", i, Float:ArrayGetCell(array, i));
|
||||
}
|
||||
}
|
||||
|
||||
public Command_TestSortADTFloats()
|
||||
{
|
||||
new Array:array = ArrayCreate();
|
||||
ArrayPushCell(array, 6.0);
|
||||
ArrayPushCell(array, 7.0);
|
||||
ArrayPushCell(array, 3.0);
|
||||
ArrayPushCell(array, 2.0);
|
||||
ArrayPushCell(array, 8.0);
|
||||
ArrayPushCell(array, 5.0);
|
||||
ArrayPushCell(array, 0.0);
|
||||
ArrayPushCell(array, 1.0);
|
||||
ArrayPushCell(array, 4.0);
|
||||
ArrayPushCell(array, 9.0);
|
||||
|
||||
server_print("Testing ascending sort:")
|
||||
SortADTArray(array, Sort_Ascending, Sort_Float)
|
||||
PrintADTArrayFloats(array)
|
||||
|
||||
server_print("Testing descending sort:")
|
||||
SortADTArray(array, Sort_Descending, Sort_Float)
|
||||
PrintADTArrayFloats(array)
|
||||
|
||||
server_print("Testing random sort:")
|
||||
SortADTArray(array, Sort_Random, Sort_Float)
|
||||
PrintADTArrayFloats(array)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
PrintADTArrayStrings(Array:array)
|
||||
{
|
||||
new size = ArraySize(array);
|
||||
new buffer[64];
|
||||
for (new i=0; i<size;i++)
|
||||
{
|
||||
ArrayGetString(array, i, buffer, sizeof(buffer));
|
||||
server_print("array[%d] = %s", i, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public Command_TestSortADTStrings()
|
||||
{
|
||||
new Array:array = ArrayCreate(64);
|
||||
ArrayPushString(array, "faluco");
|
||||
ArrayPushString(array, "bailopan");
|
||||
ArrayPushString(array, "pm onoto");
|
||||
ArrayPushString(array, "damaged soul");
|
||||
ArrayPushString(array, "sniperbeamer");
|
||||
ArrayPushString(array, "sidluke");
|
||||
ArrayPushString(array, "johnny got his gun");
|
||||
ArrayPushString(array, "gabe newell");
|
||||
ArrayPushString(array, "Hello pRED*");
|
||||
ArrayPushString(array, "WHAT?!");
|
||||
|
||||
server_print("Testing ascending sort:")
|
||||
SortADTArray(array, Sort_Ascending, Sort_String)
|
||||
PrintADTArrayStrings(array)
|
||||
|
||||
server_print("Testing descending sort:")
|
||||
SortADTArray(array, Sort_Descending, Sort_String)
|
||||
PrintADTArrayStrings(array)
|
||||
|
||||
server_print("Testing random sort:")
|
||||
SortADTArray(array, Sort_Random, Sort_String)
|
||||
PrintADTArrayStrings(array)
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
Reference in New Issue
Block a user