While testing this plugin:
PHP Code:
#include <amxmodx>
#include <engine>
#include <hamsandwich>
// random_mod(max): A small function to give a random number from 0 to max-1. Useful for get random values from arrays
#define random_mod(%1) (random_num(0, (100 * (%1)) - 1) % (%1))
new Array:g_aSpawnOrigins, Array:g_aSpawnAngles;
new g_iSpawnsCount;
public plugin_init()
{
register_plugin("[HL] Random Spawn Sort", "1.0", "Th3-822");
g_aSpawnOrigins = ArrayCreate(3);
g_aSpawnAngles = ArrayCreate(3);
}
public plugin_cfg()
{
loadSpawns();
if (g_iSpawnsCount > 1)
{
RegisterHam(Ham_Spawn, "player", "Ham_Player_Spawn_Post", 1);
}
}
loadSpawns()
{
new iEnt = get_maxplayers(), Float:fVector[3];
while ((iEnt = find_ent_by_class(iEnt, "info_player_deathmatch")))
{
entity_get_vector(iEnt, EV_VEC_origin, fVector);
ArrayPushArray(g_aSpawnOrigins, fVector);
entity_get_vector(iEnt, EV_VEC_angles, fVector);
ArrayPushArray(g_aSpawnAngles, fVector);
g_iSpawnsCount++;
}
}
is_spawn_valid(id, Float:vOrigin[3])
{
return (trace_hull(vOrigin, (get_user_flags(id) & FL_DUCKING ? HULL_HEAD : HULL_HUMAN), id, DONT_IGNORE_MONSTERS) & 2) ? 0 : 1;
}
public Ham_Player_Spawn_Post(id)
{
//if (is_user_alive(id))
//{
new iRandomSpawn = random_mod(g_iSpawnsCount), Float:fVector[3];
entity_get_vector(id, EV_VEC_origin, fVector);
server_print(" * Player %i spawned @ {%.2f, %.2f, %.2f} : is_user_alive = %i*", id, fVector[0], fVector[1], fVector[2], is_user_alive(id));
ArrayGetArray(g_aSpawnOrigins, iRandomSpawn, fVector);
if (is_spawn_valid(id, fVector))
{
entity_set_origin(id, fVector);
ArrayGetArray(g_aSpawnAngles, iRandomSpawn, fVector);
entity_set_vector(id, EV_VEC_angles, fVector);
entity_set_int(id, EV_INT_fixangle, 1);
return HAM_HANDLED;
}
//}
return HAM_IGNORED;
}
Got the following error while running it on 1.9.0.5249 (Windows):
Code:
[ENGINE] Invalid player 1 (not in-game)
[AMXX] Displaying debug trace (plugin "hl_random_spawn_sort.amxx", version "1.0")
[AMXX] Run time error 10: native error (native "trace_hull")
[AMXX] [0] hl_random_spawn_sort.sma::is_spawn_valid (line 46)
[AMXX] [1] hl_random_spawn_sort.sma::Ham_Player_Spawn_Post (line 58)
but on 1.8.2 the same plugin works fine, this happens on the first spawn when i join to the server
here are pictures from the console (i was using rehlds when i got the error, so i did had to switch to vanilla hlds to test too)
(Win) HLDS (8196) & AMXX v1.9.0.5249:

(Win) HLDS (8196) & AMXX v1.8.2:
(Win) reHLDS (3.6.0.672-dev) & AMXX v1.9.0.5249:

(Win) reHLDS (3.6.0.672-dev) & AMXX v1.8.2:
the hlds build is a couple of months old (too lazy to update it), but the issue gets noticed on the images with the server version and meta dll too (also tested with other metamod with the same)
also, i wasn't expecting is_user_alive returning 0 in Ham_Spawn_Post, but, as the result is the same as 1.9.0, i will do a workaround for it
--- Edit 1 ---
Forgot to add that, on the 1.9.0 tests, i tested both plugins: Compiled with 1.9.0 and with 1.8.2 and the issue was present on both cases (just in case)
--- Edit 2 ---
Got to test on a linux server too (just with reHLDS 3.7.0.687-dev) and it was the same result
(Linux) reHLDS (3.7.0.687-dev) & AMXX v1.9.0.5249:

(Linux) reHLDS (3.7.0.6872-dev) & AMXX v1.8.2:
--- Edit 3 ---
Solved, the issue was on 1.8.2, more info:
https://forums.alliedmods.net/showpo...87&postcount=5
If anybody wants to use the plugin, apply the workaround on the post and uncomment the "if" block