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

Help with Creating entity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Facksy
Senior Member
Join Date: Apr 2017
Location: +2+2
Old 10-18-2017 , 11:40   Help with Creating entity
Reply With Quote #1

Hey guys, i've got some problems with creating entity with CreateEntityByName, for example, i'm trying to create an "env_fog_controller" but it doesnt work, here is the code:
PHP Code:
public Action:Cmd_Cre(clientargs)
{
    new 
Particle CreateEntityByName("env_fog_controller");
    
    if(
IsValidEntity(Particle))
    {
        
DispatchKeyValue(Particle"fogstart""1.0");
        
DispatchKeyValue(Particle"fogend""5000.0");
        
DispatchKeyValue(Particle"fogcolor""172 185 194");
        
        
DispatchSpawn(Particle);        
        
ActivateEntity(Particle);
    }

Facksy is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 10-18-2017 , 11:56   Re: Help with Creating entity
Reply With Quote #2

1. You're not declaring "Particle" correct. When you create entity by name you're actually storing an index. So you need to declare it with int.

PHP Code:
int Particle CreateEntityByName("env_fog_controller"); 
Secondly no need to check for IsValidEntity.

Thirdly, change

PHP Code:
ActivateEntity(Particle); 
to this

PHP Code:
AcceptEntityInput(Particle"TurnOn"); 
Halt is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 10-18-2017 , 17:19   Re: Help with Creating entity
Reply With Quote #3

Quote:
Originally Posted by Halt View Post
1. You're not declaring "Particle" correct. When you create entity by name you're actually storing an index. So you need to declare it with int.

PHP Code:
int Particle CreateEntityByName("env_fog_controller"); 
Secondly no need to check for IsValidEntity.

Thirdly, change

PHP Code:
ActivateEntity(Particle); 
to this

PHP Code:
AcceptEntityInput(Particle"TurnOn"); 
The "new" keyword in the old syntax is equivalent to the keyword "int"
__________________

Last edited by WildCard65; 10-18-2017 at 17:19.
WildCard65 is offline
Facksy
Senior Member
Join Date: Apr 2017
Location: +2+2
Old 10-18-2017 , 13:07   Re: Help with Creating entity
Reply With Quote #4

Still dont work :/
Facksy is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 10-18-2017 , 14:45   Re: Help with Creating entity
Reply With Quote #5

Add a check, so try this.

PHP Code:
public Action:Cmd_Cre(clientargs

    
int Particle CreateEntityByName("env_fog_controller");    
        
DispatchSpawn(Particle);  
        
DispatchKeyValue(Particle"fogstart""1.0"); 
        
DispatchKeyValue(Particle"fogend""5000.0"); 
        
DispatchKeyValue(Particle"fogcolor""172 185 194"); 

        
AcceptEntityInput(Particle"TurnOn");  
    }

    
PrintToChat(Client"Entity created %i"Particle);

If you get a message in chat, it will tell you the entities index and the block that the entity creation is in is executing. If you do not get a message in chat then your command isn't functioning properly.
Halt is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 10-18-2017 , 15:38   Re: Help with Creating entity
Reply With Quote #6

I thought you dispatch key values before spawn.
__________________
Neuro Toxin is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-18-2017 , 15:58   Re: Help with Creating entity
Reply With Quote #7

Quote:
Originally Posted by Neuro Toxin View Post
I thought you dispatch key values before spawn.
Strangely, the game lets you dispatch keys at any time, even in the middle of gameplay.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 10-18-2017 , 16:32   Re: Help with Creating entity
Reply With Quote #8

You should check if the entity exists first. This code sample works.

PHP Code:
int fog FindEntityByClassname(-1"env_fog_controller");

if (
fog == -1)
    
fog CreateEntityByName("env_fog_controller");

if (
fog != -1) {
    
DispatchKeyValueFloat(fog"fogstart"0.0);
    
DispatchKeyValueFloat(fog"fogend"600.0);
    
DispatchKeyValueFloat(fog"fogmaxdensity"0.998);
    
DispatchKeyValue(fog"fogcolor""255 255 255");
    
AcceptEntityInput(fog"TurnOn");

Spoiler

Last edited by Kolapsicle; 10-18-2017 at 16:35.
Kolapsicle is offline
Facksy
Senior Member
Join Date: Apr 2017
Location: +2+2
Old 10-19-2017 , 11:12   Re: Help with Creating entity
Reply With Quote #9

Quote:
Originally Posted by Kolapsicle View Post
You should check if the entity exists first. This code sample works.

PHP Code:
int fog FindEntityByClassname(-1"env_fog_controller");

if (
fog == -1)
    
fog CreateEntityByName("env_fog_controller");

if (
fog != -1) {
    
DispatchKeyValueFloat(fog"fogstart"0.0);
    
DispatchKeyValueFloat(fog"fogend"600.0);
    
DispatchKeyValueFloat(fog"fogmaxdensity"0.998);
    
DispatchKeyValue(fog"fogcolor""255 255 255");
    
AcceptEntityInput(fog"TurnOn");

Spoiler
Well, it doesnt work in TF2 apparently
Facksy is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 10-19-2017 , 13:07   Re: Help with Creating entity
Reply With Quote #10

Here's an example from my plugin, keep in mind I'm storing the entity in an array so its a bit different.

PHP Code:
    ArtillarySmoke[0] = CreateEntityByName("env_smokestack");
    
DispatchKeyValue(ArtillarySmoke[0], "InitialState""1");
    
DispatchKeyValue(ArtillarySmoke[0], "SpreadSpeed""10");
    
DispatchKeyValue(ArtillarySmoke[0], "Speed""15");
    
DispatchKeyValue(ArtillarySmoke[0], "StartSize""8");
    
DispatchKeyValue(ArtillarySmoke[0], "EndSize""16");
    
DispatchKeyValue(ArtillarySmoke[0], "Rate""10");
    
DispatchKeyValue(ArtillarySmoke[0], "JetLength""150");
    
DispatchKeyValue(ArtillarySmoke[0], "WindAngle""23");
    
DispatchKeyValue(ArtillarySmoke[0], "WindSpeed""10");
    
DispatchKeyValue(ArtillarySmoke[0], "rendercolor""233 3 9");
    
DispatchKeyValue(ArtillarySmoke[0], "twist""5");
    
DispatchKeyValue(ArtillarySmoke[0], "roll""3");
    
DispatchKeyValue(ArtillarySmoke[0], "SmokeMaterial""particle/SmokeStack.vmt");
    
DispatchSpawn(ArtillarySmoke[0]);
    
TeleportEntity(ArtillarySmoke[0], ArtillarySmokePos1NULL_VECTORNULL_VECTOR);
    
AcceptEntityInput(ArtillarySmoke[0], "TurnOn"); 
Halt 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 14:43.


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