Raised This Month: $ Target: $400
 0% 

Help native error ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 12-08-2017 , 15:20   Help native error ?
Reply With Quote #1

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 Targeti
    
for(02i++)
    {
        
Target = -1
        
while((Target find_ent_by_class(TargetEntsToRemove[i])))
        {
            if(
pev_valid(Target))
            {
                
server_print("Removing %i ent[ %s ]"TargetEntsToRemove[i])
                
remove_entity(Target)
            }
        }
    }

    
//Search for info_player_team1 and info_player_team2 ents
    
new Data[EntityProp]
    
Target = -1
    
new FloatBrushOrigin[3]
    for(new 
02i++)
    {
        while((
Target find_ent_by_class(TargetEntClassnames[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(TargetBrushOrigin)
                
                
Data[EntityIndex] = Target
                Data
[EntityType] = i
                Data
[BrushEntityOrigin] = _:BrushOrigin
                ArrayPushArray
(ArrayEntsData)
            }
        }
    }

    
//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(
0EntsArraySizei++)
    {
        
ArrayGetArray(ArrayEntsiData)
        
Team Team 1
        
if(Data[EntityType] == Team)
        {
            
ArrayPushArray(TempArrayData)
        }
    }
    
    
ArrayGetArray(TempArrayrandom_num(0ArraySize(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(idSearchOrigin))
    {
        
//Teleport the player
        
set_pev(idpev_originSearchOrigin)
    }
    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 600iFloat:FoundOrigin[3]
        while(--
RestrictMaxSearches 0)
        {
            
//Get some random origins around our one
            
for(03i++)
            {
                
FoundOrigin[i] = random_float(SearchOrigin[i] - 5SearchOrigin[i] + 5)
            }
            if(
ValidSpotFound(idFoundOrigin))
            {
                
//A valid spot has been found, set player origin and stop the loop
                
set_pev(idpev_originFoundOrigin)
                break
            }
        }
    }
}

bool:ValidSpotFound(idFloat: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_TraceHullSearchOriginSearchOriginIGNORE_MONSTERSpev(idpev_flags) & FL_DUCKING HULL_HEAD HULL_HUMANidHandleGlobalTraceLine)    
    if(
get_tr2(HandleGlobalTraceLineTR_InOpen) && !(get_tr2(HandleGlobalTraceLineTR_StartSolid) || get_tr2(HandleGlobalTraceLineTR_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(TempArrayrandom_num(0ArraySize(TempArray) - 1), Data
__________________
abdobiskra is offline
Send a message via Skype™ to abdobiskra
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-08-2017 , 18:01   Re: Help native error ?
Reply With Quote #2

Looks like the array is empty.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
E1_531G
Senior Member
Join Date: Dec 2017
Old 12-08-2017 , 18:59   Re: Help native error ?
Reply With Quote #3

PHP Code:
new EntsArraySize ArraySize(ArrayEnts), Data[EntityProp], 
    
new Array: TempArray ArrayCreate(EntityProp)
for(
0EntsArraySizei++) // here, Size can be zero
    

        
ArrayGetArray(ArrayEntsiData
        
Team Team 
        
if(Data[EntityType] == Team
        { 
            
ArrayPushArray(TempArrayData// if above Size == 0, this Push was not executed
        

    } 
     
    
ArrayGetArray(TempArrayrandom_num(0ArraySize(TempArray) - 1), Data// if above Push was not execute, array is empty, what mean even index 0 don't exist (not valid for get/set) 
Should be:
Quote:
new size = ArraySize(TempArray)
if( size )
ArrayGetArray(TempArray, random_num(0, size - 1), Data)
__________________
My English is A0

Last edited by E1_531G; 12-08-2017 at 19:01.
E1_531G is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-08-2017 , 19:43   Re: Help native error ?
Reply With Quote #4

And simply random(size) instead of random_num.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 12-09-2017 , 01:53   Re: Help native error ?
Reply With Quote #5

Thanks for your rplay
But now the plugin does not work on random spawn of players.
The player can spawn in just one point of any map
This is what I've tried from your feedback :
PHP Code:
public CBasePlayer_Spawn(id)
{
    
client_print(0print_chat"Spawn has been triggered")
    
    
//Filter invalid spawns.
    
if(!is_user_alive(id))
    {
        return 
    }
    
client_print(0print_chat"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)//random_num(0, sizeof g_SoundBombExplode-1)
   // ArrayGetArray(TempArray, random(ArraySize(TempArray)), Data)
   
   
new size ArraySize(TempArray)
   if( 
size )
       
ArrayGetArray(TempArrayrandom(size), 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(idSearchOrigin))
    {
        
//Teleport the player
        
set_pev(idpev_originSearchOrigin)
    }
    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 600iFloat:FoundOrigin[3]
        while(--
RestrictMaxSearches 0)
        {
            
//Get some random origins around our one
            
for(03i++)
            {
                
FoundOrigin[i] = random_float(SearchOrigin[i] - 5SearchOrigin[i] + 5)
            }
            if(
ValidSpotFound(idFoundOrigin))
            {
                
//A valid spot has been found, set player origin and stop the loop
                
set_pev(idpev_originFoundOrigin)
                break
            }
        }
    }

__________________
abdobiskra is offline
Send a message via Skype™ to abdobiskra
E1_531G
Senior Member
Join Date: Dec 2017
Old 12-09-2017 , 09:51   Re: Help native error ?
Reply With Quote #6

The for loop must remain.
Try to find why ArrayEnts is empty.
__________________
My English is A0
E1_531G is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:18.


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