Raised This Month: $51 Target: $400
 12% 

[?]Invalid entity error!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
heliumdream
Senior Member
Join Date: Aug 2006
Old 01-21-2007 , 16:44   [?]Invalid entity error!
Reply With Quote #1

Yoski - me again. Hopefully this will be another short and sweet lesson in coding. I've fixed up all my out of bounds errors, and now I still have other persisting errors. The next one I'm tackling is this...
Code:
L 01/21/2007 - 15:27:52: [ENGINE] Invalid entity 27
L 01/21/2007 - 15:27:52: [AMXX] Displaying debug trace (plugin "sh_frieza.amxx")
L 01/21/2007 - 15:27:52: [AMXX] Run time error 10: native error (native "entity_set_vector")
L 01/21/2007 - 15:27:52: [AMXX]    [0] sh_frieza.sma::frieza_disklife (line 158)
Code:
//----------------------------------------------------------------------------------------
public frieza_disklife(){ 
    for(new id = 1; id <= SH_MAXSLOTS; id++){ 
        if(g_hasfriezaPowers[id] && is_user_alive(id)){ 
            if(diskTimer[id] > 0){ 
                diskTimer[id]-- 
                new Float: fVelocity[3]
                //gets the velocity by the direction you are looking at
                velocity_by_aim(id, get_cvar_num("frieza_diskspeed"), fVelocity)
                //sets the new velocity
                // ----* Line 158 Below *-----
                entity_set_vector(disk[id], EV_VEC_velocity, fVelocity)
            } 
            else if(diskTimer[id] == 0){
                new Float: fOrigin[3]
                new origin[3]
                //gets the current position of entity
                entity_get_vector(disk[id], EV_VEC_origin, fOrigin)
                //converts a floating vector to an integer vector
                FVecIVec(fOrigin, origin)
                decay_effects(disk[id], origin)
                diskTimer[id]-- 
            } 
        } 
    } 
} 
//----------------------------------------------------------------------------------------
I've attached the entire script if that is needed.

Thank in advance to all the sharks out there. xD
Attached Files
File Type: sma Get Plugin or Get Source (sh_frieza.sma - 899 views - 11.9 KB)
heliumdream is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 01-21-2007 , 20:46   Re: [?]Invalid entity error!
Reply With Quote #2

It looks like for some reason the script is failing to create an entity, it's being called at the wrong time, or the disk is destroyed and the timer is was never stopped (the latter is the most likely and it appears to be that way in the script). Try setting diskTimer[id] = 0 when the disk touches something, also be sure to remove_entity() on it.

Also just for protection:
Code:
// Be sure to replace myEnt with the correct variable. if (is_valid_ent(myEnt))      log_amx("Invalid entity detected (%d)", myEnt);

Just post that above the line and tell me what happens.

Another bug that I can see:
Code:
if(pTouched == entity_get_edict(pToucher, EV_ENT_owner) && diskTimer[pTouched] > self_immune)     return PLUGIN_HANDLED

This is online 261. It looks as if this is the code used to create self immunity for 0.2 seconds (or w/e self immune is set to). However, as you can see it's not checking if the timer is still withing the self_immune time meaning that it will actually provide immunity past 0.2 seconds (or self immune). The greater than check should be change to a less than check or at the very best a less than or equal to check ('<=').
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
heliumdream
Senior Member
Join Date: Aug 2006
Old 01-22-2007 , 02:02   Re: [?]Invalid entity error!
Reply With Quote #3

