Creating Player Hat

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Creating Player Hat

Postby decompile » Wed Apr 26, 2017 1:27 am

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
Predz
Senior Member
Posts: 158
Joined: Wed Aug 08, 2012 9:05 pm
Location: Bristol, United Kingdom

Re: Creating Player Hat

Postby Predz » Wed Apr 26, 2017 7:46 am

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?
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Creating Player Hat

Postby iPlayer » Wed Apr 26, 2017 9:10 am

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.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: Creating Player Hat

Postby decompile » Wed Apr 26, 2017 1:15 pm

Thanks guys!

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

Appreciate it
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Creating Player Hat

Postby L'In20Cible » Wed Apr 26, 2017 10:19 pm

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.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 21 guests