Raised This Month: $ Target: $400
 0% 

native error


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Closer456
Member
Join Date: May 2013
Old 06-03-2013 , 21:22   native error
Reply With Quote #1

Can someone tell me whats wrong here?

PHP Code:
L 06/03/2013 21:18:01: [AMXXDisplaying debug trace (plugin "map_weapons_manager.amxx")
L 06/03/2013 21:18:01: [AMXXRun time error 10native error (native "pev"
L 06/03/2013 21:18:01: [AMXX]    [018309.attach::respawn_weapon (line 354
L 06/03/2013 21:18:01: [FAKEMETAInvalid entity 
Line 354:
PHP Code:
public respawn_weapon(arraypos// This is line 354 in amxx studio..
{
    if (
g_NewIndexList[arraypos] && fm_get_entity_visibility(g_NewIndexList[arraypos]))
        return
    else if (
pev_valid(g_NewIndexList[arraypos])) 
        
fm_remove_entity(g_NewIndexList[arraypos])
    new 
ent create_armoury_entity(g_ItemList[arraypos],g_CountList[arraypos],g_OriginList[arraypos])
    if (
pev_valid(ent)) {
        
g_NewIndexList[arraypos] = ent
    
}
    return

Full code:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>

#define MAX_ENTITIES 100
#define MAX_CREATED_ENTITIES MAX_ENTITIES / 2


// ----------FAKEMETA_UTIL----------------
#define fm_remove_entity(%1) engfunc(EngFunc_RemoveEntity, %1)
#define fm_create_entity(%1) engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, %1))
#define fm_get_entity_visibility(%1) (!(pev(%1, pev_effects) & EF_NODRAW))
#define fm_DispatchSpawn(%1) dllfunc(DLLFunc_Spawn, %1)
#define fm_find_ent_in_sphere(%1,%2,%3) engfunc(EngFunc_FindEntityInSphere, %1, %2, %3)

stock fm_entity_set_origin(index, const Float:origin[3]) {
    new 
Float:mins[3], Float:maxs[3]
    
pev(indexpev_minsmins)
    
pev(indexpev_maxsmaxs)
    
engfunc(EngFunc_SetSizeindexminsmaxs)

    return 
engfunc(EngFunc_SetOriginindexorigin)
}

stock fm_set_kvd(entity, const key[], const value[], const classname[] = "") {
    if (
classname[0])
        
set_kvd(0KV_ClassNameclassname)
    else {
        new class[
32]
        
pev(entitypev_classname, class, sizeof class - 1)
        
set_kvd(0KV_ClassName, class)
    }

    
set_kvd(0KV_KeyNamekey)
    
set_kvd(0KV_Valuevalue)
    
set_kvd(0KV_fHandled0)

    return 
dllfunc(DLLFunc_KeyValueentity0)
}
// --------------------------------------
new cvar_on
new cvar_time

new g_IndexList[MAX_ENTITIES]
new 
g_IndexListSize 0
new g_CountList[MAX_ENTITIES]
new 
g_ItemList[MAX_ENTITIES]
new 
Float:g_OriginList[MAX_ENTITIES][3]
new 
g_LastEnt

new g_NewIndexList[MAX_ENTITIES]

new 
Float:g_TimeList[19]

new 
g_LineList[MAX_ENTITIES]
new 
g_LineSize 0

new g_WeaponNames[19][] = {
    
"MP5",
    
"TMP",
    
"P90",
    
"MAC10",
    
"AK47",
    
"SG552",
    
"M4A1",
    
"AUG",
    
"Scout",
    
"G3SG1",
    
"AWP",
    
"M3",
    
"XM1014",
    
"M249",
    
"Flashbang",
    
"HE Grenade",
    
"Kevlar",
    
"Kevlar + Helmet",
    
"Smoke Grenade"
}

new 
g_ConfigsDir[64]
new 
g_MapName[32]

public 
plugin_precache() {
    
register_forward(FM_KeyValue,"log_weapons")
}

public 
plugin_init() {
    
register_plugin("Weapon Respawner","1.0","danielkza")
    
    
cvar_on register_cvar("weapon_respawn","1")
    
cvar_time register_cvar("weapon_respawn_time","10.0")
    
    
copy(g_NewIndexList,sizeof g_IndexList,g_IndexList)
    
register_forward(FM_Touch,"touch")
    
register_clcmd("weapon_create","createspawn_cmd",ADMIN_RCON,"<weapon_name count> - Creates a permanent weapon spawn of given weapon name on your current position")
    
register_clcmd("weapon_delete","removespawn_cmd",ADMIN_RCON,"Removes closest weapon spawn.Be careful:original map weapons can only be restored manually"
    for(new 
i=0;i<g_IndexListSize;i++) {
        
pev(g_IndexList[i],pev_origin,g_OriginList[i])
    }
}

public 
plugin_cfg() {
    
arrayset(g_LineList,-1,sizeof g_LineList)
    new 
filename[90]
    
get_configsdir(g_ConfigsDir,63)
    
get_mapname(g_MapName,31)
    
    
format(filename,99,"%s/weapons",g_ConfigsDir)
    if (!
dir_exists(filename))
        
mkdir(filename)
    
    
format(filename,89,"%s/weapons/RespawnTimes.cfg",g_ConfigsDir)
    new 
linestr[64],weapstr[20],i,file
    
if(!file_exists(filename)) {
        
file fopen(filename,"w+")
        for(
i=0;sizeof g_WeaponNames;i++) {
            
fprintf(file,"^"%s^" ^"default^"^n",g_WeaponNames[i])
        }
        
fclose(file)
    }
    else {
        new 
timestr[20],weapnum
        file 
fopen(filename,"r")
        if (!
file)
            
server_print("[AMXX] Error: can't read file %s",filename)
        while((
fgets(file,linestr,63))) {
            
replace(linestr,sizeof linestr,"^n","")
            
parse(linestr,weapstr,19,timestr,19)
            if(!
equali(timestr,"default")) {
                
weapnum find_string_in_array(weapstr,g_WeaponNames,sizeof g_WeaponNames)
                if(
weapnum > -1)
                    
g_TimeList[weapnum] = str_to_float(timestr)
            }
        }
        
fclose(file)
    }

    
format(filename,89,"%s/weapons/%s.cfg",g_ConfigsDir,g_MapName)
    if(
file_exists(filename)) {
        new 
countstr[4],x[16],y[16],z[16],Float:origin[3],line
        file 
fopen(filename,"r")
        
        while((
fgets(file,linestr,63)) && g_IndexListSize MAX_ENTITIES) {
            
replace(linestr,sizeof linestr,"^n","")
            
parse(linestr,weapstr,19,countstr,3,x,15,y,15,z,15)
            
            new 
weapnum find_string_in_array(weapstr,g_WeaponNames,sizeof g_WeaponNames)
            if (
weapnum == -1)
                
server_print("[AMXX] Error parsing custom spawn: Weapon %s not found",weapstr)
            else {
                
origin[0] = str_to_float(x)
                
origin[1] = str_to_float(y)
                
origin[2] = str_to_float(z)
                
                
createspawn(weapnum,str_to_num(countstr),origin,line++)
                
            }
        }
        
fclose(file)
    }
}

public 
log_weapons(entKVD_Handle) {
    
// Skip Players and check if entity is valid
    
if (g_IndexListSize >= MAX_ENTITIES || ent <= get_maxplayers() || !pev_valid(ent))
        return 
FMRES_IGNORED
        
    
// Start reading of KeyValues
    
static class[32]
    
    
get_kvd(KVD_HandleKV_ClassName, class,31)
    
    
// Too Obvious
    
if (!equali(class, "armoury_entity"))
        return 
FMRES_IGNORED
    
    
static key[32], value[32
    new 
numvalue
    
    
// Check if entity's index hasn't been logged yet
    // and if negative, do it
    
if (ent != g_LastEnt) {
        if(
g_LastEnt 0)
            
g_IndexList[++g_IndexListSize] = ent
        
else
            
g_IndexList[g_IndexListSize] = ent
        g_LastEnt 
ent
    
}
    
    
get_kvd(KVD_HandleKV_KeyNamekey31)
    
get_kvd(KVD_HandleKV_Valuevalue31)
    
numvalue str_to_num(value)
    
    
// Log the keys and values of the weapons to an array
    
if (equali(key,"count",5)) {
        
g_CountList[g_IndexListSize] = numvalue
    
}
    
    if(
equali(key,"item",4)) {
        
g_ItemList[g_IndexListSize] = numvalue
    
}
    

    
    return 
FMRES_IGNORED
}

public 
createspawn_cmd(id,level,cid) {
    if(!
cmd_access(id,level,cid,3))
        return 
PLUGIN_HANDLED
    
    
if(g_IndexListSize >= MAX_ENTITIES) {
        
client_print(id,print_console,"Error: Max spawns reached.Try deleting others to create more.")
        return 
PLUGIN_HANDLED
    
}
    new 
weaponarg[20],weaponcount[8],count,weapnum
    read_argv
(1,weaponarg,19)
    
read_argv(2,weaponcount,7)
    
    
count=str_to_num(weaponcount)
    
    
weapnum find_string_in_array(weaponarg,g_WeaponNames,sizeof g_WeaponNames)
    if (
weapnum == -1) {
        
client_print(id,print_console,"[AMXX] Error: Weapon not found")
        return 
PLUGIN_HANDLED
    
}
    
    if (!
is_user_connected(id))
        return 
PLUGIN_HANDLED
        
    
new Float:origin[3]    
    
pev(id,pev_origin,origin)
    
    
createspawn(weapnum,count,origin,g_LineSize)
    
    new 
filename[100],linestr[100]

    
format(filename,99,"%s/weapons/%s.cfg",g_ConfigsDir,g_MapName)
    
format(linestr,100,"^"%s^" %d %f %f %f",g_WeaponNames[weapnum],count,origin[0],origin[1],origin[2])
    
    
write_file(filename,linestr,-1)
    
client_print(id,print_console,"Weapon %s created sucessfully",g_WeaponNames[weapnum])
    
    return 
PLUGIN_HANDLED
}

public 
createspawn(weapnum,count,Float:origin[3],line) {
    new 
ent create_armoury_entity(weapnum,count,origin)
    if (!
ent) return 0
    
else {
        
g_LineList[g_IndexListSize] = line
        g_LineSize
++
        
        
g_NewIndexList[g_IndexListSize] = ent
        g_ItemList
[g_IndexListSize] = weapnum
        g_CountList
[g_IndexListSize] = count
        g_OriginList
[g_IndexListSize++] = origin
    
}
    return 
ent
}

public 
removespawn_cmd(id,level,cid) {
    if(!
cmd_access(id,level,cid,0))
        return 
PLUGIN_HANDLED

    
if (!is_user_connected(id))
        return 
PLUGIN_HANDLED
        
    
new Float:origin[3]    
    
pev(id,pev_origin,origin)
    
    new 
ent,arraypos,filename[100]
    
format(filename,99,"%s/weapons/%s.cfg",g_ConfigsDir,g_MapName)
    
    while((
ent=fm_find_ent_in_sphere(ent,origin,50.0))) {
        if((
arraypos=find_int_in_array(ent,g_NewIndexList,g_IndexListSize)) != -1) {
            if (
g_LineList[arraypos] > -1) {
                
write_file(filename,"",g_LineList[arraypos])
                
fm_remove_entity(g_NewIndexList[arraypos])
            }
            else {
                
client_print(id,print_console,"[AMXX] Error: You can only delete weapons created by the plugin")
                return 
PLUGIN_HANDLED
            
}
                    
            for(new 
i=arraypos+1;g_IndexListSize;i++) {
                
g_NewIndexList[i-1] = g_NewIndexList[i]
            }
            
g_NewIndexList[g_IndexListSize--] = 0
            client_print
(id,print_console,"[AMXX] Weapon deleted sucessfully")
            return 
PLUGIN_HANDLED
        
}
    }
    
    
client_print(id,print_console,"[AMXX] No plugin-created weapon spawns near enough")
    
    return 
PLUGIN_HANDLED
}

public 
touch(touched,toucher) {
    if (!
get_pcvar_num(cvar_on) || !pev_valid(touched) || !pev_valid(toucher))
        return 
FMRES_IGNORED
        
    
new class[32]
    
pev(touched,pev_classname,class,31)
    if (!
equali(class,"armoury_entity") && !equali(class,"item_kevlar") && !equali(class,"item_assaultsuit")) {
        return 
FMRES_IGNORED
    
}
    
    new 
arraypos find_int_in_array(touched,g_NewIndexList,g_IndexListSize)
    if (
arraypos == -1) return FMRES_IGNORED
    
    
new Float:time
    
if(!(time=g_TimeList[g_ItemList[arraypos]]))    
        
time get_pcvar_float(cvar_time)    

    
set_task(time,"respawn_weapon",arraypos)
    return 
FMRES_IGNORED
}

public 
create_armoury_entity(item,count,Float:origin[3]) {
    new 
ent,item_string[3],count_string[4]
    
ent fm_create_entity("armoury_entity")
    if (!
pev_valid(ent)) 
        return 
0
    num_to_str
(item,item_string,2)
    
num_to_str(count,count_string,3)
    
fm_set_kvd(ent,"item",item_string,"armoury_entity")
    
fm_set_kvd(ent,"count",count_string,"armoury_entity")
    
fm_DispatchSpawn(ent)
    
fm_entity_set_origin(ent,origin)
    return 
ent
}

public 
find_int_in_array(num,array[],len) {
    for(new 
i=0;len;i++) {
        if (array[
i] == num) {
            return 
i
        
}
    }
    return -
1
}

public 
find_string_in_array(string[],array[][],len) {
    for(new 
i=0;len;i++) {
        if (
equali(array[i],string)) {
            return 
i
        
}
    }
    return -
1
}

public 
respawn_weapon(arraypos
{
    if (
g_NewIndexList[arraypos] && fm_get_entity_visibility(g_NewIndexList[arraypos]))
        return
    else if (
pev_valid(g_NewIndexList[arraypos])) 
        
fm_remove_entity(g_NewIndexList[arraypos])
    new 
ent create_armoury_entity(g_ItemList[arraypos],g_CountList[arraypos],g_OriginList[arraypos])
    if (
pev_valid(ent)) {
        
g_NewIndexList[arraypos] = ent
    
}
    return


Last edited by Closer456; 06-03-2013 at 21:44.
Closer456 is offline
 



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 16:25.


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