Here's muh new stuff...I can't tell if it's getting better or worse.
Code:
L 01/21/2007 - 22:31:10: [ENGINE] Invalid entity 149
L 01/21/2007 - 22:31:10: [AMXX] Displaying debug trace (plugin "sh_frieza.amxx")
L 01/21/2007 - 22:31:10: [AMXX] Run time error 10: native error (native "entity_get_vector")
L 01/21/2007 - 22:31:10: [AMXX]    [0] sh_frieza.sma::frieza_disklife (line 165)
L 01/21/2007 - 22:40:43: [ENGINE] Invalid player 0 (not in-game)
L 01/21/2007 - 22:40:43: [AMXX] Displaying debug trace (plugin "sh_frieza.amxx")
L 01/21/2007 - 22:40:43: [AMXX] Run time error 10: native error (native "entity_get_vector")
L 01/21/2007 - 22:40:43: [AMXX]    [0] sh_frieza.sma::touch_event (line 275)
Code:
//Frieza 

#include <amxmodx> 
#include <superheromod> 
#include <engine>   

/*THE CVARS TO COPY AND PASTE IN SHCONFIG.CFG
//Frieza
frieza_level 10
frieza_damage 200
frieza_cooldown 50
frieza_diskspeed 750
frieza_disklife 50
*/

/*    Version 1.0:  The hero is born.
    Version 1.1:  Made the disk position right in front of user, and added
              0.2 seconds of immunity. Since many people have IMed me complaining
              about when they fire the disk at an incline it kills them.  So 
              this version will fix that problem up.

*/

