Page 1 of 1

Spawning a 'ghost entity'

Posted: Fri Mar 04, 2016 6:56 pm
by BackRaw
Hey,

is it possible to create and spawn a temporary 'ghost' player entity? One that isn't a really a bot nor is a 'solid' entity.

I want to create a shock effect right before the actual player to quickly spawn that ghost and remove it shortly after.

Thanks :D

Edit: What I mean by 'not solid' is that, whenever spawned, the entity won't be joining a team and thus will never influence the gameplay, e.g. player_team and player_spawn won't fire for it.

Posted: Fri Mar 04, 2016 7:07 pm
by Kami
Do you want this entitiy to move around?
If not, you could just spawn a prop_dynamic entity and change its model to whatever you want. Otherwise you'd be asking for NPCs which aren't that easy to add.

Not sure if that's what you ment^^

Edit: Oh and what about hostage entities? You can make them follow the player, change their models and make them invincible :)

Posted: Fri Mar 04, 2016 7:16 pm
by BackRaw
Kami wrote:Do you want this entitiy to move around?
If not, you could just spawn a prop_dynamic entity and change its model to whatever you want. Otherwise you'd be asking for NPCs which aren't that easy to add.

Not sure if that's what you ment^^
Yeah the prop_dynamic approach would be the closest I guess. No, I don't want them to walk around, just fly around without any weapons.

Edit: Oh and what about hostage entities? You can make them follow the player, change their models and make them invincible :)

This, of course, would be a good one, too. Gonna have to test that, thanks. Can I spawn them on any map?

I just looked through the source code and noticed EntityFactory. Would using this be any better?

Posted: Fri Mar 04, 2016 7:25 pm
by Kami
I'm not really sure what EntityFactory even is, so no clue if using that is any better.

But for the hostage approach, here are some informations which I gathered for a pet plugin:

The entity name: hostage_entity

The prop you need to change in order for them to follow a player: CHostage.m_leader <player index>

And yes, you should be able to spawn them ony any map. The just don't like rescue zones (as they will be rescued and removed) so you should remove those if you don't need them (if you use maps that have them)

With this method, you should also think about making them slower (When I tested the pet thing in CS:GO the hostage entity always went exactly to my coordinates, not behind me, which would propably be bad for a ghost)

Also, as you can hit E to make the hostages stop following you, you should hook "hostage_follows" and "hostage_stops_following" and make them follow again in that case :)

Posted: Fri Mar 04, 2016 7:29 pm
by BackRaw
Kami wrote:I'm not really sure what EntityFactory even is, so no clue if using that is any better.

But for the hostage approach, here are some informations which I gathered for a pet plugin:

The entity name: hostage_entity

The prop you need to change in order for them to follow a player: CHostage.m_leader <player index>

And yes, you should be able to spawn them ony any map. The just don't like rescue zones (as they will be rescued and removed) so you should remove those if you don't need them (if you use maps that have them)

With this method, you should also think about making them slower (When I tested the pet thing in CS:GO the hostage entity always went exactly to my coordinates, not behind me, which would propably be bad for a ghost)

Also, as you can hit E to make the hostages stop following you, you should hook "hostage_follows" and "hostage_stops_following" and make them follow again in that case :)


Awesome, thanks! I'll try that one out then.

Posted: Fri Mar 04, 2016 7:48 pm
by satoon101
Note that we have CHostage.m_leader wrapped for both CS:S and CS:GO. This means, if you have an Entity object for a hostage_entity, you can just use <Entity>.leader. Though, the value is not the player index. It is the player's integer handle (or <Player>.inthandle).

Syntax: Select all

from commands.say import SayCommand
from entities.entity import Entity
from players.entity import Player

@SayCommand('!ghost')
def ghost_command(command, player_index, team_only):
player = Player(player_index)
hostage = Entity.create('hostage_entity')
hostage.leader = player.inthandle


*Edit: one issue that could obviously arise is if there is a func_hostage_rescue entity on the map. If a hostage is following you, and it enters into one of these zones, it will be "rescued" and removed from the server. You can combat this, if necessary, by using an EntityPreHook on CHostage.on_rescue_zone_touch:

Syntax: Select all

from entities.hooks import EntityCondition
from entities.hooks import EntityPreHook


@EntityPreHook(EntityCondition.equals_entity_classname('hostage_entity'), 'on_rescue_zone_touch')
def pre_rescue_zone_touch(args):
# You might want to find if this is an entity you don't
# wish to allow this for prior to stopping
return False

Posted: Fri Mar 04, 2016 8:05 pm
by BackRaw
satoon101 wrote:Note that we have CHostage.m_leader wrapped for both CS:S and CS:GO. This means, if you have an Entity object for a hostage_entity, you can just use <Entity>.leader. Though, the value is not the player index. It is the player's integer handle (or <Player>.inthandle).

Syntax: Select all

from commands.say import SayCommand
from entities.entity import Entity
from players.entity import Player

@SayCommand('!ghost')
def ghost_command(command, player_index, team_only):
player = Player(player_index)
hostage = Entity.create('hostage_entity')
hostage.leader = player.inthandle


*Edit: one issue that could obviously arise is if there is a func_hostage_rescue entity on the map. If a hostage is following you, and it enters into one of these zones, it will be "rescued" and removed from the server. You can combat this, if necessary, by using an EntityPreHook on CHostage.on_rescue_zone_touch:

Syntax: Select all

from entities.hooks import EntityCondition
from entities.hooks import EntityPreHook


@EntityPreHook(EntityCondition.equals_entity_classname('hostage_entity'), 'on_rescue_zone_touch')
def pre_rescue_zone_touch(args):
# You might want to find if this is an entity you don't
# wish to allow this for prior to stopping
return False


Perfect, thanks. :D

Posted: Fri Mar 04, 2016 8:11 pm
by Kami
Just a quick question, what is the inthandle? Like in comparison to index and userid.

And which of those would be equivalent (if there is one) to the sourcemod client id?

Posted: Fri Mar 04, 2016 8:20 pm
by BackRaw
Kami wrote:Just a quick question, what is the inthandle? Like in comparison to index and userid.

And which of those would be equivalent (if there is one) to the sourcemod client id?


For example, a flashbang's owner property is a player's inthandle value. Hope it helps.

Posted: Fri Mar 04, 2016 9:02 pm
by BackRaw
satoon101 wrote:

Syntax: Select all

from commands.say import SayCommand
from entities.entity import Entity
from players.entity import Player

@SayCommand('!ghost')
def ghost_command(command, player_index, team_only):
player = Player(player_index)
hostage = Entity.create('hostage_entity')
hostage.leader = player.inthandle

This doesn't spawn anything, sadly. Not even if I put in a

Syntax: Select all

hostage.spawn()
Edit: It does. I just need to set its origin. Thanks!!

Posted: Mon Mar 07, 2016 12:00 pm
by stonedegg
In case you did not know, csgo has a ghost model and you can simply spawn it as a prop_dynamic (models/ghost/ghost.mdl).

https://i.gyazo.com/a47839f4a90ed57c15414acfcba1989d.png