Spawning a 'ghost entity'

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Spawning a 'ghost entity'

Postby BackRaw » Fri Mar 04, 2016 6:56 pm

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.
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Postby Kami » Fri Mar 04, 2016 7:07 pm

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 :)
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Fri Mar 04, 2016 7:16 pm

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?
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Postby Kami » Fri Mar 04, 2016 7:25 pm

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 :)
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Fri Mar 04, 2016 7:29 pm

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.
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri Mar 04, 2016 7:48 pm

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
Image
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Fri Mar 04, 2016 8:05 pm

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
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Postby Kami » Fri Mar 04, 2016 8:11 pm

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?
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Fri Mar 04, 2016 8:20 pm

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.
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Fri Mar 04, 2016 9:02 pm

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!!
My Github repositories:

Source.Python: https://github.com/backraw
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Mon Mar 07, 2016 12:00 pm

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

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 126 guests