AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved hide entity (https://forums.alliedmods.net/showthread.php?t=343562)

Tote 08-06-2023 13:56

hide entity
 
Hello.
Im trying to find a way to hide an entity which is being used in another plugin. For example an entity class name(d) "ent_hat" is being used in a plugin, if i want to get the classname of this entity in another plugin how can i do it?

Here's what im trying to do to get entity class name from another plugin:
static classname[32]
pev(ent, pev_classname, classname, 31)
if(is_valid(ent))
{
if(equal(classname, "ent_hat"))
{
do something//
}
}

fysiks 08-06-2023 16:04

Re: hide entity
 
Where are you putting that code? Also, I think you'll probably want to use something like find_ent_by_class().

MrPickles 08-06-2023 19:56

Re: hide entity
 
PHP Code:

#define INVISBLE 128
#define VISIBLE 0

stock HideHats()
{
    static 
ent;
    
ent = -1

    
while((ent find_ent_by_class(ent,"ent_hat") != 0)
   {
        if(
is_valid_ent(ent)) // am not sure if the function find ent by class check if is valid ent earlier but in any case...
           
entity_set_intentEV_INT_effectsINVISIBLE ); 

          
// entity_set_int( ent, EV_INT_effects, VISIBLE ); 
   
}



Tote 08-07-2023 03:04

Re: hide entity
 
Quote:

Originally Posted by fysiks (Post 2808302)
Where are you putting that code? Also, I think you'll probably want to use something like find_ent_by_class().

Thanks for reply, Im putting it in FmAddToFullPack

Tote 08-07-2023 03:04

Re: hide entity
 
Thanks, I'll try it out !

Tote 08-07-2023 03:29

Re: hide entity
 
i tried using this: it works, but it lags the server uses too much CPU suddenly and spams Errors in Console:
ERRORS:
L 08/07/2023 - 00:11:47: [FAKEMETA] Invalid entity
L 08/07/2023 - 00:11:47: [AMXX] Displaying debug trace (plugin "Untitled.amxx", version "1.0")
L 08/07/2023 - 00:11:47: [AMXX] Run time error 10: native error (native "pev")
L 08/07/2023 - 00:11:47: [AMXX] [0] Untitled.sma::ForwardAddToFullPack (line 3453)
L 08/07/2023 - 00:11:47: [FAKEMETA] Invalid entity
Thats the error which spams in my console and i have tried your way too @Mr.Pickles

if(!is_valid_ent(ent))
return 1;
if(equal(classname, "ent_hat") == ent || ent == equal(classname, "ent_hat"))
{
set_es( es_handle, ES_RenderMode, kRenderTransAlpha );
set_es( es_handle, ES_RenderAmt, 0 );
}

Tote 08-07-2023 03:42

Re: hide entity
 
SOLVED!
Used:
new entu = engfunc( EngFunc_FindEntityByString, -1, "classname", "ent_hat" );
Thanks for your help guys!

MrPickles 08-07-2023 21:08

Re: hide entity
 
Quote:

Originally Posted by Tote (Post 2808323)
SOLVED!
Used:
new entu = engfunc( EngFunc_FindEntityByString, -1, "classname", "ent_hat" );
Thanks for your help guys!

The code that I gave you must have worked perfectly, you don't need to use add to full pack for that, with that,you are searching each frame for the entity with that classname, with which I gave you only activate/deactivate invisibility once.

You could also try sending the error it gave you, you sent the error of your code only.

fysiks 08-07-2023 23:25

Re: hide entity
 
Quote:

Originally Posted by Tote (Post 2808323)
SOLVED!
Used:
new entu = engfunc( EngFunc_FindEntityByString, -1, "classname", "ent_hat" );
Thanks for your help guys!

That's essentially the same thing. Also, as Mr. Pickles said, calling the function multiple times per second is most likely not necessary at all. Just set the visibility when you need to change it.

Also, if the entity is a long-lived entity (e.g. created once during the map), you only need to search for it once and simply save the entity ID and re-use it when you need to do something with it.

MrPickles 08-08-2023 00:40

Re: hide entity
 
Quote:

Originally Posted by fysiks (Post 2808364)
That's essentially the same thing. Also, as Mr. Pickles said, calling the function multiple times per second is most likely not necessary at all. Just set the visibility when you need to change it.

Also, if the entity is a long-lived entity (e.g. created once during the map), you only need to search for it once and simply save the entity ID and re-use it when you need to do something with it.

What happens is that he has it in separate plugins, he would have to create a library saving the index of the hat, in order to obtain it in the other plugin, make a loop with the maximum number of connected players and verify if the hat is a valid entity, I think that the find ent by class is more appropriate in this case.


All times are GMT -4. The time now is 16:08.

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