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

The best classname for an NPC?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dexon
Member
Join Date: Aug 2019
Old 12-05-2022 , 11:09   The best classname for an NPC?
Reply With Quote #1

I've created zombie NPC's with many stuff and pathfinding, yet I'm struggling and having a really hard time finding out the problem of having crash if I put in any external plugin that uses entities or entity calls. It doesn't happen instantly, but randomly at certain actions with no log but segmentation fault and I can't use for example a sandbag plugin or other extra item. I can't really find bad code in those plugins.

Info:
  • I'm currently using info_target as a basic classname then I set it's own after creation.
  • There are no troubles when I only have my plugins.
  • I've created other entity plugins that are using info_target and those are fine.

P.S. Here is the code one of the plugins that makes the server crash randomly:
PHP Code:
#include <amxmodx> 
#include <amxmisc> 
#include <fakemeta> 
#include <hamsandwich> 
#include <engine>
#include <xs> 
#include <fun> 
#include <beams>
#include <zm_core>

// The sizes of models 
#define PALLET_MINS Float:{ -27.260000, -22.280001, -22.290001 } 
#define PALLET_MAXS Float:{  27.340000,  26.629999,  29.020000 } 
// from fakemeta util by VEN 
#define fm_find_ent_by_class(%1,%2) engfunc(EngFunc_FindEntityByString, %1, "classname", %2) 
#define fm_remove_entity(%1) engfunc(EngFunc_RemoveEntity, %1) 
// this is mine 
#define fm_drop_to_floor(%1) engfunc(EngFunc_DropToFloor,%1) 
// cvars 
new remove_nrnd 

new const SB_CLASSNAME[] = "FakeSandBag"
// num of pallets with bags 
/* Models for pallets with bags . 
Are available 2 models, will be set a random of them  */ 
new g_models[][] = 

    
"models/zombie_mutation/sandbags.mdl"

new 
g_bolsas[33]; 
new 
Sb_owner[33]
new 
cvar_unitsg_iMaxPlayers;
new 
iSandBagHealth[33]
new 
iTeamLimitgAlreadyBought[33];
new 
g_pSB[33], g_pBeam[33], iSBCanBePlaced[33]
new 
Float:ivecOrigin[3]
/************************************************************* 
************************* AMXX PLUGIN ************************* 
**************************************************************/ 
public plugin_init()  

    
/* Register the plugin */ 
    
    
register_plugin("[ZP] Extra: SandBags""1.1""LARP"
    
/* Register the cvars */ 
    
remove_nrnd register_cvar("zp_pb_remround","1"); 
    
cvar_units register_cvar("zp_sandbag_units""42")
    
    
g_iMaxPlayers get_maxplayers();
    
    
/* Game Events */ 
    
register_event("HLTV","event_newround""a","1=0""2=0"); // it's called every on new round 
    
    /* This is for menuz: */ 
    
register_clcmd("say /sb","show_the_menu"); 
    
register_clcmd("say_team /sb","show_the_menu");
    
    
register_think(SB_CLASSNAME"SB_Think");

    
RegisterHam(Ham_TakeDamage,"func_wall","fw_TakeDamage"); 
    
RegisterHam(Ham_Killed"func_wall""fw_PlayerKilled"1)

    
register_clcmd("say asd""asd")
    
}