new gHeroName[] = "Frieza" 
new bool:g_hasfriezaPowers[SH_MAXSLOTS+1] 
new diskTimer[SH_MAXSLOTS+1] 
//This variable will represent the disk being made. 
new disk[SH_MAXSLOTS+1]
new flash
//------------------------------------------------------------------------------------ 
public plugin_init() 
{ 
    //Special thanks to avalanche for helping me to debug my hero.
    register_plugin("SUPERHERO frieza", "1.1", "Gorlag/Batman  /  XxAvalanchexX") 

    //THE CVARS 
    register_cvar("frieza_level", "10") 
    register_cvar("frieza_damage", "200")  
    register_cvar("frieza_cooldown", "50") 
    register_cvar("frieza_diskspeed", "750") 
    register_cvar("frieza_disklife", "50") 

    //THIS LINE MAKES THE HERO SELECTABLE 
    shCreateHero(gHeroName, "Energy Disk", "Unleash an energy disk and take control of where it flies!", true, "frieza_level") 

    //INITIAL ACTIONS 
    register_srvcmd("frieza_init", "frieza_init") 
    shRegHeroInit(gHeroName, "frieza_init") 

    //KEY DOWN COMMAND 
    register_srvcmd("frieza_kd", "frieza_kd") 
    shRegKeyDown(gHeroName, "frieza_kd") 

    //SPAWNING EVENT 
    register_event("ResetHUD", "newSpawn", "b") 

    //THIS EVENT IS TRIGGERED WHEN SOMEONE DIES
    register_event("DeathMsg", "frieza_kill", "a")

    //SET THE LIFE OF THE DISK 
    set_task(0.1, "frieza_disklife", 0, "", 0, "b") 

    //REGISTERS A TOUCH EVENT, WHEN TWO THINGS TOUCH
    register_touch("disk", "*", "touch_event")
} 
//-------------------------------------------------------------------------------------- 
public plugin_precache() 
{ 
    precache_model("models/shmod/frieza_friezadisc.mdl") 
    precache_sound("shmod/frieza_destructodisc.wav") 
    flash = precache_model("sprites/muzzleflash2.spr")
} 
//--------------------------------------------------------------------------------------- 
public frieza_init() 
{ 
    new temp[6] //To store temporary information 

    //First Argument is the id of the player 
    read_argv(1,temp,5) //Converts the string to a number 
    new id = str_to_num(temp) //gets the id of the player

    //Second Argument is either 0 or 1 depending on whether the person has the hero or not 
    read_argv(2,temp,5) 
    new hasPowers = str_to_num(temp) //Makes the string into a number 
    g_hasfriezaPowers[id] = (hasPowers != 0) //tells if player has power or not

    if(hasPowers){
    disk[id] = 0
        diskTimer[id] = -1 
    }

    if(!hasPowers && diskTimer[id] > 0){ //When a player doesn't have power anymore
        diskTimer[id] = -1
        new Float: fOrigin[3]
    new origin[3]
    if(is_valid_ent(disk[id])){
        entity_get_vector(disk[id], EV_VEC_origin, fOrigin)
        FVecIVec(fOrigin, origin)
        decay_effects(disk[id], origin)
    }
    } 

} 
//--------------------------------------------------------------------------------------- 
public frieza_kd() 
{ 
    if(!hasRoundStarted()) return 

    new temp[6] 

    //Get the id of the player 
    read_argv(1,temp,5) 
    new id = str_to_num(temp) //the player id

    if(!is_user_alive(id) || !g_hasfriezaPowers[id]) return 

    if(gPlayerUltimateUsed[id]){ 
        playSoundDenySelect(id) 
        return 
    } 
    diskTimer[id] = get_cvar_num("frieza_disklife") //How long the disk can fly

    fire_disk(id) 

    if(get_cvar_float("frieza_cooldown") > 0.0) 
        ultimateTimer(id, get_cvar_float("frieza_cooldown")) //cooldown timer
} 
//---------------------------------------------------------------------------------------- 
public newSpawn(id) 
{ 
    gPlayerUltimateUsed[id] = false  //Makes you able to use power again 
} 
//---------------------------------------------------------------------------------------- 
public frieza_kill()  //triggered everytime someone dies
{
    new id = read_data(2)  //This tells who the victim is
    if(g_hasfriezaPowers[id] && diskTimer[id] > 0){
        diskTimer[id] = -1
        new Float: fOrigin[3]
        new origin[3]
        //gets current position of entity
        entity_get_vector(disk[id], EV_VEC_origin, fOrigin)
        //converts a floating vector into an integer vector
        FVecIVec(fOrigin, origin)
        decay_effects(disk[id], origin)
    }
}
//----------------------------------------------------------------------------------------
public frieza_disklife()
{ 
    for(new id = 1; id <= SH_MAXSLOTS; id++){ 
        if(g_hasfriezaPowers[id] && is_user_alive(id)){ 
            if(diskTimer[id] > 0){ 
                diskTimer[id]-- 
                new Float: fVelocity[3]
                //gets the velocity by the direction you are looking at
                velocity_by_aim(id, get_cvar_num("frieza_diskspeed"), fVelocity)
                //sets the new velocity
                entity_set_vector(disk[id], EV_VEC_velocity, fVelocity)
            } 
            else if(diskTimer[id] == 0){
                new Float: fOrigin[3]
                new origin[3]
                //gets the current position of entity
                //*------Line 165 Below------*
                entity_get_vector(disk[id], EV_VEC_origin, fOrigin)
                //converts a floating vector to an integer vector
                FVecIVec(fOrigin, origin)
                decay_effects(disk[id], origin)
                diskTimer[id]-- 
            } 
        } 
    } 
} 
//----------------------------------------------------------------------------------------
public fire_disk(id) 
{   //makes sure that the number of entities created does not exceed the maximum amount
    //of entities allowed
    if(entity_count() == get_global_int(GL_maxEntities)){
    client_print(id, print_chat, "[SH] Cannot create more entities")
    return
    } 

    //Makes an array of origin in the (x,y,z) coordinate system.
    new origin[3]

    //Makes an array of velocity, specifically in the (x,y,z) coordinate system 
    new velocity[3] 

    new Float:fOrigin[3], Float:fVelocity[3]
    get_user_origin(id, origin, 1)
    new Float: minBound[3] = {-50.0, -50.0, 0.0}  //sets the minimum bound of entity
    new Float: maxBound[3] = {50.0, 50.0, 0.0}    //sets the maximum bound of entity
    IVecFVec(origin, fOrigin)

    //This will make it so that the disk appears in front of the user
    new Float:viewing_angles[3]
    new distance_from_user = 70
    entity_get_vector(id, EV_VEC_angles, viewing_angles)
    fOrigin[0] += floatcos(viewing_angles[1], degrees) * distance_from_user
    fOrigin[1] += floatsin(viewing_angles[1], degrees) * distance_from_user
    fOrigin[2] += floatsin(-viewing_angles[0], degrees) * distance_from_user

    new NewEnt = create_entity("info_target")  //Makes an object 
    entity_set_string(NewEnt, EV_SZ_classname, "disk") //sets the classname of the entity
    disk[id] = NewEnt

    //This tells what the object will look like 
    entity_set_model(NewEnt, "models/shmod/frieza_friezadisc.mdl") 

    //This will set the origin of the entity 
    entity_set_origin(NewEnt, fOrigin) 

    //This will set the movetype of the entity 
    entity_set_int(NewEnt,EV_INT_movetype, MOVETYPE_NOCLIP) 

    //This makes the entity touchable
    entity_set_int(NewEnt, EV_INT_solid, SOLID_TRIGGER)

    //This will set the velocity of the entity 
    velocity_by_aim(id, get_cvar_num("frieza_diskspeed"), fVelocity) 
    FVecIVec(fVelocity, velocity) //converts a floating vector to an integer vector

    //Sets the size of the entity
    entity_set_size(NewEnt, minBound, maxBound)

    //Sets who the owner of the entity is
    entity_set_edict(NewEnt, EV_ENT_owner, id)

    //This will set the entity in motion 
    entity_set_vector(NewEnt, EV_VEC_velocity, fVelocity) 

    //This will make the entity have sound.
    emit_sound(NewEnt, CHAN_VOICE, "shmod/frieza_destructodisc.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)

    new lifetime = get_cvar_num("frieza_disklife")

    //This is the trail effects, to learn more about animation effects go to this link
    //http://shero.rocks-hideout.com/forums/viewtopic.php?t=1941
    message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    write_byte(22)       //TE_BEAMFOLLOW
    write_short(NewEnt)  //The entity to attach the sprite to
    write_short(flash)  //sprite's model
    write_byte(lifetime)   //life in 0.1 seconds
    write_byte(50)   //width of sprite
    write_byte(255)  //red
    write_byte(0)    //green
    write_byte(255)  //blue
    write_byte(255)  //brightness
    message_end()

    return

} 
//-----------------------------------------------------------------------------------------    
public touch_event(pToucher, pTouched)  //This is triggered when two entites touch
{ 
    new aimvec[3], Float:fAimvec[3]  //This is the position where the disk collides 
    entity_get_vector(pTouched, EV_VEC_origin, fAimvec) 
    FVecIVec(fAimvec, aimvec) 
    new self_immune = get_cvar_num("frieza_disklife") - 2 //Gives split-second immunity

    if(pTouched == entity_get_edict(pToucher, EV_ENT_owner) && diskTimer[pTouched] <= self_immune)
    return PLUGIN_HANDLED
    //Checks to see if entity is a player or an inanimate object. 
    if(is_user_connected(pTouched)){
    special_effects(pToucher, pTouched, aimvec)
    return PLUGIN_CONTINUE
    }

    special_effects(pToucher, 0, aimvec) // *------Can anyone explain wtf this does?------*

    new id = read_data(2)  //This tells who the victim is
    new Float: fOrigin[3]
    new origin[3]
    //*--------Line 275 Below---------*
    entity_get_vector(disk[id], EV_VEC_origin, fOrigin)
    FVecIVec(fOrigin, origin)
    
    diskTimer[id] = 0
    decay_effects(disk[id], origin)    
    
    // Be sure to replace myEnt with the correct variable.
    if (is_valid_ent(disk[id]))
    log_amx("Invalid entity detected (%d)", disk[id]);

    return PLUGIN_CONTINUE 
} 
//----------------------------------------------------------------------------------------- 
public special_effects(pToucher, pTouched, aimvec[3]) //effects for when disk touch
{
    new Float:fVelocity[3]
    new velocity[3]
    new damage
    entity_get_vector(pToucher, EV_VEC_velocity, fVelocity)
    FVecIVec(fVelocity, velocity)

    //Got to know who's the one using the disk
    //So that when the victim dies, he knows who's the killer
    //That used the disk
    new killer = entity_get_edict(pToucher, EV_ENT_owner)

    //To learn more about animation effects go to this link
    //http://shero.rocks-hideout.com/forums/viewtopic.php?t=1941
    if(is_user_alive(pTouched)){
        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
        write_byte(101)  //BLOODSTREAM
        write_coord(aimvec[0])
        write_coord(aimvec[1])
        write_coord(aimvec[2])
        write_coord(velocity[0])
        write_coord(velocity[1])
        write_coord(velocity[2])
        write_byte(95)
        write_byte(100)
        message_end()

        damage = get_cvar_num("frieza_damage")
        new victim = pTouched
        shExtraDamage(victim, killer, damage, "Frieza's Energy Disk")
    }
    //Same link for here to http://shero.rocks-hideout.com/forums/viewtopic.php?t=1941
    message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    write_byte(9)  //SPARKS
    write_coord(aimvec[0])
    write_coord(aimvec[1])
    write_coord(aimvec[2])
    message_end()
}
//-----------------------------------------------------------------------------------------
public decay_effects(NewEnt, origin[3])  //removes the entity plus adds a decaying effect
{
    if(is_valid_ent(NewEnt)){
        remove_entity(NewEnt)
        //To learn more about animation effects go to this link
        //http://shero.rocks-hideout.com/forums/viewtopic.php?t=1941
        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
        write_byte(14) //IMPLOSION
        write_coord(origin[0])
        write_coord(origin[1])
        write_coord(origin[2])
        write_byte(50)
        write_byte(10)
        write_byte(10)
        message_end()
    }
}
//------------------------------------------------------------------------------------------
public client_disconnect(id)  //This makes sure that the disk isn't flying after disconnect
{
    if(g_hasfriezaPowers[id] && diskTimer[id] > 0){
        new Float: fOrigin[3]
        new origin[3]
        entity_get_vector(disk[id], EV_VEC_origin, fOrigin)
        FVecIVec(fOrigin, origin)
        decay_effects(disk[id], origin)
    }
}
//------------------------------------------------------------------------------------------
heliumdream is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 01-22-2007 , 02:18   Re: [?]Invalid entity error!
Reply With Quote #4

i'm guessing line 165 is around frieza_kill... so you should do this
Code:
public frieza_kill()  //triggered everytime someone dies
{
    new id = read_data(2)  //This tells who the victim is
    if(g_hasfriezaPowers[id] && diskTimer[id] > 0 && is_valid_ent(disk[id])){
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
vittu
SuperHero Moderator
Join Date: Oct 2004
Location: L.A. County, CA
Old 01-22-2007 , 02:18   Re: [?]Invalid entity error!
Reply With Quote #5

Gorlag/Batman, should still be around to fix this. If not I'll get around to it when i can but the error implies that disk[id] = 0, when it should equal the id of the created entity... So basically needs to not run that code cause it thinks there is no disk...
vittu is offline
Send a message via AIM to vittu Send a message via MSN to vittu Send a message via Yahoo to vittu
heliumdream
Senior Member
Join Date: Aug 2006
Old 01-22-2007 , 11:23   Re: [?]Invalid entity error!
Reply With Quote #6

Sick guys, I'm about to leave for school but when I come home I'm going to add the check on that frieza kill function like Emp says to see if the disk is a valid entity.

Is that going to fix what vittu is talking about tho? Or is that another beast
heliumdream 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 08:11.


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