amxmodx/plugins/include/core.inc

203 lines
4.6 KiB
PHP
Raw Normal View History

2004-01-31 23:56:22 +03:00
/* Core functions
2004-02-08 14:31:54 +03:00
*
* (c) Copyright 1998-2003, ITB CompuPhase
*
* This file is provided as is (no warranties).
*/
2004-01-31 23:56:22 +03:00
#if defined _core_included
2015-02-25 00:51:36 +03:00
#endinput
#endif
#define _core_included
2015-02-17 19:51:56 +03:00
/**
* Returns the free memory space available to the plugin.
*
* @note This is a debugging function that is not intended for general plugin
* use.
*
* @return Free memory space in bytes
*/
2004-01-31 23:56:22 +03:00
native heapspace();
2015-02-17 19:51:56 +03:00
/**
* Returns the function index of a public function declared in the plugin.
*
* @param name Function name
*
* @return Function index > 0 on success, -1 if function was not found
* @error If the function name is too long (longer than 63 characters)
* an error will be thrown.
*/
2004-01-31 23:56:22 +03:00
native funcidx(const name[]);
2015-02-17 19:51:56 +03:00
/**
* Returns the number of arguments passed into the currently executed function.
*
* @return Number of arguments passed
*/
2004-01-31 23:56:22 +03:00
native numargs();
2015-02-17 19:51:56 +03:00
/**
* Retrieves an argument value passed into the currently executed function.
*
* @param arg Argument index
* @param index Index to retrieve from the argument (for arrays and strings)
*
* @return Argument value at given index
*/
native getarg(arg, index = 0);
/**
* Sets the value of an argument passed into the currently executed function.
*
* @note This is not equal to assigning a new value to a by-reference argument.
*
* @param arg Argument index
* @param index Index to set in the argument (for arrays and strings)
*/
native setarg(arg, index = 0, value);
/**
* Converts a character to lowercase.
*
* @note This is not UTF8 or locale-safe.
*
* @param c Character to convert
*
* @return Converted character
*/
2004-01-31 23:56:22 +03:00
native tolower(c);
2015-02-17 19:51:56 +03:00
/**
* Converts a character to uppercase.
*
* @note This is not UTF8 or locale-safe.
*
* @param c Character to convert
*
* @return Converted character
*/
2004-01-31 23:56:22 +03:00
native toupper(c);
2015-02-17 19:51:56 +03:00
/**
* Swaps the bytes of a value (the lowest byte becomes the highest byte).
*
* @param c Value to swap
*
* @return Byte-swapped value
*/
2004-01-31 23:56:22 +03:00
native swapchars(c);
2015-02-17 19:51:56 +03:00
/**
* Returns a random number between 0 and a specified upper bound.
*
* @param max Exclusive upper bound
*
* @return Random value
*/
2004-01-31 23:56:22 +03:00
native random(max);
2015-02-17 19:51:56 +03:00
/**
* Returns the smaller of two provided values.
*
* @param value1 Value one
* @param value2 Value two
*
* @return Smaller of the two values
*/
2004-01-31 23:56:22 +03:00
native min(value1, value2);
2015-02-17 19:51:56 +03:00
/**
* Returns the bigger of two provided values.
*
* @param value1 Value one
* @param value2 Value two
*
* @return Bigger of the two values
*/
2004-01-31 23:56:22 +03:00
native max(value1, value2);
2015-02-17 19:51:56 +03:00
/**
* Limits a provided value between two specified bounds.
*
* @param value Value to clamp
* @param min Lower bound
* @param max Upper bound
*
* @return The value if it is between the lower and upper bound, min if
* value is below, max if it is above the specified bounds.
*/
native clamp(value, min = cellmin, max = cellmax);
/**
* Returns a value raised to a specified exponent.
*
* @param value Value
* @param exponent Exponent to raise value to
*
* @return Value to the power of exponent
*/
2004-01-31 23:56:22 +03:00
native power(value, exponent);
2015-02-17 19:51:56 +03:00
/**
* Returns the approximated square root of a value.
*
* @note This uses a simple successice approximation algorithm (continuously
* dividing the value) and only deals with integers, this makes it very
* imprecise.
*
* @param value Value
*
* @return Square root of the value
*/
2004-01-31 23:56:22 +03:00
native sqroot(value);
2015-02-17 19:51:56 +03:00
/**
* Retrieves the current time in hours, minutes and seconds.
*
* @param hour Variable to store hours in
* @param minute Variable to store minutes in
* @param second Variable to store seconds in
*
* @return Unix timestamp
*/
native time(&hour = 0, &minute = 0, &second = 0);
/**
* Retrieves the current date in year, month and day.
*
* @param hour Variable to store year in
* @param minute Variable to store month in
* @param second Variable to store day in
*
* @noreturn
*/
native date(&year = 0, &month = 0, &day = 0);
2004-01-31 23:56:22 +03:00
2015-02-17 19:51:56 +03:00
/**
* Returns the elapsed CPU seconds.
*
* @note This is a debugging function that is not intended for general plugin
* use.
* @note This uses the C clock() function internally and comes with all its
* drawbacks attached.
*
* @param granularity Unused
*
* @return Number of CPU seconds elapsed
*/
native tickcount(&granularity = 0);
2005-09-08 16:58:17 +04:00
2015-02-17 19:51:56 +03:00
/**
* Returns the absolute value of a number.
*
* @param x Integral value
*
* @return Absolute value of x (x if it is greater than 0, -x otherwise)
*/
2005-09-08 16:58:17 +04:00
stock abs(x)
{
2015-02-25 00:51:36 +03:00
return x > 0 ? x : -x;
}