//Here is what I am tryin to make just owner and zombie to be able to destroy sandbags 
public fw_TakeDamage(victiminflictorattackerFloat:damagedamage_type
{

    
//Victim is not aa sandbag. 
    
new sz_classname[32
    
entity_get_stringvictim EV_SZ_classname sz_classname31 )
    
    if( !
equali(sz_classname,"amxx_pallets") ) 
    return 
HAM_IGNORED;

    new 
Float:iHealthpev(victimpev_healthiHealth)
    
    if( 
iHealth 200.0 && iHealth 400.0 // more than 200 glow a bit blue
    
{
        
set_rendering victimkRenderFxGlowShell25500kRenderNormal16)
    }
    else if( 
iHealth 400.0 && iHealth 600.0 // More than 400 glow green
    
{
        
set_rendering victimkRenderFxGlowShell25520326kRenderNormal16)
    }
    else if( 
iHealth 600.0// More than 400 glow green
    
{
        
set_rendering victimkRenderFxGlowShell02550kRenderNormal16)
    }
        
    
//Attacker is zombie 
    
if( attacker 32 || zm_is_user_zombieattacker )) 
    return 
HAM_IGNORED
        
    
//Block Damage 
    
return HAM_SUPERCEDE

public 
fw_PlayerKilled(victimattackershouldgibid)
{  
    new 
sz_classname[32], Floathealth 
    entity_get_string
victim EV_SZ_classname sz_classnamecharsmax(sz_classname))
    
health entity_get_float(victimEV_FL_health)
    if(
equal(sz_classname"amxx_pallets") && health <= 0.0 && is_valid_ent(victim) && (zm_is_npc(attacker) || zm_is_user_zombie(attacker)))
    {
        return 
HAM_IGNORED;
    }
    if (
g_pSB[victim] && is_valid_ent(g_pSB[victim]))
        
remove_entity(g_pSB[victim]);    
    if (
g_pBeam[victim] && is_valid_ent(g_pBeam[victim]))
        
remove_entity(g_pBeam[victim])
    return 
HAM_IGNORED;

public 
plugin_precache() 

    for(new 
i;sizeof g_models;i++) 
    
engfunc(EngFunc_PrecacheModel,g_models[i]); 
}
    
public 
show_the_menu(id)
{
    new 
Menu menu_create("\ySandbags \yMenu""menu_command")
    
menu_additem(Menu"Buy/Place From Extra Items")
    
    
menu_setpropMenuMPROP_EXITMEXIT_ALL );
    
    if(
g_bolsas[id] > && !zm_is_user_zombie(id))
    {
        
menu_display(idMenu);
        
CreateFakeSandBag(id)
    }
}

SetBar(iId){
    
client_cmd(iId"spk sound/sb.wav")
    
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("BarTime"), _iId)
    
write_short(1);
    
message_end();
    
set_pev(iIdpev_flagspev(iIdpev_flags) | FL_FROZEN )
    
set_task(1.0"place_palletwbags"iId)
}

