AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   AMXx 1.60 Scripting Changes (https://forums.alliedmods.net/showthread.php?t=17885)

BAILOPAN 09-11-2005 02:01

AMXx 1.60 Scripting Changes
 
Upcoming AMX Mod X 1.60 will have a few scripting changes which will greatly improve the power and flexibility of plugins. The Dark Ages of Small are diminishing as AMX Mod X introduces primitive exception handling, control over the module/native system, and client-cvar querying.

Error Filters
Plugins can now trap errors that occur, blocking the debugger/RTE message, and then decide how to handle it. Furthermore, they have access to their own stack traces (which include function names, line numbers, and file names). An example of this is here:

Code:
public plugin_init() {     set_error_filter("error_filter") } public error_filter(err, debugging, msg[]) {     new buffer[512]     dbg_fmt_error(buffer, 511)     if (buffer[0])         server_print("Debug msg: %s", buffer)     if (!debugging)         return PLUGIN_HANDLED     new trace = dbg_trace_begin()     if (!trace)     {         server_print("no trace found!")         return PLUGIN_HANDLED     }         new num = 0     new func[32], file[64], line     while (trace) {         dbg_trace_info(trace, line, func, 31, file, 63)         server_print(" [%d] file: %s func: %s line: %d", num++, file, func, line)         trace = dbg_trace_next(trace)     }         return PLUGIN_HANDLED }

Furthermore, debug traces are now much more informative. Especially with array bounds, error messages are extremely detailed:
Code:

] amx_test
L 09/11/2005 - 00:37:59: [AMXX] Displaying debug trace (plugin "test.amxx")
L 09/11/2005 - 00:37:59: [AMXX] Run time error 4: index out of bounds (array "mylist[2][3][4]") (indexed "[1][2][60]")
L 09/11/2005 - 00:37:59: [AMXX]    [0] test.sma::amx_test (line 24)

(Note the array bounds reporting system is a non-deterministic guess, and if it thinks it will guess incorrectly, does not attempt to report array sizes)

Native/Module Filtering System
With AMX Mod X 1.60, you have total control over the auto-module require system. The biggest usage is that you can make your plugins load even if they use natives or modules that don't exist -- or you can override the errors that occur if they don't.

The two best applications of this system are:
1. You have a plugin that supports different modules doing the same thing. For example, you have a #define between CSTRIKE/DOD or VAULT/NVAULT/MYSQL. You can eliminate the need for the #defines by using native+module filters. Your plugin will load even when a certain module doesn't exist and the natives aren't there. Or, a module could add specific enhancements that aren't required. The filtering system makes it optional without two compiled versions.

2. You have a plugin and users somehow don't understand the "check your modules.ini" message. This allows you to override that message with something somehow more informative.

This system is best seen in PLMENU. In AMX Mod X 1.55, PLMENU used #define CSTRIKE to switch in between mod versions. In 1.60, it uses the filtering system:

Code:
new g_cstrike = 0 public plugin_natives() {     set_module_filter("module_filter")     set_native_filter("native_filter") } public module_filter(const module[]) {     if (equali(module, "cstrike"))         return PLUGIN_HANDLED     return PLUGIN_CONTINUE } public native_filter(const name[], index, trap) {     if (!trap)         return PLUGIN_HANDLED             return PLUGIN_CONTINUE } public plugin_init() {     //code     if (module_exists("cstrike"))         g_cstrike = 1 } public some_event(id) {     new team     if (g_cstrike)         team = cs_get_user_team(id)     else         team = get_user_team(id) }
This plugin will load and run even if the CSTRIKE module is not loaded!

Client CVAR Querying
PM OnoTo has added a client cvar querying system to AMX Mod X! This means plugins can now find out the exact values of a cvar on a client.

For a good example of this, you can see PM's excellent CVAR Rules plugin (unreleased) that lets you define rules for the boundaries of client cvars.

An example:
Code:
public getInterp(id, const cvar[], const value[]) {     server_print("Client %d's cvar %s has value: %s", id, cvar, value) } public client_putinserver(id) {     query_client_cvar(id, "ex_interp", getInterp) }

Check out the funcwiki entry for query_client_cvar for more info.

Also two new natives have been added to string.inc: float_to_str and str_to_float.

If you have any questions, feel free to post here!

Freecode 09-11-2005 02:06

i gave him the idea ladies and gentlmen :D

BAILOPAN 09-11-2005 02:07

;] no, #2 is a direct consequence of [gh]ferret asking if plugins could use modules and still load without them. The rest is random things we thought were good ideas while fixing up 1.55

{NM}Jason 09-11-2005 02:07

keep up the good work ..!

atambo 09-11-2005 02:10

we need a super duper nvault :? where are you Suzuka? :P

Greentryst 09-11-2005 02:11

Quote:

Originally Posted by Freecode
i gave him the idea ladies and gentlmen :D

HELLO LADIES!

FeuerSturm 09-11-2005 07:44

awsome news guys!

can't await to have 1.60 on the desk as there's already a bunch of fixes
(like the ones in DoDx module) that a lot of serveradmins need
(and so stop complaining about my plugins not working correctly :evil: ).

keep up the great work! 8)

v3x 09-11-2005 12:01

Good job, I wanted those last 2 natives mentioned. :D

Hawk552 09-11-2005 13:04

Will 1.60 be a stable or beta release? (Since there's no other real topics about it)

BAILOPAN 09-11-2005 13:13

Yes, it will be stable or beta.


All times are GMT -4. The time now is 08:39.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.