Hi
There is a problem with this plugin but I would like some help to fix it
So you can replace the line that contains the problem .. Or maybe change the function of the plugin in full ..
In fact, I have no idea how to fix the bugs
Any help please!!
PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <hamsandwich>
enum _:EntityProp
{
EntityIndex,
EntityType,
Float:BrushEntityOrigin[3]
}
new const EntsToRemove[][] =
{
"info_player_deathmatch",
"info_player_start"
}
new const EntClassnames[][] =
{
"info_player_team1",
"info_player_team2"
}
new Array:ArrayEnts
public plugin_init()
{
ArrayEnts = ArrayCreate(EntityProp)
//Remove ents
new Target, i
for(i = 0; i < 2; i++)
{
Target = -1
while((Target = find_ent_by_class(Target, EntsToRemove[i])))
{
if(pev_valid(Target))
{
server_print("Removing %i ent[ %s ]", Target, EntsToRemove[i])
remove_entity(Target)
}
}
}
//Search for info_player_team1 and info_player_team2 ents
new Data[EntityProp]
Target = -1
new Float: BrushOrigin[3]
for(new i = 0; i < 2; i++)
{
while((Target = find_ent_by_class(Target, EntClassnames[i])))
{
//Found a valid entity
if(pev_valid(Target))
{
//Save it's index, type(for t or ct) and origin
//Push everything in the array
get_brush_entity_origin(Target, BrushOrigin)
Data[EntityIndex] = Target
Data[EntityType] = i
Data[BrushEntityOrigin] = _:BrushOrigin
ArrayPushArray(ArrayEnts, Data)
}
}
}
//Hook spawn
RegisterHam(Ham_Spawn, "player", "CBasePlayer_Spawn", true)
}
public plugin_end()
{
//Destroy the array to free memory
ArrayDestroy(ArrayEnts)
}
public CBasePlayer_Spawn(id)
{
server_print("Spawn has been triggered")
//Filter invalid spawns.
if(!is_user_alive(id))
{
return
}
server_print("Player is succesfully spawned")
new Team = get_user_team(id)
new EntsArraySize = ArraySize(ArrayEnts), Data[EntityProp], i
new Array: TempArray = ArrayCreate(EntityProp)
for(i = 0; i < EntsArraySize; i++)
{
ArrayGetArray(ArrayEnts, i, Data)
Team = Team - 1
if(Data[EntityType] == Team)
{
ArrayPushArray(TempArray, Data)
}
}
ArrayGetArray(TempArray, random_num(0, ArraySize(TempArray) - 1), Data)
ArrayDestroy(TempArray)//done with that array, destroy it
new Float:SearchOrigin[3]
SearchOrigin = Data[BrushEntityOrigin]
//Check if the origin that we have is empty
if(ValidSpotFound(id, SearchOrigin))
{
//Teleport the player
set_pev(id, pev_origin, SearchOrigin)
}
else
{
//If the sport is not free we need to do some searches
//I've set the max searches to 300, you can increase it if it's found nothing and fail to teleport the player
new RestrictMaxSearches = 600, i, Float:FoundOrigin[3]
while(--RestrictMaxSearches > 0)
{
//Get some random origins around our one
for(i = 0; i < 3; i++)
{
FoundOrigin[i] = random_float(SearchOrigin[i] - 5, SearchOrigin[i] + 5)
}
if(ValidSpotFound(id, FoundOrigin))
{
//A valid spot has been found, set player origin and stop the loop
set_pev(id, pev_origin, FoundOrigin)
break
}
}
}
}
bool:ValidSpotFound(id, Float:SearchOrigin[3])
{
//Send a TraceHull to check if the spot that we found is empty
//Return true if found
//False otherwise
new HandleGlobalTraceLine
engfunc(EngFunc_TraceHull, SearchOrigin, SearchOrigin, IGNORE_MONSTERS, pev(id, pev_flags) & FL_DUCKING ? HULL_HEAD : HULL_HUMAN, id, HandleGlobalTraceLine)
if(get_tr2(HandleGlobalTraceLine, TR_InOpen) && !(get_tr2(HandleGlobalTraceLine, TR_StartSolid) || get_tr2(HandleGlobalTraceLine, TR_AllSolid)))
{
return true
}
return false
}
Quote:
L 12/07/2017 - 108:01: Start of error session.
L 12/07/2017 - 108:01: Info (map "agctf_duff") (file "addons/amxmodx/logs/error_20171207.log")
L 12/07/2017 - 108:01: Invalid index 0 (count: 0)
L 12/07/2017 - 108:01: [AMXX] Displaying debug trace (plugin "team_spawn.amxx", version "unknown")
L 12/07/2017 - 108:01: [AMXX] Run time error 10: native error (native "ArrayGetArray")
L 12/07/2017 - 108:01: [AMXX] [0] team_spawn.sma::CBasePlayer_Spawn (line 104)
|
line 104 :
PHP Code:
ArrayGetArray(TempArray, random_num(0, ArraySize(TempArray) - 1), Data)
__________________