PDA

View Full Version : Check entity name


atomen
04-27-2008, 08:26
Hello

I searched but I didn't find any answers.
Though I'm sure this has been answered before :grrr:

How do you check an entity's name ?

For example :


You play a map and in the map it exist an info_target,
info_target is the class name. But the author of the map
has also specified a name for the entity.

Lets say he named it "Super".


So how do I check if this entity is named "Super" ?

EDIT : is it "pev_globalname" ?

dangerix
04-27-2008, 09:01
I'd say it is "pev_targetname".
"targetname" usually is the entities name attribute.

atomen
04-27-2008, 09:40
Are you sure ?

Isn't that more like "trigger_teleport's" target ?

dangerix
04-27-2008, 09:53
No, I think that's pev_target.
Just try and find out.

Based on mapping, "targetname" is a ent's own name and "target" is a ent's target.

atomen
04-27-2008, 10:01
But what does "pev_targetname" return ?
I'm receiving a tag mismatch with this code :
if( equali ( pev ( index, pev_targetname ) , "Super" )Shouldn't it return a string :roll: ?

atomen
04-27-2008, 10:03
Thanks Ray, though I'm still wondering why I'm receiving a tag mismatch :/

Arkshine
04-27-2008, 10:23
The output of pev_targetname is a string. So, you have to retrieve its value before.

new s_TargetName[ 32 ];
pev ( index, pev_targetname, s_TargetName )

atomen
04-27-2008, 10:37
Thanks arkshine though this isn't working :
//...

new const g_RemoveEnt[] = "func_wall"

public plugin_init()
{
//...
register_forward(FM_Spawn, "fwd_Spawn")
}

//...

public fwd_Spawn(ent)
{
if(g_Plugin)
{
if(!pev_valid(ent))
return FMRES_IGNORED

static ClassName[32]
pev(ent, pev_classname, ClassName, 31)

if(equali(ClassName, g_RemoveEnt))
{
new s_TargetName[32]
pev(ent, pev_targetname, s_TargetName)

if(equali(s_TargetName, "super"))
{
engfunc(EngFunc_RemoveEntity, ent)
return FMRES_SUPERCEDE
}
}
}
return FMRES_IGNORED
}Thx Exolent for the code

Arkshine
04-27-2008, 10:46
FM_Spawn has to be registered into the plugin_precache() forward.

atomen
04-27-2008, 10:50
Thank you once again :]

atomen
04-27-2008, 11:03
Well it isn't working :/
//...

new const g_RemoveEnt[] = "func_wall"

//...

public plugin_precache() register_forward(FM_Spawn, "fwd_Spawn")

public plugin_init()
{
//...
}

//...

public fwd_Spawn(ent)
{
if(g_Plugin)
{
if(!pev_valid(ent))
return FMRES_IGNORED

static ClassName[32]
pev(ent, pev_classname, ClassName, 31)

if(equali(ClassName, g_RemoveEnt))
{
new s_TargetName[32]
pev(ent, pev_targetname, s_TargetName)

if(equali(s_TargetName, "super"))
{
engfunc(EngFunc_RemoveEntity, ent)
return FMRES_SUPERCEDE
}
}
}
return FMRES_IGNORED
}

Arkshine
04-27-2008, 11:11
atomen. Stop to say 'it isn't working', and try to understand why. Debug it.

Add some log_amx() or server_print(), and see by yourself. You have to understand by yourself otherwise you won't improve your experience/knowledge.

atomen
04-27-2008, 11:43
Sorry for my rush.

Here's the errors, didn't succeed to fix'em
L 04/27/2008 - 17:39:24: [FAKEMETA] Invalid return type
L 04/27/2008 - 17:39:24: [AMXX] Displaying debug trace (plugin "custom.amxx")
L 04/27/2008 - 17:39:24: [AMXX] Run time error 10: native error (native "pev")
L 04/27/2008 - 17:39:24: [AMXX] [0] custom.sma::fwd_Spawn (line 33)

Arkshine
04-27-2008, 11:50
Show your whole code, because the code works for me. At least, I don't have errors.

atomen
04-27-2008, 11:53
//Remove an named entity
#include <amxmodx>
#include <fakemeta>

#define PLUGIN_NAME "custom"
#define PLUGIN_VERSION "1.0"
#define PLUGIN_AUTHOR "Author"

new const g_RemoveEnt[] = "func_wall"

public plugin_precache() register_forward(FM_Spawn, "fwd_Spawn")

public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
}

public fwd_Spawn(ent)
{
log_amx("[Hello] I'm triggered :)")

if(!pev_valid(ent))
return FMRES_IGNORED

static ClassName[32]
pev(ent, pev_classname, ClassName, 31)

if(equali(ClassName, g_RemoveEnt))
{
log_amx("[Hello] Ent equal")

new s_TargetName[32]
pev(ent, pev_targetname, s_TargetName)

if(equali(s_TargetName, "super"))
{
engfunc(EngFunc_RemoveEntity, ent)
log_amx("[Hello] Ent Deleted")
return FMRES_SUPERCEDE
}
}
return FMRES_IGNORED
}

Arkshine
04-27-2008, 12:11
I got no errors with your code...

atomen
04-27-2008, 12:23
It's probably because on the map you are playing there isn't any "func_wall" entity named "super". So here's the problem.
if(equali(s_TargetName, "super"))
{
engfunc(EngFunc_RemoveEntity, ent)
log_amx("[Hello] Ent Deleted")
return FMRES_SUPERCEDE
}

Arkshine
04-27-2008, 12:27
What's the output of s_TargetName just before ? Did you look at least ?

atomen
04-27-2008, 12:46
The whole plugin stops at the marked line
public fwd_Spawn(ent)
{
log_amx("[Hello] I'm loaded and up :]")

if(!pev_valid(ent))
return FMRES_IGNORED

static ClassName[32]
pev(ent, pev_classname, ClassName, 31)

if(equali(ClassName, g_RemoveEnt))
{
log_amx("[Hello] Ent equal")

new s_TargetName[32]
@@ pev(ent, pev_targetname, s_TargetName)

log_amx("[Hello] s_TargetName is : %s", s_TargetName)

if(equali(s_TargetName, "super"))
{
engfunc(EngFunc_RemoveEntity, ent)
log_amx("[Hello] Ent Deleted")
return FMRES_SUPERCEDE
}
}
return FMRES_IGNORED
}This line is never displayed so that's where the plugin halts
log_amx("[Hello] s_TargetName is : %s", s_TargetName)

atomen
04-27-2008, 12:49
Can't edit because of the pawn tags :/
But I haven't tested but the line should be like this
pev(ent, pev_targetname, s_TargetName, 31)

Arkshine
04-27-2008, 12:50
Oh, I understand. You would have been able to find alone...

pev(ent, pev_targetname, s_TargetName, 31)


EDIT. Eh. You have understood. ^^

atomen
04-27-2008, 12:54
Just posting to confirm that it is fully working.
Thread locked ?

Styles
04-28-2008, 11:28
pev(ent,*pev_targetname,*s_TargetName)

looks like its throwing the error.
first, pev(ent,*pev_targetname,*s_TargetName, 31) I believe is how it is. its hard to tell. I'm on a pda.

now I manualy counted the lines..so... yeah.

also it doesn't like your return type.

when you do return*FMRES_SUPERCEDE try FMRES-HANDLED

atomen
04-28-2008, 17:43
Thanks style though I've solved the problem yesterday.
But I can change return type.

Styles
04-28-2008, 18:55
Yeah I noticed, I was on my PDA and didn't see the second page. I then deleted it but... it doesn't seem it was deleted.. So what ever... haha