AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Spawned a NULL entity (https://forums.alliedmods.net/showthread.php?t=338425)

Fixsek Kot 07-04-2022 14:19

Spawned a NULL entity
 
Hi,

I've been struggling creating a lasermine, just can't understand it, because people have to make their codes way to hard to read for some reason. So I wrote some code, tested it in game and I got a fatal error: "Spawned a NULL entity!" I tried to search what this means and how to fix it, so I'm begging for not only a help to solve this issue, but also explain to me at least a little, how to make the lasermine work, because I guess it won't work properly:

Quote:

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fakemeta>
#include <engine>
#include <xs>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"
new LM_MODEL[] = "models/zombiechronicbykot/lasermine/lasermine.mdl"
enum _:SERVER_DATA
{
LASER_ENTITY
}
enum _:LASER_PROPS
{
LASER_OWNER = pev_iuser1,
LASER_BEAM = pev_iuser2,
LASER_TEAM = pev_iuser3,
LASER_STEP = pev_iuser4,
LASER_END = pev_vuser1,
LASER_ANGLES = pev_angles,
LASER_ORIGIN = pev_origin,
LASER_POWERUP = 0,
LASER_ACTIVATED = 1,
LASER_EXPLODE = 2,
LASER_CREATE = 3,
LASER_REMOVE = 4
}
enum _:LASER_VECTOR
{
Float:LV_PLAYER,
Float:LV_ANGLES,
Float:LV_END,
Float:LV_NORMAL,
}
new server_data[SERVER_DATA]
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
}
public plugin_precache()
{
precache_model(LM_MODEL)
}
public client_putinserver(id)
{
set_task(8.0, "CreateUserLaser", id)
}
public CreateUserLaser(iTask)
{
static id, iEnt

iEnt = engfunc(EngFunc_CreateNamedEntity, server_data[LASER_ENTITY])

engfunc(EngFunc_SetModel, iEnt, LM_MODEL);
engfunc(EngFunc_SetSize, iEnt, { -4.0,-4.0,-4.0 }, { 4.0,4.0,4.0 });

set_pev(iEnt, pev_classname, "zm_laser");
set_pev(iEnt, pev_solid, SOLID_NOT);
set_pev(iEnt, pev_movetype, MOVETYPE_FLY);

set_pev(iEnt, pev_health, 750.0);
set_pev(iEnt, pev_takedamage, 0.0);

set_pev(iEnt, pev_iuser1, id);
set_pev(iEnt, pev_iuser3, get_user_team(id));
set_pev(iEnt, pev_iuser4, 0);

SetLaserPosition(id, iEnt);

set_pev(iEnt, pev_frame, 0);
set_pev(iEnt, pev_framerate, 0);
set_pev(iEnt, pev_body, 3);
set_pev(iEnt, pev_sequence, 7);
set_pev(iEnt, pev_nextthink, get_gametime() + 3.0)
}
SetLaserPosition(const id, const iEnt)
{
static Float:fVector[LASER_VECTOR][3], Float:fFraction, iTrace;
iTrace = create_tr2();

pev(id, pev_origin, fVector[LV_PLAYER]);
pev(id, pev_v_angle, fVector[LV_ANGLES]);

angle_vector(fVector[LV_ANGLES], ANGLEVECTOR_FORWARD, fVector[LV_ANGLES]);

xs_vec_mul_scalar(fVector[LV_ANGLES], 128.0, fVector[LV_ANGLES]);
xs_vec_add(fVector[LV_PLAYER], fVector[LV_ANGLES], fVector[LV_END]);

engfunc(EngFunc_TraceLine, fVector[LV_PLAYER], fVector[LV_END], DONT_IGNORE_MONSTERS, id, iTrace);

get_tr2(iTrace, TR_flFraction, fFraction);
get_tr2(iTrace, TR_vecEndPos, fVector[LV_END]);
get_tr2(iTrace, TR_vecPlaneNormal, fVector[LV_NORMAL]);

free_tr2(iTrace);
iTrace = create_tr2();

xs_vec_mul_scalar(fVector[LV_NORMAL], 8.0, fVector[LV_NORMAL]);
xs_vec_add(fVector[LV_END], fVector[LV_NORMAL], fVector[LV_END]);

engfunc(EngFunc_SetOrigin, iEnt, fVector[LV_END]);

vector_to_angle(fVector[LV_NORMAL], fVector[LV_ANGLES]);
set_pev(iEnt, LASER_ANGLES, fVector[LV_ANGLES]);

if (fFraction < 1.0)
{
xs_vec_mul_scalar(fVector[LV_NORMAL], 8192.0, fVector[LV_NORMAL]);
engfunc(EngFunc_TraceLine, fVector[LV_END], fVector[LV_NORMAL], IGNORE_MONSTERS, iEnt, iTrace);

get_tr2(iTrace, TR_vecEndPos, fVector[LV_END]);
free_tr2(iTrace);
}

set_pev(iEnt, LASER_END, fVector[LV_END])
}
Best regards,

