Page 1 of 1

Creating Player Hat

Posted: Wed Apr 26, 2017 1:27 am
by decompile
Hey,

Im trying to give players a santa hat on holidays, and im currently struggling on creating the hat.

Syntax: Select all

SANTA_HAT_MODEL = Model('models/player/holiday/santahat.mdl')

prop_dynamic_override = Entity.create('prop_dynamic_override')
prop_dynamic_override.set_model(SANTA_HAT_MODEL)
prop_dynamic_override.spawn_flags = 256
prop_dynamic_override.set_parent(player)


And the my questions are:

1. How can I make it not solid
2. How do I properly set it on top of the player? (Just +64 units ..?)
3. How can I hide it for the player itself
4. How can I remove the hat e.g. on player_death

Re: Creating Player Hat

Posted: Wed Apr 26, 2017 7:46 am
by Predz
1. I believe by default all props that use the override tag will always be solid but you can still try using the "enable/disable_collision" inputs available for prop entities. As I can see you have tried to use the spawnflags for non-solid and I guess that is not working.

2. Use the attachment argument in "set_parent".

Syntax: Select all

<Entity>.set_parent(<Entity>, <Attachment Index>)


3. Best way I would think of for that would be to hook "set_transmit". You are going to need to remember the hat/player pairs for this though obviously.

Syntax: Select all

from entities import CheckTransmitInfo
from entities.entity import Entity
from entities.helpers import index_from_edict
from entities.hooks import EntityCondition, EntityPreHook
from memory import make_object
from players.entity import Player

hats = {}

def transmit_filter(entity, player):
return player.index in hats and hats[player.index] == entity.index


entity_condition = EntityCondition.equals_entity_classname(
"prop_dynamic_override")


@EntityPreHook(entity_condition, 'set_transmit')
def pre_set_transmit(args):
entity = make_object(Entity, args[0])
edict = make_object(CheckTransmitInfo, args[1]).client
player = Player(index_from_edict(edict))

return None if transmit_filter(entity, player) else False


Credit to iPlayer for set_transmit example!

4. When parented to a player they should disappear when the player entity dies due to being parented. Is this not happening?

Re: Creating Player Hat

Posted: Wed Apr 26, 2017 9:10 am
by iPlayer
4. When parented to a player they should disappear when the player entity dies due to being parented. Is this not happening?

Well, when an entity gets removed, its "children" get teleported to (0, 0, 0).

But the thing is that the player entity is never removed (only when player disconnects). In fact, if you remove that entity when its owner is still on the server, the server will crash.

I think the hat will just fly with player's death cam. And upon respawning, the hat will be on its place.

Re: Creating Player Hat

Posted: Wed Apr 26, 2017 1:15 pm
by decompile
Thanks guys!

What are these attachements? And I couldnt find an available list for that cause.

Appreciate it

Re: Creating Player Hat

Posted: Wed Apr 26, 2017 10:19 pm
by L'In20Cible
decompile wrote:What are these attachements? And I couldnt find an available list for that cause.

Take a look at Entity.lookup_attachment which is a good example of how to iterate over attachments of a specific entity.