public 
ZM_Turn_Post(id){
    if (
g_pSB[id] && is_valid_ent(g_pSB[id]))
        
remove_entity(g_pSB[id]);    
    if (
g_pBeam[id] && is_valid_ent(g_pBeam[id]))
        
remove_entity(g_pBeam[id])
}
public 
free_sb(id)
{
    
g_bolsas[id] = 10
}
public 
menu_command(idmenuitem)
{
    
menu_destroy(menu);
        
    if (!
g_pSB[id] || !is_valid_ent(g_pSB[id]))
    return 
PLUGIN_HANDLED;    
    
    switch(
item)
    {
        case 
0:  
        { 
            if ( !
zm_is_user_zombie(id) ) 
            { 
                if(
iSBCanBePlaced[id] == 2)
                {
                    
show_the_menu(id); 
                    return 
PLUGIN_CONTINUE;
                }
                new 
money g_bolsas[id
                if ( 
money 
                { 
                    return 
PLUGIN_CONTINUE 
                
}
                
g_bolsas[id]-= 1
                SetBar
(id)
                
show_the_menu(id); 
                if(
Sb_owner[id] > 0)
                {
                    
Sb_owner[id] -= 1
                
}
            }
            return 
PLUGIN_CONTINUE     
        

        case 
MENU_EXIT:
        {
            if (
g_pSB[id] && is_valid_ent(g_pSB[id]))
                
remove_entity(g_pSB[id]);
                
            if (
g_pBeam[id] && is_valid_ent(g_pBeam[id]))
                
remove_entity(g_pBeam[id]);            
        }
    }    
    return 
PLUGIN_HANDLED
}

public 
CreateFakeSandBag(id)
{
    if (
g_pSB[id] && is_valid_ent(g_pSB[id]))
        
remove_entity(g_pSB[id]);
        
    if (
g_pBeam[id] && is_valid_ent(g_pBeam[id]))
        
remove_entity(g_pBeam[id]);
        
    new 
iSB create_entity("info_target")
    
    if (!
iSB)
        return;
        
    static 
Float:vecAngles[3]
    
GetOriginAimEndEyes(id128ivecOriginvecAngles)
    
engfunc(EngFunc_SetModeliSB,g_models[random(sizeof g_models)]);
    
engfunc(EngFunc_SetOriginiSBivecOrigin);
    
    
set_pev(iSBpev_classnameSB_CLASSNAME);
    
set_pev(iSBpev_ownerid);
    
set_pev(iSBpev_rendermodekRenderTransAdd);
    
set_pev(iSBpev_renderamt200.0);
    
set_pev(iSBpev_body1);
    
set_pev(iSBpev_nextthinkget_gametime());
    
set_pev(iSB,pev_movetype,MOVETYPE_PUSHSTEP); // Movestep <- for Preview

    
new pBeam Beam_Create("sprites/laserbeam.spr"6.0);
    
    if (
pBeam != FM_NULLENT)
    {    
        
Beam_EntsInit(pBeamiSBid);
        
Beam_SetColor(pBeamFloat:{150.00.00.0});
        
Beam_SetScrollRate(pBeam255.0);
        
Beam_SetBrightness(pBeam200.0);
    }
    else
    {
        
pBeam 0;
    }
    
    
g_pBeam[id] = pBeam;
    
g_pSB[id] = iSB;
}

public 
SB_Think(SandBag)
{
    if (
pev_valid(SandBag) != 2)
        return;

    static 
pOwner;
    
pOwner pev(SandBagpev_owner);
    
    if (!(
<= pOwner <= g_iMaxPlayers) || !is_user_alive(pOwner))
        return;
        
    static 
iBodyFloat:vecColor[3], Float:vecAngles[3];

    
GetOriginAimEndEyes(pOwner128ivecOriginvecAngles);
    
iBody 2
    xs_vec_set
(vecColor250.00.00.0);
    
engfunc(EngFunc_SetOriginSandBagivecOrigin);    

    if (!
IsHullVacant(ivecOriginHULL_HEADSandBag))
    {
        if(
CheckSandBag() || CheckSandBagFake())
        {
        
iBody 1
        xs_vec_set
(vecColor0.0250.00.0);
        }
    }    
    
    if (
g_pBeam[pOwner] && is_valid_ent(g_pBeam[pOwner]))
    {
        
Beam_RelinkBeam(g_pBeam[pOwner]);
        
Beam_SetColor(g_pBeam[pOwner], vecColor);
    }    
    
    
iSBCanBePlaced[pOwner] = iBody    
    set_pev
(SandBagpev_anglesvecAngles);
    
set_pev(SandBagpev_bodyiBody);
    
set_pev(SandBagpev_nextthinkget_gametime() + 0.01);
    
    return;
}
    
public 
place_palletwbags(id
{
    if(!
is_user_alive(id) || zm_is_user_zombie(id)){
        if (
g_pSB[id] && is_valid_ent(g_pSB[id]))
            
remove_entity(g_pSB[id]);    
        if (
g_pBeam[id] && is_valid_ent(g_pBeam[id]))
            
remove_entity(g_pBeam[id])
        return
    }

    
set_pev(idpev_flagspev(idpev_flags) & ~FL_FROZEN )

    new 
Ent engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"func_wall")); 
    
    
set_pev(Ent,pev_classname,"amxx_pallets"); 

    
engfunc(EngFunc_SetModel,Ent,g_models[random(sizeof g_models)]); 
    
    static 
Float:p_mins[3], Float:p_maxs[3], Float:vecOrigin[3], Float:vecAngles[3];
    
p_mins PALLET_MINS
    
p_maxs PALLET_MAXS
    
engfunc(EngFunc_SetSizeEntp_minsp_maxs); 
    
set_pev(Entpev_minsp_mins); 
    
set_pev(Entpev_maxsp_maxs ); 
    
set_pev(Entpev_absminp_mins); 
    
set_pev(Entpev_absmaxp_maxs );     
    
set_pev(Entpev_body3);
    
//vecOrigin[2] -= 8.0;
    
GetOriginAimEndEyes(id128vecOriginvecAngles);
    
engfunc(EngFunc_SetOriginEntvecOrigin); 

    
set_pev(Ent,pev_solid,SOLID_BBOX); // touch on edge, block 

    
set_rendering EntkRenderFxGlowShell02550kRenderNormal16)
    
    
set_pev(Ent,pev_movetype,MOVETYPE_FLY); // no gravity, but still collides with stuff 
    
    
new Float:p_cvar_health float(iSandBagHealth[id])
    
set_pev(Ent,pev_health,p_cvar_health); 
    
set_pev(Ent,pev_takedamage,DAMAGE_YES); 

    static 
Float:rvec[3]; 
    
pev(Ent,pev_v_angle,rvec); 
    
    
rvec[0] = 0.0
    
    
set_pev(Ent,pev_angles,rvec); 
    
    
set_pev(Entpev_ownerid);

    if (
g_pBeam[id] && is_valid_ent(g_pBeam[id]))
        
remove_entity(g_pBeam[id]);
        
    if (
g_pSB[id] && is_valid_ent(g_pSB[id]))
        
remove_entity(g_pSB[id])


/* ==================================================== 
This is called on every round, at start up, 
with HLTV logevent. So if the "pallets_wbags_nroundrem" 
cvar is set to 1, all placed pallets with bugs will be 
removed. 
====================================================*/ 
public event_newround() 

    
iTeamLimit 0    
    
for ( new idid <= get_maxplayers(); id++) 
    {         
        if( 
get_pcvar_num remove_nrnd ) == 1
        
remove_allpalletswbags(); 
        
g_bolsas[id] = 0  
        Sb_owner
[id] = 0
        gAlreadyBought
[id] = 0
        
        
if (g_pBeam[id] && is_valid_ent(g_pBeam[id]))
            
remove_entity(g_pBeam[id])
        if (
g_pSB[id] && is_valid_ent(g_pSB[id]))
            
remove_entity(g_pSB[id]);
    } 

}  
/* ==================================================== 
This is a stock to help for remove all pallets with 
bags placed . Is called on new round if the cvar 
"pallets_wbags_nroundrem" is set 1. 
====================================================*/ 
stock remove_allpalletswbags() 

    new 
pallets = -1
    while((
pallets fm_find_ent_by_class(pallets"amxx_pallets"))) 
    
fm_remove_entity(pallets); 
}
 