-Fixsek Kot

Bugsy 07-04-2022 22:13

Re: Spawned a NULL entity
 
Please use php or pawn tags instead of quote for code.

Fixsek Kot 07-05-2022 15:02

Re: Spawned a NULL entity
 
oh I tried PHP but I didn't see the icon of it before now I see it, so I apologize :3
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fakemeta>
#include <engine>
#include <xs>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"
new LM_MODEL[] = "models/zombiechronicbykot/lasermine/lasermine.mdl"
enum _:SERVER_DATA
{
    
LASER_ENTITY
}
enum _:LASER_PROPS
{
    
LASER_OWNER pev_iuser1,
    
LASER_BEAM pev_iuser2,
    
LASER_TEAM pev_iuser3,
    
LASER_STEP pev_iuser4,
    
LASER_END pev_vuser1,
    
LASER_ANGLES pev_angles,
    
LASER_ORIGIN pev_origin,
    
LASER_POWERUP 0,
    
LASER_ACTIVATED 1,
    
LASER_EXPLODE 2,
    
LASER_CREATE 3,
    
LASER_REMOVE 4
}
enum _:LASER_VECTOR
{
    
Float:LV_PLAYER,
    
Float:LV_ANGLES,
    
Float:LV_END,
    
Float:LV_NORMAL,
}
new 
server_data[SERVER_DATA]
public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
}
public 
plugin_precache()
{
    
precache_model(LM_MODEL)
}
public 
client_putinserver(id)
{
    
set_task(8.0"CreateUserLaser"id)
}
public 
CreateUserLaser(iTask)
{
    static 
idiEnt
    
    iEnt 
engfunc(EngFunc_CreateNamedEntityserver_data[LASER_ENTITY])
    
    
engfunc(EngFunc_SetModeliEntLM_MODEL);
    
engfunc(EngFunc_SetSizeiEnt, { -4.0,-4.0,-4.0 }, { 4.0,4.0,4.0 });
    
    
set_pev(iEntpev_classname"zm_laser");
    
set_pev(iEntpev_solidSOLID_NOT);
    
set_pev(iEntpev_movetypeMOVETYPE_FLY);
    
    
set_pev(iEntpev_health750.0);
    
set_pev(iEntpev_takedamage0.0);
    
    
set_pev(iEntpev_iuser1id);
    
set_pev(iEntpev_iuser3get_user_team(id));
    
set_pev(iEntpev_iuser40);
    
    
SetLaserPosition(idiEnt);
    
    
set_pev(iEntpev_frame0);
    
set_pev(iEntpev_framerate0);
    
set_pev(iEntpev_body3);
    
set_pev(iEntpev_sequence7);
    
set_pev(iEntpev_nextthinkget_gametime() + 3.0)
}
SetLaserPosition(const id, const iEnt)
{
    static 
Float:fVector[LASER_VECTOR][3], Float:fFractioniTrace;
    
iTrace create_tr2();
    
    
pev(idpev_originfVector[LV_PLAYER]);
    
pev(idpev_v_anglefVector[LV_ANGLES]);
    
    
angle_vector(fVector[LV_ANGLES], ANGLEVECTOR_FORWARDfVector[LV_ANGLES]);
    
    
xs_vec_mul_scalar(fVector[LV_ANGLES], 128.0fVector[LV_ANGLES]);
    
xs_vec_add(fVector[LV_PLAYER], fVector[LV_ANGLES], fVector[LV_END]);
    
    
engfunc(EngFunc_TraceLinefVector[LV_PLAYER], fVector[LV_END], DONT_IGNORE_MONSTERSidiTrace);
    
    
get_tr2(iTraceTR_flFractionfFraction);
    
get_tr2(iTraceTR_vecEndPosfVector[LV_END]);
    
get_tr2(iTraceTR_vecPlaneNormalfVector[LV_NORMAL]);
    
    
free_tr2(iTrace);
    
iTrace create_tr2();
    
    
xs_vec_mul_scalar(fVector[LV_NORMAL], 8.0fVector[LV_NORMAL]);
    
xs_vec_add(fVector[LV_END], fVector[LV_NORMAL], fVector[LV_END]);
    
    
engfunc(EngFunc_SetOriginiEntfVector[LV_END]);
    
    
vector_to_angle(fVector[LV_NORMAL], fVector[LV_ANGLES]);
    
set_pev(iEntLASER_ANGLESfVector[LV_ANGLES]);
    
    if (
fFraction 1.0)
    {    
    
xs_vec_mul_scalar(fVector[LV_NORMAL], 8192.0fVector[LV_NORMAL]);
    
engfunc(EngFunc_TraceLinefVector[LV_END], fVector[LV_NORMAL], IGNORE_MONSTERSiEntiTrace);
    
    
get_tr2(iTraceTR_vecEndPosfVector[LV_END]);
    
free_tr2(iTrace);
    }
    
    
set_pev(iEntLASER_ENDfVector[LV_END])



Mistrick 07-05-2022 15:31

Re: Spawned a NULL entity
 
Have a look at using engfunc with EngFunc_CreateNamedEntity.
PHP Code:

iEnt engfunc(EngFunc_CreateNamedEntityserver_data[LASER_ENTITY]) 

server_data[LASER_ENTITY] - should be init by using engfunc(EngFunc_AllocString, "info_target") where "info_target" is classname, which can be changed to suit your needs.
There is no server_data[LASER_ENTITY] initialization in your code, by default all variables in the pawn are initialized to zero.
https://github.com/dreamstalker/rehl....cpp#L901-L902

Fixsek Kot 07-06-2022 07:27

Re: Spawned a NULL entity
 
Nice it finally doesn't crash, but the lasermine still doesn't seem to appear, when the set_task is activated, the lasermine won't spawn :/

+ARUKARI- 07-06-2022 22:28

Re: Spawned a NULL entity
 
Why not use a plugin that already exists?

Fixsek Kot 07-07-2022 07:14

Re: Spawned a NULL entity
 
I want to add the lasermine in my menu, yeah you can say that I can copy the code from someone else's plugin, but the problem is all these .smas contain at least 2000 lines of code and a lot of authors seem they did everything to make the code as much hard as possible to read and rewrite. I just need a little hint, what functions or registers do I need for my lasermine, so I can copy them. Just don't wanna spend my whole day to read the entire plugin to find out that 80% of the .sma is just some useless garbage I don't need.

+ARUKARI- 07-07-2022 20:09

Re: Spawned a NULL entity
 
My plugin provides a Native function, which allows Lasermine to be used from other plugins.
So there is no need to write complicated code such as entity creation.

Fixsek Kot 07-08-2022 08:21

Re: Spawned a NULL entity
 
ooh nice I got it working as I wanted! I Didn't notice the natives before though xD it's solved, thanks so much!


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

Powered by vBulletin®
Copyright ©2000 - 2022, vBulletin Solutions, Inc.