From 10d5c8e9addb6140c4b48fed3f0c729b7d81f722 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Tue, 5 Aug 2014 09:49:32 +0200 Subject: [PATCH 1/4] Add change_level() native. --- amxmodx/amxmodx.cpp | 13 +++++++++++++ plugins/admincmd.sma | 2 +- plugins/include/amxmodx.inc | 13 +++++++++++++ plugins/mapsmenu.sma | 2 +- plugins/nextmap.sma | 2 +- 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index 5dec0e6e..281eee5d 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -2574,6 +2574,18 @@ static cell AMX_NATIVE_CALL change_task(AMX *amx, cell *params) return g_tasksMngr.changeTasks(params[1], params[3] ? 0 : amx, flNewTime); } +static cell AMX_NATIVE_CALL change_level(AMX *amx, cell *params) +{ + int length; + const char* new_map = get_amxstring(amx, params[1], 0, length); + + // Same as calling "changelevel" command but will trigger "server_changelevel" AMXX forward as well. + // Filling second param will call "changelevel2" command, but this is not usable in multiplayer game. + g_pEngTable->pfnChangeLevel(new_map, NULL); + + return 1; +} + static cell AMX_NATIVE_CALL task_exists(AMX *amx, cell *params) /* 1 param */ { return g_tasksMngr.taskExists(params[1], params[2] ? 0 : amx); @@ -4838,6 +4850,7 @@ AMX_NATIVE_INFO amxmodx_Natives[] = {"callfunc_push_str", callfunc_push_str}, {"callfunc_push_array", callfunc_push_array}, {"change_task", change_task}, + {"change_level", change_level}, {"client_cmd", client_cmd}, {"client_print", client_print}, {"client_print_color", client_print_color}, diff --git a/plugins/admincmd.sma b/plugins/admincmd.sma index b233b0d3..e067b02e 100755 --- a/plugins/admincmd.sma +++ b/plugins/admincmd.sma @@ -654,7 +654,7 @@ public cmdSlap(id, level, cid) public chMap(map[]) { - server_cmd("changelevel %s", map) + change_level(map); } public cmdMap(id, level, cid) diff --git a/plugins/include/amxmodx.inc b/plugins/include/amxmodx.inc index 6c11fddd..6e7cb1a2 100755 --- a/plugins/include/amxmodx.inc +++ b/plugins/include/amxmodx.inc @@ -84,6 +84,19 @@ native precache_sound(const name[]); /* Precaches any file. */ native precache_generic(const szFile[]); +/** + * Changes map. + * + * @note This calls the pfnChangelLevel engine function. + * @note This has the same behavior as calling "changelevel" server command, + * but this will trigger properly server_changelevel() forward. + * + * @aparam map The map name to change. + * + * @noreturn + */ +native change_level(const map[]); + /* Sets info for player. */ native set_user_info(index,const info[],const value[]); diff --git a/plugins/mapsmenu.sma b/plugins/mapsmenu.sma index b07ad7bc..9375df3c 100755 --- a/plugins/mapsmenu.sma +++ b/plugins/mapsmenu.sma @@ -321,7 +321,7 @@ public cmdMapsMenu(id, level, cid) } public delayedChange(mapname[]) - server_cmd("changelevel %s", mapname) + change_level(mapname) public actionVoteMapMenu(id, key) { diff --git a/plugins/nextmap.sma b/plugins/nextmap.sma index 4af491fa..dc2fbe22 100755 --- a/plugins/nextmap.sma +++ b/plugins/nextmap.sma @@ -118,7 +118,7 @@ public delayedChange(param[]) if (g_mp_chattime) { set_pcvar_float(g_mp_chattime, get_pcvar_float(g_mp_chattime) - 2.0) } - server_cmd("changelevel %s", param) + change_level(param) } public changeMap() From c9ea68d1d3521553af9bd565f0372bfb724bcd0b Mon Sep 17 00:00:00 2001 From: Arkshine Date: Tue, 5 Aug 2014 11:41:55 +0200 Subject: [PATCH 2/4] Fix typo in documentation. --- plugins/include/amxmodx.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/include/amxmodx.inc b/plugins/include/amxmodx.inc index 6e7cb1a2..84354d75 100755 --- a/plugins/include/amxmodx.inc +++ b/plugins/include/amxmodx.inc @@ -91,7 +91,7 @@ native precache_generic(const szFile[]); * @note This has the same behavior as calling "changelevel" server command, * but this will trigger properly server_changelevel() forward. * - * @aparam map The map name to change. + * @param map The map name to change. * * @noreturn */ From e9eaae4dd1b9945bf38bb7d0df0ad7fd6e5c521e Mon Sep 17 00:00:00 2001 From: Arkshine Date: Thu, 7 Aug 2014 01:21:22 +0200 Subject: [PATCH 3/4] Fix documentation. --- plugins/include/amxmodx.inc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/include/amxmodx.inc b/plugins/include/amxmodx.inc index 84354d75..439d1a33 100755 --- a/plugins/include/amxmodx.inc +++ b/plugins/include/amxmodx.inc @@ -88,8 +88,9 @@ native precache_generic(const szFile[]); * Changes map. * * @note This calls the pfnChangelLevel engine function. - * @note This has the same behavior as calling "changelevel" server command, - * but this will trigger properly server_changelevel() forward. + * @note This has the same behavior as calling the "changelevel" server command,, + * but this will also trigger the server_changelevel() forward in AMXX plugins. + * It will also notify any Metamod plugins that are hooking pfnChangeLevel. * * @param map The map name to change. * From 58b6f9f3538f4686da40d9606b237d2136f2803e Mon Sep 17 00:00:00 2001 From: Arkshine Date: Thu, 7 Aug 2014 01:26:05 +0200 Subject: [PATCH 4/4] fix the documentation. How it's possible to not see a double comma! --- plugins/include/amxmodx.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/include/amxmodx.inc b/plugins/include/amxmodx.inc index 439d1a33..2d6604cc 100755 --- a/plugins/include/amxmodx.inc +++ b/plugins/include/amxmodx.inc @@ -88,7 +88,7 @@ native precache_generic(const szFile[]); * Changes map. * * @note This calls the pfnChangelLevel engine function. - * @note This has the same behavior as calling the "changelevel" server command,, + * @note This has the same behavior as calling the "changelevel" server command, * but this will also trigger the server_changelevel() forward in AMXX plugins. * It will also notify any Metamod plugins that are hooking pfnChangeLevel. *