public 
asd(id)
{
    
g_bolsas[id]+= 
    gAlreadyBought
[id] = 1
    iTeamLimit
++
    
set_task(0.3,"show_the_menu",id
    
Sb_owner[id] = 2
    iSandBagHealth
[id] = 750
   
}

public 
client_disconnected(id)
{    
    if (
g_pSB[id] && is_valid_ent(g_pSB[id]))
        
remove_entity(g_pSB[id]);
    
    if (
g_pBeam[id] && is_valid_ent(g_pBeam[id]))
        
remove_entity(g_pBeam[id]);
}

bool:IsHullVacant(const Float:vecSrc[3], iHullpEntToSkip 0)
{
    
engfunc(EngFunc_TraceHullvecSrcvecSrcDONT_IGNORE_MONSTERSiHullpEntToSkip0);
    return 
bool:(!get_tr2(0TR_AllSolid) && !get_tr2(0TR_StartSolid) && get_tr2(0TR_InOpen));
}

GetOriginAimEndEyes(thisiDistanceFloat:vecOut[3], Float:vecAngles[3])
{
    static 
Float:vecSrc[3], Float:vecEnd[3], Float:vecViewOfs[3], Float:vecVelocity[3];
    static 
Float:flFraction;

    
pev(thispev_originvecSrc);
    
pev(thispev_view_ofsvecViewOfs);

    
xs_vec_add(vecSrcvecViewOfsvecSrc);
    
velocity_by_aim(thisiDistancevecVelocity);
    
xs_vec_add(vecSrcvecVelocityvecEnd);

    
engfunc(EngFunc_TraceLinevecSrcvecEndDONT_IGNORE_MONSTERSthis0);
    
    
get_tr2(0TR_flFractionflFraction);
    
    if (
flFraction 1.0)
    {
        static 
Float:vecPlaneNormal[3];

        
get_tr2(0TR_PlaneNormalvecPlaneNormal);
        
get_tr2(0TR_vecEndPosvecOut);

        
xs_vec_mul_scalar(vecPlaneNormal1.0vecPlaneNormal);
        
xs_vec_add(vecOutvecPlaneNormalvecOut);
    }
    else
    {
        
xs_vec_copy(vecEndvecOut);
    }
    
    
vecVelocity[2] = 0.0;
    
vector_to_angle(vecVelocityvecAngles);
}

public 
CheckSandBag()
{
    static 
victim
    victim 
= -1
    
while ( ( victim find_ent_in_sphere(victim,ivecOrigin,get_pcvar_float(cvar_units))) != )
    {
        if(
victim 32)
            continue

        new 
sz_classname[32
        
entity_get_stringvictim EV_SZ_classname sz_classname31 )
        if( !
equali(sz_classname,"amxx_pallets") ) 
        {
        
//our dude has sandbags and wants to place them near to him
        
if(is_user_connected(victim) && is_user_alive(victim) && Sb_owner[victim] == 0)
            return 
false
        }
    }
    return 
true
}

public 
CheckSandBagFake()
{
    static 
victim
    victim 
= -1
    
while ( ( victim find_ent_in_sphere(victim,ivecOrigin,get_pcvar_float(cvar_units))) != )
    {
        if(
victim 32)
            continue

        new 
sz_classname[32
        
entity_get_stringvictim EV_SZ_classname sz_classname31 )
        if( !
equali(sz_classname,"FakeSandBag") ) 
        {
            
//our dude has sandbags and wants to place them near to him
            
if(is_user_connected(victim) && is_user_alive(victim) && Sb_owner[victim] == 0)
                return 
false
        }
    }
    return 
true

__________________
[ExTasY] Zombie Mutation [ZOMBIE NPC]

Join now!

Video: https://www.youtube.com/watch?v=fNahCsS8DOU&t=328s
DC: https://discord.gg/swARTUZCZ4

Creating private plugins, reference above.
Dexon is offline
DeMNiX
Veteran Member
Join Date: Nov 2011
Location: Russia
Old 12-05-2022 , 23:26   Re: The best classname for an NPC?
Reply With Quote #2

Not sure that problem in this plugin
show me debug.log
__________________
My channel with test codes
https://www.youtube.com/user/demnix03

Zombie Riot [Scenario & bots-zombie 11.11.2023]
https://youtu.be/8ZZan-aq2sc

Last edited by DeMNiX; 12-05-2022 at 23:26.
DeMNiX is offline
losinn
New Member
Join Date: Jan 2023
Old 01-04-2023 , 02:47   Re: The best classname for an NPC?
Reply With Quote #3

Queens Center Mall opens during all federal holidays. Below we share Queens Center Mall Holiday Hours on the table. If you want to know queens center holiday hours
losinn is offline
Reply


Thread Tools
Display Modes

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 07:28.


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