Raised This Month: $32 Target: $400
 8% 

[CS] Create Named Entity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-13-2014 , 05:15   [CS] Create Named Entity
Reply With Quote #1


Some optimizations were made into dll, for each entity classname the game creates a hash -> all ents are cached, the new entities created by amxx are not taken into account.

Type in server console print_ent command.
Spoiler


Generaly this is not a problem, but when you are creating a weaponbox or item_armoury the problems start. The first one doesn't get removed on new round and the other one doesn't respawn on new round. Without that utility removing and respawning manually is needed.
This method is cs specific, because in cs we have a function called CREATE_NAMED_ENTITY which calls the engine function pfnCreateNamedEntity and also AddEntityHashValue.

FM/Engine's functions which create entities doesn't call AddEntityHashValue. A possible solution may be to hook AddEntityHashValue with orpheu/okapi and make our custom entity to be taken into accout.

Anyway, now I come with a better solution, by hooking CREATE_NAMED_ENTITY. This will do the trick, allow us to have our custom ents taken into accout without extra code, and all the job is done by game. In most of cases it's better to let the game to work for you.

I've create a native create_named_entity which only needs a class name and will return a completly valid entity which you can use.


You need orpheu for that plugin to run and you also need to include create_named_entity.inc in your plugin.

A short example:
Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <fakemeta> #include <create_named_entity> new const Model[] = "models/w_weaponbox.mdl" public something() {     new iEnt = create_named_entity("weaponbox")     if(!pev_valid(iEnt))     {         return     }         //set an origin by yourself     engfunc(EngFunc_SetModel, iEnt, Model)     engfunc(EngFunc_SetSize, iEnt, Float:{0.0, 0.0, 0.0} , Float:{0.0, 0.0, 0.0})         set_pev(iEnt, pev_movetype, MOVETYPE_TOSS)     set_pev(iEnt, pev_solid, SOLID_TRIGGER)             dllfunc(DLLFunc_Spawn, iEnt) }

The only thing that is different is:
Code:
create_named_entity("classname")

I'm going to leave here the needed game code:
PHP Code:
edict_t *CREATE_NAMED_ENTITY(string_t iClass)
{
    
edict_t *named g_engfuncs.pfnCreateNamedEntity(iClass);

    if (
named)
    {
        
AddEntityHashValue(&named->vSTRING(iClass), CLASSNAME);
    }

    return 
named;

The point is to see that it calls AddEntityHashValue

Credits: Arkshine
Attached Files
File Type: inc create_named_entity.inc (346 Bytes, 260 views)
File Type: gz CREATE_NAMED_ENTITY.tar.gz (363 Bytes, 502 views)
File Type: sma Get Plugin or Get Source (create_named_entity.sma - 1228 views - 2.1 KB)
__________________

Last edited by HamletEagle; 02-04-2015 at 04:38.
HamletEagle is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-13-2014 , 07:12   Re: Create Named Entity
Reply With Quote #2

Quote:
As you probably know
Likely almost no one. That's not really common knowledge. This might be a good idea to explain the whole thing.

Quote:
is cs specific
Please make the thread more obvious about this, like a tag or similar. It will help when people will search.

Quote:
It's always good to work with the game and not to re-create stuffs, for compatibility purpose.
You should elaborate a bit more as it's a general sentence out of context. Here the advantage of calling CREATE_NAMED_ENTITY is simply that the games will call itself pfnCreateNamedEntity and since sent from game, any plugins/modules will be able to hook your custom entity creation.


As side-note, it's probably not a good idea to allocate each time a string with Engfunc_AllocString because even for a same string, it will allocate a new one and memory is kept until you shutdown HLDS. For plugin creating a lot of entities this could be a nice waste of memory. Unfortunately, we have not really the choice from a pawn plugin. This could be lowered by caching the value though.

Will add CS native for that, as it's quite useful.
__________________

Last edited by Arkshine; 12-13-2014 at 07:26.
Arkshine is offline
Old 12-13-2014, 09:59
NiHiLaNTh
This message has been deleted by NiHiLaNTh. Reason: i'm blind
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-13-2014 , 10:07   Re: Create Named Entity
Reply With Quote #3

Quote:
Originally Posted by Arkshine
Will add CS native for that, as it's quite useful.
__________________

Last edited by Arkshine; 12-13-2014 at 10:07.
Arkshine is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-13-2014 , 11:18   Re: Create Named Entity
Reply With Quote #4

You may add it, but until you do, it's usefull to have this plugin..
__________________

Last edited by HamletEagle; 12-13-2014 at 11:19.
HamletEagle is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-13-2014 , 12:21   Re: Create Named Entity
Reply With Quote #5

I don't see where I did say that plugin was useless?
__________________
Arkshine is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-13-2014 , 13:04   Re: Create Named Entity
Reply With Quote #6

No, I mean that I created this because I needed it and I'll keep it here until you add that native
__________________
HamletEagle is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 12-13-2014 , 14:12   Re: Create Named Entity
Reply With Quote #7

  1. This isn't something recent. You can check older cs versions and they have print_ent command and AddEntityHashValue functions on it.
  2. Before this thread Arkshine said it was going to add it to cstrike module :v
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-14-2014 , 09:25   Re: Create Named Entity
Reply With Quote #8

Quote:
Originally Posted by meTaLiCroSS View Post
  1. This isn't something recent. You can check older cs versions and they have print_ent command and AddEntityHashValue functions on it.
  2. Before this thread Arkshine said it was going to add it to cstrike module :v
1. I know, where I say that this is something new ?
2. He didn't added it yet, anyway I'm using it for one of my projects so I thought it worth to share.
__________________

Last edited by HamletEagle; 12-14-2014 at 09:26.
HamletEagle is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 12-14-2014 , 14:46   Re: Create Named Entity
Reply With Quote #9

Quote:
As you probably know some optimizations were made into dll
Looong time ago
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 12-16-2014 , 01:39   Re: Create Named Entity
Reply With Quote #10

Nice job, could be useful in my next mod.
__________________
Kia 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 14:44.


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